Search in sources :

Example 1 with CompleteCondition

use of org.apache.cxf.jaxrs.ext.search.client.CompleteCondition in project cxf by apache.

the class SearchContextImpl method convertPlainQueriesToFiqlExp.

private String convertPlainQueriesToFiqlExp(MultivaluedMap<String, String> params) {
    SearchConditionBuilder builder = SearchConditionBuilder.instance();
    List<CompleteCondition> list = new ArrayList<>(params.size());
    for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        list.add(getOrCondition(builder, entry));
    }
    return builder.and(list).query();
}
Also used : ArrayList(java.util.ArrayList) CompleteCondition(org.apache.cxf.jaxrs.ext.search.client.CompleteCondition) ArrayList(java.util.ArrayList) List(java.util.List) SearchConditionBuilder(org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder) LinkedHashMap(java.util.LinkedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Map(java.util.Map)

Example 2 with CompleteCondition

use of org.apache.cxf.jaxrs.ext.search.client.CompleteCondition in project syncope by apache.

the class SearchUtils method buildFIQL.

public static String buildFIQL(final List<SearchClause> clauses, final AbstractFiqlSearchConditionBuilder builder, final Map<String, PlainSchemaTO> availableSchemaTypes) {
    LOG.debug("Generating FIQL from List<SearchClause>: {}", clauses);
    CompleteCondition prevCondition;
    CompleteCondition condition = null;
    boolean notTheFirst = false;
    for (SearchClause clause : clauses) {
        prevCondition = condition;
        if (clause.getType() != null) {
            String value = clause.getValue() == null ? null : clause.getValue().replace(",", "%252C").replace(";", "%253B");
            switch(clause.getType()) {
                case GROUP_MEMBER:
                    switch(clause.getComparator()) {
                        case EQUALS:
                            condition = ((GroupFiqlSearchConditionBuilder) builder).withMembers(value);
                            break;
                        case NOT_EQUALS:
                            condition = ((GroupFiqlSearchConditionBuilder) builder).withoutMembers(value);
                            break;
                        default:
                    }
                    break;
                case GROUP_MEMBERSHIP:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        String groupKey = clause.getProperty();
                        if (builder instanceof UserFiqlSearchConditionBuilder) {
                            condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? ((UserFiqlSearchConditionBuilder) builder).inGroups(groupKey) : ((UserFiqlSearchConditionBuilder) builder).notInGroups(groupKey);
                        } else {
                            condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? ((AnyObjectFiqlSearchConditionBuilder) builder).inGroups(groupKey) : ((AnyObjectFiqlSearchConditionBuilder) builder).notInGroups(groupKey);
                        }
                    }
                    break;
                case RESOURCE:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        condition = clause.getComparator() == SearchClause.Comparator.EQUALS ? builder.hasResources(clause.getProperty()) : builder.hasNotResources(clause.getProperty());
                    }
                    break;
                case ATTRIBUTE:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        boolean isLong = false;
                        boolean isDouble = false;
                        if (availableSchemaTypes.get(clause.getProperty()) != null) {
                            isLong = availableSchemaTypes.get(clause.getProperty()).getType() == AttrSchemaType.Long;
                            isDouble = availableSchemaTypes.get(clause.getProperty()).getType() == AttrSchemaType.Double;
                        }
                        SyncopeProperty property = builder.is(clause.getProperty());
                        switch(clause.getComparator()) {
                            case IS_NULL:
                                condition = builder.isNull(clause.getProperty());
                                break;
                            case IS_NOT_NULL:
                                condition = builder.isNotNull(clause.getProperty());
                                break;
                            case LESS_THAN:
                                condition = isLong ? property.lessThan(NumberUtils.toLong(value)) : isDouble ? property.lessThan(NumberUtils.toDouble(value)) : property.lexicalBefore(value);
                                break;
                            case LESS_OR_EQUALS:
                                condition = isLong ? property.lessOrEqualTo(NumberUtils.toLong(value)) : isDouble ? property.lessOrEqualTo(NumberUtils.toDouble(value)) : property.lexicalNotAfter(value);
                                break;
                            case GREATER_THAN:
                                condition = isLong ? property.greaterThan(NumberUtils.toLong(value)) : isDouble ? property.greaterThan(NumberUtils.toDouble(value)) : property.lexicalAfter(value);
                                break;
                            case GREATER_OR_EQUALS:
                                condition = isLong ? property.greaterOrEqualTo(NumberUtils.toLong(value)) : isDouble ? property.greaterOrEqualTo(NumberUtils.toDouble(value)) : property.lexicalNotBefore(value);
                                break;
                            case NOT_EQUALS:
                                condition = property.notEqualTolIgnoreCase(value);
                                break;
                            case EQUALS:
                                condition = isLong ? property.equalTo(NumberUtils.toLong(value)) : isDouble ? property.equalTo(NumberUtils.toDouble(value)) : property.equalToIgnoreCase(value);
                                break;
                            default:
                                condition = property.equalToIgnoreCase(value);
                                break;
                        }
                    }
                    break;
                case ROLE_MEMBERSHIP:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        switch(clause.getComparator()) {
                            case EQUALS:
                                condition = ((UserFiqlSearchConditionBuilder) builder).inRoles(clause.getProperty());
                                break;
                            case NOT_EQUALS:
                                condition = ((UserFiqlSearchConditionBuilder) builder).notInRoles(clause.getProperty());
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                case PRIVILEGE:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        switch(clause.getComparator()) {
                            case EQUALS:
                                condition = ((UserFiqlSearchConditionBuilder) builder).withPrivileges(clause.getProperty());
                                break;
                            case NOT_EQUALS:
                                condition = ((UserFiqlSearchConditionBuilder) builder).withoutPrivileges(clause.getProperty());
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                case RELATIONSHIP:
                    if (StringUtils.isNotBlank(clause.getProperty())) {
                        if (builder instanceof UserFiqlSearchConditionBuilder) {
                            switch(clause.getComparator()) {
                                case IS_NOT_NULL:
                                    condition = ((UserFiqlSearchConditionBuilder) builder).inRelationshipTypes(clause.getProperty());
                                    break;
                                case IS_NULL:
                                    condition = ((UserFiqlSearchConditionBuilder) builder).notInRelationshipTypes(clause.getProperty());
                                    break;
                                case EQUALS:
                                    condition = ((UserFiqlSearchConditionBuilder) builder).inRelationships(value);
                                    break;
                                case NOT_EQUALS:
                                    condition = ((UserFiqlSearchConditionBuilder) builder).notInRelationships(value);
                                    break;
                                default:
                                    break;
                            }
                        } else {
                            switch(clause.getComparator()) {
                                case IS_NOT_NULL:
                                    condition = ((AnyObjectFiqlSearchConditionBuilder) builder).inRelationshipTypes(clause.getProperty());
                                    break;
                                case IS_NULL:
                                    condition = ((AnyObjectFiqlSearchConditionBuilder) builder).notInRelationshipTypes(clause.getProperty());
                                    break;
                                case EQUALS:
                                    condition = ((AnyObjectFiqlSearchConditionBuilder) builder).inRelationships(value);
                                    break;
                                case NOT_EQUALS:
                                    condition = ((AnyObjectFiqlSearchConditionBuilder) builder).notInRelationships(value);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        if (notTheFirst) {
            if (clause.getOperator() == SearchClause.Operator.AND) {
                condition = builder.and(prevCondition, condition);
            }
            if (clause.getOperator() == SearchClause.Operator.OR) {
                condition = builder.or(prevCondition, condition);
            }
        }
        notTheFirst = true;
    }
    String fiql = condition == null ? null : condition.query();
    LOG.debug("Generated FIQL: {}", fiql);
    return fiql;
}
Also used : SyncopeProperty(org.apache.syncope.common.lib.search.SyncopeProperty) CompleteCondition(org.apache.cxf.jaxrs.ext.search.client.CompleteCondition) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) AnyObjectFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder)

Aggregations

CompleteCondition (org.apache.cxf.jaxrs.ext.search.client.CompleteCondition)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 SearchConditionBuilder (org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder)1 AnyObjectFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder)1 SyncopeProperty (org.apache.syncope.common.lib.search.SyncopeProperty)1 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)1