Search in sources :

Example 1 with AnyObjectFiqlSearchConditionBuilder

use of org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder in project syncope by apache.

the class SearchCondConverterTest method type.

@Test
public void type() {
    String fiql = new AnyObjectFiqlSearchConditionBuilder("PRINTER").query();
    assertEquals(SpecialAttr.TYPE + "==PRINTER", fiql);
    AnyTypeCond acond = new AnyTypeCond();
    acond.setAnyTypeKey("PRINTER");
    SearchCond simpleCond = SearchCond.getLeafCond(acond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) AnyObjectFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 2 with AnyObjectFiqlSearchConditionBuilder

use of org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder in project syncope by apache.

the class SearchCondConverterTest method relationshipTypes.

@Test
public void relationshipTypes() {
    String fiql = new UserFiqlSearchConditionBuilder().inRelationshipTypes("type1").query();
    assertEquals(SpecialAttr.RELATIONSHIP_TYPES + "==type1", fiql);
    RelationshipTypeCond relationshipCond = new RelationshipTypeCond();
    relationshipCond.setRelationshipTypeKey("type1");
    SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
    fiql = new AnyObjectFiqlSearchConditionBuilder("PRINTER").inRelationshipTypes("neighborhood").query();
    assertEquals(SpecialAttr.RELATIONSHIP_TYPES + "==neighborhood;" + SpecialAttr.TYPE + "==PRINTER", fiql);
}
Also used : UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) AnyObjectFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 3 with AnyObjectFiqlSearchConditionBuilder

use of org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder 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

AnyObjectFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder)3 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)2 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)2 Test (org.junit.jupiter.api.Test)2 CompleteCondition (org.apache.cxf.jaxrs.ext.search.client.CompleteCondition)1 SyncopeProperty (org.apache.syncope.common.lib.search.SyncopeProperty)1 AnyTypeCond (org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond)1 RelationshipTypeCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond)1