use of org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond in project syncope by apache.
the class SearchCondConverterTest method relationshipTypes.
@Test
public void relationshipTypes() {
String fiql = new UserFiqlSearchConditionBuilder().inRelationshipTypes("type1").query();
assertEquals(SpecialAttr.RELATIONSHIP_TYPES + "==type1", fiql);
RelationshipTypeCond relationshipCond = new RelationshipTypeCond();
relationshipCond.setRelationshipTypeKey("type1");
SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
assertEquals(simpleCond, SearchCondConverter.convert(fiql));
fiql = new AnyObjectFiqlSearchConditionBuilder("PRINTER").inRelationshipTypes("neighborhood").query();
assertEquals(SpecialAttr.RELATIONSHIP_TYPES + "==neighborhood;" + SpecialAttr.TYPE + "==PRINTER", fiql);
}
use of org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond in project syncope by apache.
the class AnySearchTest method anyObjectMatch.
@Test
public void anyObjectMatch() {
AnyObject anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
assertNotNull(anyObject);
RelationshipCond relationshipCond = new RelationshipCond();
relationshipCond.setAnyObject("Canon MF 8030cn");
assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipCond)));
RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
relationshipTypeCond.setRelationshipTypeKey("neighborhood");
assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(relationshipTypeCond)));
}
use of org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond in project syncope by apache.
the class AnySearchTest method searchByRelationshipType.
@Test
public void searchByRelationshipType() {
// 1. first search for printers involved in "neighborhood" relationship
RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
relationshipTypeCond.setRelationshipTypeKey("neighborhood");
AnyTypeCond tcond = new AnyTypeCond();
tcond.setAnyTypeKey("PRINTER");
SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(relationshipTypeCond), SearchCond.getLeafCond(tcond));
assertTrue(searchCondition.isValid());
List<AnyObject> anyObjects = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
assertNotNull(anyObjects);
assertEquals(2, anyObjects.size());
assertTrue(anyObjects.stream().anyMatch(any -> "fc6dbc3a-6c07-4965-8781-921e7401a4a5".equals(any.getKey())));
assertTrue(anyObjects.stream().anyMatch(any -> "8559d14d-58c2-46eb-a2d4-a7d35161e8f8".equals(any.getKey())));
// 2. search for users involved in "neighborhood" relationship
searchCondition = SearchCond.getLeafCond(relationshipTypeCond);
List<User> users = searchDAO.search(searchCondition, AnyTypeKind.USER);
assertNotNull(users);
assertEquals(1, users.size());
assertTrue(users.stream().anyMatch(any -> "c9b2dec2-00a7-4855-97c0-d854842b4b24".equals(any.getKey())));
}
use of org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond in project syncope by apache.
the class SearchCondVisitor method visitPrimitive.
@SuppressWarnings("ConvertToStringSwitch")
private SearchCond visitPrimitive(final SearchCondition<SearchBean> sc) {
String name = getRealPropertyName(sc.getStatement().getProperty());
Optional<SpecialAttr> specialAttrName = SpecialAttr.fromString(name);
String value = null;
try {
value = SearchUtils.toSqlWildcardString(URLDecoder.decode(sc.getStatement().getValue().toString(), StandardCharsets.UTF_8.name()), false).replaceAll("\\\\_", "_");
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("While decoding " + sc.getStatement().getValue(), e);
}
Optional<SpecialAttr> specialAttrValue = SpecialAttr.fromString(value);
AttributeCond attributeCond = createAttributeCond(name);
attributeCond.setExpression(value);
ConditionType ct = sc.getConditionType();
if (sc instanceof SyncopeFiqlSearchCondition && sc.getConditionType() == ConditionType.CUSTOM) {
SyncopeFiqlSearchCondition<SearchBean> sfsc = (SyncopeFiqlSearchCondition<SearchBean>) sc;
if (SyncopeFiqlParser.IEQ.equals(sfsc.getOperator())) {
ct = ConditionType.EQUALS;
} else if (SyncopeFiqlParser.NIEQ.equals(sfsc.getOperator())) {
ct = ConditionType.NOT_EQUALS;
} else {
throw new IllegalArgumentException(String.format("Condition type %s is not supported", sfsc.getOperator()));
}
}
SearchCond leaf;
switch(ct) {
case EQUALS:
case NOT_EQUALS:
if (!specialAttrName.isPresent()) {
if (specialAttrValue.isPresent() && specialAttrValue.get() == SpecialAttr.NULL) {
attributeCond.setType(AttributeCond.Type.ISNULL);
attributeCond.setExpression(null);
} else if (value.indexOf('%') == -1) {
attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.IEQ : AttributeCond.Type.EQ);
} else {
attributeCond.setType(sc.getConditionType() == ConditionType.CUSTOM ? AttributeCond.Type.ILIKE : AttributeCond.Type.LIKE);
}
leaf = SearchCond.getLeafCond(attributeCond);
} else {
switch(specialAttrName.get()) {
case TYPE:
AnyTypeCond typeCond = new AnyTypeCond();
typeCond.setAnyTypeKey(value);
leaf = SearchCond.getLeafCond(typeCond);
break;
case RESOURCES:
ResourceCond resourceCond = new ResourceCond();
resourceCond.setResourceKey(value);
leaf = SearchCond.getLeafCond(resourceCond);
break;
case GROUPS:
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup(value);
leaf = SearchCond.getLeafCond(groupCond);
break;
case RELATIONSHIPS:
RelationshipCond relationshipCond = new RelationshipCond();
relationshipCond.setAnyObject(value);
leaf = SearchCond.getLeafCond(relationshipCond);
break;
case RELATIONSHIP_TYPES:
RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
relationshipTypeCond.setRelationshipTypeKey(value);
leaf = SearchCond.getLeafCond(relationshipTypeCond);
break;
case ROLES:
RoleCond roleCond = new RoleCond();
roleCond.setRole(value);
leaf = SearchCond.getLeafCond(roleCond);
break;
case PRIVILEGES:
PrivilegeCond privilegeCond = new PrivilegeCond();
privilegeCond.setPrivilege(value);
leaf = SearchCond.getLeafCond(privilegeCond);
break;
case DYNREALMS:
DynRealmCond dynRealmCond = new DynRealmCond();
dynRealmCond.setDynRealm(value);
leaf = SearchCond.getLeafCond(dynRealmCond);
break;
case ASSIGNABLE:
AssignableCond assignableCond = new AssignableCond();
assignableCond.setRealmFullPath(realm);
leaf = SearchCond.getLeafCond(assignableCond);
break;
case MEMBER:
MemberCond memberCond = new MemberCond();
memberCond.setMember(value);
leaf = SearchCond.getLeafCond(memberCond);
break;
default:
throw new IllegalArgumentException(String.format("Special attr name %s is not supported", specialAttrName));
}
}
if (ct == ConditionType.NOT_EQUALS) {
if (leaf.getAttributeCond() != null && leaf.getAttributeCond().getType() == AttributeCond.Type.ISNULL) {
leaf.getAttributeCond().setType(AttributeCond.Type.ISNOTNULL);
} else if (leaf.getAnyCond() != null && leaf.getAnyCond().getType() == AnyCond.Type.ISNULL) {
leaf.getAnyCond().setType(AttributeCond.Type.ISNOTNULL);
} else {
leaf = SearchCond.getNotLeafCond(leaf);
}
}
break;
case GREATER_OR_EQUALS:
attributeCond.setType(AttributeCond.Type.GE);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case GREATER_THAN:
attributeCond.setType(AttributeCond.Type.GT);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case LESS_OR_EQUALS:
attributeCond.setType(AttributeCond.Type.LE);
leaf = SearchCond.getLeafCond(attributeCond);
break;
case LESS_THAN:
attributeCond.setType(AttributeCond.Type.LT);
leaf = SearchCond.getLeafCond(attributeCond);
break;
default:
throw new IllegalArgumentException(String.format("Condition type %s is not supported", ct.name()));
}
return leaf;
}
use of org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond in project syncope by apache.
the class AnySearchTest method userMatch.
@Test
public void userMatch() {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
assertNotNull(user);
MembershipCond groupCond = new MembershipCond();
groupCond.setGroup("secretary");
assertFalse(searchDAO.matches(user, SearchCond.getLeafCond(groupCond)));
groupCond.setGroup("root");
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(groupCond)));
RoleCond roleCond = new RoleCond();
roleCond.setRole("Other");
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(roleCond)));
PrivilegeCond privilegeCond = new PrivilegeCond();
privilegeCond.setPrivilege("postMighty");
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(privilegeCond)));
user = userDAO.find("c9b2dec2-00a7-4855-97c0-d854842b4b24");
assertNotNull(user);
RelationshipCond relationshipCond = new RelationshipCond();
relationshipCond.setAnyObject("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(relationshipCond)));
RelationshipTypeCond relationshipTypeCond = new RelationshipTypeCond();
relationshipTypeCond.setRelationshipTypeKey("neighborhood");
assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(relationshipTypeCond)));
}
Aggregations