Search in sources :

Example 6 with UserFiqlSearchConditionBuilder

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

the class SearchCondConverterTest method isNotNull.

@Test
public void isNotNull() {
    String fiql = new UserFiqlSearchConditionBuilder().is("loginDate").notNullValue().query();
    assertEquals("loginDate!=" + SpecialAttr.NULL, fiql);
    AttributeCond attrCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
    attrCond.setSchema("loginDate");
    SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 7 with UserFiqlSearchConditionBuilder

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

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

the class SearchCondConverterTest method isNull.

@Test
public void isNull() {
    String fiql = new UserFiqlSearchConditionBuilder().is("loginDate").nullValue().query();
    assertEquals("loginDate==" + SpecialAttr.NULL, fiql);
    AttributeCond attrCond = new AttributeCond(AttributeCond.Type.ISNULL);
    attrCond.setSchema("loginDate");
    SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 9 with UserFiqlSearchConditionBuilder

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

the class SearchCondConverterTest method roles.

@Test
public void roles() {
    String fiql = new UserFiqlSearchConditionBuilder().inRoles("User reviewer").query();
    assertEquals(SpecialAttr.ROLES + "==User reviewer", fiql);
    RoleCond roleCond = new RoleCond();
    roleCond.setRole("User reviewer");
    SearchCond simpleCond = SearchCond.getLeafCond(roleCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 10 with UserFiqlSearchConditionBuilder

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

UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)19 Test (org.junit.jupiter.api.Test)18 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)17 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)8 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)6 AnyObjectFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder)2 CompleteCondition (org.apache.cxf.jaxrs.ext.search.client.CompleteCondition)1 SyncopeProperty (org.apache.syncope.common.lib.search.SyncopeProperty)1 DynRealmCond (org.apache.syncope.core.persistence.api.dao.search.DynRealmCond)1 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)1 PrivilegeCond (org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond)1 RelationshipCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipCond)1 RelationshipTypeCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond)1 ResourceCond (org.apache.syncope.core.persistence.api.dao.search.ResourceCond)1 RoleCond (org.apache.syncope.core.persistence.api.dao.search.RoleCond)1