Search in sources :

Example 16 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject 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)

Example 17 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AnySearchTest method assignable.

@Test
public void assignable() {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath("/even/two");
    SearchCond searchCondition = SearchCond.getLeafCond(assignableCond);
    assertTrue(searchCondition.isValid());
    List<Group> groups = searchDAO.search(searchCondition, AnyTypeKind.GROUP);
    assertTrue(groups.stream().anyMatch(group -> "additional".equals(group.getName())));
    assertFalse(groups.stream().anyMatch(group -> "fake".equals(group.getName())));
    assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath("/odd");
    searchCondition = SearchCond.getLeafCond(assignableCond);
    assertTrue(searchCondition.isValid());
    List<AnyObject> anyObjects = searchDAO.search(searchCondition, AnyTypeKind.ANY_OBJECT);
    assertFalse(anyObjects.stream().anyMatch(anyObject -> "9e1d130c-d6a3-48b1-98b3-182477ed0688".equals(anyObject.getKey())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) Test(org.junit.jupiter.api.Test) List(java.util.List) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) 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 AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject 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())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) RoleCond(org.apache.syncope.core.persistence.api.dao.search.RoleCond) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) PrivilegeCond(org.apache.syncope.core.persistence.api.dao.search.PrivilegeCond) ArrayList(java.util.ArrayList) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) ResourceCond(org.apache.syncope.core.persistence.api.dao.search.ResourceCond) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AMembership(org.apache.syncope.core.persistence.api.entity.anyobject.AMembership) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) MemberCond(org.apache.syncope.core.persistence.api.dao.search.MemberCond) Test(org.junit.jupiter.api.Test) List(java.util.List) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) RelationshipCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipCond) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) AnyTypeCond(org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond) User(org.apache.syncope.core.persistence.api.entity.user.User) RelationshipTypeCond(org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond) 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 19 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AnyObjectTest method find.

@Test
public void find() {
    AnyObject anyObject = anyObjectDAO.find("8559d14d-58c2-46eb-a2d4-a7d35161e8f8");
    assertNotNull(anyObject);
    assertNotNull(anyObject.getType());
    assertFalse(anyObject.getType().getClasses().isEmpty());
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 20 with AnyObject

use of org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject in project syncope by apache.

the class AnyObjectTest method save.

@Test
public void save() {
    AnyObject anyObject = entityFactory.newEntity(AnyObject.class);
    anyObject.setName("a name");
    anyObject.setType(anyTypeDAO.find("PRINTER"));
    anyObject.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
    anyObject = anyObjectDAO.save(anyObject);
    assertNotNull(anyObject);
}
Also used : AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)29 Group (org.apache.syncope.core.persistence.api.entity.group.Group)18 User (org.apache.syncope.core.persistence.api.entity.user.User)15 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)11 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Transactional (org.springframework.transaction.annotation.Transactional)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)7 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)7 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)7 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)7 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)7 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)7 Collections (java.util.Collections)6 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)6