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"));
}
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());
}
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());
}
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());
}
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;
}
Aggregations