org.apache.cxf.jaxrs.ext.search.ConditionType Java Examples

The following examples show how to use org.apache.cxf.jaxrs.ext.search.ConditionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void visit(SearchCondition<T> sc) {
    if (state.get() == null) {
        reset();
    }
    PrimitiveStatement statement = sc.getStatement();
    if (statement != null) {
        if (statement.getProperty() != null) {
            state.get().peek().add(buildSimpleQuery(sc.getConditionType(),
                                     statement.getProperty(),
                                     statement.getValue()));
        }
    } else {
        state.get().push(new ArrayList<>());
        for (SearchCondition<T> condition : sc.getSearchConditions()) {
            condition.accept(this);
        }
        boolean orCondition = sc.getConditionType() == ConditionType.OR;
        List<Query> queries = state.get().pop();
        state.get().peek().add(createCompositeQuery(queries, orCondition));
    }
}
 
Example #2
Source File: SearchCondVisitor.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected static ConditionType getConditionType(final SearchCondition<SearchBean> sc) {
    ConditionType ct = sc.getConditionType();
    if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) {
        SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc;
        switch (sfsc.getOperator()) {
            case SyncopeFiqlParser.IEQ:
                ct = ConditionType.EQUALS;
                break;

            case SyncopeFiqlParser.NIEQ:
                ct = ConditionType.NOT_EQUALS;
                break;

            default:
                throw new IllegalArgumentException(
                        String.format("Condition type %s is not supported", sfsc.getOperator()));
        }
    }

    return ct;
}
 
Example #3
Source File: LdapQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static String conditionTypeToLdapOperator(ConditionType ct) {
    String op;
    switch (ct) {
    case EQUALS:
    case NOT_EQUALS:
        op = "=";
        break;
    case GREATER_THAN:
    case GREATER_OR_EQUALS:
        op = ">=";
        break;
    case LESS_THAN:
    case LESS_OR_EQUALS:
        op = "<=";
        break;
    default:
        String msg = String.format("Condition type %s is not supported", ct.name());
        throw new RuntimeException(msg);
    }
    return op;
}
 
Example #4
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createFloatRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Float floatValue = Float.valueOf(value.toString());
    Float min = getMin(type, floatValue);
    if (min == null) {
        min = Float.NEGATIVE_INFINITY;
    } else if (!minInclusive) {
        min = Math.nextUp(min);
    }

    Float max = getMax(type, floatValue);
    if (max == null) {
        max = Float.POSITIVE_INFINITY;
    } else if (!maxInclusive) {
        max = Math.nextDown(max);
    }

    return FloatPoint.newRangeQuery(name, min, max);
}
 
Example #5
Source File: SyncopeFiqlParser.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
public SearchCondition<T> build() throws SearchParseException {
    String templateName = getSetter(name);
    T cond = createTemplate(templateName);
    ConditionType ct = operatorsMap.get(operator);

    if (isPrimitive(cond)) {
        return new SyncopeFiqlSearchCondition<>(ct, cond);
    } else {
        String templateNameLCase = templateName.toLowerCase();
        return new SyncopeFiqlSearchCondition<>(Map.of(templateNameLCase, ct),
                Map.of(templateNameLCase, name),
                Map.of(templateNameLCase, tvalue.getTypeInfo()),
                cond, operator);
    }
}
 
Example #6
Source File: SyncopeFiqlParser.java    From syncope with Apache License 2.0 6 votes vote down vote up
public SyncopeFiqlParser(
        final Class<T> tclass,
        final Map<String, String> contextProperties,
        final Map<String, String> beanProperties) {

    super(tclass, contextProperties, beanProperties);

    operatorsMap.put(IEQ, ConditionType.CUSTOM);
    operatorsMap.put(NIEQ, ConditionType.CUSTOM);

    CONDITION_MAP.put(ConditionType.CUSTOM, IEQ);
    CONDITION_MAP.put(ConditionType.CUSTOM, NIEQ);

    String comparators = GT + '|' + GE + '|' + LT + '|' + LE + '|' + EQ + '|' + NEQ + '|' + IEQ + '|' + NIEQ;
    String s1 = "[\\p{ASCII}]+(" + comparators + ')';
    comparatorsPattern = Pattern.compile(s1);
}
 
Example #7
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createDoubleRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Double doubleValue = Double.valueOf(value.toString());
    Double min = getMin(type, doubleValue);
    if (min == null) {
        min = Double.NEGATIVE_INFINITY;
    } else if (!minInclusive) {
        min = Math.nextUp(min);
    }

    Double max = getMax(type, doubleValue);
    if (max == null) {
        max = Double.POSITIVE_INFINITY;
    } else if (!maxInclusive) {
        max = Math.nextDown(max);
    }
    return DoublePoint.newRangeQuery(name, min, max);
}
 
Example #8
Source File: FiqlParserTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseComplex1() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
    assertEquals(ConditionType.AND, filter.getConditionType());

    List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
    assertEquals(2, conditions.size());
    PrimitiveStatement st1 = conditions.get(0).getStatement();
    PrimitiveStatement st2 = conditions.get(1).getStatement();
    assertTrue((ConditionType.EQUALS.equals(st1.getCondition())
        && ConditionType.GREATER_THAN.equals(st2.getCondition()))
        || (ConditionType.EQUALS.equals(st2.getCondition())
            && ConditionType.GREATER_THAN.equals(st1.getCondition())));

    assertTrue(filter.isMet(new Condition("amichalec", 12, new Date())));
    assertTrue(filter.isMet(new Condition("ami", 12, new Date())));
    assertFalse(filter.isMet(new Condition("ami", 8, null)));
    assertFalse(filter.isMet(new Condition("am", 20, null)));
}
 
Example #9
Source File: FiqlParserTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseComplex2() throws SearchParseException {
    SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
    assertEquals(ConditionType.OR, filter.getConditionType());

    List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
    assertEquals(2, conditions.size());

    PrimitiveStatement st1 = conditions.get(0).getStatement();
    PrimitiveStatement st2 = conditions.get(1).getStatement();
    assertTrue((ConditionType.EQUALS.equals(st1.getCondition())
        && ConditionType.GREATER_THAN.equals(st2.getCondition()))
        || (ConditionType.EQUALS.equals(st2.getCondition())
            && ConditionType.GREATER_THAN.equals(st1.getCondition())));

    assertTrue(filter.isMet(new Condition("ami", 0, new Date())));
    assertTrue(filter.isMet(new Condition("foo", 20, null)));
    assertFalse(filter.isMet(new Condition("foo", 0, null)));
}
 
Example #10
Source File: SearchUtils.java    From syncope with Apache License 2.0 6 votes vote down vote up
private static List<SearchClause> getCompoundSearchClauses(final SearchCondition<SearchBean> sc) {
    List<SearchClause> clauses = new ArrayList<>();

    sc.getSearchConditions().forEach(searchCondition -> {
        if (searchCondition.getStatement() == null) {
            clauses.addAll(getCompoundSearchClauses(searchCondition));
        } else {
            SearchClause clause = getPrimitiveSearchClause(searchCondition);
            if (sc.getConditionType() == ConditionType.AND) {
                clause.setOperator(SearchClause.Operator.AND);
            }
            if (sc.getConditionType() == ConditionType.OR) {
                clause.setOperator(SearchClause.Operator.OR);
            }
            clauses.add(clause);
        }
    });

    return clauses;
}
 
Example #11
Source File: ServerApplicationManagementService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
private org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.ComplexOperator
getComplexOperatorFromOdata(org.apache.cxf.jaxrs.ext.search.ConditionType odataConditionType) {

    org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.ComplexOperator
            complexConditionType = null;
    switch (odataConditionType) {
        case OR:
            complexConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType
                    .ComplexOperator.OR;
            break;
        case AND:
            complexConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType
                    .ComplexOperator.AND;
            break;
    }
    return complexConditionType;
}
 
Example #12
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createLongRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Long longValue = Long.valueOf(value.toString());
    Long min = getMin(type, longValue);
    if (min == null) {
        min = Long.MIN_VALUE;
    } else if (!minInclusive) {
        min = Math.addExact(min, 1L);
    }

    Long max = getMax(type, longValue);
    if (max == null) {
        max = Long.MAX_VALUE;
    } else if (!maxInclusive) {
        max = Math.addExact(max, -1L);
    }
    return LongPoint.newRangeQuery(name, min, max);
}
 
Example #13
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Query createIntRangeQuery(final String name, final Object value,
        final ConditionType type, final boolean minInclusive, final boolean maxInclusive) {
    final Integer intValue = Integer.valueOf(value.toString());
    Integer min = getMin(type, intValue);
    if (min == null) {
        min = Integer.MIN_VALUE;
    } else if (!minInclusive) {
        min = Math.addExact(min, 1);
    }

    Integer max = getMax(type, intValue);
    if (max == null) {
        max = Integer.MAX_VALUE;
    } else if (!maxInclusive) {
        max = Math.addExact(max, -1);
    }

    return IntPoint.newRangeQuery(name, min, max);
}
 
Example #14
Source File: ServerIdpManagementService.java    From identity-api-server with Apache License 2.0 6 votes vote down vote up
private org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.ComplexOperator
getComplexOperatorFromOdata(org.apache.cxf.jaxrs.ext.search.ConditionType odataConditionType) {

    org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.ComplexOperator
            complexConditionType = null;
    switch (odataConditionType) {
        case OR:
            complexConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType
                    .ComplexOperator.OR;
            break;
        case AND:
            complexConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType
                    .ComplexOperator.AND;
            break;
    }
    return complexConditionType;
}
 
Example #15
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Query createRangeQuery(Class<?> cls, String name, Object value, ConditionType type) {

        boolean minInclusive = type == ConditionType.GREATER_OR_EQUALS || type == ConditionType.EQUALS;
        boolean maxInclusive = type == ConditionType.LESS_OR_EQUALS || type == ConditionType.EQUALS;

        if (String.class.isAssignableFrom(cls) || Number.class.isAssignableFrom(cls)) {
            Query query = null;

            if (Double.class.isAssignableFrom(cls)) {
                query = createDoubleRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else if (Float.class.isAssignableFrom(cls)) {
                query = createFloatRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else if (Long.class.isAssignableFrom(cls)) {
                query = createLongRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else {
                query = createIntRangeQuery(name, value, type, minInclusive, maxInclusive);
            }

            return query;
        } else if (Date.class.isAssignableFrom(cls)) {
            final Date date = getValue(Date.class, getFieldTypeConverter(), value.toString());
            final String luceneDateValue = getString(Date.class, getFieldTypeConverter(), date);

            if (type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS) {
                return TermRangeQuery.newStringRange(name, null, luceneDateValue, minInclusive, maxInclusive);
            }
            return TermRangeQuery.newStringRange(name, luceneDateValue,
                DateTools.dateToString(new Date(), Resolution.MILLISECOND), minInclusive, maxInclusive);
        } else {
            return null;
        }
    }
 
Example #16
Source File: ServerIdpManagementService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve search condition from @{SearchContext}.
 *
 * @param templateType  Template type.
 * @param tenantDomain  Tenant domain.
 * @param searchContext Search context.
 * @return  Condition.
 */
private Condition getSearchCondition(String templateType, String tenantDomain, SearchContext searchContext) {

    if (searchContext != null) {
        SearchCondition<ResourceSearchBean> searchCondition = searchContext.getCondition(ResourceSearchBean.class);
        if (searchCondition != null) {
            Condition result = buildSearchCondition(searchCondition);
            Condition typeCondition = new PrimitiveCondition(Constants.TEMPLATE_TYPE_KEY, EQUALS, templateType);
            Condition tenantCondition = new PrimitiveCondition(Constants.TENANT_DOMAIN_KEY, EQUALS, tenantDomain);

            List<Condition> list = new ArrayList<>();
            list.add(result);
            list.add(typeCondition);
            list.add(tenantCondition);
            return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND),
                    list);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Search condition parsed from the search expression is invalid.");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find a valid search context.");
        }
    }
    return null;
}
 
Example #17
Source File: CollectionCheckCondition.java    From cxf with Apache License 2.0 5 votes vote down vote up
public CollectionCheckCondition(String propertyName,
                                Object propertyValue,
                                Type propertyType,
                                ConditionType ct,
                                T condition,
                                CollectionCheckInfo checkInfo) {
    super(propertyName, propertyValue, propertyType, ct, condition);
    this.checkInfo = checkInfo;
}
 
Example #18
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Query buildSimpleQuery(ConditionType ct, String name, Object value) {
    name = super.getRealPropertyName(name);
    validatePropertyValue(name, value);

    Class<?> clazz = getPrimitiveFieldClass(name, value.getClass());


    Query query = null;
    switch (ct) {
    case EQUALS:
        query = createEqualsQuery(clazz, name, value);
        break;
    case NOT_EQUALS:
        BooleanQuery.Builder booleanBuilder = new BooleanQuery.Builder();
        booleanBuilder.add(createEqualsQuery(clazz, name, value), BooleanClause.Occur.MUST_NOT);
        BooleanQuery booleanQuery = booleanBuilder.build();
        query = booleanQuery;
        break;
    case GREATER_THAN:
        query = createRangeQuery(clazz, name, value, ct);
        break;
    case GREATER_OR_EQUALS:
        query = createRangeQuery(clazz, name, value, ct);
        break;
    case LESS_THAN:
        query = createRangeQuery(clazz, name, value, ct);
        break;
    case LESS_OR_EQUALS:
        query = createRangeQuery(clazz, name, value, ct);
        break;
    default:
        break;
    }
    return query;
}
 
Example #19
Source File: FiqlSearchConditionBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected String toFiqlPrimitiveCondition(ConditionType type) {
    String fiqlType = FiqlParser.CONDITION_MAP.get(type);
    if (fiqlType == null) {
        throw new IllegalArgumentException("Only primitive condition types are supported");
    }
    return fiqlType;
}
 
Example #20
Source File: FiqlParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public SearchCondition<T> build() throws SearchParseException {
    String templateName = getSetter(name);
    T cond = createTemplate(templateName);
    ConditionType ct = operatorsMap.get(operator);

    if (isPrimitive(cond)) {
        return new SimpleSearchCondition<>(ct, cond);
    }
    String templateNameLCase = templateName.toLowerCase();
    return new SimpleSearchCondition<>(Collections.singletonMap(templateNameLCase, ct),
                                        Collections.singletonMap(templateNameLCase, name),
                                        Collections.singletonMap(templateNameLCase, tvalue.getTypeInfo()),
                                        cond);
}
 
Example #21
Source File: FiqlParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates FIQL parser.
 *
 * @param tclass - class of T used to create condition objects in built syntax tree. Class T must have
 *            accessible no-arg constructor and complementary setters to these used in FIQL expressions.
 * @param contextProperties
 * @param beanProperties
 */
public FiqlParser(Class<T> tclass,
                  Map<String, String> contextProperties,
                  Map<String, String> beanProperties) {
    super(tclass, contextProperties, beanProperties);

    if (PropertyUtils.isTrue(this.contextProperties.get(SUPPORT_SINGLE_EQUALS))) {
        operatorsMap = new HashMap<>(operatorsMap);
        operatorsMap.put("=", ConditionType.EQUALS);
        comparatorsPattern = COMPARATORS_PATTERN_SINGLE_EQUALS;
    }
}
 
Example #22
Source File: AbstractJPATypedQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private Predicate doBuildCollectionPredicate(ConditionType ct, Path<?> path, CollectionCheckInfo collInfo) {
    Predicate pred = null;

    Expression<Integer> exp = builder.size((Expression<? extends Collection>)path);
    Integer value = Integer.valueOf(collInfo.getCollectionCheckValue().toString());

    switch (ct) {
    case GREATER_THAN:
        pred = builder.greaterThan(exp, value);
        break;
    case EQUALS:
        pred = builder.equal(exp, value);
        break;
    case NOT_EQUALS:
        pred = builder.notEqual(exp, value);
        break;
    case LESS_THAN:
        pred = builder.lessThan(exp, value);
        break;
    case LESS_OR_EQUALS:
        pred = builder.lessThanOrEqualTo(exp, value);
        break;
    case GREATER_OR_EQUALS:
        pred = builder.greaterThanOrEqualTo(exp, value);
        break;
    default:
        break;
    }
    return pred;
}
 
Example #23
Source File: SyncopeFiqlParserTest.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * Simple test for ensuring there's no regression.
 */
@Test
public void testEquals() {
    SyncopeFiqlSearchCondition<SearchBean> cond = parse("name==ami*");
    assertEquals(FiqlParser.EQ, cond.getOperator());
    assertEquals(ConditionType.EQUALS, cond.getConditionType());
    assertEquals("ami*", cond.getCondition().get("name"));
}
 
Example #24
Source File: SyncopeFiqlParserTest.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotEqualsIgnoreCase() {
    SyncopeFiqlSearchCondition<SearchBean> cond = parse("name!~ami*");
    assertEquals(SyncopeFiqlParser.NIEQ, cond.getOperator());
    assertEquals(ConditionType.CUSTOM, cond.getConditionType());
    assertEquals("ami*", cond.getCondition().get("name"));
}
 
Example #25
Source File: SyncopeFiqlParserTest.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsIgnoreCase() {
    SyncopeFiqlSearchCondition<SearchBean> cond = parse("name=~ami*");
    assertEquals(SyncopeFiqlParser.IEQ, cond.getOperator());
    assertEquals(ConditionType.CUSTOM, cond.getConditionType());
    assertEquals("ami*", cond.getCondition().get("name"));
}
 
Example #26
Source File: SyncopeFiqlSearchCondition.java    From syncope with Apache License 2.0 5 votes vote down vote up
public SyncopeFiqlSearchCondition(
        final Map<String, ConditionType> getters2operators,
        final Map<String, String> realGetters,
        final Map<String, Beanspector.TypeInfo> propertyTypeInfo,
        final T condition,
        final String operator) {

    super(getters2operators, realGetters, propertyTypeInfo, condition);
    this.operator = operator;
}
 
Example #27
Source File: ServerApplicationManagementService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.PrimitiveOperator
getPrimitiveOperatorFromOdata(org.apache.cxf.jaxrs.ext.search.ConditionType odataConditionType) {

    org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.PrimitiveOperator
            primitiveConditionType = null;
    switch (odataConditionType) {
        case EQUALS:
            primitiveConditionType = EQUALS;
            break;
        case GREATER_OR_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.GREATER_OR_EQUALS;
            break;
        case LESS_OR_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.LESS_OR_EQUALS;
            break;
        case GREATER_THAN:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.GREATER_THAN;
            break;
        case NOT_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.NOT_EQUALS;
            break;
        case LESS_THAN:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.LESS_THAN;
            break;
    }
    return primitiveConditionType;
}
 
Example #28
Source File: ServerApplicationManagementService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private Condition buildSearchCondition(SearchCondition searchCondition) {

        if (!(searchCondition.getStatement() == null)) {
            PrimitiveStatement primitiveStatement = searchCondition.getStatement();

            if (ApplicationManagementConstants.TemplateProperties.SEARCH_KEYS.contains(primitiveStatement.getProperty
                    ())) {
                List<Condition> list = new ArrayList<>();
                Condition attrKeyCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties
                        .ATTR_KEY, EQUALS, primitiveStatement.getProperty());
                Condition attrValueCondition = new PrimitiveCondition(ApplicationManagementConstants
                        .TemplateProperties.ATTR_VALUE, getPrimitiveOperatorFromOdata(primitiveStatement.getCondition
                        ()), primitiveStatement.getValue());
                list.add(attrKeyCondition);
                list.add(attrValueCondition);
                return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND),
                        list);
            } else if (ApplicationManagementConstants.TemplateProperties.SEARCH_KEY_NAME.equals(primitiveStatement
                    .getProperty())) {
                return new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties
                        .SEARCH_KEY_NAME_INTERNAL, getPrimitiveOperatorFromOdata(primitiveStatement
                        .getCondition()), primitiveStatement.getValue());
            } else {
                throw buildClientError(ApplicationManagementConstants.ErrorMessage
                        .ERROR_CODE_ERROR_INVALID_SEARCH_FILTER, null);
            }
        } else {
            List<Condition> conditions = new ArrayList<>();
            for (Object condition : searchCondition.getSearchConditions()) {
                Condition buildCondition = buildSearchCondition((SearchCondition) condition);
                conditions.add(buildCondition);
            }
            return new ComplexCondition(getComplexOperatorFromOdata(searchCondition.getConditionType()), conditions);
        }
    }
 
Example #29
Source File: ServerApplicationManagementService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve search condition from @{SearchContext}.
 *
 * @param templateType  Template type.
 * @param tenantDomain  Tenant domain.
 * @param searchContext Search context.
 * @return  Condition.
 */
private Condition getSearchCondition(String templateType, String tenantDomain, SearchContext searchContext) {

    if (searchContext != null) {
        SearchCondition<ResourceSearchBean> searchCondition = searchContext.getCondition(ResourceSearchBean.class);
        if (searchCondition != null) {
            Condition result = buildSearchCondition(searchCondition);
            List<Condition> list = new ArrayList<>();
            Condition typeCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties
                    .TEMPLATE_TYPE_KEY, EQUALS, templateType);
            Condition tenantCondition = new PrimitiveCondition(ApplicationManagementConstants.TemplateProperties
                    .TENANT_DOMAIN_KEY, EQUALS, tenantDomain);
            if (result instanceof ComplexCondition) {
                list = ((ComplexCondition) result).getConditions();
                list.add(typeCondition);
                list.add(tenantCondition);
            } else if (result instanceof PrimitiveCondition) {
                list.add(result);
                list.add(typeCondition);
                list.add(tenantCondition);
            }
            return new ComplexCondition(getComplexOperatorFromOdata(ConditionType.AND),
                    list);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Search condition parsed from the search expression is invalid.");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cannot find a valid search context.");
        }
    }
    return null;
}
 
Example #30
Source File: ServerIdpManagementService.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.PrimitiveOperator
getPrimitiveOperatorFromOdata(org.apache.cxf.jaxrs.ext.search.ConditionType odataConditionType) {

    org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.PrimitiveOperator
            primitiveConditionType = null;
    switch (odataConditionType) {
        case EQUALS:
            primitiveConditionType = EQUALS;
            break;
        case GREATER_OR_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.GREATER_OR_EQUALS;
            break;
        case LESS_OR_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.LESS_OR_EQUALS;
            break;
        case GREATER_THAN:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.GREATER_THAN;
            break;
        case NOT_EQUALS:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.NOT_EQUALS;
            break;
        case LESS_THAN:
            primitiveConditionType = org.wso2.carbon.identity.configuration.mgt.core.search.constant
                    .ConditionType.PrimitiveOperator.LESS_THAN;
            break;
    }
    return primitiveConditionType;
}