Search in sources :

Example 6 with ROrgClosure

use of com.evolveum.midpoint.repo.sql.data.common.ROrgClosure in project midpoint by Evolveum.

the class AbstractOrgClosureTest method getActualChildrenOf.

protected Set<String> getActualChildrenOf(String ancestor) {
    List<ROrgClosure> descendantRecords = getOrgClosureByAncestor(ancestor);
    Set<String> rv = new HashSet<String>();
    for (ROrgClosure c : descendantRecords) {
        rv.add(c.getDescendantOid());
    }
    return rv;
}
Also used : ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) HashSet(java.util.HashSet)

Example 7 with ROrgClosure

use of com.evolveum.midpoint.repo.sql.data.common.ROrgClosure in project midpoint by Evolveum.

the class OrgStructTest method test001addOrgStructObjectsIncorrect.

@Test
public void test001addOrgStructObjectsIncorrect() throws Exception {
    OperationResult opResult = new OperationResult("test001addOrgStructObjectsIncorrect");
    List<PrismObject<? extends Objectable>> orgStructIncorrect = prismContext.parserFor(new File(ORG_STRUCT_OBJECTS_INCORRECT)).parseObjects();
    for (PrismObject<? extends Objectable> o : orgStructIncorrect) {
        repositoryService.addObject((PrismObject<ObjectType>) o, null, opResult);
    }
    opResult.computeStatusIfUnknown();
    AssertJUnit.assertTrue(opResult.isSuccess());
    Session session = open();
    try {
        LOGGER.info("==============CLOSURE TABLE==========");
        // descendants of F007 - F007<0>, F009<1>, F008<2>, F0010<2>
        Criteria criteria = session.createCriteria(ROrgClosure.class).createCriteria("ancestor", "anc").setFetchMode("ancestor", FetchMode.JOIN).add(Restrictions.eq("anc.oid", ORG_F007_OID));
        List<ROrgClosure> orgClosure = criteria.list();
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}", c.getDescendant());
        }
        AssertJUnit.assertEquals(4, orgClosure.size());
        criteria = session.createCriteria(ROrgClosure.class).createCriteria("ancestor", "anc").setFetchMode("ancestor", FetchMode.JOIN).add(Restrictions.eq("anc.oid", ORG_F009_OID));
        orgClosure = criteria.list();
        AssertJUnit.assertEquals(3, orgClosure.size());
        ObjectQuery query = QueryBuilder.queryFor(UserType.class, prismContext).item(UserType.F_NAME).eq(ELAINE_NAME1).build();
        List<PrismObject<UserType>> users = repositoryService.searchObjects(UserType.class, query, null, opResult);
        AssertJUnit.assertNotNull(users);
        AssertJUnit.assertEquals(1, users.size());
        UserType elaine1 = users.get(0).asObjectable();
        LOGGER.info("--->elaine1<----");
        AssertJUnit.assertEquals("Expected name elaine1, but got " + elaine1.getName().getOrig(), "elaine1", elaine1.getName().getOrig());
        AssertJUnit.assertEquals("Expected elaine has one org ref, but got " + elaine1.getParentOrgRef().size(), 2, elaine1.getParentOrgRef().size());
        AssertJUnit.assertEquals("Parent org ref oid not equal.", "00000000-8888-6666-0000-100000000011", elaine1.getParentOrgRef().get(0).getOid());
    } finally {
        close(session);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Criteria(org.hibernate.Criteria) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) Objectable(com.evolveum.midpoint.prism.Objectable) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 8 with ROrgClosure

use of com.evolveum.midpoint.repo.sql.data.common.ROrgClosure in project midpoint by Evolveum.

the class OrgStructTest method test004modifyOrgStructAddUser.

// users are not in the closure any more
@Test(enabled = false)
public void test004modifyOrgStructAddUser() throws Exception {
    Session session = open();
    try {
        OperationResult opResult = new OperationResult("test004modifyOrgStructAddUser");
        //test modification of org ref in another org type..
        ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_ADD_USER_FILENAME), ObjectModificationType.COMPLEX_TYPE);
        ObjectDelta<UserType> delta = DeltaConvertor.createObjectDelta(modification, UserType.class, prismContext);
        repositoryService.modifyObject(UserType.class, ELAINE_OID, delta.getModifications(), opResult);
        LOGGER.info("==>after modify - add user to org<==");
        List<ROrgClosure> orgClosure = getOrgClosureByDescendant(ELAINE_OID, session);
        AssertJUnit.assertEquals(7, orgClosure.size());
        LOGGER.info("==============CLOSURE TABLE==========");
        for (ROrgClosure o : orgClosure) {
            LOGGER.info("=> A: {}, D: {}", o.getAncestor(), o.getDescendant());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 9 with ROrgClosure

use of com.evolveum.midpoint.repo.sql.data.common.ROrgClosure in project midpoint by Evolveum.

the class OrgStructTest method test003modifyOrgStructDeleteRefIncorrect.

@Test
public void test003modifyOrgStructDeleteRefIncorrect() throws Exception {
    // test modification of org ref - delete org ref
    OperationResult opResult = new OperationResult("test003modifyOrgStructDeleteRefIncorrect");
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_INCORRECT_DELETE_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    Session session = open();
    try {
        LOGGER.info("==>before modify - delete<==");
        List<ROrgClosure> orgClosure = getOrgClosure(ORG_F012_OID, MODIFY_ORG_INCORRECT_DELETE_REF_OID, session);
        AssertJUnit.assertEquals(0, orgClosure.size());
        session.getTransaction().commit();
        repositoryService.modifyObject(OrgType.class, MODIFY_ORG_INCORRECT_DELETE_REF_OID, delta.getModifications(), opResult);
        session.clear();
        session.beginTransaction();
        LOGGER.info("==>after modify - delete<==");
        orgClosure = getOrgClosure(ORG_F012_OID, MODIFY_ORG_INCORRECT_DELETE_REF_OID, session);
        AssertJUnit.assertEquals(0, orgClosure.size());
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

ROrgClosure (com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 Session (org.hibernate.Session)7 Test (org.testng.annotations.Test)7 File (java.io.File)6 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)5 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 ArrayList (java.util.ArrayList)2 Objectable (com.evolveum.midpoint.prism.Objectable)1 HashSet (java.util.HashSet)1 Criteria (org.hibernate.Criteria)1 Query (org.hibernate.Query)1