Search in sources :

Example 6 with SearchCond

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

the class DefaultPullCorrelationRule method getSearchCond.

@Override
public SearchCond getSearchCond(final ConnectorObject connObj, final Provision provision) {
    Map<String, Item> mappingItems = provision.getMapping().getItems().stream().collect(Collectors.toMap(Item::getIntAttrName, Function.identity()));
    // search for anys by attribute(s) specified in the policy
    SearchCond searchCond = null;
    for (String schema : conf.getSchemas()) {
        Item mappingItem = mappingItems.get(schema);
        Attribute attr = mappingItem == null ? null : connObj.getAttributeByName(mappingItem.getExtAttrName());
        if (attr == null) {
            throw new IllegalArgumentException("Connector object does not contains the attributes to perform the search: " + schema);
        }
        AttributeCond.Type type;
        String expression = null;
        if (attr.getValue() == null || attr.getValue().isEmpty() || (attr.getValue().size() == 1 && attr.getValue().get(0) == null)) {
            type = AttributeCond.Type.ISNULL;
        } else {
            type = AttributeCond.Type.EQ;
            expression = attr.getValue().size() > 1 ? attr.getValue().toString() : attr.getValue().get(0).toString();
        }
        SearchCond nodeCond;
        // any objects: just key or name can be selected
        if ("key".equalsIgnoreCase(schema) || "username".equalsIgnoreCase(schema) || "name".equalsIgnoreCase(schema)) {
            AnyCond cond = new AnyCond();
            cond.setSchema(schema);
            cond.setType(type);
            cond.setExpression(expression);
            nodeCond = SearchCond.getLeafCond(cond);
        } else {
            AttributeCond cond = new AttributeCond();
            cond.setSchema(schema);
            cond.setType(type);
            cond.setExpression(expression);
            nodeCond = SearchCond.getLeafCond(cond);
        }
        searchCond = searchCond == null ? nodeCond : SearchCond.getAndCond(searchCond, nodeCond);
    }
    return searchCond;
}
Also used : Item(org.apache.syncope.core.persistence.api.entity.resource.Item) Attribute(org.identityconnectors.framework.common.objects.Attribute) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond)

Example 7 with SearchCond

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

the class SearchCondConverterTest method ilike.

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

Example 8 with SearchCond

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

the class SearchCondConverterTest method ieq.

@Test
public void ieq() {
    String fiql = new UserFiqlSearchConditionBuilder().is("username").equalToIgnoreCase("rossini").query();
    assertEquals("username=~rossini", fiql);
    AnyCond attrCond = new AnyCond(AttributeCond.Type.IEQ);
    attrCond.setSchema("username");
    attrCond.setExpression("rossini");
    SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : 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 9 with SearchCond

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

the class SearchCondConverterTest method eq.

@Test
public void eq() {
    String fiql = new UserFiqlSearchConditionBuilder().is("username").equalTo("rossini").query();
    assertEquals("username==rossini", fiql);
    AnyCond attrCond = new AnyCond(AttributeCond.Type.EQ);
    attrCond.setSchema("username");
    attrCond.setExpression("rossini");
    SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : 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 10 with SearchCond

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

the class SearchCondConverterTest method relationships.

@Test
public void relationships() {
    String fiql = new UserFiqlSearchConditionBuilder().inRelationships("ca20ffca-1305-442f-be9a-3723a0cd88ca").query();
    assertEquals(SpecialAttr.RELATIONSHIPS + "==ca20ffca-1305-442f-be9a-3723a0cd88ca", fiql);
    RelationshipCond relationshipCond = new RelationshipCond();
    relationshipCond.setAnyObject("ca20ffca-1305-442f-be9a-3723a0cd88ca");
    SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Aggregations

SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)74 Test (org.junit.jupiter.api.Test)55 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)30 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)26 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)25 User (org.apache.syncope.core.persistence.api.entity.user.User)20 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)17 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)12 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)11 ArrayList (java.util.ArrayList)10 Group (org.apache.syncope.core.persistence.api.entity.group.Group)10 List (java.util.List)8 AnyTypeCond (org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond)8 AssignableCond (org.apache.syncope.core.persistence.api.dao.search.AssignableCond)7 MemberCond (org.apache.syncope.core.persistence.api.dao.search.MemberCond)7 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)6 RelationshipCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipCond)6 ResourceCond (org.apache.syncope.core.persistence.api.dao.search.ResourceCond)6