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:org.isatools.isatab.export.sra.SraExportSampleComponent.java

/**
 * Builds a single SRA sample, working only on the sample description and attributes. This is used by
 * {@link #buildSingleExportedSample(MaterialNode)}.
 *
 * @param sampleNode the ISATAB node about the input material. All the ISATAB material types are considered SRA samples
 *                   (there is a tag "Material Role" that have values like bio-source,sample, extract, etc.)
 * @return an instance of the SRA SAMPLE element.
 *///from w  ww  .  j  av a  2  s . com
private SampleType buildSingleExportedSample(MaterialNode sampleNode) {
    Material sample = sampleNode.getMaterial();

    SampleType xsample = SampleType.Factory.newInstance();
    SAMPLENAME xsampleName = SAMPLENAME.Factory.newInstance();

    xsample.setCenterName(centerName);
    xsample.setBrokerName(brokerName);

    String xsampleDescription = StringUtils.trimToEmpty(sample.getSingleAnnotationValue("description"));

    SAMPLEATTRIBUTES sampleAttrs = SAMPLEATTRIBUTES.Factory.newInstance();

    MaterialRole sampleType = sample.getType();

    if (StringUtils.containsIgnoreCase(sampleType.getAcc(), "sample")) {
        xsample.setAlias(sample.getAcc());

        String sampleName = StringUtils.trimToNull(sample.getName());
        if (sampleName != null) {
            // TODO: Common name is a GeneBank identifier and not supported for the moment
            // xsampleName.setCOMMONNAME ( sampleName );
            xsample.setTITLE(sampleName);

        }
    }

    extractNCBITaxonomyInformation(sample, sampleAttrs, xsampleName);

    // Lookup the sample this sample derives from and and collect all their characteristics. We think it makes sense to
    // do that cause we're not sure the sample members (in a pool) will be taken into account
    // by SRA software recipients. Moreover, we merge together biomaterials that are not samples (extracts,
    // labeled extracts).
    //
    Collection<MaterialNode> backwardNodes = ProcessingUtils.findBackwardMaterialNodes(sampleNode, "", false);
    for (MaterialNode backwardNode : backwardNodes) {
        Material backwardMaterial = backwardNode.getMaterial();

        sampleType = backwardMaterial.getType();
        if (StringUtils.trimToNull(xsample.getAlias()) == null
                && StringUtils.containsIgnoreCase(sampleType.getAcc(), "sample")) {
            xsample.setAlias(backwardMaterial.getAcc());

            String sampleName = StringUtils.trimToNull(backwardMaterial.getName());
            if (sampleName != null) {
                // TODO: Common name is a GeneBank identifier and not supported for the moment
                // xsampleName.setCOMMONNAME ( sampleName );
                //               sampleAttrs.addNewSAMPLEATTRIBUTE ();
                //               sampleAttrs.setSAMPLEATTRIBUTEArray ( sampleAttrs.sizeOfSAMPLEATTRIBUTEArray () - 1, 
                //                  buildSampleAttribute ( "Material Name", sampleName, null )
                //               );
                xsample.setTITLE(sampleName);
            }
        }

        extractNCBITaxonomyInformation(backwardMaterial, sampleAttrs, xsampleName);
    }

    // TODO: should we check that xsample.getAlias () is not null?
    //
    xsample.setSAMPLENAME(xsampleName);

    if (sampleAttrs.sizeOfSAMPLEATTRIBUTEArray() > 0) {
        xsample.setSAMPLEATTRIBUTES(sampleAttrs);
    }

    if (xsampleDescription.length() != 0) {
        xsample.setDESCRIPTION(xsampleDescription);
    }

    return xsample;
}

From source file:org.isatools.isatab.export.sra.SraExportSampleComponent.java

private void extractNCBITaxonomyInformation(Material material, SAMPLEATTRIBUTES sampleAttrs,
        SAMPLENAME xsampleName) {/* w ww  . j a  v  a2  s  .c o m*/
    for (CharacteristicValue cvalue : material.getCharacteristicValues()) {
        AttributeType xattr = characteristicValue2SampleAttr(cvalue);

        boolean isOrganismTag = checkCharacteristicValue(cvalue, "(?i)tax|(?i)organism");

        if (xattr != null) {
            if (!isOrganismTag) {
                sampleAttrs.addNewSAMPLEATTRIBUTE();
                sampleAttrs.setSAMPLEATTRIBUTEArray(sampleAttrs.sizeOfSAMPLEATTRIBUTEArray() - 1, xattr);
            }
        }

        // Set the NCBI term if found. TODO: factorize
        for (OntologyTerm oe : cvalue.getOntologyTerms()) {
            ReferenceSource src = oe.getSource();
            if (src == null) {
                break;
            }
            if ((!StringUtils.containsIgnoreCase(src.getDescription(), "NCBI"))
                    || (!StringUtils.containsIgnoreCase(src.getDescription(), "Taxonomy"))) {
                break;
            }
            String taxon = oe.getAcc();
            if (taxon == null) {
                break;
            }
            try {

                log.info("cvalue.getType().getValue()) = " + cvalue.getType().getValue());

                if (isOrganismTag) {
                    xsampleName.setTAXONID(Integer.parseInt(taxon));
                    xsampleName.setSCIENTIFICNAME(oe.getName());
                }

            } catch (NumberFormatException ex) {
                nonRepeatedMessages.add("Invalid NCBI ID '" + taxon + "', ignoring it");
            }
            break; // Only the first one
        }

    } // for ( cvalue )
}

From source file:org.isatools.isatab.export.sra.SraExportSampleComponent.java

/**
 * Attempts to build an SRA pool, starting from the BII owner's node. It assumes that the owner is a
 * sample and tries to see if left nodes are sample too. If not, or if there is more than one level of
 * pooling (not permitted in SRA), files an error message and returns null.
 * <p/>//from   w w w  .  j  a v a 2s. c o m
 * assay is used just to report user messages.
 */
private Set<SampleType> buildExportedPool(MaterialNode poolOwnerNode, Assay assay) {
    Set<SampleType> result = new HashSet<SampleType>();

    String firstLeftType = null;

    for (MaterialNode leftNode : ProcessingUtils.findBackwardMaterialNodes(poolOwnerNode, "", true)) {
        Material leftMat = leftNode.getMaterial();
        MaterialRole leftTypeTerm = leftMat.getType();
        String leftType = leftTypeTerm.getAcc();
        if (StringUtils.containsIgnoreCase(leftType, "sample")) {
            leftType = "sample";
        } else if (StringUtils.containsIgnoreCase(leftType, "source")) {
            leftType = "source";
        } else {
            String msg = MessageFormat.format(
                    "The assay file of type {0} / {1} for study {2} has biomaterials of type {3}"
                            + " before some sample, this is not valid for the SRA format. Please review the ISATAB/SRA formatting"
                            + " guidelines",
                    assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc(),
                    leftTypeTerm.getName());
            nonRepeatedMessages.add(msg);
            log.trace(msg + ". Assay is: " + assay.getAcc());
            return null;
        }
        if (firstLeftType == null) {
            firstLeftType = leftType;
        }

        if ("sample".equals(firstLeftType)) {
            if (!"sample".equals(leftType)) {
                // Should never happen, cause we don't allow gaps, but anyway...
                String msg = MessageFormat.format(
                        "The assay file of type {0} / {1} for study {2} has an experimental graph structure that is not "
                                + "compatible with the SRA format (irregular pooling structure). "
                                + "Please review the ISATAB/SRA formatting guidelines",
                        assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc());
                nonRepeatedMessages.add(msg);
                log.trace(msg + ". Assay is: " + assay.getAcc());
                return null;
            }

            Collection<MaterialNode> leftLeftNodes = ProcessingUtils.findBackwardMaterialNodes(leftNode, "",
                    true);
            if (leftLeftNodes.size() == 0) {
                // OK, doesn't have sources, strange, but let's say the left node is a pool member
                result.add(buildSingleExportedSample(leftNode));
                continue;
            }

            MaterialNode leftLeftNode = leftLeftNodes.iterator().next();
            Material leftLeftMaterial = leftLeftNode.getMaterial();
            MaterialRole leftLeftRole = leftLeftMaterial.getType();
            if (!StringUtils.containsIgnoreCase(leftLeftRole.getAcc(), "source")) {
                String msg = MessageFormat.format(
                        "The assay file of type {0} / {1} for study {2} has nested pooled samples, this is not supported by "
                                + "the SRA format. Please review the ISATAB/SRA formatting guidelines",
                        assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc());
                nonRepeatedMessages.add(msg);
                log.trace(msg + ". Assay is: " + assay.getAcc());
                return null;
            }

            if (leftLeftNode.getDownstreamProcessings().size() != 0) {
                String msg = MessageFormat.format(
                        "The assay file of type {0} / {1} for study {2} has an experimental graph structure that is not "
                                + "compatible with the SRA format (sources with derived nodes). Please review the ISATAB/SRA "
                                + "formatting guidelines",
                        assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc());
                nonRepeatedMessages.add(msg);
                log.trace(msg + ". Assay is: " + assay.getAcc());
                return null;
            }

            // OK, the structure is fine, let's add a new sample
            result.add(buildSingleExportedSample(leftNode));
        } else {
            // It's a source: check we have all sources on the left and that they are the first nodes.
            //
            if (!"source".equals(leftType)) {
                // Should never happen, cause we don't allow gaps, but anyway...
                String msg = MessageFormat.format(
                        "The assay file of type {0} / {1} for study {2} has an experimental graph structure that is not "
                                + "compatible with the SRA format (irregular pooling structure). "
                                + "Please review the ISATAB/SRA formatting guidelines",
                        assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc());
                nonRepeatedMessages.add(msg);
                log.trace(msg + ". Assay is: " + assay.getAcc());
                return null;
            }

            if (leftNode.getDownstreamProcessings().size() != 0) {
                String msg = MessageFormat.format(
                        "The assay file of type {0} / {1} for study {2} has an experimental graph structure that is not "
                                + "compatible with the SRA format (sources with derived nodes). "
                                + "Please review the ISATAB/SRA formatting guidelines",
                        assay.getMeasurement().getName(), assay.getTechnologyName(), assay.getStudy().getAcc());
                nonRepeatedMessages.add(msg);
                log.trace(msg + ". Assay is: " + assay.getAcc());
                return null;
            }
        } // if on type cases
    } // for leftNode

    return result;
}

From source file:org.isatools.isatab.mapping.AssayTypeEntries.java

/**
 * @param measurmentTypeLabel/*from  ww  w.  ja va 2s . c o m*/
 * @param technologyTypeLabel
 * @return
 */
public static String getDispatchTargetIdFromLabels(String measurmentTypeLabel, String technologyTypeLabel) {
    measurmentTypeLabel = convertMeasurmentTypeLabel(measurmentTypeLabel);
    technologyTypeLabel = convertTechnologyLabel(technologyTypeLabel);

    // First try with the stuff in the ISA Configuration's Configurator
    //
    IsaTabConfigurationType cfg = isaConfiguratorCfg.getConfig(measurmentTypeLabel, technologyTypeLabel);
    if (cfg != null) {
        String conversionTarget = StringUtils.trimToNull(cfg.getIsatabConversionTarget());
        if (conversionTarget != null) {
            return conversionTarget;
        }
    }

    // TODO: we want to eventually remove the CSV file
    //

    for (String[] entry : getEntries()) {
        if (StringUtils.trimToEmpty(entry[COL_MEASURMENT_LABEL]).equalsIgnoreCase(measurmentTypeLabel)
                && StringUtils.trimToEmpty(entry[COL_TECHNOLOGY_LABEL]).equalsIgnoreCase(technologyTypeLabel)) {
            String dispatchTarget = StringUtils.trimToNull(entry[COL_DISPATCH_ID]);
            if (StringUtils.containsIgnoreCase(dispatchTarget, "New European Nucleotide Archive database")) {
                dispatchTarget = "sra";
            } else if (StringUtils.containsIgnoreCase(dispatchTarget, "ArrayExpress")) {
                dispatchTarget = "magetab";
            } else if (StringUtils.containsIgnoreCase(dispatchTarget, "Pride")) {
                dispatchTarget = "prideml";
            } else if (StringUtils.containsIgnoreCase(dispatchTarget, "BII metabolomic")) {
                dispatchTarget = "meda";
            } else if (StringUtils.containsIgnoreCase(dispatchTarget, "BII conventional assay")) {
                dispatchTarget = "generic";
            }

            return dispatchTarget;
        }
    }
    return null;
}

From source file:org.isatools.isatab.mapping.AssayTypeEntries.java

public static Measurement getMeasurementTypeFromLabel(String label) {
    label = convertMeasurmentTypeLabel(label);

    // First try with what you have in the ISA Configurator Information
    ///*from  w w w  .  j  ava2s .c o m*/
    OntologyEntryType ctype = isaConfiguratorCfg.getMeasurementFromLabel(label);

    if (ctype != null) {
        label = ctype.getTermLabel();
        String acc = StringUtils.trimToNull(ctype.getTermAccession());
        if (acc == null) {
            acc = "NULL-ACCESSION";
        }

        ReferenceSource osrc;
        String sourceAcc = StringUtils.trimToNull(ctype.getSourceAbbreviation());

        if (sourceAcc == null || "obi".equalsIgnoreCase(sourceAcc)) {
            osrc = getOBISource();
        } else {
            osrc = new ReferenceSource(sourceAcc, sourceAcc);
            osrc.setDescription(ctype.getSourceTitle());
            osrc.setUrl(ctype.getSourceTitle());
        }
        return new Measurement(acc, label, osrc);
    }

    for (String[] entry : getEntries()) {
        String epLabel = StringUtils.trimToEmpty(entry[COL_MEASURMENT_LABEL]);
        if (!label.equalsIgnoreCase(epLabel)) {
            continue;
        }

        String acc = StringUtils.trimToEmpty(entry[COL_MEASURMENT_ACC]);
        if (acc.length() == 0 || StringUtils.containsIgnoreCase(acc, "submitted to OBI")
                || StringUtils.containsIgnoreCase(acc, "old terms"))
        // There isn't much else I can do...
        {
            acc = "NULL-ACCESSION";
        }

        return new Measurement(acc, label, getOBISource());
    }
    return null;
}

From source file:org.isatools.isatab.mapping.AssayTypeEntries.java

public static AssayTechnology getAssayTechnologyFromLabel(String label) {
    label = convertTechnologyLabel(label);

    // First try with what you have in the ISA Configurator Information
    ////from   w w  w.j  a  v  a  2  s  .  co  m
    OntologyEntryType ctype = isaConfiguratorCfg.getTechnologyFromLabel(label);

    if (ctype != null) {
        label = ctype.getTermLabel();
        String acc = StringUtils.trimToNull(ctype.getTermAccession());
        if (acc == null) {
            acc = "NULL-ACCESSION";
        }

        ReferenceSource osrc;
        String sourceAcc = StringUtils.trimToNull(ctype.getSourceAbbreviation());

        if (sourceAcc == null || "obi".equalsIgnoreCase(sourceAcc)) {
            osrc = getOBISource();
        } else {
            osrc = new ReferenceSource(sourceAcc, sourceAcc);
            osrc.setDescription(ctype.getSourceTitle());
            osrc.setUrl(ctype.getSourceTitle());
        }
        return new AssayTechnology(acc, label, osrc);
    }

    for (String[] entry : getEntries()) {
        String techLabel = StringUtils.trimToEmpty(entry[COL_TECHNOLOGY_LABEL]);
        if (!label.equalsIgnoreCase(techLabel)) {
            continue;
        }

        String acc = StringUtils.trimToEmpty(entry[COL_TECHNOLOGY_ACC]);
        if (acc.length() == 0 || StringUtils.containsIgnoreCase(acc, "submitted to OBI")
                || StringUtils.containsIgnoreCase(acc, "old terms"))
        // There isn't much else I can do...
        {
            acc = "NULL-ACCESSION";
        }

        return new AssayTechnology(acc, label, getOBISource());
    }

    return null;
}

From source file:org.jahia.test.services.render.JSessionIDTest.java

private void findJSessionId(boolean removeJsessionId) throws IOException {
    SettingsBean.getInstance().setDisableJsessionIdParameter(removeJsessionId);
    SettingsBean.getInstance().setJsessionIdParameterName(jsessionid);

    GetMethod displayLoginMethod = new GetMethod(getBaseServerURL() + Jahia.getContextPath() + "/start");
    try {/*from   ww  w.  j a  v  a  2 s  . c  o  m*/
        int statusCode = httpClient.executeMethod(displayLoginMethod);

        assertEquals("Method failed: " + displayLoginMethod.getStatusLine(), HttpStatus.SC_UNAUTHORIZED,
                statusCode);

        String responseBodyAsString = displayLoginMethod.getResponseBodyAsString();

        Pattern p = Pattern.compile("action=\"([^\"]*)\"");
        Matcher m = p.matcher(responseBodyAsString);
        assertTrue(m.find());

        String url = m.group(1);
        if (!removeJsessionId) {
            logger.info("Unencoded URL: " + getBaseServerURL() + Jahia.getContextPath() + "/start");
            logger.info("Encoded redirect URL: "
                    + getResponse().encodeRedirectURL(getBaseServerURL() + Jahia.getContextPath() + "/start"));
            logger.info("Encoded URL: "
                    + getResponse().encodeURL(getBaseServerURL() + Jahia.getContextPath() + "/start"));
        }

        assertEquals(
                "jsession ID is not " + (removeJsessionId ? "removed" : "present")
                        + " in administration login url:" + url,
                removeJsessionId, !StringUtils.containsIgnoreCase(url, jsessionid));
    } finally {
        displayLoginMethod.releaseConnection();
    }
}

From source file:org.jajuk.util.filters.TestAudioFilter.java

/**
 * Test method for {@link org.jajuk.util.filters.AudioFilter#getDescription()}
 * ./*ww w .  j a v a 2  s.c om*/
 */
public void testGetDescription() {
    StartupCollectionService.registerTypes();
    assertTrue(AudioFilter.getInstance().getDescription(),
            StringUtils.containsIgnoreCase(AudioFilter.getInstance().getDescription(), "mp3"));
    assertTrue(AudioFilter.getInstance().getDescription(),
            StringUtils.containsIgnoreCase(AudioFilter.getInstance().getDescription(), "ogg"));
    // try removing all types
    TypeManager.getInstance().clear();
    assertEquals("", AudioFilter.getInstance().getDescription());
}

From source file:org.jdto.tools.verifiercases.NestedIncorrectVerifierCase.java

@Override
public void test(List<Diagnostic<? extends JavaFileObject>> diagnostics, String stdoutS, Boolean result) {

    //in this case we should have a compilation error saying that annotation has no effect on setters.

    for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
        if (diagnostic.getKind() == Kind.MANDATORY_WARNING) {

            if (!StringUtils.containsIgnoreCase(diagnostic.getMessage(null), "not found on type")) {
                continue;
            } else {
                //test should succeed.
                return;
            }//from  www. j  a v  a2s  . co  m

        }
    }

    fail("No relevant compilation warning found.");
}

From source file:org.jdto.tools.verifiercases.SetterAnnotatedVerifierCase.java

@Override
public void test(List<Diagnostic<? extends JavaFileObject>> diagnostics, String stdoutS, Boolean result) {

    //in this case we should have a compilation error saying that annotation has no effect on setters.

    for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
        if (diagnostic.getKind() == Kind.MANDATORY_WARNING) {

            if (!StringUtils.containsIgnoreCase(diagnostic.getMessage(null), "Setter")) {
                continue;
            } else {
                //test should succeed.
                return;
            }//w w w  .  jav  a2  s .  com

        }
    }

    fail("A warning saying that setters mustn't be annotated should have been printed.");
}