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

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

Introduction

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

Prototype

public static String deleteWhitespace(String str) 

Source Link

Document

Deletes all whitespaces from a String as defined by Character#isWhitespace(char) .

Usage

From source file:com.hangum.tadpole.rdb.core.editors.main.composite.ResultSetComposite.java

/**
 *  .// ww  w .  j a  v  a2  s  . co m
 * 
 * @param reqQuery
 * @param queryTimeOut
 * @param strUserEmail
 * @param intSelectLimitCnt
 * @param intStartCnt
 * @param strNullValue 
 * @return
 * @throws Exception
 */
public QueryExecuteResultDTO runSelect(final RequestQuery reqQuery, final int queryTimeOut,
        final String strUserEmail, final int intSelectLimitCnt, final int intStartCnt) throws Exception {
    String strSQL = reqQuery.getSql();
    if (!PermissionChecker.isExecute(getDbUserRoleType(), getUserDB(), strSQL)) {
        throw new Exception(Messages.get().MainEditor_21);
    }
    if (logger.isDebugEnabled())
        logger.debug("==> real execute query : " + strSQL);

    tadpole_system_message = "";
    QueryExecuteResultDTO queryResultDAO = null;

    //  ??   ???  .
    IMainEditorExtension[] extensions = getRdbResultComposite().getMainEditor().getMainEditorExtions();
    if (extensions != null) {
        for (IMainEditorExtension iMainEditorExtension : extensions) {
            String strCostumSQL = iMainEditorExtension.sqlCostume(strSQL);
            if (!strCostumSQL.equals(strSQL)) {
                if (logger.isDebugEnabled())
                    logger.debug("** extension costume sql is : " + strCostumSQL); //$NON-NLS-1$
                strSQL = strCostumSQL;
            }
        }
    }

    //  ??   ???  .
    ResultSet resultSet = null;
    java.sql.Connection javaConn = null;
    Statement statement = null;
    PreparedStatement preparedStatement = null;

    try {
        if (DBGroupDefine.TAJO_GROUP == getUserDB().getDBGroup()) {
            javaConn = ConnectionPoolManager.getDataSource(getUserDB()).getConnection();
        } else {
            if (reqQuery.isAutoCommit()) {
                SqlMapClient client = TadpoleSQLManager.getInstance(getUserDB());
                javaConn = client.getDataSource().getConnection();
            } else {
                javaConn = TadpoleSQLTransactionManager.getInstance(strUserEmail, getUserDB());
            }
        }
        if (javaConn == null) {
            throw new Exception("Cann't create session. Please check system.");
        }

        // if statement type is prepared statement?
        if (reqQuery.getSqlStatementType() == SQL_STATEMENT_TYPE.NONE) {
            statement = javaConn.createStatement();

            statement.setFetchSize(intSelectLimitCnt);
            if (DBGroupDefine.HIVE_GROUP != getUserDB().getDBGroup()) {
                statement.setQueryTimeout(queryTimeOut);
                statement.setMaxRows(intSelectLimitCnt);
            }

            // check stop thread
            esCheckStop = Executors.newSingleThreadExecutor();
            CheckStopThread cst = new CheckStopThread(statement);
            cst.setName("TDB Query Stop checker"); //$NON-NLS-1$
            esCheckStop.execute(cst);

            // execute query
            execServiceQuery = Executors.newSingleThreadExecutor();
            if (intStartCnt == 0) {
                resultSet = _runSQLSelect(statement, strSQL);
            } else {
                strSQL = PartQueryUtil.makeSelect(getUserDB(), strSQL, intStartCnt, intSelectLimitCnt);

                if (logger.isDebugEnabled())
                    logger.debug("part sql called : " + strSQL);
                resultSet = _runSQLSelect(statement, strSQL);
            }

        } else if (reqQuery.getSqlStatementType() == SQL_STATEMENT_TYPE.PREPARED_STATEMENT) {
            preparedStatement = javaConn.prepareStatement(strSQL);

            preparedStatement.setFetchSize(intSelectLimitCnt);
            if (DBGroupDefine.HIVE_GROUP != getUserDB().getDBGroup()) {
                preparedStatement.setQueryTimeout(queryTimeOut);
                preparedStatement.setMaxRows(intSelectLimitCnt);
            }

            // check stop thread
            esCheckStop = Executors.newSingleThreadExecutor();
            CheckStopThread cst = new CheckStopThread(preparedStatement);
            cst.setName("TDB Query Stop checker"); //$NON-NLS-1$
            esCheckStop.execute(cst);

            // execute query
            execServiceQuery = Executors.newSingleThreadExecutor();
            if (intStartCnt == 0) {
                resultSet = _runSQLSelect(preparedStatement, reqQuery.getStatementParameter());
            } else {
                strSQL = PartQueryUtil.makeSelect(getUserDB(), strSQL, intStartCnt, intSelectLimitCnt);

                if (logger.isDebugEnabled())
                    logger.debug("part sql called : " + strSQL);
                resultSet = _runSQLSelect(preparedStatement, reqQuery.getStatementParameter());
            }
        }

        queryResultDAO = new QueryExecuteResultDTO(getUserDB(), reqQuery.getSql(), true, resultSet,
                intSelectLimitCnt, intStartCnt);
        if (resultSet == null) {
            if (StringUtils.isEmpty(StringUtils.deleteWhitespace(tadpole_system_message))) {
                tadpole_system_message = CMD_COMPLETE_MSG;
            }

        }
        queryResultDAO.setQueryMsg(tadpole_system_message);

    } catch (Exception e) {
        throw e;
    } finally {
        isCheckRunning = false;
        try {
            if (preparedStatement != null)
                preparedStatement.close();
        } catch (Exception e) {
        }
        try {
            if (statement != null)
                statement.close();
        } catch (Exception e) {
        }
        try {
            if (resultSet != null)
                resultSet.close();
        } catch (Exception e) {
        }

        if (reqQuery.isAutoCommit()) {
            try {
                if (javaConn != null)
                    javaConn.close();
            } catch (Exception e) {
            }
        }
    }

    return queryResultDAO;
}

From source file:eu.eidas.auth.engine.EIDASSAMLEngine.java

/**
 * Gets the country from X.509 Certificate.
 * /*from  www  .j av  a  2  s  . c om*/
 * @param keyInfo the key info
 * 
 * @return the country
 */
private String getCountry(final KeyInfo keyInfo) {
    LOG.trace("Recover country information.");

    String result = "";
    try {
        final org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0)
                .getX509Certificates().get(0);

        // Transform the KeyInfo to X509Certificate.
        CertificateFactory certFact;
        certFact = CertificateFactory.getInstance("X.509");

        final ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(xmlCert.getValue()));

        final X509Certificate cert = (X509Certificate) certFact.generateCertificate(bis);

        String distName = cert.getSubjectDN().toString();

        distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName));

        final String countryCode = "C=";
        final int init = distName.indexOf(countryCode);

        if (init > StringUtils.INDEX_NOT_FOUND) {
            // Exist country code.
            int end = distName.indexOf(',', init);

            if (end <= StringUtils.INDEX_NOT_FOUND) {
                end = distName.length();
            }

            if (init < end && end > StringUtils.INDEX_NOT_FOUND) {
                result = distName.substring(init + countryCode.length(), end);
                //It must be a two characters value
                if (result.length() > 2) {
                    result = result.substring(0, 2);
                }
            }
        }

    } catch (CertificateException e) {
        LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate. {}", e.getMessage());
        LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate. {}", e);
    }
    return result.trim();
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.TemplateEditor.java

/**
 * Automaps a filed name to the Specify Schema
 * @param fieldNameArg the field name/*  w  ww .  ja va2s. c  o m*/
 * @return the Table Field Pair
 */
protected FieldInfo autoMapFieldName(final String fieldNameArg, List<Pair<String, TableFieldPair>> automappings,
        Set<FieldInfo> previouslyMapped) {
    String fieldNameLower = fieldNameArg.toLowerCase();
    String fieldNameLowerNoWS = StringUtils.deleteWhitespace(fieldNameLower);

    FieldInfo fieldInfo = null;

    // If we had no luck then just loop through everything looking for it.
    // Actually we should do this search first since it is more specific.
    if (fieldInfo == null) {
        Vector<TableInfo> tbls = getTablesForAutoMapping();
        for (TableInfo tblInfo : tbls) {
            for (FieldInfo fi : tblInfo.getFieldItems()) {
                DBFieldInfo dbFieldInfo = fi.getFieldInfo();

                String tblFieldName = dbFieldInfo.getName().toLowerCase();
                String tblColumnName = dbFieldInfo.getColumn().toLowerCase();

                // System.out.println("["+tblFieldName+"]["+fieldNameLower+"]");
                if (tblFieldName.equals(fieldNameLower) || tblColumnName.equals(fieldNameLower)
                        || tblColumnName.equals(fieldNameLowerNoWS) || tblFieldName.equals(fieldNameLowerNoWS)
                        || tblFieldName.startsWith(fieldNameLower)
                        || tblColumnName.startsWith(fieldNameLower)) {
                    fieldInfo = fi;
                    break;
                }
            }
            if (fieldInfo != null) {
                break;
            }
        }
    }

    // find the mapping that matches this column name
    for (Pair<String, TableFieldPair> mapping : automappings) {
        //System.out.println("["+fieldName+"]["+mapping.first+"]");
        if (fieldNameLowerNoWS.matches(mapping.first)) {
            TableFieldPair tblFldPair = mapping.second;
            //fieldInfo = new FieldInfo(tblFldPair.getTableinfo(),tblFldPair.getFieldInfo());
            //System.out.println("["+fieldInfo.hashCode()+"]["+tblFldPair.getTableinfo().hashCode()+"]["+tblFldPair.getFieldInfo().hashCode()+"]");
            log.debug("Mapping incoming column name '" + fieldNameArg + "' to "
                    + tblFldPair.getTableinfo().getName() + "." + tblFldPair.getFieldInfo().getName());
            for (int i = 0; i < tableModel.size(); i++) {
                TableInfo tblInfo = tableModel.getElementAt(i);
                for (FieldInfo fi : tblInfo.getFieldItems()) {
                    if (fi.getFieldInfo() == tblFldPair.getFieldInfo()) {
                        //System.out.println("["+fi.hashCode()+"]["+tblFldPair.getTableinfo().hashCode()+"]["+tblFldPair.getFieldInfo().hashCode()+"]");
                        fieldInfo = fi;
                        break;
                    }
                }
                if (fieldInfo != null)
                    break;
            }
        }
        if (fieldInfo != null)
            break;
    }

    //check to see if a mapping to fieldInfo has already been made.
    if (fieldInfo != null && previouslyMapped.add(fieldInfo)) {
        return fieldInfo;
    }
    return null;
}

From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java

/**
 * Gets the country from X.509 Certificate.
 * //from www .j  ava  2 s  .  co m
 * @param keyInfo the key info
 * 
 * @return the country
 */
private String getCountry(final KeyInfo keyInfo) {
    LOG.debug("Recover country information.");

    String result = "";
    try {
        final org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0)
                .getX509Certificates().get(0);

        // Transform the KeyInfo to X509Certificate.
        CertificateFactory certFact;
        certFact = CertificateFactory.getInstance("X.509");

        final ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(xmlCert.getValue()));

        final X509Certificate cert = (X509Certificate) certFact.generateCertificate(bis);

        String distName = cert.getSubjectDN().toString();

        distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName));

        final String countryCode = "C=";
        final int init = distName.indexOf(countryCode);

        if (init > StringUtils.INDEX_NOT_FOUND) { // Exist country code.
            int end = distName.indexOf(',', init);

            if (end <= StringUtils.INDEX_NOT_FOUND) {
                end = distName.length();
            }

            if (init < end && end > StringUtils.INDEX_NOT_FOUND) {
                result = distName.substring(init + countryCode.length(), end);
                //It must be a two characters value
                if (result.length() > 2) {
                    result = result.substring(0, 2);
                }
            }
        }

    } catch (CertificateException e) {
        LOG.error("Procces getCountry from certificate.");
    }
    return result.trim();
}

From source file:edu.ku.brc.specify.dbsupport.SpecifySchemaUpdateService.java

/**
 * Check to make sure two version number are double and the new one is greater or equals to the existing one.
 * @param versionFromDB the existing version number
 * @param localVersionNum the new version number
 * @param notNumericErrKey I18N localization key
 * @param localVerTooOldKey I18N localization key
 * @param localVerTooNewKey I18N localization key
 * @return true if OK// w  ww  .j  a  va  2 s .co  m
 */
protected boolean checkVersion(final String versionFromDB, final String localVersionNum,
        final String notNumericErrKey, final String localVerTooOldKey, final String localVerTooNewKey,
        final boolean checkForTooNew) {
    try {
        log.debug("App - Prev[" + versionFromDB + "] New[" + localVersionNum + "]");

        Integer verNumFromDB = Integer
                .parseInt(StringUtils.replace(StringUtils.deleteWhitespace(versionFromDB), ".", ""));
        Integer localVerNum = Integer
                .parseInt(StringUtils.replace(StringUtils.deleteWhitespace(localVersionNum), ".", ""));

        log.debug("App - Prev[" + verNumFromDB + "] New[" + localVerNum + "]");

        if (verNumFromDB > localVerNum) {
            UIRegistry.showLocalizedError(localVerTooOldKey, localVersionNum, versionFromDB);

            return false;

        } else if (checkForTooNew && verNumFromDB < localVerNum) {
            UIRegistry.showLocalizedError(localVerTooNewKey, localVersionNum, versionFromDB);
            return false;
        }
        return true;

    } catch (NumberFormatException ex) {
        UIRegistry.showLocalizedError(notNumericErrKey, localVersionNum, versionFromDB);
    }

    return false;
}

From source file:ninja.text.TextImpl.java

@Override
public Text removeWhitespaces() {
    return Text.of(StringUtils.deleteWhitespace(data.toString()));
}

From source file:nl.b3p.catalog.xml.mdeXml2Html.java

private static boolean removeEmptyNode(Element node) {
    boolean deleteOK = true;
    // check children
    List<Element> children = node.getChildren();
    List<Element> childrenToBeRemoved = new ArrayList<Element>();
    for (Element e : children) {
        if (removeEmptyNode(e)) {
            childrenToBeRemoved.add(e);/*from   w w  w .ja  v a 2s.  com*/
        } else {
            deleteOK = false;
        }
    }
    for (Element re : childrenToBeRemoved) {
        node.removeContent(re);
    }
    // check node text
    if (deleteOK) {
        String value = StringUtils.deleteWhitespace(node.getText());
        if (value != null && !value.isEmpty()) {
            deleteOK = false;
        }
    }
    // check relevant attributes
    if (deleteOK) {
        List<Attribute> attrs = node.getAttributes();
        for (Attribute a : attrs) {
            // codeList always has value, but only codeListValue is relevant
            // uom is not relevant
            // namespace is not relevant
            String n = a.getName();
            if (!n.equals("codeList") && !n.equals("uom") && !n.startsWith("xmlns:")) {

                // codeListValue may be present but empty
                String value = a.getValue();
                if (n.equals("codeListValue") && (value == null || value.isEmpty())) {
                    continue;
                }

                deleteOK = false;
                break;
            }
        }
    }
    // if CI_RoleCode check if there is a
    // organisation name present, if not ignore
    if (!deleteOK && node.getName().equals("CI_RoleCode")) {
        deleteOK = true;
        Element oe = node.getParentElement().getParentElement(); //CI_ResponsibleParty
        List<Element> oecs = oe.getChildren();
        for (Element e : oecs) {
            if (e.getName().equals("organisationName")) {
                List<Element> ecs = e.getChildren();
                for (Element o : ecs) {
                    if (o.getName().equals("CharacterString")) {
                        String value = StringUtils.deleteWhitespace(o.getText());
                        if (value != null && !value.isEmpty()) {
                            deleteOK = false;
                            break;
                        }
                    }
                }
            }
        }
    }

    // if CI_DateTypeCode check if there is a
    // date present, if not ignore
    if (!deleteOK && node.getName().equals("CI_DateTypeCode")) {
        deleteOK = true;
        Element oe = node.getParentElement().getParentElement(); //CI_Date
        List<Element> oecs = oe.getChildren();
        for (Element e : oecs) {
            if (e.getName().equals("date")) {
                List<Element> ecs = e.getChildren();
                for (Element o : ecs) {
                    if (o.getName().equals("Date") || o.getName().equals("DateTime")) {
                        String value = StringUtils.deleteWhitespace(o.getText());
                        if (value != null && !value.isEmpty()) {
                            deleteOK = false;
                            break;
                        }
                    }
                }
            }
        }
    }

    return deleteOK;
}

From source file:nl.strohalm.cyclos.http.SanitizerFilter.java

@Override
public void init(final FilterConfig config) throws ServletException {
    super.init(config);

    String excluded = config.getInitParameter("exclusionPattern");
    if (StringUtils.isNotEmpty(excluded)) {
        excluded = StringUtils.deleteWhitespace(StringUtils.replace(excluded, "\n", "|"));
        if (StringUtils.isNotEmpty(excluded)) {
            exclusionPattern = Pattern.compile(excluded);
        }/*from  w  w w .  j  a v a2  s  . c o  m*/
    }
}

From source file:org.ala.dao.TaxonConceptSHDaoImpl.java

/**
 * Index the supplied taxon concept.//from w  w w .  j  a v a  2  s. c  om
 * 
 * @param guid
 * @return
 */
public List<SolrInputDocument> indexTaxonConcept(String guid, Scanner scanner) throws Exception {

    List<SolrInputDocument> docsToAdd = new ArrayList<SolrInputDocument>();

    // get taxon concept details
    TaxonConcept taxonConcept = scanner != null
            ? (TaxonConcept) scanner.getValue(ColumnType.TAXONCONCEPT_COL.getColumnName(), TaxonConcept.class)
            : getByGuid(guid);

    if (taxonConcept != null) {
        // get synonyms concepts
        List<SynonymConcept> synonyms = scanner != null
                ? (List) scanner.getListValue(ColumnType.SYNONYM_COL.getColumnName(), SynonymConcept.class)
                : getSynonymsFor(guid);

        // get congruent concepts
        // List<TaxonConcept> congruentTcs = getCongruentConceptsFor(guid);

        // treat congruent objects the same way we do synonyms
        // synonyms.addAll(congruentTcs);

        // get common names
        List<CommonName> commonNames = scanner != null
                ? (List) scanner.getListValue(ColumnType.VERNACULAR_COL.getColumnName(), CommonName.class)
                : getCommonNamesFor(guid);

        // add the parent id to enable tree browsing with this index
        List<TaxonConcept> children = scanner != null
                ? (List) scanner.getListValue(ColumnType.IS_PARENT_COL_OF.getColumnName(), TaxonConcept.class)
                : getChildConceptsFor(guid);

        // add conservation and pest status'
        List<ConservationStatus> conservationStatuses = scanner != null
                ? (List) scanner.getListValue(ColumnType.CONSERVATION_STATUS_COL.getColumnName(),
                        ConservationStatus.class)
                : getConservationStatuses(guid);
        // List<PestStatus> pestStatuses = getPestStatuses(guid);

        List<Category> categories = scanner != null
                ? (List) scanner.getListValue(ColumnType.CATEGORY_COL.getColumnName(), Category.class)
                : getCategories(guid);

        // add text properties
        List<SimpleProperty> simpleProperties = scanner != null
                ? (List) scanner.getListValue(ColumnType.TEXT_PROPERTY_COL.getColumnName(),
                        SimpleProperty.class)
                : getTextPropertiesFor(guid);

        // save all infosource ids to add in a Set to index at the end
        Set<String> infoSourceIds = new TreeSet<String>();
        Set<String> infoSourceUids = new TreeSet<String>();

        // get alternative ids
        List<String> identifiers = scanner != null
                ? (List) scanner.getListValue(ColumnType.IDENTIFIER_COL.getColumnName(), String.class)
                : getIdentifiers(guid);

        List<TaxonConcept> otherTaxonConcepts = scanner != null
                ? (List) scanner.getListValue(ColumnType.SAME_AS_COL.getColumnName(), TaxonConcept.class)
                : getSameAsFor(guid);

        // TODO this index should also include nub ids
        SolrInputDocument doc = new SolrInputDocument();

        //if the doc is an ala generated concept include a flag
        if (guid.startsWith("ALA"))
            doc.addField("is_ala_b", "true");

        //add the "isExcluded" value
        doc.addField("is_excluded_b", taxonConcept.getIsExcluded());

        doc.addField("idxtype", IndexedTypes.TAXON);

        // is this species iconic
        Boolean iconic = null;
        Boolean australian = null;
        if (scanner != null) {
            iconic = (Boolean) scanner.getValue(ColumnType.IS_ICONIC.getColumnName(), Boolean.class);
            if (iconic == null)
                iconic = false;
            australian = (Boolean) scanner.getValue(ColumnType.IS_AUSTRALIAN.getColumnName(), Boolean.class);
            if (australian == null)
                australian = false;
        }
        Boolean isAustralian = australian == null ? isAustralian(guid) : australian;
        boolean isIconic = iconic == null ? isIconic(guid) : iconic;
        // does this taxon have occurrence records associated with it?
        Integer count = scanner != null
                ? (Integer) scanner.getValue(ColumnType.OCCURRENCE_RECORDS_COUNT_COL.getColumnName(),
                        Integer.class)
                : getOccurrenceRecordCount(guid);
        // boolean isGs=count != null && count.size() >0 && count.get(0)>0;
        if (count != null) {
            doc.addField("occurrenceCount", count);
        }
        //Index the Georeferenced count
        Integer gsCount = scanner != null
                ? (Integer) scanner.getValue(ColumnType.GEOREF_RECORDS_COUNT_COL.getColumnName(), Integer.class)
                : getGeoreferencedRecordsCount(guid);
        if (gsCount != null) {
            doc.addField("georeferencedCount", gsCount);
        }

        if (taxonConcept.getNameString() != null) {

            doc.addField("id", taxonConcept.getGuid());
            doc.addField("guid", taxonConcept.getGuid());

            for (TaxonConcept tc : otherTaxonConcepts) {
                doc.addField("otherGuid", tc.getGuid());
            }

            for (String identifier : identifiers) {
                doc.addField("otherGuid", identifier);
            }
            // add the numeric checklistbank id
            doc.addField("otherGuid", taxonConcept.getId());

            addToSetSafely(infoSourceIds, taxonConcept.getInfoSourceId());
            addToSetSafely(infoSourceUids, taxonConcept.getInfoSourceUid());

            //TODO do we want to add all the associated TaxonNames???
            TaxonName taxonName = null;
            if (scanner != null) {
                List<TaxonName> tns = (List) scanner.getListValue(ColumnType.TAXONNAME_COL.getColumnName(),
                        TaxonName.class);
                if (tns.size() > 0) {
                    taxonName = tns.get(0);
                }
            } else {
                taxonName = getTaxonNameFor(guid);
            }
            if (taxonName != null && taxonName.getNameComplete() != null) {
                doc.addField("nameComplete", taxonName.getNameComplete());
            } else {
                doc.addField("nameComplete", taxonConcept.getNameString());
            }

            // add multiple forms of the scientific name to the index]
            try {
                addScientificNameToIndex(doc, taxonConcept.getNameString(), taxonConcept.getRankString(),
                        taxonConcept.getRankID());
                //now add the supplied name string as the "sortable" singleScientificName
                doc.addField(SINGLE_SCI_NAME, taxonConcept.getNameString());
            } catch (NullPointerException e) {
                System.out.println("TAXONCONCEPT WITH NPE: " + taxonConcept);
                e.printStackTrace();
            }

            if (taxonConcept.getParentGuid() != null) {
                doc.addField("parentGuid", taxonConcept.getParentGuid());
            }
            if (taxonConcept.getParentId() != null) {
                doc.addField("parentId", taxonConcept.getParentId());
            }

            // add the nested set values
            doc.addField("left", taxonConcept.getLeft());
            doc.addField("right", taxonConcept.getRight());
            doc.addField("author", taxonConcept.getAuthor());

            for (ConservationStatus cs : conservationStatuses) {
                if (cs.getRawStatus() != null) {
                    doc.addField("conservationStatus", cs.getRawStatus(), 0.6f);
                    addToSetSafely(infoSourceIds, cs.getInfoSourceId());
                    addToSetSafely(infoSourceUids, cs.getInfoSourceUid());
                    if (cs.getRegion() != null && Regions.getRegion(cs.getRegion()) != null) {
                        Regions r = Regions.getRegion(cs.getRegion());
                        doc.addField("conservationStatus" + r.getAcronym(), cs.getRawStatus());
                    }
                }
            }

            //add the category information
            for (Category category : categories) {
                //add the category to the "general" field so all categories from all dr's can be filetred on
                doc.addField("category_m_s", category.getCategory());
                //add to a dr specific category so that faceting can be performed on individual DR's categories eg weeds or animal pests.
                doc.addField(category.getInfoSourceUid() + "_category_m_s", category.getCategory());
                //add state limiting facet if necessary
                if (StringUtils.isNotBlank(category.getStateProvince())) {
                    doc.addField("category_" + getStateAbbreviation(category.getStateProvince()) + "_m_s",
                            category.getCategory());
                }
                addToSetSafely(infoSourceUids, category.getInfoSourceUid());
            }

            for (SimpleProperty sp : simpleProperties) {
                // index *Text properties
                if (sp.getName().endsWith("Text")) {
                    // Field textField = new Field("simpleText",
                    // sp.getValue(), Store.YES, Index.ANALYZED);
                    // textField.setBoost(0.4f);
                    doc.addField("simpleText", sp.getValue(), 0.4f);
                    addToSetSafely(infoSourceIds, sp.getInfoSourceId());
                    addToSetSafely(infoSourceUids, sp.getInfoSourceUid());
                }
            }

            // StringBuffer cnStr = new StringBuffer();
            Set<String> commonNameSet = new TreeSet<String>();
            List<String> higherPriorityNames = new ArrayList<String>();
            for (CommonName cn : commonNames) {
                if (cn.getNameString() != null && !cn.getIsBlackListed()) {
                    // normalise the common names for display
                    String commonNameString = WordUtils.capitalizeFully(cn.getNameString());
                    commonNameString.trim();
                    commonNameSet.add(commonNameString);

                    if (cn.isPreferred()) {
                        higherPriorityNames.add(cn.getNameString());
                    }
                    addToSetSafely(infoSourceIds, cn.getInfoSourceId());
                    addToSetSafely(infoSourceUids, cn.getInfoSourceUid());

                    // push CAAB preferred common name up
                    if (cn.getRanking() != null && cn.getRanking() > 90000) {
                        logger.debug("**********: " + cn.getNameString() + " , " + cn.getRanking() + "\n");
                        doc.addField("preferredName", cn.getNameString().trim().toLowerCase());
                    }
                }
            }

            if (commonNameSet.size() > 0) {
                String commonNamesConcat = StringUtils.deleteWhitespace(StringUtils.join(commonNameSet, " "));
                doc.addField("commonNameSort", commonNamesConcat);
                // add each common name separately
                // We need to add all common names to the commonNameExact
                // because the CommonName also stores the "parts" of the
                // common name
                for (String commonName : commonNameSet) {
                    if (isIconic) {
                        doc.addField("commonName", commonName, 100f);
                        doc.addField("commonNameExact", commonName, 100f);
                    } else if (higherPriorityNames.contains(commonName)) {
                        doc.addField("commonName", commonName, 5f);
                        doc.addField("commonNameExact", commonName, 5f);
                    } else {
                        doc.addField("commonName", commonName, 1.4f);
                        doc.addField("commonNameExact", commonName, 1.4f);
                    }
                    // pull apart the common name
                    String[] parts = commonName.split(" ");
                    if (parts.length > 1) {
                        String lastPart = parts[parts.length - 1];
                        if (isIconic) {
                            doc.addField("commonName", lastPart, 100f);
                        } else {
                            doc.addField("commonName", lastPart, 2.5f);
                        }
                    }
                }

                doc.addField("commonNameDisplay", StringUtils.join(commonNameSet, ", "));
                doc.addField("commonNameSingle", commonNames.get(0).getNameString().trim());
            }
            String lastNameLsid = null;
            for (SynonymConcept synonym : synonyms) {
                if (synonym.getNameString() != null
                        && (synonym.getNameGuid() != null && !synonym.getNameGuid().equals(lastNameLsid))) {
                    lastNameLsid = synonym.getNameGuid();
                    logger.debug("adding synonym to index: " + synonym.getNameString());
                    // add a new document for each synonym
                    SolrInputDocument synonymDoc = new SolrInputDocument();
                    synonymDoc.addField("id", synonym.getGuid() + taxonConcept.getGuid());//combination of the 2 uniquely identifies a synonym
                    synonymDoc.addField("syn_guid", synonym.getGuid());
                    synonymDoc.addField("guid", taxonConcept.getGuid());
                    synonymDoc.addField("idxtype", IndexedTypes.TAXON);
                    addScientificNameToIndex(synonymDoc, synonym.getNameString(), null, -1);
                    synonymDoc.addField("acceptedConceptName", taxonConcept.getNameString());
                    if (!commonNames.isEmpty()) {
                        synonymDoc.addField("commonNameSort", commonNames.get(0).getNameString());
                        synonymDoc.addField("commonNameDisplay", StringUtils.join(commonNameSet, ", "));
                    }
                    addRankToIndex(synonymDoc, taxonConcept.getRankString(), taxonConcept.getRankID(),
                            taxonConcept.getRawRankString());
                    //add the synonym author
                    synonymDoc.addField("author", synonym.getAuthor());

                    //set the concept as australian if the "accepted" concept is australian
                    if (isAustralian != null && isAustralian) {
                        synonymDoc.addField("australian_s", "recorded");
                        synonymDoc.addField("aus_s", "yes");
                    }
                    //add the synonym type
                    synonymDoc.addField("synonymRelationship_s", synonym.getRelationship());
                    synonymDoc.addField("synonymDescription_s", synonym.getDescription());

                    // add the synonym as a separate document
                    docsToAdd.add(synonymDoc);
                    // store the source
                    if (synonym.getInfoSourceId() != null) {
                        infoSourceIds.add(synonym.getInfoSourceId()); // getting
                        // NPE
                    }
                    addToSetSafely(infoSourceUids, synonym.getInfoSourceUid());
                }
            }

            List<Classification> classifications = scanner != null
                    ? (List) scanner.getListValue(ColumnType.CLASSIFICATION_COL.getColumnName(),
                            Classification.class)
                    : getClassifications(guid);

            for (Classification classification : classifications) {
                addIfNotNull(doc, "kingdom", classification.getKingdom());
                addIfNotNull(doc, "phylum", classification.getPhylum());
                addIfNotNull(doc, "class", classification.getClazz());
                addIfNotNull(doc, "bioOrder", classification.getOrder());
                addIfNotNull(doc, "family", classification.getFamily());
                addIfNotNull(doc, "genus", classification.getGenus());

                //if we have something higher than a genus, add groups
                if (classification.getRankId() != null && classification.getRankId() > 6000) {
                    List<String> speciesGroups = speciesGroupsUtil.getSpeciesGroup(classification);
                    for (String g : speciesGroups) {
                        doc.addField("speciesGroup", g);
                    }
                    List<String> speciesSubgroups = speciesGroupsUtil.getSpeciesSubgroup(classification);
                    for (String g : speciesSubgroups) {
                        doc.addField("speciesSubgroup", g);
                    }
                }
            }

            //check valid image (not blacklisted)
            List<Image> images = scanner != null
                    ? (List) scanner.getListValue(ColumnType.IMAGE_COL.getColumnName(), Image.class)
                    : getImages(guid);

            boolean hasImages = false;
            int firstValidImage = -1;
            int imageCount = 0;
            Set<String> imageSources = new HashSet<String>();
            if (!images.isEmpty()) {
                for (int i = 0; i < images.size(); i++) {
                    Image image = images.get(i);
                    if (!image.getIsBlackListed()) {
                        if (firstValidImage < 0) {
                            firstValidImage = i;
                            hasImages = true;
                        }
                        imageCount++;
                        imageSources.add(image.getInfoSourceUid());
                    }
                }
            }

            //get image count (non-blacklisted sources only)
            doc.addField("imageCount", imageCount);
            //get infosource count  (non-blacklisted sources only)
            doc.addField("imagesSourceCount", imageSources.size());
            //get infosource count  (non-blacklisted sources only)
            for (String imageSource : imageSources)
                doc.addField("imageSources", imageSource);

            if (hasImages && firstValidImage >= 0) {
                // FIXME should be replaced by the highest ranked image
                Image image = images.get(firstValidImage);
                if (image.getRepoLocation() != null) {
                    doc.addField("image", image.getRepoLocation());
                    try {
                        String imageInfosourceId = getImageInfosourceId(image.getRepoLocation());
                        logger.debug("!!!" + imageInfosourceId);
                        infoSourceIds.add(imageInfosourceId);
                        addToSetSafely(infoSourceUids, image.getInfoSourceUid());
                    } catch (Exception e) {
                        logger.warn("Image infosourceId could not be retrieved");
                    }
                    // Change to adding this in earlier
                    String thumbnail = image.getRepoLocation().replace("raw", "thumbnail");
                    doc.addField("thumbnail", thumbnail);
                    doc.addField("imageSource", image.getInfoSourceUid());
                } else {
                    logger.error("Error adding image to concept: " + image);
                }
            }

            doc.addField("hasImage", hasImages);

            if (isAustralian != null && isAustralian) {
                doc.addField("australian_s", "recorded");
                doc.addField("aus_s", "yes");
            }

            String linkIdentifier = scanner != null
                    ? (String) scanner.getValue(ColumnType.LINK_IDENTIFIER.getColumnName(), String.class)
                    : getLinkIdentifier(guid);
            if (linkIdentifier != null) {
                doc.addField("linkIdentifier", linkIdentifier);
            }

            addRankToIndex(doc, taxonConcept.getRankString(), taxonConcept.getRankID(),
                    taxonConcept.getRawRankString());

            doc.addField("hasChildren", Boolean.toString(!children.isEmpty()));
            //doc.addField("dataset", StringUtils.join(infoSourceIds, " "));
            //Add all the dataset id's individually so that they can be searched indivdually
            for (String iid : infoSourceIds) {
                doc.addField("dataset", iid);
            }
            for (String uid : infoSourceUids) {
                doc.addField("uid", uid);
            }
            docsToAdd.add(doc);
        }
    }
    return docsToAdd;
}

From source file:org.apache.flume.sink.couchbase.CouchBaseSink.java

@Override
public void configure(Context context) {
    if (StringUtils.isNotBlank(context.getString(HOSTNAMES))) {
        baseURIs = convertURI(StringUtils.deleteWhitespace(context.getString(HOSTNAMES)).split(","));
    }/*w  w  w  . j  a va  2  s .co  m*/
    Preconditions.checkState(baseURIs != null && baseURIs.size() > 0, "Missing Param:" + HOSTNAMES);

    if (StringUtils.isNotBlank(context.getString(BUCKET_NAME))) {
        this.bucketName = context.getString(BUCKET_NAME);
    }

    if (!bucketName.equals(DEFAULT_BUCKET_NAME) && StringUtils.isNotBlank(context.getString(PASSWORD))) {
        password = context.getString(PASSWORD);
    } else {
        password = "";
    }

    if (StringUtils.isNotBlank(context.getString(BATCH_SIZE))) {
        this.batchSize = Integer.getInteger(context.getString(BATCH_SIZE));
    }

    if (StringUtils.isNotBlank(context.getString(TTL))) {
        this.ttlMs = Integer.getInteger(context.getString(TTL));
        Preconditions.checkState(ttlMs >= 0, TTL + " must be non-negative integer or 0!");
    }

    if (StringUtils.isNotBlank(context.getString(BUFFER_SIZE))) {
        this.bufferSize = Integer.getInteger(context.getString(BUFFER_SIZE));
    }

    if (StringUtils.isNotBlank(context.getString(KEY_PREFIX))) {
        this.keyPrefix = context.getString(KEY_PREFIX);
    }

    if (sinkCounter == null) {
        sinkCounter = new SinkCounter(getName());
    }

    String serializerClazz = DEFAULT_SERIALIZER_CLASS;
    if (StringUtils.isNotBlank(context.getString(SERIALIZER))) {
        serializerClazz = context.getString(SERIALIZER);
    }

    try {
        @SuppressWarnings("unchecked")
        Class<? extends Configurable> clazz = (Class<? extends Configurable>) Class.forName(serializerClazz);
        Configurable serializer = clazz.newInstance();

        if (serializer instanceof CouchBaseJsonSerializer) {
            eventSerializer = (CouchBaseJsonSerializer) serializer;
        } else {
            throw new IllegalArgumentException(serializerClazz + " is not an CouchBaseEventSerializer");
        }
    } catch (Exception e) {
        logger.error("Could not instantiate event serializer.", e);
        Throwables.propagate(e);
    }
}