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