Example usage for org.apache.commons.lang StringUtils containsIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils containsIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils containsIgnoreCase.

Prototype

public static boolean containsIgnoreCase(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String irrespective of case, handling null.

Usage

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * @param settings//ww  w.j  av  a 2s.c om
 * @return results, if the settings.termUri is populated. This includes gene uris.
 */
private Map<Class<?>, List<SearchResult>> ontologyUriSearch(SearchSettings settings) {
    Map<Class<?>, List<SearchResult>> results = new HashMap<Class<?>, List<SearchResult>>();

    // 1st check to see if the query is a URI (from an ontology).
    // Do this by seeing if we can find it in the loaded ontologies.
    // Escape with general utilities because might not be doing a lucene backed search. (just a hibernate one).
    String termUri = settings.getTermUri();

    if (StringUtils.isBlank(termUri)) {
        termUri = settings.getQuery();
    }

    if (!termUri.startsWith("http://")) {
        return results;
    }

    OntologyTerm matchingTerm = null;
    String uriString = null;

    uriString = StringEscapeUtils.escapeJava(StringUtils.strip(termUri));

    if (StringUtils.containsIgnoreCase(uriString, NCBI_GENE)) {
        // Perhaps is a valid gene URL. Want to search for the gene in gemma.
        // 1st get objects tagged with the given gene identifier
        Collection<Class<?>> classesToFilterOn = new HashSet<Class<?>>();
        classesToFilterOn.add(ExpressionExperiment.class);

        Collection<Characteristic> foundCharacteristics = characteristicService.findByUri(classesToFilterOn,
                uriString);
        Map<Characteristic, Object> parentMap = characteristicService.getParents(classesToFilterOn,
                foundCharacteristics);

        Collection<SearchResult> characteristicOwnerResults = filterCharacteristicOwnersByClass(
                classesToFilterOn, parentMap);

        if (!characteristicOwnerResults.isEmpty()) {
            results.put(ExpressionExperiment.class, new ArrayList<SearchResult>());
            results.get(ExpressionExperiment.class).addAll(characteristicOwnerResults);
        }

        if (settings.getSearchGenes()) {
            // Get the gene
            String ncbiAccessionFromUri = StringUtils.substringAfterLast(uriString, "/");
            Gene g = null;

            try {
                g = geneService.findByNCBIId(Integer.parseInt(ncbiAccessionFromUri));
            } catch (NumberFormatException e) {
                // ok
            }

            if (g != null) {
                results.put(Gene.class, new ArrayList<SearchResult>());
                results.get(Gene.class).add(new SearchResult(g));
            }
        }
        return results;
    }

    /*
     * Not searching for a gene.
     */
    Collection<SearchResult> matchingResults;
    Collection<Class<?>> classesToSearch = new HashSet<Class<?>>();
    if (settings.getSearchExperiments()) {
        classesToSearch.add(ExpressionExperiment.class); // not sure ...
        classesToSearch.add(BioMaterial.class);
        classesToSearch.add(FactorValue.class);
    }

    // this doesn't seem to be implemented yet, LiteratureEvidence and GenericEvidence aren't handled in the
    // fillValueObjects method downstream
    /*
     * if ( settings.getSearchPhenotypes() ) { classesToSearch.add( PhenotypeAssociationImpl.class ); }
     */
    matchingTerm = this.ontologyService.getTerm(uriString);
    if (matchingTerm == null || matchingTerm.getUri() == null) {
        /*
         * Maybe the ontology isn't loaded. Look anyway.
         */

        Map<Characteristic, Object> parentMap = characteristicService.getParents(classesToSearch,
                characteristicService.findByUri(classesToSearch, uriString));
        matchingResults = filterCharacteristicOwnersByClass(classesToSearch, parentMap);

    } else {

        log.info("Found ontology term: " + matchingTerm);

        // Was a URI from a loaded ontology soo get the children.
        Collection<OntologyTerm> terms2Search4 = matchingTerm.getChildren(true);
        terms2Search4.add(matchingTerm);

        matchingResults = this.databaseCharacteristicExactUriSearchForOwners(classesToSearch, terms2Search4);
    }

    for (SearchResult searchR : matchingResults) {
        if (results.containsKey(searchR.getResultClass())) {
            results.get(searchR.getResultClass()).add(searchR);
        } else {
            List<SearchResult> rs = new ArrayList<SearchResult>();
            rs.add(searchR);
            results.put(searchR.getResultClass(), rs);
        }
    }

    return results;
}

From source file:uk.ac.ebi.bioinvindex.model.HasReferences.java

/**
 * It's like {@link #getXrefs(String)}, but uses a containment criterion
 * /*from ww w . j  a va2 s.  c o m*/
 */
@SuppressWarnings("unchecked")
public List<Xref> getXrefsContaining(final String sourceAcc) {
    return (List<Xref>) CollectionUtils.select(refs, new Predicate() {
        public boolean evaluate(Object xref) {
            ReferenceSource source = ((Xref) xref).getSource();
            if (source == null)
                return false;
            if (sourceAcc == null)
                return source.getAcc() == null;
            return StringUtils.containsIgnoreCase(source.getAcc(), sourceAcc);
        }
    });
}

From source file:uk.ac.ebi.bioinvindex.utils.processing.ProcessingUtils.java

/**
 * Finds the biomaterials that contains a given string in the type. When some material is found, does not further the
 * search downstream if shallowSearch is true. Does not work if you haven't assigned the type to 
 * the materials. When shallowSearch is true takes only the steps from which the end node
 * directly derives. Results are returned in breadth-first fashion. 
 * /* ww  w.  j ava 2 s  . com*/
 */
public static Collection<MaterialNode> findBackwardMaterialNodes(final Node<?, ?> endNode, final String typeStr,
        final boolean shallowSearch) {
    Collection<MaterialNode> result = new HashSet<MaterialNode>();

    Collection<Processing<?, ?>> downStreamProcessings = (Collection<Processing<?, ?>>) endNode
            .getDownstreamProcessings();

    for (Processing<?, ?> downProc : downStreamProcessings) {
        for (Node<?, ?> inNode : downProc.getInputNodes()) {
            if (!(inNode instanceof MaterialNode))
                continue;
            MaterialNode mnode = (MaterialNode) inNode;
            // Add if the current node is of the requested type
            Material inMaterial = mnode.getMaterial();
            MaterialRole inType = inMaterial.getType();
            if (inType != null && StringUtils.containsIgnoreCase(inType.getAcc(), typeStr))
                result.add(mnode);
        }
    }

    if (shallowSearch)
        return result;

    // It's better to return results in Breath-first fashion
    for (Processing<?, ?> downProc : downStreamProcessings)
        for (Node<?, ?> inNode : downProc.getInputNodes())
            result.addAll(findBackwardMaterialNodes(inNode, typeStr, shallowSearch));

    return result;
}

From source file:uk.ac.ebi.bioinvindex.utils.processing.ProcessingUtils.java

/**
 * Finds all the processing steps applying a given protocol
 * /*from ww  w .ja va 2  s.  c om*/
 * @param pname protocol name must contain this (AND search, ignored if null)
 * @param ptype protocol type name must contain this
 * @param shallowSearch when true takes only the steps from which the end node
 * directly derives. 
 * @return
 */
public static Collection<Processing<?, ?>> findBackwardProcessings(final Node<?, ?> endNode, final String ptype,
        final String pname, final boolean shallowSearch) {
    Collection<Processing<?, ?>> result = new HashSet<Processing<?, ?>>();

    Collection<Processing<?, ?>> downStreamProcessings = (Collection<Processing<?, ?>>) endNode
            .getDownstreamProcessings();

    for (Processing<?, ?> downProc : downStreamProcessings) {
        for (ProtocolApplication papp : downProc.getProtocolApplications()) {
            Protocol proto = papp.getProtocol();
            String piname = null, pitypeStr = null;

            if (proto != null) {
                piname = proto.getName();
                ProtocolType pitype = proto.getType();
                if (pitype != null)
                    pitypeStr = pitype.getName();
            }

            if ((pname == null || StringUtils.containsIgnoreCase(piname, pname))
                    && (ptype == null || StringUtils.containsIgnoreCase(pitypeStr, ptype))) {
                result.add(downProc);
                break;
            }
        }
    }

    if (shallowSearch)
        return result;

    // We better return results in Breath-first fashion
    for (Processing<?, ?> downProc : downStreamProcessings)
        for (Node<?, ?> inNode : downProc.getInputNodes())
            result.addAll(findBackwardProcessings(inNode, ptype, pname, shallowSearch));

    return result;
}

From source file:uk.ac.ebi.bioinvindex.utils.processing.ProcessingUtils.java

/**
 * Finds all protocol applications needed to produce a certain end node. Filters by protocol type or protocol name
 * (partial matching supported). When shallowSearch is true takes only the steps from which the end node
 * directly derives. //  w w  w . ja va 2 s  .  c  o  m
 * 
 */
public static Collection<ProtocolApplication> findBackwardProtocolApplications(final Node<?, ?> endNode,
        final String ptype, final String pname, final boolean shallowSearch) {
    Collection<ProtocolApplication> result = new LinkedList<ProtocolApplication>();

    for (Processing<?, ?> proc : findBackwardProcessings(endNode, ptype, pname, shallowSearch))
        for (ProtocolApplication papp : proc.getProtocolApplications()) {
            Protocol proto = papp.getProtocol();
            String piname = null, pitypeStr = null;

            if (proto != null) {
                piname = proto.getName();
                ProtocolType pitype = proto.getType();
                if (pitype != null)
                    pitypeStr = pitype.getName();
            }

            if ((pname == null || StringUtils.containsIgnoreCase(piname, pname))
                    && (ptype == null || StringUtils.containsIgnoreCase(pitypeStr, ptype)))
                result.add(papp);
        }
    return result;

}

From source file:uk.ac.ebi.metabolights.utils.sampletab.SampleTabExporter.java

/**
 * Get additional data from the file, the sample file in ISAcreator is not enough for the sampleDb output
 * @param sampleData/*ww  w. j  av  a2s  .  c o m*/
 * @param study
 * @return TRUE if we managed to get and set the sample data from the s_*.txt file(s)
 */
private boolean setSampleObjectData(SampleData sampleData, Study study) {
    if (sampleData == null || study == null)
        return false; //Must have a valid sampleData object and assay information from the study to add to it.

    //Get additional data from the file, the sample file in ISAcreator is not good enough for the sampleDb
    List<Map<String, String>> additionalFileData = isaTabReader.getAdditionalData(study,
            isaTabReader.getStudyFactors(study));
    for (Map<String, String> columns : additionalFileData) {

        SampleNode samplenode = new SampleNode(); //Per sample row in ISA-tab

        if (columns.containsKey(isaTabReader.SAMPLE_NAME)) {
            String sampleName = columns.get(isaTabReader.SAMPLE_NAME);
            samplenode.setNodeName(sampleName); //The proper name of the sample
        }

        String organism = null;

        if (columns.containsKey(isaTabReader.ORGANISM)) {
            organism = columns.get(isaTabReader.ORGANISM);

            if (organism == null || organism == "")
                continue; //Skip this row

            String termSource = columns.get(isaTabReader.ORGANISM_TERM_SOURCE_REF);
            String termNumber = tools
                    .cleanTermAttributes(columns.get(isaTabReader.ORGANISM_TERM_ACCESSION_NUMBER));

            if (!tools.isInteger(termNumber)) { //Check if the term is a number
                logger.error("Term number from the sample file is not a number or is empty!");
                return false;
            }

            Integer termId = new Integer(termNumber);
            //samplenode.addAttribute(new CharacteristicAttribute(isaTabReader.ORGANISM_HEADER,organism));
            OrganismAttribute organismAttribute = new OrganismAttribute(organism, termSource, termId);
            samplenode.addAttribute(organismAttribute);
        }

        if (columns.containsKey(isaTabReader.ORGANISM_PART)) { //TODO, should also reflect the ontology
            String organismPart = columns.get(isaTabReader.ORGANISM_PART);

            if (organismPart != "") { //The Organism part column is normally present but with an empty string value if no data recorded, ignore this

                boolean addStrain = false;

                for (String subs : subClassification) {
                    if (StringUtils.containsIgnoreCase(organismPart, subs)) {
                        organismPart = cleanStrainName(organismPart, subs); //Remove the 'offending' words
                        addStrain = true;
                        break; //Don't loop through the rest
                    }
                }

                if (!organismPart.equals(organism)) { //QuickFix. Make sure that the Organism Part is different from Organism

                    String orgPartHeader = isaTabReader.ORGANISM_PART_HEADER;

                    if (addStrain)
                        orgPartHeader = "strain or line";

                    samplenode.addAttribute(new CharacteristicAttribute(orgPartHeader, organismPart));
                }

                //Add two new named attributes to capture the ontologies for organism part
                String termSource = columns.get(isaTabReader.ORGPART_TERM_SOURCE_REF);
                NamedAttribute orgPartTermSource = new NamedAttribute(isaTabReader.TERM_SOURCE_REF, termSource);
                samplenode.addAttribute(orgPartTermSource);

                String termNumber = tools
                        .cleanTermAttributes(columns.get(isaTabReader.ORGPART_TERM_ACCESSION_NUMBER));
                NamedAttribute orgPartTermNumber = new NamedAttribute(isaTabReader.TERM_SOURCE_ID, termNumber);
                samplenode.addAttribute(orgPartTermNumber);

            }
        }

        //TODO, add the study design factors as well
        //Check what has been used for study desing in the investigation, then add dynamically as "Comment[other]" on the sample

        List<String> allAttributes = isaTabReader.getStudyFactors(study);
        for (String attribute : allAttributes) {

            if (columns.containsKey(attribute)) {
                CommentAttribute commentAttribute = new CommentAttribute("other", columns.get(attribute));
                //commentAttribute.setAttributeValue(columns.get(attribute));

                String termSourceHeader = "TSI " + attribute;
                if (columns.containsKey(termSourceHeader)) {
                    String termSourceId = columns.get(termSourceHeader);
                    commentAttribute.setTermSourceID(termSourceId);

                    if (tools.isInteger(termSourceId))
                        commentAttribute.setTermSourceIDInteger(new Integer(termSourceId));
                }

                String termSourceRefHeader = "TSR " + attribute;
                if (columns.containsKey(termSourceRefHeader))
                    commentAttribute.setTermSourceREF(columns.get(termSourceRefHeader));

                if (commentAttribute.getAttributeValue() != "")
                    samplenode.addAttribute(commentAttribute);
            }

        }

        try {
            sampleData.scd.addNode(samplenode);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return false;
        }

    }

    return true;
}

From source file:uk.ac.edukapp.renderer.LtiRenderer.java

private void setOwner(WidgetInstance widgetInstance, Map<String, String[]> parameters) {
    boolean isModerator = false;
    if (parameters.get("roles") != null && parameters.get("roles").length > 0) {
        for (String role : BASICLTI_ADMIN_ROLES) {
            if (StringUtils.containsIgnoreCase(parameters.get("roles")[0], role))
                isModerator = true;/*from w  w  w. j  a va2s. c  o m*/
        }
    }
    if (isModerator)
        setPreference(widgetInstance, "moderator", "true");
}