Search in sources :

Example 16 with SearchCond

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

the class SearchCondConverterTest method roles.

@Test
public void roles() {
    String fiql = new UserFiqlSearchConditionBuilder().inRoles("User reviewer").query();
    assertEquals(SpecialAttr.ROLES + "==User reviewer", fiql);
    RoleCond roleCond = new RoleCond();
    roleCond.setRole("User reviewer");
    SearchCond simpleCond = SearchCond.getLeafCond(roleCond);
    assertEquals(simpleCond, SearchCondConverter.convert(fiql));
}
Also used : RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) UserFiqlSearchConditionBuilder(org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 17 with SearchCond

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

the class AnySearchTest method searchByType.

@Test
public void searchByType() {
    AnyTypeCond tcond = new AnyTypeCond();
    tcond.setAnyTypeKey("PRINTER");
    SearchCond searchCondition = SearchCond.getLeafCond(tcond);
    assertTrue(searchCondition.isValid());
    List<AnyObject> printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertNotNull(printers);
    assertEquals(3, printers.size());
    tcond.setAnyTypeKey("UNEXISTING");
    printers = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertNotNull(printers);
    assertTrue(printers.isEmpty());
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) 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 18 with SearchCond

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

the class AnySearchTest method searchByKey.

@Test
public void searchByKey() {
    AnyCond idLeafCond = new AnyCond(AnyCond.Type.EQ);
    idLeafCond.setSchema("id");
    idLeafCond.setExpression("74cd8ece-715a-44a4-a736-e17b46c4e7e6");
    SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
    assertTrue(searchCondition.isValid());
    List<User> users = searchDAO.search(searchCondition, AnyTypeKind.USER);
    assertNotNull(users);
    assertEquals(1, users.size());
    assertEquals("74cd8ece-715a-44a4-a736-e17b46c4e7e6", users.iterator().next().getKey());
}
Also used : User(org.apache.syncope.core.persistence.api.entity.user.User) 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 19 with SearchCond

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

the class AnySearchTest method groupOrderBy.

@Test
public void groupOrderBy() {
    AnyCond idLeafCond = new AnyCond(AnyCond.Type.LIKE);
    idLeafCond.setSchema("name");
    idLeafCond.setExpression("%r");
    SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
    assertTrue(searchCondition.isValid());
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    List<Group> groups = searchDAO.search(searchCondition, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.GROUP), groups.size());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) 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 20 with SearchCond

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

the class AnySearchTest method issueSYNCOPE980.

@Test
public void issueSYNCOPE980() {
    AnyType service = entityFactory.newEntity(AnyType.class);
    service.setKey("SERVICE");
    service.setKind(AnyTypeKind.ANY_OBJECT);
    service = anyTypeDAO.save(service);
    Group citizen = groupDAO.findByName("citizen");
    assertNotNull(citizen);
    AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
    anyObject.setName("one");
    anyObject.setType(service);
    anyObject.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
    AMembership membership = entityFactory.newEntity(AMembership.class);
    membership.setRightEnd(citizen);
    membership.setLeftEnd(anyObject);
    anyObject.add(membership);
    anyObjectDAO.save(anyObject);
    anyObject = anyObjectDAO.find("fc6dbc3a-6c07-4965-8781-921e7401a4a5");
    membership = entityFactory.newEntity(AMembership.class);
    membership.setRightEnd(citizen);
    membership.setLeftEnd(anyObject);
    anyObject.add(membership);
    anyObjectDAO.save(anyObject);
    anyObjectDAO.flush();
    MembershipCond groupCond = new MembershipCond();
    groupCond.setGroup("citizen");
    SearchCond searchCondition = SearchCond.getLeafCond(groupCond);
    List<AnyObject> matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertEquals(2, matching.size());
    AnyTypeCond anyTypeCond = new AnyTypeCond();
    anyTypeCond.setAnyTypeKey(service.getKey());
    searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupCond), SearchCond.getLeafCond(anyTypeCond));
    matching = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertEquals(1, matching.size());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

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