Example usage for java.lang String compareToIgnoreCase

List of usage examples for java.lang String compareToIgnoreCase

Introduction

In this page you can find the example usage for java.lang String compareToIgnoreCase.

Prototype

public int compareToIgnoreCase(String str) 

Source Link

Document

Compares two strings lexicographically, ignoring case differences.

Usage

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

private boolean isNull(String s) {
    if (s == null)
        return true;
    s = s.trim();//from  w  w  w. j  a v  a2s.  c  o m
    if (s.length() == 0)
        return true;
    if (s.compareTo("") == 0)
        return true;
    if (s.compareToIgnoreCase("null") == 0)
        return true;
    return false;
}

From source file:de.juwimm.cms.remote.EditionServiceSpringImpl.java

private void createDeployFinishedTask(String message, EditionHbm edition) {
    if (log.isDebugEnabled())
        log.debug("start createDeployFinishedTask");
    if (log.isDebugEnabled() && message != null)
        log.debug("parameter message: " + message);
    if (log.isDebugEnabled() && edition != null)
        log.debug("parameter edition(id): " + edition.getEditionId());
    TaskHbm finish = TaskHbm.Factory.newInstance();
    finish.setComment(message);/*from   w  w  w.jav a 2  s .  co m*/
    finish.setCreationDate(new Date().getTime());
    finish.setReceiverRole("deploy");
    finish.setSender(edition.getCreator());
    finish.setUnit(getUnitHbmDao().load(edition.getUnitId()));
    finish.setTaskType(Constants.TASK_SYSTEMMESSAGE_INFORMATION);
    if (message.compareToIgnoreCase("ImportSuccessful") == 0) {
        message = "Edition " + edition.getComment() + " (" + edition.getEditionId()
                + ") has been deployed successfully.";
    } else {
        message = "Edition " + edition.getComment() + " (" + edition.getEditionId()
                + ") could not be deployed. Please contact your administrator.";
    }
    getTaskHbmDao().create(finish);
    edition.setDeployStatus("Finished".getBytes());
    getEditionHbmDao().update(edition);
    if (log.isDebugEnabled())
        log.debug("end createDeployFinishedTask");
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

private void initializeSortParameters() {
    _propertyLocalNameListHashMap = new HashMap();
    try {//from  w  w w. ja v  a  2 s  .  co m
        NCItBrowserProperties properties = NCItBrowserProperties.getInstance();
        String sort_str = properties.getProperty(NCItBrowserProperties.SORT_BY_SCORE);
        _sort_by_pt_only = true;
        _apply_sort_score = true;
        if (sort_str != null) {
            if (sort_str.compareTo("false") == 0) {
                _apply_sort_score = false;
            } else if (sort_str.compareToIgnoreCase("all") == 0) {
                _sort_by_pt_only = false;
            }
        }

    } catch (Exception ex) {

    }
}

From source file:org.etudes.mneme.impl.SubmissionServiceImpl.java

/**
 * Get the submissions to assessments in this context made by this user. Consider:
 * <ul>/*from   w ww  .j a  v a  2 s . c  om*/
 * <li>published and valid assessments (if filtering)</li>
 * <li>assessments in this context</li>
 * <li>assessments this user can submit to and have submitted to</li>
 * <li>the one (of many for this user) submission that will be the official (graded) (depending on the assessment settings, and submission time and score)</li>
 * </ul>
 * 
 * @param context
 *        The context to use.
 * @param userId
 *        The user id - if null, use the current user.
 * @param sortParam
 *        The sort order.
 * @param filter
 *        - if true, filter away invalid and unpublished, else include them.
 * @return A List<Submission> of the submissions that are the official submissions for assessments in the context by this user, sorted.
 */
protected List<Submission> getUserContextSubmissions(String context, String userId,
        GetUserContextSubmissionsSort sortParam, boolean filter) {
    if (context == null)
        throw new IllegalArgumentException();
    if (userId == null)
        userId = sessionManager.getCurrentSessionUserId();
    if (sortParam == null)
        sortParam = GetUserContextSubmissionsSort.title_a;
    final GetUserContextSubmissionsSort sort = sortParam;
    Date asOf = new Date();

    if (M_log.isDebugEnabled())
        M_log.debug("getUserContextSubmissions: context: " + context + " userId: " + userId + ": " + sort);

    // if we are in a test drive situation, or not filtering, use unpublished as well
    Boolean publishedOnly = Boolean.TRUE;
    Boolean skipHidden = Boolean.TRUE;
    if (securityService.checkSecurity(userId, MnemeService.MANAGE_PERMISSION, context)
            && (!securityService.checkSecurity(userId, MnemeService.SUBMIT_PERMISSION, context))) {
        publishedOnly = Boolean.FALSE;
        skipHidden = Boolean.FALSE;
    } else if (!filter) {
        publishedOnly = Boolean.FALSE;
        skipHidden = Boolean.FALSE;
    }

    // read all the submissions for this user in the context
    List<SubmissionImpl> all = this.storage.getUserContextSubmissions(context, userId, publishedOnly);

    // filter out invalid assessments
    if (filter) {

        for (Iterator i = all.iterator(); i.hasNext();) {
            Submission s = (Submission) i.next();
            if (!s.getAssessment().getIsValid()) {
                i.remove();
            } else {
                if (skipHidden) {
                    Date currentDate = new java.util.Date();
                    if (s.getAssessment().getDates().getHideUntilOpen() != null
                            && s.getAssessment().getDates().getHideUntilOpen()
                            && s.getAssessment().getDates().getOpenDate() != null
                            && s.getAssessment().getDates().getOpenDate().after(currentDate)) {
                        i.remove();
                    }
                }
            }
        }
    }

    // get all the assessments for this context
    List<Assessment> assessments = this.assessmentService.getContextAssessments(context,
            AssessmentService.AssessmentsSort.title_a, publishedOnly);

    // if any valid (or, if not filtering, any at all) assessment is not represented in the submissions we found, add an empty submission for it
    for (Assessment a : assessments) {
        if (filter && (!a.getIsValid()))
            continue;

        boolean found = false;
        for (Submission s : all) {
            if (s.getAssessment().equals(a)) {
                found = true;
                break;
            }
        }

        if (!found) {
            SubmissionImpl s = this.getPhantomSubmission(userId, a);
            all.add(s);
        }
    }
    if (filter && skipHidden) {
        for (Iterator i = all.iterator(); i.hasNext();) {
            SubmissionImpl s = (SubmissionImpl) i.next();
            Date currentDate = new java.util.Date();
            if (s.getAssessment().getDates().getHideUntilOpen() != null
                    && s.getAssessment().getDates().getHideUntilOpen()
                    && s.getAssessment().getDates().getOpenDate() != null
                    && s.getAssessment().getDates().getOpenDate().after(currentDate)) {
                i.remove();
            }
        }
    }

    // sort
    // status sorts first by due date descending, then status final sorting is done in the service
    Collections.sort(all, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            int rv = 0;
            switch (sort) {
            case title_a: {
                String s0 = StringUtil.trimToZero(((Submission) arg0).getAssessment().getTitle());
                String s1 = StringUtil.trimToZero(((Submission) arg1).getAssessment().getTitle());
                rv = s0.compareToIgnoreCase(s1);
                break;
            }
            case title_d: {
                String s0 = StringUtil.trimToZero(((Submission) arg0).getAssessment().getTitle());
                String s1 = StringUtil.trimToZero(((Submission) arg1).getAssessment().getTitle());
                rv = -1 * s0.compareToIgnoreCase(s1);
                break;
            }
            case type_a: {
                rv = ((Submission) arg0).getAssessment().getType().getSortValue()
                        .compareTo(((Submission) arg1).getAssessment().getType().getSortValue());
                break;
            }
            case type_d: {
                rv = -1 * ((Submission) arg0).getAssessment().getType().getSortValue()
                        .compareTo(((Submission) arg1).getAssessment().getType().getSortValue());
                break;
            }
            case published_a: {
                rv = ((Submission) arg0).getAssessment().getPublished()
                        .compareTo(((Submission) arg1).getAssessment().getPublished());
                break;
            }
            case published_d: {
                rv = -1 * ((Submission) arg0).getAssessment().getPublished()
                        .compareTo(((Submission) arg1).getAssessment().getPublished());
                break;
            }
            case dueDate_a: {
                // no due date sorts high
                if (((Submission) arg0).getAssessment().getDates().getDueDate() == null) {
                    if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                        rv = 0;
                        break;
                    }
                    rv = 1;
                    break;
                }
                if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                    rv = -1;
                    break;
                }
                rv = ((Submission) arg0).getAssessment().getDates().getDueDate()
                        .compareTo(((Submission) arg1).getAssessment().getDates().getDueDate());
                break;
            }
            case dueDate_d:
            case status_a:
            case status_d: {
                // no due date sorts high
                if (((Submission) arg0).getAssessment().getDates().getDueDate() == null) {
                    if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                        rv = 0;
                        break;
                    }
                    rv = -1;
                    break;
                }
                if (((Submission) arg1).getAssessment().getDates().getDueDate() == null) {
                    rv = 1;
                    break;
                }
                rv = -1 * ((Submission) arg0).getAssessment().getDates().getDueDate()
                        .compareTo(((Submission) arg1).getAssessment().getDates().getDueDate());
                break;
            }
            }

            return rv;
        }
    });

    // see if any needs to be completed based on time limit or dates
    checkAutoComplete(all, asOf);

    // pick one for each assessment - the one in progress, or the official complete one
    List<Submission> official = officializeByAssessment(all);

    // // if sorting by due date, fix it so null due dates are LARGE not SMALL
    // if (sort == GetUserContextSubmissionsSort.dueDate_a || sort == GetUserContextSubmissionsSort.dueDate_d
    // || sort == GetUserContextSubmissionsSort.status_a || sort == GetUserContextSubmissionsSort.status_d)
    // {
    // // pull out the null date entries
    // List<Submission> nulls = new ArrayList<Submission>();
    // for (Iterator i = official.iterator(); i.hasNext();)
    // {
    // Submission s = (Submission) i.next();
    // if (s.getAssessment().getDates().getDueDate() == null)
    // {
    // nulls.add(s);
    // i.remove();
    // }
    // }
    //
    // // for ascending, treat the null dates as LARGE so put them at the end
    // if ((sort == GetUserContextSubmissionsSort.dueDate_a) || (sort == GetUserContextSubmissionsSort.status_d))
    // {
    // official.addAll(nulls);
    // }
    //
    // // for descending, (all status is first sorted date descending) treat the null dates as LARGE so put them at the beginning
    // else
    // {
    // nulls.addAll(official);
    // official.clear();
    // official.addAll(nulls);
    // }
    // }

    // if sorting by status, do that sort
    if (sort == GetUserContextSubmissionsSort.status_a || sort == GetUserContextSubmissionsSort.status_d) {
        official = sortByAssessmentSubmissionStatus((sort == GetUserContextSubmissionsSort.status_d), official);
    }

    return official;
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByName(String scheme, String version, String matchText,
        String source, String matchAlgorithm, boolean ranking, int maxToReturn, NameSearchType nameSearchType) {
    if (matchText == null || matchText.length() == 0)
        return null;

    matchText = matchText.trim();//  www.  ja v  a2  s  .  c  om
    if (matchAlgorithm.compareToIgnoreCase("startsWith") == 0) {
        // No literalStartsWith support
    } else if (matchAlgorithm.compareToIgnoreCase("contains") == 0) { // p11.1-q11.1
                                                                      // /100{WBC}
                                                                      // matchAlgorithm = CONTAIN_SEARCH_ALGORITHM;
        matchAlgorithm = findBestContainsAlgorithm(matchText);
        // _logger.debug("algorithm: " + matchAlgorithm);
    }

    ResolvedConceptReferencesIterator iterator = null;
    if (nameSearchType == NameSearchType.All || nameSearchType == NameSearchType.Name) {
        CodedNodeSet cns = null;
        CodedNodeSet.PropertyType[] propertyTypes = new CodedNodeSet.PropertyType[1];
        propertyTypes[0] = PropertyType.PRESENTATION;

        try {
            LexBIGService lbSvc = new RemoteServerUtil().createLexBIGService();
            if (lbSvc == null) {
                _logger.warn("lbSvc = null");
                return null;
            }
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            if (version != null)
                versionOrTag.setVersion(version);

            cns = lbSvc.getNodeSet(scheme, versionOrTag, null);
            if (cns == null) {
                _logger.warn("cns = null");
                return null;
            }

            // LocalNameList contextList = null;
            try {
                LocalNameList sourceList = null;
                if (source != null && source.compareToIgnoreCase("ALL") != 0) {
                    sourceList = new LocalNameList();
                    sourceList.addEntry(source);
                }

                cns = cns.restrictToMatchingDesignations(matchText, SearchDesignationOption.ALL, matchAlgorithm,
                        null);
                cns = cns.restrictToProperties(null, propertyTypes, sourceList, null, null);

            } catch (Exception ex) {
                return null;
            }

            LocalNameList restrictToProperties = null;// new
                                                      // LocalNameList();
            LocalNameList propertyNames = Constructors.createLocalNameList("Semantic_Type");
            // boolean resolveConcepts = true; // Semantic_Type is no longer
            // required.

            SortOptionList sortCriteria = null;
            boolean resolveConcepts = true;
            LocalNameList filterOptions = null;
            propertyTypes = null;
            try {
                try {
                    long ms = System.currentTimeMillis(), delay = 0;
                    cns = restrictToSource(cns, source);
                    // iterator = cns.resolve(sortCriteria, propertyNames,
                    // restrictToProperties, null, resolveConcepts);
                    iterator = cns.resolve(sortCriteria, filterOptions, propertyNames, propertyTypes,
                            resolveConcepts);
                    /*
                     * Debug.println("cns.resolve delay ---- Run time (ms): "
                     * + (delay = System.currentTimeMillis() - ms) +
                     * " -- matchAlgorithm " + matchAlgorithm);
                     */
                    // DBG.debugDetails(delay, "cns.resolve",
                    // "searchByName, CodedNodeSet.resolve");
                } catch (Exception e) {
                    _logger.error("ERROR: cns.resolve throws exceptions.");
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                return null;
            }

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    if (nameSearchType == NameSearchType.All || nameSearchType == NameSearchType.Code) {
        try {
            int size = iterator != null ? iterator.numberRemaining() : 0;
            if (size == 0) {
                iterator = matchConceptCode(scheme, version, matchText, source, CODE_SEARCH_ALGORITHM);
            }
            size = iterator.numberRemaining();
            if (size == 0) {
                iterator = findConceptWithSourceCodeMatching(scheme, version, source, matchText, maxToReturn,
                        true);
            }
            // Find ICD9CM concepts by code
            size = iterator.numberRemaining();
            if (size < 20) {
                // heuristic rule (if the number of matches is large,
                // then it's less likely that the matchText is a code)
                Vector w = new Vector();
                w.add(iterator);
                ResolvedConceptReferencesIterator itr1 = matchConceptCode(scheme, version, matchText, source,
                        CODE_SEARCH_ALGORITHM);
                if (itr1 != null)
                    w.add(itr1);
                ResolvedConceptReferencesIterator itr2 = findConceptWithSourceCodeMatching(scheme, version,
                        source, matchText, maxToReturn, true);
                if (itr2 != null)
                    w.add(itr2);
                iterator = getResolvedConceptReferencesIteratorUnion(scheme, version, w);
            }
        } catch (Exception e) {
        }
    }
    return new ResolvedConceptReferencesIteratorWrapper(iterator);
}

From source file:it.fub.jardin.server.DbUtils.java

public int importFile(MailUtility mailUtility, final Credentials credentials, final int resultsetId,
        final File importFile, final String ts, final String fs, final String tipologia, final String type,
        final String condition, String operazione) throws HiddenException, VisibleException, SQLException {

    // this.getUser(credentials);

    int opCode = 0;
    BufferedReader in = null;/*from  w  ww . j av a2 s.  c o  m*/

    try {
        in = new BufferedReader(new FileReader(importFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new HiddenException("file " + importFile.getName() + " non trovato");
    }

    String recordLine;
    String[] columns = null;
    List<BaseModelData> recordList = new ArrayList<BaseModelData>();
    ArrayList<String> regExSpecialChars = new ArrayList<String>();
    regExSpecialChars.add("\\");
    regExSpecialChars.add("^");
    regExSpecialChars.add("$");
    regExSpecialChars.add("{");
    regExSpecialChars.add("}");
    regExSpecialChars.add("[");
    regExSpecialChars.add("}");
    regExSpecialChars.add("(");
    regExSpecialChars.add(")");
    regExSpecialChars.add(".");
    regExSpecialChars.add("*");
    regExSpecialChars.add("+");
    regExSpecialChars.add("?");
    regExSpecialChars.add("|");
    regExSpecialChars.add("<");
    regExSpecialChars.add(">");
    regExSpecialChars.add("-");
    regExSpecialChars.add("&");

    try {
        // recordLine = in.readLine();
        if (tipologia.compareToIgnoreCase("fix") == 0) {
            // TODO gestione campo a lunghezza fissa da db!
        } else {

        }

        // recordLine = in.readLine();
        CSVParser csvp = new CSVParser(in);
        String delim = new String(fs);
        String quote = new String(ts);
        String commentDelims = new String("#");
        csvp.changeDelimiter(delim.charAt(0));
        csvp.changeQuote(quote.charAt(0));
        csvp.setCommentStart(commentDelims);

        String[] t = null;
        columns = csvp.getLine(); // la prima riga deve contenere i nomi delle
        // colonne

        ArrayList<String> colsCheck = new ArrayList<String>();
        for (String col : columns) {
            boolean present = false;
            HashMap<Integer, String> rsFieldList = getResultsetFields(resultsetId);

            if (rsFieldList.containsValue(col)) {
                present = true;
            }
            if (!present) {
                colsCheck.add(col);
            }
        }

        if (colsCheck.size() != 0) {
            throw new VisibleException("Attenzione!!! Colonna '" + colsCheck.get(0) + "' non riconosciuta");
        }

        int lineFailed = 0;
        try {
            while ((t = csvp.getLine()) != null) {
                lineFailed++;
                BaseModelData bm = new BaseModelData();
                // System.out.println("lunghezza riga: " + t.length);
                // System.out.print("" + csvp.lastLineNumber() + ":");
                for (int i = 0; i < t.length; i++) {
                    // System.out.println("valorizzazione campo: " +
                    // columns[i] + " = "
                    // + t[i]);
                    bm.set(columns[i], t[i]);
                    // System.out.println("\"" + t[i] + "\";");
                }
                recordList.add(bm);
            }
        } catch (ArrayIndexOutOfBoundsException ex) {
            // Log.warn("Troppi campi nel file: " + t.length + " alla riga "
            // + (lineFailed + 1), ex);
            throw new VisibleException("Troppi campi nel file: " + t.length + " alla riga " + (lineFailed + 1));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new HiddenException("impossibile leggere il file: " + importFile.getName());
    }
    if (type.compareToIgnoreCase(UploadDialog.TYPE_INSERT) == 0) {
        opCode = this.setObjects(resultsetId, recordList, credentials.getUsername());
    } else {
        opCode = this.updateObjects(resultsetId, recordList, condition, credentials.getUsername());
    }
    if (opCode > 0) {
        JardinLogger.info(credentials.getUsername(), "Objects successfull setted for resultset " + resultsetId);
        try {
            this.notifyChanges(mailUtility, resultsetId, recordList, operazione, credentials.getUsername());
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else
        JardinLogger.error(credentials.getUsername(),
                "Error in setting objects for resultset " + resultsetId + "!");
    return opCode;
}

From source file:com.ah.ui.actions.BaseAction.java

public List<HmDomain> getReassignDomains() {
    List<HmDomain> reassignDomains = new ArrayList<HmDomain>();
    try {/*from  w  ww  .j  a v a  2s .  c om*/
        List<HmDomain> domains = getSwitchDomains();
        for (HmDomain domain : domains) {
            if (HmDomain.HOME_DOMAIN.equals(domain.getDomainName())) {
                continue;
            }
            reassignDomains.add(domain);
        }
    } catch (Exception e) {
    }
    // order by name
    Collections.sort(reassignDomains, new Comparator<HmDomain>() {
        @Override
        public int compare(HmDomain o1, HmDomain o2) {
            String n1 = o1.getDomainName();
            String n2 = o2.getDomainName();
            return n1.compareToIgnoreCase(n2);
        }
    });
    return reassignDomains;
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByName(Vector<String> schemes, Vector<String> versions,
        String matchText, String source, String matchAlgorithm, boolean ranking, int maxToReturn) {
    try {//from ww w. j  a  v a  2  s  .c  o m
        if (matchText == null || matchText.trim().length() == 0)
            return null;

        Utils.StopWatch stopWatch = new Utils.StopWatch();
        Utils.StopWatch stopWatchTotal = new Utils.StopWatch();
        boolean debug_flag = false;

        matchText = matchText.trim();
        _logger.debug("searchByName ... " + matchText);

        // p11.1-q11.1  // /100{WBC}
        if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
            // matchAlgorithm = Constants.CONTAIN_SEARCH_ALGORITHM;
            matchAlgorithm = findBestContainsAlgorithm(matchText);
        }

        LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
        Vector<CodedNodeSet> cns_vec = new Vector<CodedNodeSet>();
        for (int i = 0; i < schemes.size(); i++) {
            stopWatch.start();
            String scheme = (String) schemes.elementAt(i);
            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            String version = (String) versions.elementAt(i);
            if (version != null)
                versionOrTag.setVersion(version);

            CodedNodeSet cns = getNodeSet(lbSvc, scheme, versionOrTag);
            if (cns != null) {
                cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null);
                cns = restrictToSource(cns, source);
            }

            if (cns != null)
                cns_vec.add(cns);
            if (debug_flag)
                _logger.debug("Restricting CNS on " + scheme + " delay (msec): " + stopWatch.duration());
        }

        SortOptionList sortCriteria = null;
        LocalNameList restrictToProperties = new LocalNameList();
        boolean resolveConcepts = false;
        if (ranking) {
            sortCriteria = null;// Constructors.createSortOptionList(new
                                // String[]{"matchToQuery"});
        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
        }

        stopWatch.start();
        if (debug_flag)
            _logger.debug("Calling cns.resolve to resolve the union CNS ... ");
        ResolvedConceptReferencesIterator iterator = new QuickUnionIterator(cns_vec, sortCriteria, null,
                restrictToProperties, null, resolveConcepts);
        if (debug_flag)
            _logger.debug("Resolve CNS union delay (msec): " + stopWatch.duration());

        if (iterator.numberRemaining() <= 0) {
            stopWatch.start();
            iterator = matchConceptCode(schemes, versions, matchText, source, CODE_SEARCH_ALGORITHM);
            if (debug_flag)
                _logger.debug("Match concept code delay (msec): " + stopWatch.duration());
        }

        _logger.debug("Total search delay (msec): " + stopWatchTotal.duration());
        return new ResolvedConceptReferencesIteratorWrapper(iterator);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.ah.ui.actions.BaseAction.java

public List<HmDomain> getSwitchDomainData() {
    if (null == userContext || !userContext.isSuperUser()) {
        return new ArrayList<HmDomain>();
    }//from   w  w w  .  jav  a  2  s  .  c o  m
    List<HmDomain> domains = getSwitchDomains();
    try {
        Long switchDomainId = null;
        if (userContext != null && userContext.getSwitchDomain() != null) {
            switchDomainId = userContext.getSwitchDomain().getId();
        }
        for (HmDomain domain : domains) {
            if (domain.getId().equals(switchDomainId)) {
                domain.setSelected(true);
            } else {
                domain.setSelected(false);
            }
        }
    } catch (Exception e) {
        log.error("getSwitchDomainData", e.getMessage());
    }

    // filter domain if user is vad admin
    if (userContext != null && userContext.isVadAdmin()) {
        for (Iterator<HmDomain> iterator = domains.iterator(); iterator.hasNext();) {
            HmDomain domain = iterator.next();

            // filter domain which not belong to this vad admin
            if (domain.getPartnerId() == null || !domain.getPartnerId().equals(userContext.getCustomerId())) {
                iterator.remove();
            }
        }
    }
    HmDomain homeDomain = null;
    for (int i = 0; i < domains.size(); i++) {
        if (HmDomain.HOME_DOMAIN.equals(domains.get(i).getDomainName())) {
            homeDomain = domains.remove(i);
            break;
        }
    }
    // order by name
    Collections.sort(domains, new Comparator<HmDomain>() {
        @Override
        public int compare(HmDomain o1, HmDomain o2) {
            String n1 = o1.getDomainName();
            String n2 = o2.getDomainName();
            return n1.compareToIgnoreCase(n2);
        }
    });
    if (null != homeDomain) {
        domains.add(0, homeDomain);
    }
    return domains;
}

From source file:gov.nih.nci.evs.browser.utils.SearchUtils.java

public ResolvedConceptReferencesIteratorWrapper searchByNameAndCode(Vector<String> schemes,
        Vector<String> versions, String matchText, String source, String matchAlgorithm, boolean ranking,
        int maxToReturn) {
    try {/*from   w w w.ja v a  2s .  co  m*/
        if (matchText == null || matchText.trim().length() == 0)
            return null;

        Utils.StopWatch stopWatch = new Utils.StopWatch();
        Utils.StopWatch stopWatchTotal = new Utils.StopWatch();
        boolean debug_flag = false;

        matchText = matchText.trim();
        _logger.debug("searchByName ... " + matchText);

        // p11.1-q11.1  // /100{WBC}
        if (matchAlgorithm.compareToIgnoreCase("contains") == 0) {
            // matchAlgorithm = Constants.CONTAIN_SEARCH_ALGORITHM;
            matchAlgorithm = findBestContainsAlgorithm(matchText);
        }

        LexBIGService lbSvc = RemoteServerUtil.createLexBIGService();
        Vector<CodedNodeSet> cns_vec = new Vector<CodedNodeSet>();

        for (int i = 0; i < schemes.size(); i++) {
            stopWatch.start();
            String scheme = (String) schemes.elementAt(i);

            CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
            String version = (String) versions.elementAt(i);
            if (version != null)
                versionOrTag.setVersion(version);

            //Name search
            CodedNodeSet cns = getNodeSet(lbSvc, scheme, versionOrTag);
            if (cns != null) {
                cns = cns.restrictToMatchingDesignations(matchText, null, matchAlgorithm, null);
                cns = restrictToSource(cns, source);
            }
            if (cns != null)
                cns_vec.add(cns);

            CodedNodeSet.PropertyType[] propertyTypes = null;
            LocalNameList sourceList = null;
            LocalNameList contextList = null;
            NameAndValueList qualifierList = null;

            // concept code match:

            /*
            CodedNodeSet cns_code = getNodeSet(lbSvc, scheme, versionOrTag);
                    
            if (source != null) {
            cns_code = restrictToSource(cns_code, source);
            }
            CodedNodeSet.PropertyType[] propertyTypes = null;
            LocalNameList sourceList = null;
            LocalNameList contextList = null;
            NameAndValueList qualifierList = null;
            cns_code = cns_code.restrictToMatchingProperties(ConvenienceMethods
            .createLocalNameList(new String[] { "conceptCode" }),
            propertyTypes, sourceList, contextList, qualifierList,
            matchText, CODE_SEARCH_ALGORITHM, null);
            //matchText, "exactMatch", null);
                    
            */
            String code = matchText;
            CodedNodeSet cns_code = getCodedNodeSetContrainingCode(lbSvc, scheme, versionOrTag, code);

            if (cns_code != null && includeInQuickUnion(cns_code)) {
                cns_vec.add(cns_code);
            }

            //if (cns_code != null) cns_vec.add(cns_code);

            // source code match:
            CodedNodeSet cns_src_code = null;

            if (DataUtils.hasSourceCodeQualifier(scheme)) {
                String sourceAbbr = source;

                qualifierList = null;
                if (code != null && code.compareTo("") != 0) {
                    qualifierList = new NameAndValueList();
                    NameAndValue nv = new NameAndValue();
                    nv.setName("source-code");
                    nv.setContent(code);
                    qualifierList.addNameAndValue(nv);
                }

                LocalNameList propertyLnL = null;
                // sourceLnL
                Vector<String> w2 = new Vector<String>();
                LocalNameList sourceLnL = null;

                if (sourceAbbr != null
                        && (sourceAbbr.compareTo("*") == 0 || sourceAbbr.compareToIgnoreCase("ALL") == 0)) {
                    sourceLnL = null;
                } else if (sourceAbbr != null) {
                    w2.add(sourceAbbr);
                    sourceLnL = vector2LocalNameList(w2);
                }

                SortOptionList sortCriteria = null;// Constructors.createSortOptionList(new
                // String[]{"matchToQuery", "code"});
                contextList = null;

                try {
                    cns_src_code = getNodeSet(lbSvc, scheme, versionOrTag);
                    CodedNodeSet.PropertyType[] types = new PropertyType[] { PropertyType.PRESENTATION };
                    cns_src_code = cns_src_code.restrictToProperties(propertyLnL, types, sourceLnL, contextList,
                            qualifierList);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (cns_src_code != null)
                cns_vec.add(cns_src_code);

        }

        if (debug_flag)
            _logger.debug("searchByNameAndCode QuickUnion delay (msec): " + stopWatch.duration());

        SortOptionList sortCriteria = null;
        LocalNameList restrictToProperties = new LocalNameList();
        boolean resolveConcepts = false;
        if (ranking) {
            sortCriteria = null;// Constructors.createSortOptionList(new
                                // String[]{"matchToQuery"});
        } else {
            sortCriteria = Constructors.createSortOptionList(new String[] { "entityDescription" }); // code
            _logger.debug("*** Sort alphabetically...");
        }

        stopWatch.start();
        if (debug_flag)
            _logger.debug("Calling cns.resolve to resolve the union CNS ... ");
        ResolvedConceptReferencesIterator iterator = new QuickUnionIterator(cns_vec, sortCriteria, null,
                restrictToProperties, null, resolveConcepts);
        if (debug_flag)
            _logger.debug("Resolve CNS union delay (msec): " + stopWatch.duration());

        _logger.debug("Total search delay (msec): " + stopWatchTotal.duration());
        return new ResolvedConceptReferencesIteratorWrapper(iterator);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}