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:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java

/**
 * This heuristic creates associations based on the in-reply: header field
 * of messages/*from w  w  w .j a  v a  2  s. c  o  m*/
 */
private void heuristicInreply(List<MM2Message> messages, Connection connection) {
    // This is the msg_id ==> in-reply-to
    Hashtable<String, String> msg_id_to_message_id = new Hashtable<String, String>();

    // This is message-id ==> msg_id
    Hashtable<String, String> message_id_to_msg_id = new Hashtable<String, String>();

    // This is child ==> parent
    Hashtable<String, String> msg_id_to_msg_id = new Hashtable<String, String>();
    Pattern messageid_pattern = Pattern.compile("<(.*?@.*?)>");

    try {
        for (MM2Message msg : messages) {

            // Step One: check whether the message has a message-id header
            // We assume that the "message-id" field is always set - at least to "" and is not null
            String h_message_id = msg.getHeaderEntry("message-id");
            if (h_message_id.length() > 2) {
                // We try to identify the message identifier part
                String maybeMatch = findLongestPatternMatch(h_message_id, messageid_pattern);
                if (!maybeMatch.equalsIgnoreCase("")) {
                    String extracted_message_id = maybeMatch;
                    String msg_id = msg.getHeaderEntry("msg_id");
                    // Add the information to the reverse lookup table that we will need later
                    message_id_to_msg_id.put(extracted_message_id, msg_id);
                    Main.getLogger().debug(5, this,
                            "I know that message " + msg_id + " has message-id " + extracted_message_id);
                }
            }

            // Step Two: check whether the message has an in-reply-to header
            // Again we assume that the "in-reply-to" field is at least "" and not null
            String h_in_reply_to = msg.getHeaderEntry("in-reply-to");
            if (h_in_reply_to.contains(">") && h_in_reply_to.contains("<")) {
                // We try to identify the message identifier part
                String maybeMatch = findLongestPatternMatch(h_in_reply_to, messageid_pattern);
                if (!maybeMatch.equalsIgnoreCase("")) {
                    String extracted_in_reply_to_messageid = maybeMatch;
                    String msg_id = msg.getHeaderEntry("msg_id");
                    // Add the information into the forward lookup table
                    Main.getLogger().debug(5, this, "I know that message " + msg_id + " is a reply to "
                            + extracted_in_reply_to_messageid);
                    msg_id_to_message_id.put(msg_id, extracted_in_reply_to_messageid);
                }
            }
        }

        // Step Three: After we obtained the previous information, we will
        // resolve each in-reply-to id to a msg_id. so we know for each key in the
        // forward lookup table the msg_id it is a reply to:

        for (String child_msg_id : msg_id_to_message_id.keySet()) {
            String parent_msg_id = message_id_to_msg_id.get(msg_id_to_message_id.get(child_msg_id));
            // If we found an entry in the table
            if (parent_msg_id != null) {
                // Add this information to the parents table
                Main.getLogger().debug(5, this,
                        "I know that message " + child_msg_id + " has the parent " + parent_msg_id);
                msg_id_to_msg_id.put(child_msg_id, parent_msg_id);
            }
        }

        Main.getLogger().debug(5, "message-ids resolved to msg_ids = " + message_id_to_msg_id.size());
        Main.getLogger().debug(5, "message_ids resolved from in-reply-to = " + msg_id_to_message_id.size());

        // Store the parents and roots into the database
        Main.getLogger().log("The heuristic could resolve " + msg_id_to_msg_id.size() + " parent relations!");
        Main.getLogger().log("Storing associations found by in-reply-to heuristic in the database...");
        storeParents(msg_id_to_msg_id, connection);

    } catch (Exception e) {
        Main.getLogger().error("Error storing messages for heuristic in-reply!", e);
    }
}

From source file:edu.ku.brc.specify.utilapps.RegProcessor.java

/**
 * @param key/*from   w w w .j a  v a  2 s.co m*/
 * @param valueStr
 */
protected void subtractPrevious() {
    if (prvRegNumHash.size() > 0) {
        Hashtable<String, Boolean> trkUsageHash = new Hashtable<String, Boolean>();
        Hashtable<String, Hashtable<String, Integer>> trkCatsHash = new Hashtable<String, Hashtable<String, Integer>>();

        // First find all the Collection Register Numbers
        // that were the same from 
        Vector<String> collectionNumbers = new Vector<String>(trackRegNumHash.keySet());
        System.out.println("========================");
        for (String colKey : collectionNumbers) {
            RegProcEntry entry = trackRegNumHash.get(colKey);
            System.out.println("CUR " + entry.get("date") + "  " + colKey);
            for (Object keyObj : entry.keySet()) {
                String pName = keyObj.toString();
                String value = entry.get(pName);

                if (pName.startsWith("Usage_")) {
                    addToTracks(pName.substring(6), value, trkUsageHash, trkCatsHash);

                } else if (pName.startsWith("DE_") || pName.startsWith("WB_") || pName.startsWith("SS_")
                        || pName.startsWith("RS_") || pName.startsWith("QB_") || pName.startsWith("TREE_OPEN_")
                        || pName.startsWith("RunCount") || pName.startsWith("Tools_")) {
                    addToTracks(pName, value, trkUsageHash, trkCatsHash);
                }
            }
        }
        System.out.println("========================!");
        prvTrackUsageHash.clear();
        prvTrackCatsHash.clear();

        for (String colKey : collectionNumbers) {
            RegProcEntry entry = prvRegNumHash.get(colKey);
            if (entry != null) {
                System.out.println("PRV " + entry.get("date") + "  " + colKey);
                for (Object keyObj : entry.keySet()) {
                    String pName = keyObj.toString();
                    String value = entry.get(pName);

                    if (pName.startsWith("Usage_")) {
                        addToTracks(pName.substring(6), value, prvTrackUsageHash, prvTrackCatsHash);

                    } else if (pName.startsWith("DE_") || pName.startsWith("WB_") || pName.startsWith("SS_")
                            || pName.startsWith("RS_") || pName.startsWith("QB_")
                            || pName.startsWith("TREE_OPEN_") || pName.startsWith("RunCount")
                            || pName.startsWith("Tools_")) {
                        addToTracks(pName, value, prvTrackUsageHash, prvTrackCatsHash);
                    }
                }
            }
        }

        for (String category : trkCatsHash.keySet()) {
            Hashtable<String, Integer> prvCountHash = prvTrackCatsHash.get(category);
            Hashtable<String, Integer> countHash = trkCatsHash.get(category);
            if (prvCountHash != null && countHash != null) {
                for (String cntKey : countHash.keySet()) {
                    Integer cnt = countHash.get(cntKey);
                    Integer prvCnt = prvCountHash.get(cntKey);
                    if (cnt != null && prvCnt != null) {
                        if (prvCnt.intValue() > cnt.intValue()) {
                            System.out.println(
                                    "   " + String.format("%5d %5d %s %s ", cnt, prvCnt, category, cntKey));
                        } else {
                            cnt -= prvCnt;
                            countHash.put(cntKey, cnt);
                            System.out.println(
                                    "OK " + String.format("%5d %5d %s %s ", cnt, prvCnt, category, cntKey));
                        }
                    }
                }
            }
        }
        trackUsageHash = trkUsageHash;
        trackCatsHash = trkCatsHash;
    }
}

From source file:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java

/**
 * This heuristic creates associations based on the references header fields
 *///from w w  w  .ja  va2 s .c  o  m
private void heuristicReferences(List<MM2Message> messages, Connection connection) {
    // This is the msg_id ==> references-id
    Hashtable<String, String> msg_id_to_message_id = new Hashtable<String, String>();

    // This is message-id ==> msg_id
    Hashtable<String, String> message_id_to_msg_id = new Hashtable<String, String>();

    // This is child ==> parent
    Hashtable<String, String> msg_id_to_msg_id = new Hashtable<String, String>();
    Pattern messageid_pattern = Pattern.compile("<(.*?@.*?)>");

    try {
        for (MM2Message msg : messages) {

            // Step One: check whether the message has a message-id header
            // We assume that the "message-id" field is always set - at least to "" and is not null
            String h_message_id = msg.getHeaderEntry("message-id");
            if (h_message_id.length() > 2) {
                // We try to identify the message identifier part
                String maybeMatch = findLongestPatternMatch(h_message_id, messageid_pattern);
                if (!maybeMatch.equalsIgnoreCase("")) {
                    String extracted_message_id = maybeMatch;
                    String msg_id = msg.getHeaderEntry("msg_id");
                    // Add the information to the reverse lookup table that we will need later
                    message_id_to_msg_id.put(extracted_message_id, msg_id);
                    Main.getLogger().debug(5, this,
                            "I know that message " + msg_id + " has message-id " + extracted_message_id);
                }
            }

            // Step Two: check whether the message has an references header
            // Again we assume that the "references" field is at least "" and not null
            String h_references = msg.getHeaderEntry("references");
            String[] split_refs = h_references.split(" ");
            for (String ref : split_refs) {
                if (ref.contains(">") && ref.contains("<")) {
                    // We try to identify the message identifier part
                    String maybeMatch = findLongestPatternMatch(h_references, messageid_pattern);
                    if (!maybeMatch.equalsIgnoreCase("")) {
                        String extracted_in_reply_to_messageid = maybeMatch;
                        String msg_id = msg.getHeaderEntry("msg_id");
                        // Add the information into the forward lookup table
                        Main.getLogger().debug(5, this, "I know that message " + msg_id + " is a reply to "
                                + extracted_in_reply_to_messageid);
                        msg_id_to_message_id.put(msg_id, extracted_in_reply_to_messageid);
                    }
                }
            }
        }

        // Step Three: After we obtained the previous information, we will
        // resolve each in-reply-to id to a msg_id. so we know for each key in the
        // forward lookup table the msg_id it is a reply to:

        for (String child_msg_id : msg_id_to_message_id.keySet()) {
            String parent_msg_id = message_id_to_msg_id.get(msg_id_to_message_id.get(child_msg_id));
            // If we found an entry in the table
            if (parent_msg_id != null) {
                // Add this information to the parents table
                Main.getLogger().debug(5, this,
                        "I know that message " + child_msg_id + " has the parent " + parent_msg_id);
                msg_id_to_msg_id.put(child_msg_id, parent_msg_id);
            }
        }

        Main.getLogger().debug(5, "message-ids resolved to msg_ids = " + message_id_to_msg_id.size());
        Main.getLogger().debug(5, "message_ids resolved from references = " + msg_id_to_message_id.size());

        // Store the parents and roots into the database
        Main.getLogger().log("The heuristic could resolve " + msg_id_to_msg_id.size() + " parent relations!");
        Main.getLogger().log("Storing associations found by references heuristic in the database...");
        storeParents(msg_id_to_msg_id, connection);

    } catch (Exception e) {
        Main.getLogger().error("Error storing messages for heuristic references!", e);
    }
}

From source file:fr.eolya.utils.http.HttpUtils.java

public static String getHtmlDeclaredLanguage(String rawData) {
    if (rawData == null || "".equals(rawData))
        return "";

    Hashtable<String, Integer> langFreq = new Hashtable<String, Integer>();
    BufferedReader in = new BufferedReader(new StringReader(rawData));
    String line;/*from  ww w. j  a v a  2 s .  c  om*/
    try {
        while ((line = in.readLine()) != null) {
            line = line.toLowerCase();

            //<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-fr">
            if (line.indexOf("<html") >= 0 && line.toLowerCase().indexOf(" xml:lang") >= 0) {
                String lang = parseAttributeValue(line, "xml:lang=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<html lang="fr">
            if (line.indexOf("<html") >= 0 && line.toLowerCase().indexOf(" lang") >= 0) {
                String lang = parseAttributeValue(line, "lang=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta http-equiv="content-language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" http-equiv") >= 0
                    && line.toLowerCase().indexOf("content-language") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta name="language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" name") >= 0
                    && line.toLowerCase().indexOf("language") >= 0
                    && line.toLowerCase().indexOf(" content") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }

            //<meta name="content-language" content="fr-fr" />
            if (line.indexOf("<meta") >= 0 && line.toLowerCase().indexOf(" name") >= 0
                    && line.toLowerCase().indexOf("content-language") >= 0
                    && line.toLowerCase().indexOf(" content") >= 0) {
                String lang = parseAttributeValue(line, "content=");
                if (lang != null && lang.length() >= 2) {
                    lang = lang.substring(0, 2);

                    if (langFreq.containsKey(lang))
                        langFreq.put(lang, langFreq.get(lang) + 1);
                    else
                        langFreq.put(lang, 1);
                }
            }
        }

        // Get the best candidate
        Vector<String> v = new Vector<String>(langFreq.keySet());
        Iterator<String> it = v.iterator();
        int max = 0;
        String lang = "";
        while (it.hasNext()) {
            String element = (String) it.next();
            //System.out.println( element + " " + encodingFreq.get(element));
            if (langFreq.get(element) > max) {
                max = langFreq.get(element);
                lang = element;
            }
        }

        return lang;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:edu.ku.brc.specify.web.SpecifyExplorer.java

/**
 * @param out//from   w  ww .  java  2  s.  c o m
 * @param ordered
 * @param unOrdered
 */
protected void fillRows(final PrintWriter out, final Hashtable<Integer, String> ordered,
        final Vector<String> unOrdered) {
    Vector<Integer> indexes = new Vector<Integer>(ordered.keySet());
    Collections.sort(indexes);
    int cnt = 1;
    for (Integer index : indexes) {
        String row = ordered.get(index);
        if (row != null) {
            if (StringUtils.contains(row, "BRDRODDEVEN")) {
                out.println(StringUtils.replace(row, "BRDRODDEVEN",
                        "brdr" + (((cnt + 1) % 2 == 0) ? "even" : "odd")));
            } else {
                out.println(row);
            }
            cnt++;
        }
    }

    if (unOrdered != null) {
        for (String row : unOrdered) {
            if (StringUtils.contains(row, "BRDRODDEVEN")) {
                out.println(StringUtils.replace(row, "BRDRODDEVEN",
                        "brdr" + (((cnt + 1) % 2 == 0) ? "even" : "odd")));
            } else {
                out.println(row);
            }
            cnt++;
        }
    }
}

From source file:edu.ku.brc.specify.web.SpecifyExplorer.java

/**
 * @param locHash// w w w  .  j  ava2  s.c om
 * @return
 */
protected String getLocalityMapString(final Hashtable<Locality, Vector<CollectionObject>> locHash) {
    StringBuilder sb = new StringBuilder();

    int loc = 0;
    for (Locality locality : locHash.keySet()) {
        //if (loc > 0) sb.append(';');
        sb.append(locality.getLocalityId() + ";");
        int i = 0;
        for (CollectionObject co : locHash.get(locality)) {
            if (i > 0)
                sb.append(',');
            sb.append(co.getCollectionObjectId());
            i++;
        }
        sb.append(";");
        loc++;
    }
    return sb.toString();
}

From source file:org.opencms.webdav.CmsWebdavServlet.java

/**
 * Process a DELETE WebDAV request for the specified resource.<p>
 * /*from   w  ww  .j  av  a2 s  .c  o  m*/
 * @param req the servlet request we are processing
 * @param resp the servlet response we are creating
 * 
 * @throws IOException if an input/output error occurs
 */
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    // Get the path to delete
    String path = getRelativePath(req);

    // Check if webdav is set to read only
    if (m_readOnly) {

        resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_WEBDAV_READ_ONLY_0));
        }

        return;
    }

    // Check if path exists
    boolean exists = m_session.exists(path);
    if (!exists) {

        resp.setStatus(CmsWebdavStatus.SC_NOT_FOUND);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_NOT_FOUND_1, path));
        }

        return;
    }

    // Check if resource is locked
    if (isLocked(req)) {

        resp.setStatus(CmsWebdavStatus.SC_LOCKED);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_LOCKED_1, path));
        }

        return;
    }

    // Check if resources found in the tree of the path are locked
    Hashtable<String, Integer> errorList = new Hashtable<String, Integer>();

    checkChildLocks(req, path, errorList);
    if (!errorList.isEmpty()) {
        sendReport(req, resp, errorList);

        if (LOG.isDebugEnabled()) {
            Iterator<String> iter = errorList.keySet().iterator();
            while (iter.hasNext()) {
                String errorPath = iter.next();
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_CHILD_LOCKED_1, errorPath));
            }
        }

        return;
    }

    // Delete the resource
    try {

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_ITEM_0));
        }

        m_session.delete(path);
    } catch (CmsVfsResourceNotFoundException rnfex) {

        // should never happen
        resp.setStatus(CmsWebdavStatus.SC_NOT_FOUND);
        return;
    } catch (CmsSecurityException sex) {
        resp.setStatus(CmsWebdavStatus.SC_FORBIDDEN);

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_NO_PERMISSION_0));
        }

        return;
    } catch (CmsException ex) {
        resp.setStatus(CmsWebdavStatus.SC_INTERNAL_SERVER_ERROR);

        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_REPOSITORY_ERROR_2, "DELETE", path), ex);
        }

        return;
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(Messages.get().getBundle().key(Messages.LOG_DELETE_SUCCESS_0));
    }

    resp.setStatus(CmsWebdavStatus.SC_NO_CONTENT);
}

From source file:unalcol.termites.boxplots.RoundNumberGlobal.java

/**
 * Creates a sample dataset.//ww  w . ja v a 2  s  .co  m
 *
 * @return A sample dataset.
 */
private BoxAndWhiskerCategoryDataset createSampleDataset(ArrayList<Double> Pf) {

    final int seriesCount = 5;
    final int categoryCount = 4;
    final int entityCount = 22;
    //String sDirectorio = "experiments\\2015-10-30-mazeoff";
    File f = new File(experimentsDir);
    String extension;
    File[] files = f.listFiles();
    Hashtable<String, String> Pop = new Hashtable<>();
    PrintWriter escribir;
    Scanner sc = null;
    ArrayList<Integer> aPops = new ArrayList<>();
    ArrayList<Double> aPf = new ArrayList<>();
    ArrayList<String> aTech = new ArrayList<>();

    Hashtable<String, List> info = new Hashtable();

    //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4"};
    for (String mode : aMode) {
        info.put(mode, new ArrayList());
    }

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    for (File file : files) {
        extension = "";
        int i = file.getName().lastIndexOf('.');
        int p = Math.max(file.getName().lastIndexOf('/'), file.getName().lastIndexOf('\\'));
        if (i > p) {
            extension = file.getName().substring(i + 1);
        }

        // System.out.println(file.getName() + "extension" + extension);
        if (file.isFile() && extension.equals("csv") && file.getName().startsWith("dataCollected")) {
            System.out.println(file.getName());
            System.out.println("get: " + file.getName());
            String[] filenamep = file.getName().split(Pattern.quote("+"));

            System.out.println("file" + filenamep[8]);

            int popsize = Integer.valueOf(filenamep[3]);
            double pf = Double.valueOf(filenamep[5]);
            String mode = filenamep[7];

            int maxIter = -1;
            //if (!filenamep[8].isEmpty()) {
            maxIter = Integer.valueOf(filenamep[9]);
            //}

            System.out.println("psize:" + popsize);
            System.out.println("pf:" + pf);
            System.out.println("mode:" + mode);
            System.out.println("maxIter:" + maxIter);

            //String[] aMode = {"random", "levywalk", "sandc", "sandclw"};
            //String[] aMode = {"levywalk", "lwphevap", "hybrid", "hybrid3", "hybrid4", "sequential"};
            //String[] aMode = {"levywalk", "lwphevap", "hybrid", "sequential"};

            if (/*Pf == pf && */isInMode(aMode, mode)) {
                final List list = new ArrayList();
                try {
                    sc = new Scanner(file);

                } catch (FileNotFoundException ex) {
                    Logger.getLogger(DataCollectedLatexConsolidatorSASOMessagesSend1.class.getName())
                            .log(Level.SEVERE, null, ex);
                }
                int roundNumber = 0;
                double globalInfoCollected = 0;

                String[] data = null;
                while (sc.hasNext()) {
                    String line = sc.nextLine();
                    data = line.split(",");
                    //System.out.println("data");
                    roundNumber = Integer.valueOf(data[0]);
                    globalInfoCollected = Double.valueOf(data[4]);

                    if (globalInfoCollected >= 90 && Pf.contains(pf)) {
                        info.get(mode).add(roundNumber);
                        break;
                    }

                }

                LOGGER.debug("Adding series " + i);
                LOGGER.debug(list.toString());
                if (Pf.contains(pf)) {
                    /*pf == 1.0E-4 || pf == 3.0E-4*/
                    if (Pf.size() == 1) {
                        dataset.add(list, popsize, getTechniqueName(mode));
                    } else {
                        dataset.add(list, String.valueOf(popsize) + "-" + pf, getTechniqueName(mode));
                    }
                }
            }
        }

    }

    for (String key : info.keySet()) {
        System.out.println(key + ":" + info.get(key).size() / 30 * 100.0);
        dataset.add(info.get(key), 10, getTechniqueName(key));
    }

    return dataset;
}

From source file:com.globalsight.everest.workflowmanager.WorkflowManagerLocal.java

/**
 * Performs system action for a workflow.
 * <p>/*  w  ww .ja v a 2  s .c  o  m*/
 * The arrayList value: first is task id, second is boolean value if need
 * create second target file, third one is use emails, fourth one is action
 * type.
 */
private ArrayList possiblyPerformSystemActions(List<WfTaskInfo> p_nextWfTaskInfos, List<Task> p_nextTasksCloned,
        Workflow p_workflow, String p_userId) throws Exception {
    ArrayList array = new ArrayList();
    if (!WorkflowTypeConstants.TYPE_TRANSLATION.equals(p_workflow.getWorkflowType())) {
        array.add(new Long(-1));
        array.add(false);
        array.add(null);
        array.add(null);
        return array;
    }
    Set<SecondaryTargetFile> stfs = p_workflow.getSecondaryTargetFiles();
    List extractedFiles = p_workflow.getTargetPages(PrimaryFile.EXTRACTED_FILE);
    // If the job doesn't have any extracted files in it then
    // don't create STFs. Un-extracted files are already in native/binary
    // format.
    if (extractedFiles.size() == 0) {
        array.add(new Long(-1));
        array.add(false);
        array.add(null);
        array.add(null);
        return array;
    }

    int size = p_nextWfTaskInfos == null ? 0 : p_nextWfTaskInfos.size();
    long taskId = -1;
    boolean flagSTF = false;
    String actionType = null;
    ArrayList userEmails = new ArrayList();
    // fix for GBS-1594
    Boolean stfState = true;
    Hashtable tasks = p_workflow.getTasks();
    Iterator it = tasks.keySet().iterator();
    while (it.hasNext()) {
        Task task = (Task) tasks.get(it.next());
        if (Task.IN_PROGRESS.equals(task.getStfCreationState())) {
            stfState = false;
            break;
        }
    }
    for (int i = 0; i < size; i++) {
        WfTaskInfo wti = (WfTaskInfo) p_nextWfTaskInfos.get(i);
        actionType = wti.getActionType();

        if (((SystemAction.CSTF.equals(actionType) && stfs.size() == 0) || SystemAction.RSTF.equals(actionType))
                && stfState) {
            flagSTF = true;
        }

        taskId = wti.getId();
        userEmails = wti.userEmail;
    }

    if (flagSTF && taskId > 0) {
        // set the tasks creation of stf state to InProgress
        updateStfCreationStateForTask(p_nextTasksCloned, taskId, Task.IN_PROGRESS);

    }

    array.add(taskId);
    array.add(flagSTF);
    array.add(userEmails);
    array.add(actionType);

    return array;
}

From source file:edu.ku.brc.specify.tasks.InteractionsTask.java

/**
 * @param existingLoan//from   ww  w  .j av a  2s.  c om
 * @param infoRequest
 * @param prepsHash
 */
protected void addPrepsToGift(final OneToManyProviderIFace existingGiftArg, final InfoRequest infoRequest,
        final Hashtable<Integer, Integer> prepsHash, final Viewable srcViewable) {
    Gift existingGift = (Gift) existingGiftArg;
    Gift gift;

    if (existingGift == null) {
        gift = new Gift();
        gift.initialize();

        Calendar dueDate = Calendar.getInstance();
        dueDate.add(Calendar.MONTH, 6); // XXX PREF Due Date

        Shipment shipment = new Shipment();
        shipment.initialize();

        // Get Defaults for Certain fields
        //SpecifyAppContextMgr appContextMgr     = (SpecifyAppContextMgr)AppContextMgr.getInstance();

        // Comment out defaults for now until we can manage them
        //PickListItemIFace    defShipmentMethod = appContextMgr.getDefaultPickListItem("ShipmentMethod", getResourceString("SHIPMENT_METHOD"));
        //if (defShipmentMethod != null)
        //{
        //     shipment.setShipmentMethod(defShipmentMethod.getValue());
        //}

        //FormDataObjIFace shippedBy = appContextMgr.getDefaultObject(Agent.class, "ShippedBy", getResourceString("SHIPPED_BY"), true, false);
        //if (shippedBy != null)
        //{
        //    shipment.setShippedBy((Agent)shippedBy);
        //}

        if (infoRequest != null && infoRequest.getAgent() != null) {
            shipment.setShippedTo(infoRequest.getAgent());
        }

        gift.addReference(shipment, "shipments");
    } else {
        gift = existingGift;
    }

    Hashtable<Integer, GiftPreparation> prepToGiftPrepHash = null;
    if (existingGift != null) {
        prepToGiftPrepHash = new Hashtable<Integer, GiftPreparation>();
        for (GiftPreparation lp : existingGift.getGiftPreparations()) {
            prepToGiftPrepHash.put(lp.getPreparation().getId(), lp);
        }
    }

    DataProviderSessionIFace session = null;
    try {
        session = DataProviderFactory.getInstance().createSession();

        for (Integer prepId : prepsHash.keySet()) {
            Preparation prep = session.get(Preparation.class, prepId);
            Integer count = prepsHash.get(prepId);
            if (prepToGiftPrepHash != null) {
                GiftPreparation gp = prepToGiftPrepHash.get(prep.getId());
                if (gp != null) {
                    int lpCnt = gp.getQuantity();
                    lpCnt += count;
                    gp.setQuantity(lpCnt);
                    //System.err.println("Adding "+count+"  to "+lp.hashCode());
                    continue;
                }
            }

            GiftPreparation gpo = new GiftPreparation();
            gpo.initialize();
            gpo.setPreparation(prep);
            gpo.setQuantity(count);
            gpo.setGift(gift);
            gift.getGiftPreparations().add(gpo);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(InteractionsTask.class, ex);

    } finally {
        if (session != null) {
            session.close();
        }
    }

    if (existingGift == null) {
        if (srcViewable != null) {
            srcViewable.setNewObject(gift);

        } else {
            DataEntryTask dataEntryTask = (DataEntryTask) TaskMgr.getTask(DataEntryTask.DATA_ENTRY);
            if (dataEntryTask != null) {
                DBTableInfo giftTableInfo = DBTableIdMgr.getInstance().getInfoById(gift.getTableId());
                dataEntryTask.openView(this, null, giftTableInfo.getDefaultFormName(), "edit", gift, true);
            }
        }
    } else {
        CommandDispatcher.dispatch(new CommandAction(INTERACTIONS, "REFRESH_GIFT_PREPS", gift));
    }
}