Search in sources :

Example 11 with AttributeCond

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

the class AnySearchTest method searchWithNotCondition.

@Test
public void searchWithNotCondition() {
    AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.EQ);
    fullnameLeafCond.setSchema("fullname");
    fullnameLeafCond.setExpression("Giuseppe Verdi");
    SearchCond cond = SearchCond.getNotLeafCond(fullnameLeafCond);
    assertTrue(cond.isValid());
    List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(4, users.size());
    Set<String> ids = users.stream().map(Entity::getKey).collect(Collectors.toSet());
    assertTrue(ids.contains("1417acbe-cbf6-4277-9372-e75e04f97000"));
    assertTrue(ids.contains("b3cbc78d-32e6-4bd4-92e0-bbe07566a2ee"));
}
Also used : 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 12 with AttributeCond

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

the class AnySearchTest method searchWithLikeCondition.

@Test
public void searchWithLikeCondition() {
    AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond.setSchema("fullname");
    fullnameLeafCond.setExpression("%o%");
    MembershipCond groupCond = new MembershipCond();
    groupCond.setGroup("root");
    AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
    loginDateCond.setSchema("loginDate");
    loginDateCond.setExpression("2009-05-26");
    SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(groupCond));
    assertTrue(subCond.isValid());
    SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
    assertTrue(cond.isValid());
    List<User> users = searchDAO.search(cond, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(1, users.size());
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) 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 13 with AttributeCond

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

the class AnySearchTest method issueSYNCOPE983.

@Test
public void issueSYNCOPE983() {
    AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond.setSchema("surname");
    fullnameLeafCond.setExpression("%o%");
    List<OrderByClause> orderByClauses = new ArrayList<>();
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("surname");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    orderByClauses.add(orderByClause);
    orderByClause = new OrderByClause();
    orderByClause.setField("username");
    orderByClause.setDirection(OrderByClause.Direction.DESC);
    orderByClauses.add(orderByClause);
    List<User> users = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, SearchCond.getLeafCond(fullnameLeafCond), -1, -1, orderByClauses, AnyTypeKind.USER);
    assertFalse(users.isEmpty());
}
Also used : OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 14 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond 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 15 with AttributeCond

use of org.apache.syncope.core.persistence.api.dao.search.AttributeCond 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)

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