Search in sources :

Example 21 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond in project syncope by apache.

the class SCIMFilterTest method name.

@Test
public void name() {
    SearchCond cond = SearchCondConverter.convert(VISITOR, "name.familyName co \"O'Malley\"");
    assertNotNull(cond);
    assertEquals(SearchCond.Type.LEAF, cond.getType());
    AttributeCond leaf = cond.getAttributeCond();
    assertNotNull(leaf);
    assertEquals("surname", leaf.getSchema());
    assertEquals(AttributeCond.Type.ILIKE, leaf.getType());
    assertEquals("%O'Malley%", leaf.getExpression());
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 22 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond in project syncope by apache.

the class SearchCondVisitor method visitPrimitive.

@SuppressWarnings("ConvertToStringSwitch")
private SearchCond visitPrimitive(final SearchCondition<SearchBean> sc) {
    String name = getRealPropertyName(sc.getStatement().getProperty());
    Optional<SpecialAttr> specialAttrName = SpecialAttr.fromString(name);
    String value = null;
    try {
        value = SearchUtils.toSqlWildcardString(URLDecoder.decode(sc.getStatement().getValue().toString(), StandardCharsets.UTF_8.name()), false).replaceAll("\\\\_", "_");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("While decoding " + sc.getStatement().getValue(), e);
    }
    Optional<SpecialAttr> specialAttrValue = SpecialAttr.fromString(value);
    AttributeCond attributeCond = createAttributeCond(name);
    attributeCond.setExpression(value);
    ConditionType ct = sc.getConditionType();
    if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) {
        SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc;
        if (SyncopeFiqlParser.IEQ.equals(sfsc.getOperator())) {
            ct = ConditionType.EQUALS;
        } else if (SyncopeFiqlParser.NIEQ.equals(sfsc.getOperator())) {
            ct = ConditionType.NOT_EQUALS;
        } else {
            throw new IllegalArgumentException(String.format("Condition type %s is not supported", sfsc.getOperator()));
        }
    }
    SearchCond leaf;
    switch(ct) {
        case EQUALS:
        case NOT_EQUALS:
            if (!specialAttrName.isPresent()) {
                if (specialAttrValue.isPresent() && specialAttrValue.get() == SpecialAttr.NULL) {
                    attributeCond.setType(AttributeCond.Type.ISNULL);
                    attributeCond.setExpression(null);
                } else if (value.indexOf('%') == -1) {
                    attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.IEQ : AttributeCond.Type.EQ);
                } else {
                    attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.ILIKE : AttributeCond.Type.LIKE);
                }
                leaf = SearchCond.getLeafCond(attributeCond);
            } else {
                switch(specialAttrName.get()) {
                    case TYPE:
                        AnyTypeCond typeCond = new AnyTypeCond();
                        typeCond.setAnyTypeKey(value);
                        leaf = SearchCond.getLeafCond(typeCond);
                        break;
                    case RESOURCES:
                        ResourceCond resourceCond = new ResourceCond();
                        resourceCond.setResourceKey(value);
                        leaf = SearchCond.getLeafCond(resourceCond);
                        break;
                    case GROUPS:
                        MembershipCond groupCond = new MembershipCond();
                        groupCond.setGroup(value);
                        leaf = SearchCond.getLeafCond(groupCond);
                        break;
                    case RELATIONSHIPS:
                        RelationshipCond relationshipCond = new RelationshipCond();
                        relationshipCond.setAnyObject(value);
                        leaf = SearchCond.getLeafCond(relationshipCond);
                        break;
                    case RELATIONSHIP_TYPES:
                        RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
                        relationshipTypeCond.setRelationshipTypeKey(value);
                        leaf = SearchCond.getLeafCond(relationshipTypeCond);
                        break;
                    case ROLES:
                        RoleCond roleCond = new RoleCond();
                        roleCond.setRole(value);
                        leaf = SearchCond.getLeafCond(roleCond);
                        break;
                    case PRIVILEGES:
                        PrivilegeCond privilegeCond = new PrivilegeCond();
                        privilegeCond.setPrivilege(value);
                        leaf = SearchCond.getLeafCond(privilegeCond);
                        break;
                    case DYNREALMS:
                        DynRealmCond dynRealmCond = new DynRealmCond();
                        dynRealmCond.setDynRealm(value);
                        leaf = SearchCond.getLeafCond(dynRealmCond);
                        break;
                    case ASSIGNABLE:
                        AssignableCond assignableCond = new AssignableCond();
                        assignableCond.setRealmFullPath(realm);
                        leaf = SearchCond.getLeafCond(assignableCond);
                        break;
                    case MEMBER:
                        MemberCond memberCond = new MemberCond();
                        memberCond.setMember(value);
                        leaf = SearchCond.getLeafCond(memberCond);
                        break;
                    default:
                        throw new IllegalArgumentException(String.format("Special attr name %s is not supported", specialAttrName));
                }
            }
            if (ct == ConditionType.NOT_EQUALS) {
                if (leaf.getAttributeCond() != null && leaf.getAttributeCond().getType() == AttributeCond.Type.ISNULL) {
                    leaf.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL);
                } else if (leaf.getAnyCond() != null && leaf.getAnyCond().getType() == AnyCond.Type.ISNULL) {
                    leaf.getAnyCond().setType(AttributeCond.Type.ISNOTNULL);
                } else {
                    leaf = SearchCond.getNotLeafCond(leaf);
                }
            }
            break;
        case GREATER_OR_EQUALS:
            attributeCond.setType(AttributeCond.Type.GE);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case GREATER_THAN:
            attributeCond.setType(AttributeCond.Type.GT);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case LESS_OR_EQUALS:
            attributeCond.setType(AttributeCond.Type.LE);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        case LESS_THAN:
            attributeCond.setType(AttributeCond.Type.LT);
            leaf = SearchCond.getLeafCond(attributeCond);
            break;
        default:
            throw new IllegalArgumentException(String.format("Condition type %s is not supported", ct.name()));
    }
    return leaf;
}
Also used : AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) SpecialAttr(org.apache.syncope.common.lib.search.SpecialAttr) SyncopeFiqlSearchCondition(org.apache.syncope.common.lib.search.SyncopeFiqlSearchCondition) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) DynRealmCond(org.apache.syncope.core.persistence.api.dao.search.DynRealmCond) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) ConditionType(org.apache.cxf.jaxrs.ext.search.ConditionType) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond)

Example 23 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond in project syncope by apache.

the class SearchCondConverterTest method or.

@Test
public void or() {
    String fiql = new UserFiqlSearchConditionBuilder().is("fullname").equalTo("*o*", "*i*", "*ini").query();
    assertEquals("fullname==*o*,fullname==*i*,fullname==*ini", fiql);
    fiql = new UserFiqlSearchConditionBuilder().is("fullname").equalTo("*o*").or("fullname").equalTo("*i*").or("fullname").equalTo("*ini").query();
    assertEquals("fullname==*o*,fullname==*i*,fullname==*ini", fiql);
    AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond1.setSchema("fullname");
    fullnameLeafCond1.setExpression("%o%");
    AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond2.setSchema("fullname");
    fullnameLeafCond2.setExpression("%i%");
    AttributeCond fullnameLeafCond3 = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond3.setSchema("fullname");
    fullnameLeafCond3.setExpression("%ini");
    SearchCond orCond = SearchCond.getOrCond(SearchCond.getLeafCond(fullnameLeafCond1), SearchCond.getOrCond(SearchCond.getLeafCond(fullnameLeafCond2), SearchCond.getLeafCond(fullnameLeafCond3)));
    assertEquals(orCond, 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 24 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond in project syncope by apache.

the class SearchCondConverterTest method nilike.

@Test
public void nilike() {
    String fiql = new UserFiqlSearchConditionBuilder().is("username").notEqualTolIgnoreCase("ros*").query();
    assertEquals("username!~ros*", fiql);
    AttributeCond attrCond = new AnyCond(AttributeCond.Type.ILIKE);
    attrCond.setSchema("username");
    attrCond.setExpression("ros%");
    SearchCond simpleCond = SearchCond.getNotLeafCond(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) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Test(org.junit.jupiter.api.Test)

Example 25 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond in project syncope by apache.

the class SearchCondConverterTest method and.

@Test
public void and() {
    String fiql = new UserFiqlSearchConditionBuilder().is("fullname").equalTo("*o*").and("fullname").equalTo("*i*").query();
    assertEquals("fullname==*o*;fullname==*i*", fiql);
    AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond1.setSchema("fullname");
    fullnameLeafCond1.setExpression("%o%");
    AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond2.setSchema("fullname");
    fullnameLeafCond2.setExpression("%i%");
    SearchCond andCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond1), SearchCond.getLeafCond(fullnameLeafCond2));
    assertEquals(andCond, 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)

Aggregations

AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)35 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)25 Test (org.junit.jupiter.api.Test)25 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)16 User (org.apache.syncope.core.persistence.api.entity.user.User)15 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)12 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)8 ArrayList (java.util.ArrayList)4 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)4 Map (java.util.Map)3 SCIMUserAddressConf (org.apache.syncope.common.lib.scim.SCIMUserAddressConf)3 SCIMUserConf (org.apache.syncope.common.lib.scim.SCIMUserConf)3 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)3 Group (org.apache.syncope.core.persistence.api.entity.group.Group)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 SCIMComplexConf (org.apache.syncope.common.lib.scim.SCIMComplexConf)2 SCIMConf (org.apache.syncope.common.lib.scim.SCIMConf)2