Search in sources :

Example 31 with SearchCond

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

the class AnySearchTest method searchByGroupNameAndKey.

@Test
public void searchByGroupNameAndKey() {
    AnyCond groupNameLeafCond = new AnyCond(AnyCond.Type.EQ);
    groupNameLeafCond.setSchema("name");
    groupNameLeafCond.setExpression("root");
    AnyCond idRightCond = new AnyCond(AnyCond.Type.EQ);
    idRightCond.setSchema("id");
    idRightCond.setExpression("37d15e4c-cdc1-460b-a591-8505c8133806");
    SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupNameLeafCond), SearchCond.getLeafCond(idRightCond));
    assertTrue(searchCondition.isValid());
    List<Group> matching = searchDAO.search(searchCondition, AnyTypeKind.GROUP);
    assertNotNull(matching);
    assertEquals(1, matching.size());
    assertEquals("root", matching.iterator().next().getName());
    assertEquals("37d15e4c-cdc1-460b-a591-8505c8133806", matching.iterator().next().getKey());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) 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) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 32 with SearchCond

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

the class AnySearchTest method issueSYNCOPE95.

@Test
public void issueSYNCOPE95() {
    for (Group group : groupDAO.findAll(1, 100)) {
        groupDAO.delete(group.getKey());
    }
    groupDAO.flush();
    AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
    coolLeafCond.setSchema("cool");
    coolLeafCond.setExpression("true");
    SearchCond cond = SearchCond.getLeafCond(coolLeafCond);
    assertTrue(cond.isValid());
    List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(1, users.size());
    assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", users.get(0).getKey());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) User(org.apache.syncope.core.persistence.api.entity.user.User) 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) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 33 with SearchCond

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

the class SearchCondVisitor method transform.

private SearchCond transform(final String operator, final String left, final String right) {
    SearchCond result = null;
    if (MULTIVALUE.contains(StringUtils.substringBefore(left, "."))) {
        if (conf.getUserConf() == null) {
            throw new IllegalArgumentException("No " + SCIMUserConf.class.getName() + " provided, cannot continue");
        }
        switch(StringUtils.substringBefore(left, ".")) {
            case "emails":
                result = complex(operator, left, right, conf.getUserConf().getEmails());
                break;
            case "phoneNumbers":
                result = complex(operator, left, right, conf.getUserConf().getPhoneNumbers());
                break;
            case "ims":
                result = complex(operator, left, right, conf.getUserConf().getIms());
                break;
            case "photos":
                result = complex(operator, left, right, conf.getUserConf().getPhotos());
                break;
            case "addresses":
                result = addresses(operator, left, right, conf.getUserConf().getAddresses());
                break;
            default:
        }
    }
    if (result == null) {
        AttributeCond attributeCond = createAttributeCond(left);
        attributeCond.setExpression(StringUtils.strip(right, "\""));
        result = setOperator(attributeCond, operator);
    }
    if (result == null) {
        throw new IllegalArgumentException("Could not handle (" + left + " " + operator + " " + right + ") for " + resource);
    }
    return result;
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SCIMUserConf(org.apache.syncope.common.lib.scim.SCIMUserConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond)

Example 34 with SearchCond

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

the class SearchCondVisitor method addresses.

private SearchCond addresses(final String operator, final String left, final String right, final List<SCIMUserAddressConf> items) {
    if (left.endsWith(".type") && "eq".equals(operator)) {
        Optional<SCIMUserAddressConf> item = items.stream().filter(object -> object.getType().name().equals(StringUtils.strip(right, "\""))).findFirst();
        if (item.isPresent()) {
            AttributeCond attributeCond = new AttributeCond();
            attributeCond.setSchema(item.get().getFormatted());
            attributeCond.setType(AttributeCond.Type.ISNOTNULL);
            return SearchCond.getLeafCond(attributeCond);
        }
    } else if (!conf.getUserConf().getEmails().isEmpty() && (MULTIVALUE.contains(left) || left.endsWith(".value"))) {
        List<SearchCond> orConds = new ArrayList<>();
        items.forEach(item -> {
            AttributeCond cond = new AttributeCond();
            cond.setSchema(item.getFormatted());
            cond.setExpression(StringUtils.strip(right, "\""));
            orConds.add(setOperator(cond, operator));
        });
        if (!orConds.isEmpty()) {
            return SearchCond.getOrCond(orConds);
        }
    }
    return null;
}
Also used : Arrays(java.util.Arrays) SCIMUserConf(org.apache.syncope.common.lib.scim.SCIMUserConf) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) Map(java.util.Map) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with SearchCond

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

the class SCIMFilterTest method gt.

@Test
public void gt() {
    SearchCond cond = SearchCondConverter.convert(VISITOR, "meta.lastModified gt \"2011-05-13T04:42:34Z\"");
    assertNotNull(cond);
    assertNotNull(cond.getAnyCond());
    assertEquals("lastChangeDate", cond.getAnyCond().getSchema());
    assertEquals(AttributeCond.Type.GT, cond.getAnyCond().getType());
    assertEquals("2011-05-13T04:42:34Z", cond.getAnyCond().getExpression());
}
Also used : 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