Example usage for java.util Hashtable keySet

List of usage examples for java.util Hashtable keySet

Introduction

In this page you can find the example usage for java.util Hashtable keySet.

Prototype

Set keySet

To view the source code for java.util Hashtable keySet.

Click Source Link

Document

Each of these fields are initialized to contain an instance of the appropriate view the first time this view is requested.

Usage

From source file:org.openmrs.module.sana.mediaviewer.web.servlet.ComplexObsServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    log.info("doGet");

    String obsId = request.getParameter("obsId");
    String type = request.getParameter("obsType");
    String view = request.getParameter("view");
    String viewType = request.getParameter("viewType");

    HttpSession session = request.getSession();

    if (obsId == null || obsId.length() == 0) {
        session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.null");
        return;/* w w w .  j a  va 2s .com*/
    }
    if (!Context.hasPrivilege(OpenmrsConstants.PRIV_VIEW_OBS)) {
        session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                "Privilege required: " + OpenmrsConstants.PRIV_VIEW_OBS);
        session.setAttribute(WebConstants.OPENMRS_LOGIN_REDIRECT_HTTPSESSION_ATTR,
                request.getRequestURI() + "?" + request.getQueryString());
        response.sendRedirect(request.getContextPath() + "/login.htm");
        return;
    }

    Obs complexObs = Context.getObsService().getComplexObs(Integer.valueOf(obsId), view);
    ComplexData cd = complexObs.getComplexData();
    Object data = cd.getData();

    if ("DOWNLOAD".equals(viewType)) {
        response.setHeader("Content-Disposition", "attachment; filename=" + cd.getTitle());
        response.setHeader("Pragma", "no-cache");
    }

    if (data instanceof byte[]) {
        ByteArrayInputStream stream = new ByteArrayInputStream((byte[]) data);
        OpenmrsUtil.copyFile(stream, response.getOutputStream());
    } else if (BufferedImage.class.isAssignableFrom(data.getClass())) {
        BufferedImage img = (BufferedImage) data;
        String[] parts = cd.getTitle().split(".");
        String extension = "jpg";
        if (parts.length > 0) {
            extension = parts[parts.length - 1];
        }

        ImageIO.write(img, extension, response.getOutputStream());
    } else if (InputStream.class.isAssignableFrom(data.getClass())) {
        InputStream stream = (InputStream) data;
        OpenmrsUtil.copyFile(stream, response.getOutputStream());
        stream.close();
    } else {
        //throw new ServletException("Couldn't serialize complex obs data for obsId=" + obsId + " of type "
        //        + data.getClass());
        String title = complexObs.getComplexData().getTitle();
        log.error("name type: " + title);

        // FIXME: This is a very hacky way to deal with mime types
        Hashtable<String, String> mimes = new Hashtable<String, String>();
        //support for audio/video files
        mimes.put("3gp", "audio/3gpp");
        mimes.put("mp3", "audio/mpeg");
        mimes.put("mp4", "video/mp4");
        mimes.put("mpg", "video/mpeg");
        mimes.put("flv", "video/x-flv");

        //support for text files
        mimes.put("txt", "text/plain");
        mimes.put("doc", "application/msword");
        mimes.put(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

        // FIXME: This is a very hacky way to deal with mime types
        for (String mime : mimes.keySet()) {
            if (title.contains("." + mime)) {
                response.setContentType(mimes.get(mime));
            }
        }

        // Write the file to response
        FileInputStream f = new FileInputStream((File) data);

        InputStream in = null;
        OutputStream out = null;
        try {
            in = f;
            out = response.getOutputStream();
            while (true) {
                int dataFromStream = in.read();
                if (dataFromStream == -1) {
                    break;
                }
                out.write(dataFromStream);
            }
            in.close();
            out.close();
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }

}

From source file:org.wso2.carbon.application.deployer.internal.ApplicationManager.java

private void removeFaultyService(CarbonApplication currentApp, AxisConfiguration axisConfiguration) {
    // remove faulty services added by CApp
    Hashtable<String, String> faultyServices = axisConfiguration.getFaultyServices();
    for (String faultService : faultyServices.keySet()) {
        // check if the service is related to the current CApp
        if (faultService.contains(currentApp.getExtractedPath())) {
            axisConfiguration.getFaultyServices().remove(faultService);
        }//from   ww  w.jav a2  s . c  om
    }
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the relative usage of the given
 * projects against the given collaborator.
 * //  w  w  w. jav  a 2 s .  c  o  m
 * @param projectCollabTable
 * @return
 */
private DefaultPieDataset createProjectDataset(
        Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) {

    DefaultPieDataset pds = new DefaultPieDataset();

    // add project summary info

    for (ProjectBean project : projectCollabTable.keySet()) {
        CollaboratorBean collabBean = projectCollabTable.get(project)
                .get(projectCollabTable.get(project).indexOf(collab));
        if (collabBean != null) {
            pds.setValue(project.getName() + " Used", new Double(collabBean.getTotalUsage().getUsed()));
            pds.setValue(project.getName() + " Avail.", new Double(collabBean.getTotalUsage().getBalance()));
            // keep track of the current project so we can explode that piece
            // of the pie.
            if (project.equals(GridChem.project)) {
                defaultProjectIndex = pds.getItemCount() - 1;
            }
        }
    }

    return pds;
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the consumption of this project's
 * allocation by each collaborator including the current user.
 * //  w  w  w.  j a va2s .c o m
 * @param project
 * @return
 */
private DefaultPieDataset createUserDataset(Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> userUsageTable = new Hashtable<String, Double>();

    for (ProjectBean project : projectCollabTable.keySet()) {
        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        for (CollaboratorBean collab : collabs) {
            String key = collab.getFirstName() + " " + collab.getLastName();
            if (userUsageTable.containsKey(key)) {
                double oldVal = userUsageTable.get(key).doubleValue();
                userUsageTable.remove(key);
                userUsageTable.put(key, new Double(oldVal + collab.getTotalUsage().getUsed()));
            } else {
                userUsageTable.put(key, new Double(collab.getTotalUsage().getUsed()));
            }
        }
    }

    // now put the tallies in the dataset
    for (String key : userUsageTable.keySet()) {
        pds.setValue(key, userUsageTable.get(key).doubleValue());
    }

    return pds;
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the normalized usage of this project
 * on each resource in the CCG.  The values shown will be the current
 * usage on each resource, however, in terms of display, they will
 * appear as relative to each other.//from www .j a  v a2 s  .  c om
 * 
 * @param project
 * @return
 */
private DefaultPieDataset createResourceDataset(
        Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> resourceUsageTable = new Hashtable<String, Double>();

    for (ProjectBean project : projectCollabTable.keySet()) {
        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        for (CollaboratorBean collab : collabs) {

            for (String systemName : collab.getUsageTable().keySet()) {
                UsageBean usage = collab.getUsageTable().get(systemName);

                if (resourceUsageTable.containsKey(systemName)) {
                    double previousUsage = resourceUsageTable.get(systemName).doubleValue();
                    resourceUsageTable.remove(systemName);
                    resourceUsageTable.put(systemName, new Double(previousUsage + usage.getUsed()));
                } else {
                    resourceUsageTable.put(systemName, new Double(usage.getUsed()));
                }
            }
        }
    }

    // now put the tallies in the dataset
    for (String systemName : resourceUsageTable.keySet()) {
        pds.setValue(systemName, resourceUsageTable.get(systemName).doubleValue());
    }

    return pds;

    //        System.out.println("found specified collaborator " + collab.getLastName() + 
    //                " with " + collab.getUsageTable().size() + " resource records.");
    //        
    //        for(String key: collab.getUsageTable().keySet()) {
    //            pds.setValue(key, collab.getUsageTable().get(key).getUsed());
    //        }
    //        
    //        return pds;
}

From source file:org.kepler.kar.KARBuilder.java

public void generateKAR(TableauFrame tableauFrame, String overrideModDeps) throws IllegalActionException {
    if (isDebugging)
        log.debug("generateKAR()");

    if (_karLSID == null) {
        try {//ww w.  j  a  v a 2 s  . c  om
            _karLSID = LSIDGenerator.getInstance().getNewLSID();
        } catch (Exception e) {
            log.error("could not generate new LSID for KAR: " + e.getMessage());
            e.printStackTrace();
        }
    }

    try {

        // Get KAREntries for the Save Initiator List
        Hashtable<KAREntry, InputStream> initiatorEntries = handleInitiatorList();
        addEntriesToPrivateItems(initiatorEntries);

        int pass = 1;

        // Loop through KAR Entry handlers until no more KAREntry objects
        // are returned
        Vector<KeplerLSID> previousPassEntryLSIDs = getKAREntryLSIDs(initiatorEntries);
        if (isDebugging)
            log.debug("Pass " + pass + " entries: " + previousPassEntryLSIDs.toString());
        while (previousPassEntryLSIDs.size() > 0) {
            pass++;

            // Get the KAREntries from all of the handlers
            Hashtable<KAREntry, InputStream> entries = queryKAREntryHandlers(previousPassEntryLSIDs,
                    tableauFrame);
            if (entries != null) {

                previousPassEntryLSIDs.removeAllElements();
                if (isDebugging)
                    log.debug("Pass " + pass + " entries: ");
                Vector<KeplerLSID> repeats = new Vector<KeplerLSID>();
                for (KAREntry karEntryKey : entries.keySet()) {
                    String entryName = karEntryKey.getName();
                    String entryType = karEntryKey.getType();
                    KeplerLSID entryLSID = karEntryKey.getLSID();
                    if (isDebugging)
                        log.debug(entryName + "  " + entryLSID + "  " + entryType);
                    if (_karItemLSIDs.contains(entryLSID)) {
                        // TODO make sure existing Entry Handlers do not produce repeated LSIDs.
                        // This should never happen.
                        System.out.println("KARBuilder generateKAR() Trying to add " + entryName + " with "
                                + "type:" + entryType + " but an entry with lsid:" + entryLSID + " has already "
                                + "been added to KAR. Will NOT add this entry.");
                        repeats.add(entryLSID);
                    } else if (_karItemNames.contains(entryName)) {
                        // TODO make sure existing Entry Handlers do not produce repeated LSIDs.
                        // This should never happen.
                        System.out.println("KARBuilder generateKAR() An entry with entryName" + entryName
                                + " has already been added to KAR. Will NOT add this entry with lsid:"
                                + entryLSID);
                        repeats.add(entryLSID);
                    } else {
                        previousPassEntryLSIDs.add(entryLSID);
                    }
                }
                // A kludge to protect against entry handlers returning entries that have already been added
                for (KeplerLSID repeatedLSID : repeats) {
                    for (KAREntry ke : entries.keySet()) {
                        if (ke.getLSID().equals(repeatedLSID)) {
                            entries.remove(ke);
                            if (isDebugging)
                                log.debug("Removed " + repeatedLSID + " from pass " + pass + " entries");
                            break;
                        }
                    }
                }

                addEntriesToPrivateItems(entries);
            }
        }

        prepareManifest(overrideModDeps);

        writeKARFile();

    } catch (Exception e) {
        throw new IllegalActionException("Error building the KAR file: " + e.getMessage());
    }

}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the cumulative usage of each user
 * across the set of projects.  /*ww  w.jav a 2s  .  co  m*/
 * 
 * @param projectCollabTable
 * @return
 */
private DefaultPieDataset createUserDataset(Hashtable<ProjectBean, List<CollaboratorBean>> usageTable,
        CollaboratorBean collab) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> userUsageTable = new Hashtable<String, Double>();

    // for every project 
    for (ProjectBean project : usageTable.keySet()) {
        // if the user is part of this project
        if (usageTable.get(project).contains(collab)) {
            userUsageTable.put(project.getName(), usageTable.get(project)
                    .get(usageTable.get(project).indexOf(collab)).getTotalUsage().getUsed());
        }
    }

    // now put the tallies in the dataset
    for (String userName : userUsageTable.keySet()) {
        pds.setValue(userName, userUsageTable.get(userName).doubleValue());
    }

    return pds;
}

From source file:dpfmanager.conformancechecker.tiff.reporting.HtmlReport.java

private String generateTagsDivs(IndividualReport ir) {
    Map<String, Boolean> hasExpert = new HashMap<>();
    Map<String, String> tagsMap = new HashMap<>();
    Map<String, String> templates = new HashMap<>();
    String row;//from   w w  w  .j a  v  a  2  s.c  o m

    /**
     * Parse TAGs
     */
    for (ReportTag tag : getTags(ir)) {
        if (tag.tv.getId() == 700) {
            String mapId = "xmp" + tag.index;
            String mapIdH = "xmp" + tag.index + "h";
            // XMP
            for (abstractTiffType to : tag.tv.getValue()) {
                XMP xmp = (XMP) to;
                try {
                    Metadata metadata = xmp.createMetadata();
                    for (String key : metadata.keySet()) {
                        row = "<tr class='xmp" + tag.index + "'><td>" + key + "</td><td>"
                                + metadata.get(key).toString().trim() + "</td></tr>";
                        String rows = tagsMap.containsKey(mapId) ? tagsMap.get(mapId) : "";
                        tagsMap.put(mapId, rows + row);
                    }
                    if (xmp.getHistory() != null) {
                        for (Hashtable<String, String> kv : xmp.getHistory()) {
                            // TODO WORKARROUND
                            String key = kv.keySet().iterator().next();
                            String value = kv.get(key);
                            row = "<tr class='##LINE## xmp" + tag.index
                                    + "'><td>##ATTR##</td><td>##VALUE##</td></tr>";
                            if (key.equals("action")) {
                                row = row.replace("##LINE##", "line-top");
                            } else {
                                row = row.replace("##LINE##", "");
                            }
                            row = row.replace("##ATTR##", key);
                            row = row.replace("##VALUE##", value);
                            String rows = tagsMap.containsKey(mapIdH) ? tagsMap.get(mapIdH) : "";
                            tagsMap.put(mapIdH, rows + row);
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            continue;
        }
        if (tag.tv.getId() == 34665) {
            // EXIF
            String mapId = "exi" + tag.index;
            IFD exif = (IFD) tag.tv.getValue().get(0);
            for (TagValue tv : exif.getTags().getTags()) {
                if (tv.getId() == 36864) {
                    tv.toString();
                }
                row = "<tr class='exi" + tag.index + "'><td>##ICON##</td><td class='tcenter'>" + tv.getId()
                        + "</td><td>" + (tv.getName().equals(tv.getId() + "") ? "Private tag" : tv.getName())
                        + "</td><td>" + tv.getDescriptiveValue() + "</td></tr>";
                row = row.replace("##ICON##",
                        "<i class=\"image-default icon-" + tv.getName().toLowerCase() + "\"></i>");
                String rows = tagsMap.containsKey(mapId) ? tagsMap.get(mapId) : "";
                tagsMap.put(mapId, rows + row);
            }
            continue;
        }
        if (tag.tv.getId() == 330) {
            // Sub IFD
            String mapId = "sub" + tag.index;
            IFD sub = (IFD) tag.tv.getValue().get(0);
            for (TagValue tv : sub.getTags().getTags()) {
                String expert = "";
                if (!showTag(tv)) {
                    expert = "expert";
                    hasExpert.put(mapId, true);
                }
                row = "<tr class='sub" + tag.index + " " + expert
                        + "'><td>##ICON##</td><td class='tcenter'>##ID##</td><td>##KEY##</td><td>##VALUE##</td></tr>";
                row = row.replace("##ICON##",
                        "<i class=\"image-default icon-" + tv.getName().toLowerCase() + "\"></i>");
                row = row.replace("##ID##", tv.getId() + "");
                row = row.replace("##KEY##",
                        (tv.getName().equals(tv.getId() + "") ? "Private tag" : tv.getName()));
                row = row.replace("##VALUE##", tv.getDescriptiveValue());
                String rows = tagsMap.containsKey(mapId) ? tagsMap.get(mapId) : "";
                tagsMap.put(mapId, rows + row);
            }
            continue;
        }
        if (tag.tv.getId() == 33723) {
            String mapId = "ipt" + tag.index;
            // IPTC
            for (abstractTiffType to : tag.tv.getValue()) {
                try {
                    IPTC iptc = (IPTC) to;
                    Metadata metadata = iptc.createMetadata();
                    for (String key : metadata.keySet()) {
                        row = "<tr class='ipt" + tag.index + "'><td>" + key + "</td><td>"
                                + metadata.get(key).toString().trim() + "</td></tr>";
                        String rows = tagsMap.containsKey(mapId) ? tagsMap.get(mapId) : "";
                        tagsMap.put(mapId, rows + row);
                    }
                } catch (Exception ex) {
                    ex.toString();
                    //ex.printStackTrace();
                }
            }
            continue;
        }
        // IFD
        String mapId = "ifd" + tag.index;
        String expert = "";
        if (tag.expert) {
            expert = " expert";
            hasExpert.put(mapId, true);
        }
        row = "<tr class='ifd" + tag.index + " " + expert
                + "'><td>##ICON##</td><td class='tcenter'>##ID##</td><td>##KEY##</td><td>##VALUE##</td></tr>";
        String sDif = "";
        if (tag.dif < 0)
            sDif = "<i class=\"fa fa-times\"></i>";
        else if (tag.dif > 0)
            sDif = "<i class=\"fa fa-plus\"></i>";
        row = row.replace("##ICON##",
                "<i class=\"image-default icon-" + tag.tv.getName().toLowerCase() + "\"></i>");
        row = row.replace("##ID##", tag.tv.getId() + sDif);
        row = row.replace("##KEY##",
                (tag.tv.getName().equals(tag.tv.getId()) ? "Private tag" : tag.tv.getName()));
        row = row.replace("##VALUE##", tag.tv.getDescriptiveValue());
        String rows = tagsMap.containsKey(mapId) ? tagsMap.get(mapId) : "";
        tagsMap.put(mapId, rows + row);
    }

    /**
     * Generate divs
     */
    String finalResult = "";
    String expertTmpl = "<div class=\"clexpert\"><input type=\"checkbox\" id=\"checkSelected##INDEX##\" onchange=\"expertChanged('##INDEX##')\"><label for=\"checkSelected##INDEX##\"><span></span> Expert mode</label></div>";
    String genTmpl = "<div id=\"div##INDEX##\" class=\"tags-divs col-md-8\" style='display: ##DISPLAY##'>\n"
            + "\t\t\t\t\t##EXPERT##\n"
            + "\t\t\t\t\t<h4 class='bold'><i class=\"fa fa-tags\"></i>  ##TITLE##</h4>\n"
            + "\t\t\t\t\t<table class=\"CustomTable3\">\n" + "\t\t\t\t        <tr>\n"
            + "\t\t\t\t            <th style=\"width: 40px;\"></th>\n"
            + "\t\t\t\t            <th style=\"width: 70px;\" class=\"bold tcenter\">Tag Id</th>\n"
            + "\t\t\t\t            <th class=\"bold\">Tag Name</th>\n"
            + "\t\t\t\t            <th class=\"bold\">Value</th>\n" + "\t\t\t\t        </tr>\n"
            + "\t\t\t\t        ##ROWS##\n" + "\t\t\t\t\t</table>\n" + "\t\t\t\t</div>";
    String subTmpl = StringUtils.replace(genTmpl, "##TITLE##", "Sub IFD Tags");
    String ifdTmpl = StringUtils.replace(genTmpl, "##TITLE##", "IFD Tags");
    String exifTmpl = StringUtils.replace(genTmpl, "##TITLE##", "EXIF");
    String iptcTmpl = "<div id=\"div##INDEX##\" class=\"tags-divs col-md-8\" style='display: ##DISPLAY##'>\n"
            + "\t\t\t\t\t##EXPERT##\n" + "\t\t\t\t\t<h4 class='bold'><i class=\"fa fa-tags\"></i>  IPTC</h4>\n"
            + "\t\t\t\t\t<table class=\"CustomTable3\">\n" + "\t\t\t\t        <tr>\n"
            + "\t\t\t\t            <th class=\"bold\">Name</th>\n"
            + "\t\t\t\t            <th class=\"bold\">Value</th>\n" + "\t\t\t\t        </tr>\n"
            + "\t\t\t\t        ##ROWS##\n" + "\t\t\t\t\t</table>\n" + "\t\t\t\t</div>";
    String xmpTmpl = "<div id=\"div##INDEX##\" class=\"tags-divs col-md-8\" style='display: ##DISPLAY##'>\n"
            + "\t\t\t\t\t##EXPERT##\n" + "\t\t\t\t\t<h4 class='bold'><i class=\"fa fa-tags\"></i>  XMP</h4>\n"
            + "\t\t\t\t\t<table class=\"CustomTable3\">\n" + "\t\t\t\t        <tr>\n"
            + "\t\t\t\t            <th class=\"bold\">Name</th>\n"
            + "\t\t\t\t            <th class=\"bold\">Value</th>\n" + "\t\t\t\t        </tr>\n"
            + "\t\t\t\t        ##ROWS##\n" + "\t\t\t\t\t</table>\n"
            + "\t\t\t\t\t<div style='display: ##DISH##;' class='top20'>\n"
            + "\t\t\t\t\t<h4 class='bold'><i class=\"fa fa-history\"></i>  History</h4>\n"
            + "\t\t\t\t\t<table class=\"CustomTable3\">\n" + "\t\t\t\t        <tr>\n"
            + "\t\t\t\t            <th class=\"bold\">Attribute</th>\n"
            + "\t\t\t\t            <th class=\"bold\">Value</th>\n" + "\t\t\t\t        </tr>\n"
            + "\t\t\t\t        ##ROWSH##\n" + "\t\t\t\t\t</table>\n" + "\t\t\t\t\t</div>\n" + "\t\t\t\t</div>";
    templates.put("ifd", ifdTmpl);
    templates.put("sub", subTmpl);
    templates.put("ipt", iptcTmpl);
    templates.put("xmp", xmpTmpl);
    templates.put("exi", exifTmpl);

    /**
     * Generate HTMLs
     */
    for (String key : tagsMap.keySet()) {
        if (key.endsWith("h"))
            continue;
        String type = key.substring(0, 3);
        String display = "none;", expert = "";
        if (key.equals("ifd0"))
            display = "block;";
        if (hasExpert.containsKey(key))
            expert = expertTmpl;
        String tmpl = templates.get(type);
        tmpl = StringUtils.replace(tmpl, "##EXPERT##", expert);
        tmpl = StringUtils.replace(tmpl, "##INDEX##", key);
        tmpl = StringUtils.replace(tmpl, "##DISPLAY##", display);
        tmpl = StringUtils.replace(tmpl, "##ROWS##", tagsMap.get(key));
        if (type.equals("xmp") && tagsMap.containsKey(key + "h")) {
            tmpl = StringUtils.replace(tmpl, "##ROWSH##", tagsMap.get(key + "h"));
            tmpl = StringUtils.replace(tmpl, "##DISH##", "block");
        } else {
            tmpl = StringUtils.replace(tmpl, "##DISH##", "none");
        }
        finalResult += tmpl;
    }
    return finalResult;
}

From source file:edu.isi.misd.tagfiler.download.FileDownloadImplementation.java

/**
 * Performs the dataset download./*  ww w .j ava  2  s. c  o m*/
 * 
 * @param destDir
 *            destination directory for the download
 * @param target
 *            resume or download all
 */
@SuppressWarnings("unchecked")
public boolean downloadFiles(String destDir, String target) {
    if (destDir == null || destDir.length() == 0 || target == null)
        throw new IllegalArgumentException(destDir + ", " + target);
    this.target = target;
    try {
        client.setBaseURL(DatasetUtils.getBaseDownloadUrl(dataset, tagFilerServerURL));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // the copy is done for performance reasons in the inner loop
    ArrayList<String> tempFiles = new ArrayList<String>(fileNames);

    List<FileWrapper> filesList = new ArrayList<FileWrapper>();
    if (target.equals(RESUME_TARGET)) {
        // resume download
        String filename = destDir + File.separator + TagFilerProperties.getProperty("tagfiler.checkpoint.file");
        File file = new File(filename);
        if (file.exists() && file.isFile() && file.canRead()) {
            // get the download check point status
            try {
                FileInputStream fis = new FileInputStream(filename);
                ObjectInputStream in = new ObjectInputStream(fis);
                Hashtable<String, Long> checkPoint = (Hashtable<String, Long>) in.readObject();
                HashMap<String, String> checksum = (HashMap<String, String>) in.readObject();
                in.close();
                fis.close();
                System.out.println("Check Points Read: " + checkPoint + "\n" + checksum);
                Set<String> keys = checkPoint.keySet();
                for (String key : keys) {
                    if (tempFiles.contains(key)) {
                        tempFiles.remove(key);
                        boolean complete = (long) bytesMap.get(key) == (long) checkPoint.get(key);
                        if (complete && enableChecksum) {
                            complete = checksum.get(key) != null && checksumMap.get(key) != null
                                    && checksum.get(key).equals(checksumMap.get(key));
                        }
                        if (complete) {
                            // file already downloaded
                            bytesMap.remove(key);
                            versionMap.remove(key);
                            checksumMap.remove(key);
                        } else {
                            // file partial downloaded
                            filesList.add(new FileWrapper(key, checkPoint.get(key), versionMap.get(key),
                                    bytesMap.get(key)));
                        }
                    }
                }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    // add the rest of the files without check points
    for (String filename : tempFiles) {
        filesList.add(new FileWrapper(filename, 0, versionMap.get(filename), bytesMap.get(filename)));
    }

    System.out.println("" + filesList.size() + " file(s) will be downloaded");

    // get the total size of the files to be downloaded and checksum
    long totalSize = 0;
    long tb = 0;
    for (FileWrapper fileWrapper : filesList) {
        tb += fileWrapper.getFileLength() - fileWrapper.getOffset();
        totalSize += fileWrapper.getFileLength() - fileWrapper.getOffset();
        if (enableChecksum) {
            totalSize += fileWrapper.getFileLength();
        }
    }
    fileDownloadListener.notifyLogMessage(
            tb + " total bytes will be transferred\n" + totalSize + " total bytes in the progress bar");
    fileDownloadListener.notifyStart(dataset, totalSize);
    if (!((AbstractTagFilerApplet) applet).allowChunksTransfering()) {
        ClientUtils.disableExpirationWarning(applet);
    }
    start = System.currentTimeMillis();
    cancel = false;
    client.download(filesList, destDir, checksumMap, bytesMap, versionMap);

    return true;
}

From source file:es.itecban.deployment.executionmanager.DefaultPlanExecutor.java

public ExecutionReportType launchPlan(DeploymentPlanType plan) throws Exception {

    boolean assetCheckActive = this.isAssetCheckingActive(plan.getEnvironment());
    if (assetCheckActive) {
        Hashtable<String, DeploymentUnitType> notApprovedAssetsHs = null;
        try {//from w w  w .jav a2s .  c o m
            // Validate with the RAM if each asset in the plan is approved
            notApprovedAssetsHs = this.ramManager.validateAssetInPlan(plan);
        } catch (ServiceUnavailableException e) {
            logger.info("Error ocurred while communicating with the RAM. "
                    + "Maybe this module is not available as it is optional ");
        }
        if (notApprovedAssetsHs != null && notApprovedAssetsHs.size() != 0) {
            //            String messageError = "The following resource is not approved in the "
            //                  + "Rational Asset Manager ";
            // Show only the first in the collection not approved
            Set<String> notApprovedAssetsSet = notApprovedAssetsHs.keySet();
            for (String notApprovedAsset : notApprovedAssetsSet) {
                // messageError = messageError
                // + "\r\n"
                // + notApprovedAsset
                // + " in component "
                // + notApprovedAssetsHs.get(notApprovedAsset)
                // .getName()
                // + " version_"
                // + notApprovedAssetsHs.get(notApprovedAsset)
                // .getVersion();
                // not tested
                throw new MessageException("running.error.assetNotApproved", notApprovedAsset,
                        notApprovedAssetsHs.get(notApprovedAsset).getName(),
                        notApprovedAssetsHs.get(notApprovedAsset).getVersion());
            }
        }
    }

    // If here, all the validations has gone succesfully
    ExecutionReportType report = null;
    try {
        report = executorService.launchPlan(plan);
        if (report == null)
            throw new Exception("running.error.problemPlan");
    } catch (Exception e) {
        logger.severe("Error launching the plan." + e.getMessage());
        throw new Exception(e.getMessage());
    }

    // Set the report launcher user

    if (report.getResult().equals(PlanResultKindType.OK) && assetCheckActive) {
        try {
            this.ramManager.changeDeployedAssetStatus(plan);
            logger.info("Plan result: " + report.getResult()
                    + ". Changes done in the RAM to the status of the assets");
        } catch (ServiceUnavailableException e) {
            logger.info("Error ocurred while communicating with the RAM. "
                    + "Maybe this module is not available as it is optional ");
        }
    } else {
        logger.info(
                "Plan result: " + report.getResult() + ". No changes done in RAM to the status of the assets");
    }
    String planName = plan.getName();
    String creationUser = planName.split("\\|")[3];

    report.setCreationUserId(creationUser);
    report.setLauncherUserId(AuthenticationManager.getUserName());
    reportManager.setCreationUserId(report.getPlanId(), report.getStartTime(), creationUser);
    reportManager.setLauncherUserId(report.getPlanId(), report.getStartTime(),
            AuthenticationManager.getUserName());
    return report;
}