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.niord.core.aton.AtonDefaultsService.java

/**
 * Computes the tag values for the given node type, key and value substring.
 * @param nodeType the node type//  w  w  w . j  av  a  2  s.  c om
 * @param key the tag key
 * @param valueStr the value string
 * @return the tag values for the given node type, key and value substring
 */
private List<String> computeValuesForNodeType(ODNodeType nodeType, String key, String valueStr) {
    ODTag tag = nodeType.tag(key);
    return computeValuesForTag(tag).stream()
            .filter(v -> valueStr == null || StringUtils.containsIgnoreCase(v, valueStr)).distinct()
            .collect(Collectors.toList());
}

From source file:org.nuxeo.ecm.platform.query.nxql.CoreQueryAndFetchPageProvider.java

protected void buildQuery() {
    List<SortInfo> sort = null;
    List<QuickFilter> quickFilters = getQuickFilters();
    String quickFiltersClause = "";

    if (quickFilters != null && !quickFilters.isEmpty()) {
        sort = new ArrayList<>();
        for (QuickFilter quickFilter : quickFilters) {
            String clause = quickFilter.getClause();
            if (!quickFiltersClause.isEmpty() && clause != null) {
                quickFiltersClause = NXQLQueryBuilder.appendClause(quickFiltersClause, clause);
            } else {
                quickFiltersClause = clause != null ? clause : "";
            }/*from  w ww  .j a v a2 s. c o m*/
            sort.addAll(quickFilter.getSortInfos());
        }
    } else if (sortInfos != null) {
        sort = sortInfos;
    }

    SortInfo[] sortArray = null;
    if (sort != null) {
        sortArray = sort.toArray(new SortInfo[] {});
    }

    String newQuery;
    PageProviderDefinition def = getDefinition();
    WhereClauseDefinition whereClause = def.getWhereClause();
    if (whereClause == null) {

        String originalPattern = def.getPattern();
        String pattern = quickFiltersClause.isEmpty() ? originalPattern
                : StringUtils.containsIgnoreCase(originalPattern, " WHERE ")
                        ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause)
                        : originalPattern + " WHERE " + quickFiltersClause;

        newQuery = NXQLQueryBuilder.getQuery(pattern, getParameters(), def.getQuotePatternParameters(),
                def.getEscapePatternParameters(), getSearchDocumentModel(), sortArray);
    } else {

        DocumentModel searchDocumentModel = getSearchDocumentModel();
        if (searchDocumentModel == null) {
            throw new NuxeoException(String.format(
                    "Cannot build query of provider '%s': " + "no search document model is set", getName()));
        }
        newQuery = NXQLQueryBuilder.getQuery(searchDocumentModel, whereClause, quickFiltersClause,
                getParameters(), sortArray);
    }

    if (query != null && newQuery != null && !newQuery.equals(query)) {
        // query has changed => refresh
        refresh();
    }
    query = newQuery;
}

From source file:org.nuxeo.ecm.platform.query.nxql.CoreQueryDocumentPageProvider.java

protected void buildQuery(CoreSession coreSession) {
    List<SortInfo> sort = null;
    List<QuickFilter> quickFilters = getQuickFilters();
    String quickFiltersClause = "";

    if (quickFilters != null && !quickFilters.isEmpty()) {
        sort = new ArrayList<>();
        for (QuickFilter quickFilter : quickFilters) {
            String clause = quickFilter.getClause();
            if (clause != null) {
                if (!quickFiltersClause.isEmpty()) {
                    quickFiltersClause = NXQLQueryBuilder.appendClause(quickFiltersClause, clause);
                } else {
                    quickFiltersClause = clause;
                }/*  w ww . j a v  a  2 s  . c o m*/
            }
            sort.addAll(quickFilter.getSortInfos());
        }
    } else if (sortInfos != null) {
        sort = sortInfos;
    }

    SortInfo[] sortArray = null;
    if (sort != null) {
        sortArray = sort.toArray(new SortInfo[] {});
    }

    String newQuery;
    PageProviderDefinition def = getDefinition();
    WhereClauseDefinition whereClause = def.getWhereClause();
    if (whereClause == null) {

        String originalPattern = def.getPattern();
        String pattern = quickFiltersClause.isEmpty() ? originalPattern
                : StringUtils.containsIgnoreCase(originalPattern, " WHERE ")
                        ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause)
                        : originalPattern + " WHERE " + quickFiltersClause;

        newQuery = NXQLQueryBuilder.getQuery(pattern, getParameters(), def.getQuotePatternParameters(),
                def.getEscapePatternParameters(), getSearchDocumentModel(), sortArray);
    } else {

        DocumentModel searchDocumentModel = getSearchDocumentModel();
        if (searchDocumentModel == null) {
            throw new NuxeoException(String.format(
                    "Cannot build query of provider '%s': " + "no search document model is set", getName()));
        }
        newQuery = NXQLQueryBuilder.getQuery(searchDocumentModel, whereClause, quickFiltersClause,
                getParameters(), sortArray);
    }

    if (query != null && newQuery != null && !newQuery.equals(query)) {
        // query has changed => refresh
        refresh();
    }
    query = newQuery;
}

From source file:org.nuxeo.elasticsearch.audit.pageprovider.ESAuditPageProvider.java

protected void buildAuditQuery(boolean includeSort) {
    PageProviderDefinition def = getDefinition();
    Object[] params = getParameters();
    List<QuickFilter> quickFilters = getQuickFilters();
    String quickFiltersClause = "";

    if (quickFilters != null && !quickFilters.isEmpty()) {
        for (QuickFilter quickFilter : quickFilters) {
            String clause = quickFilter.getClause();
            if (!quickFiltersClause.isEmpty() && clause != null) {
                quickFiltersClause = NXQLQueryBuilder.appendClause(quickFiltersClause, clause);
            } else {
                quickFiltersClause = clause != null ? clause : "";
            }/*from w  w w  .j  a va2s. c om*/
        }
    }

    WhereClauseDefinition whereClause = def.getWhereClause();
    if (whereClause == null) {
        // Simple Pattern

        if (!allowSimplePattern()) {
            throw new UnsupportedOperationException("This page provider requires a explicit Where Clause");
        }
        String originalPattern = def.getPattern();
        String pattern = quickFiltersClause.isEmpty() ? originalPattern
                : StringUtils.containsIgnoreCase(originalPattern, " WHERE ")
                        ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause)
                        : originalPattern + " WHERE " + quickFiltersClause;

        String baseQuery = getESBackend().expandQueryVariables(pattern, params);
        searchBuilder = getESBackend().buildQuery(baseQuery, null);
    } else {

        // Add the quick filters clauses to the fixed part
        String fixedPart = getFixedPart();
        if (!StringUtils.isBlank(quickFiltersClause)) {
            fixedPart = (!StringUtils.isBlank(fixedPart))
                    ? NXQLQueryBuilder.appendClause(fixedPart, quickFiltersClause)
                    : quickFiltersClause;
        }

        // Where clause based on DocumentModel
        String baseQuery = getESBackend().expandQueryVariables(fixedPart, params);
        searchBuilder = getESBackend().buildSearchQuery(baseQuery, whereClause.getPredicates(),
                getSearchDocumentModel());
    }
}

From source file:org.nuxeo.elasticsearch.provider.ElasticSearchNativePageProvider.java

protected QueryBuilder makeQueryBuilder() {
    QueryBuilder ret;/* w w w  .  j  av  a  2  s .  co m*/
    PageProviderDefinition def = getDefinition();
    List<QuickFilter> quickFilters = getQuickFilters();
    String quickFiltersClause = "";

    if (quickFilters != null && !quickFilters.isEmpty()) {
        for (QuickFilter quickFilter : quickFilters) {
            String clause = quickFilter.getClause();
            if (!quickFiltersClause.isEmpty() && clause != null) {
                quickFiltersClause = NXQLQueryBuilder.appendClause(quickFiltersClause, clause);
            } else {
                quickFiltersClause = clause != null ? clause : "";
            }
        }
    }

    WhereClauseDefinition whereClause = def.getWhereClause();
    if (whereClause == null) {

        String originalPattern = def.getPattern();
        String pattern = quickFiltersClause.isEmpty() ? originalPattern
                : StringUtils.containsIgnoreCase(originalPattern, " WHERE ")
                        ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause)
                        : originalPattern + " WHERE " + quickFiltersClause;

        ret = PageProviderQueryBuilder.makeQuery(pattern, getParameters(), def.getQuotePatternParameters(),
                def.getEscapePatternParameters(), isNativeQuery());
    } else {

        DocumentModel searchDocumentModel = getSearchDocumentModel();
        if (searchDocumentModel == null) {
            throw new NuxeoException(String.format(
                    "Cannot build query of provider '%s': " + "no search document model is set", getName()));
        }
        ret = PageProviderQueryBuilder.makeQuery(searchDocumentModel, whereClause, quickFiltersClause,
                getParameters(), isNativeQuery());
    }
    return ret;
}

From source file:org.onosproject.mtuldp.api.storage.MtuldpDataStorage.java

private DefaultMtuldpLink getLink(String urn) {
    if (StringUtils.containsIgnoreCase(urn, Link.Type.DIRECT.name())) {
        return directLinkStore.get(urn);
    } else if (StringUtils.containsIgnoreCase(urn, Link.Type.EDGE.name())) {
        return edgeLinkStore.get(urn);
    }//  w  w  w .  j  a va2 s .co m
    return null;
}

From source file:org.openbravo.advpaymentmngt.hqlinjections.MatchStatementTransformer.java

@Override
public String transformHqlQuery(String _hqlQuery, Map<String, String> requestParameters,
        Map<String, Object> queryNamedParameters) {
    String transformedHql = _hqlQuery.replace("@whereClause@",
            getWhereClause(requestParameters, queryNamedParameters));
    transformedHql = transformedHql.replace("@selectClause@", " ");
    transformedHql = transformedHql.replace("@joinClause@", " ");

    final boolean isOrder = StringUtils.containsIgnoreCase(_hqlQuery, "order by");
    transformedHql = transformedHql.replace("@orderby@",
            isOrder ? " " : getDefaultOrderByClause(requestParameters, queryNamedParameters));
    return transformedHql;
}

From source file:org.openbravo.service.datasource.HQLDataSourceService.java

/**
 * Adds the additional filters to the hql query. The additional filters include the client filter,
 * the organization filter and the filter created from the grid criteria
 * //from  ww w .  ja  v  a  2s. c om
 * @param table
 *          table being fetched
 * @param hqlQuery
 *          hql query without the additional filters
 * @param filterWhereClause
 *          filter created from the grid criteria
 * @param parameters
 *          parameters used for this request
 */
private String addAdditionalFilters(Table table, String hqlQuery, String filterWhereClause,
        Map<String, String> parameters) {
    OBContext.setAdminMode(true);
    StringBuffer additionalFilter = new StringBuffer();
    final String entityAlias = table.getEntityAlias();

    // replace the carriage returns and the tabulations with blanks
    String hqlQueryWithFilters = hqlQuery.replace("\n", " ").replace("\r", " ");

    // client filter
    additionalFilter.append(entityAlias + ".client.id in ('0', '")
            .append(OBContext.getOBContext().getCurrentClient().getId()).append("')");

    // organization filter
    final String orgs = DataSourceUtils.getOrgs(parameters.get(JsonConstants.ORG_PARAMETER));
    if (StringUtils.isNotEmpty(orgs)) {
        additionalFilter.append(AND);
        additionalFilter.append(entityAlias + ".organization in (" + orgs + ")");
    }

    addFilterWhereClause(additionalFilter, filterWhereClause);

    // the _where parameter contains the filter clause and the where clause defined at tab level
    String whereClauseParameter = parameters.get(JsonConstants.WHERE_PARAMETER);
    if (whereClauseParameter != null && !whereClauseParameter.trim().isEmpty()
            && !"null".equals(whereClauseParameter)) {
        additionalFilter.append(AND + whereClauseParameter);
    }

    if (hqlQueryWithFilters.contains(ADDITIONAL_FILTERS)) {
        // replace @additional_filters@ with the actual hql filters
        hqlQueryWithFilters = hqlQueryWithFilters.replace(ADDITIONAL_FILTERS, additionalFilter.toString());
    } else {
        // adds the hql filters in the proper place at the end of the query
        String separator = null;
        if (StringUtils.containsIgnoreCase(hqlQueryWithFilters, WHERE)) {
            // if there is already a where clause, append with 'AND'
            separator = AND;
        } else {
            // otherwise, append with 'where'
            separator = WHERE;
        }
        hqlQueryWithFilters = hqlQueryWithFilters + separator + additionalFilter.toString();
    }
    OBContext.restorePreviousMode();
    return hqlQueryWithFilters;
}

From source file:org.opencastproject.publication.youtube.YouTubeV3PublicationServiceImpl.java

@Override
public void updated(final Dictionary props) throws ConfigurationException {
    properties.merge(props);/*from w w  w.ja va 2  s.  c o m*/

    final String dataStore = YouTubeUtils.get(properties, YouTubeKey.credentialDatastore);

    try {
        final ClientCredentials clientCredentials = new ClientCredentials();
        clientCredentials.setCredentialDatastore(dataStore);
        final String path = YouTubeUtils.get(properties, YouTubeKey.clientSecretsV3);
        File secretsFile = new File(path);
        if (secretsFile.exists() && !secretsFile.isDirectory()) {
            clientCredentials.setClientSecrets(secretsFile);
            clientCredentials.setDataStoreDirectory(YouTubeUtils.get(properties, YouTubeKey.dataStore));
            //
            youTubeService.initialize(clientCredentials);
            //
            tags = StringUtils.split(YouTubeUtils.get(properties, YouTubeKey.keywords), ',');
            defaultPlaylist = YouTubeUtils.get(properties, YouTubeKey.defaultPlaylist);
            makeVideosPrivate = StringUtils
                    .containsIgnoreCase(YouTubeUtils.get(properties, YouTubeKey.makeVideosPrivate), "true");
            defaultMaxFieldLength(YouTubeUtils.get(properties, YouTubeKey.maxFieldLength, false));
        } else {
            logger.warn("Client information file does not exist: " + path);
        }
    } catch (final Exception e) {
        throw new ConfigurationException("Failed to load YouTube v3 properties", dataStore, e);
    }
}

From source file:org.openehr.am.validation.ArchetypeValidator.java

public void checkDescription(Archetype archetype, List<ValidationError> errors) {
    if (archetype.getDescription() == null) {
        return;/* w ww .ja va  2  s.  c o  m*/
    }

    // check purpose in each available language
    for (ResourceDescriptionItem detail : archetype.getDescription().getDetails()) {
        if (StringUtils.isBlank(detail.getPurpose())
                || StringUtils.containsIgnoreCase(detail.getPurpose(), "unknown")) {
            ValidationError error = new ValidationError(ErrorType.VDSCR, "PURPOSE",
                    detail.getLanguage().getCodeString());
            errors.add(error);
        }
    }

    // check original author
    Map<String, String> originalAuthor = archetype.getDescription().getOriginalAuthor();
    if (originalAuthor == null || originalAuthor.isEmpty()) {
        ValidationError error = new ValidationError(ErrorType.VDSCR, "ORIGINALAUTHOR");
        errors.add(error);
    } else {
        for (Entry<String, String> authorItem : originalAuthor.entrySet()) {
            if (StringUtils.isBlank(authorItem.getValue())
                    || StringUtils.containsIgnoreCase(authorItem.getValue(), "unknown")) {
                ValidationError error = new ValidationError(ErrorType.VDSCR, "ORIGINALAUTHORPART",
                        authorItem.getKey());
                errors.add(error);
            }
        }
    }

    // check lifecycle state
    String lifecycle = archetype.getDescription().getLifecycleState();
    if (StringUtils.isBlank(lifecycle) || StringUtils.containsIgnoreCase(lifecycle, "unknown")
            || StringUtils.isNumeric(lifecycle)) {
        ValidationError error = new ValidationError(ErrorType.VDSCR, "LIFECYCLE");
        errors.add(error);
    }
}