Search in sources :

Example 1 with ROrgClosure

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

the class OrgClosureManager method handleAdd.

// parents may be non-existent at this point
private void handleAdd(String oid, Set<String> parents, Context context, Session session) {
    // adding self-record
    session.save(new ROrgClosure(oid, oid, 1));
    session.flush();
    session.clear();
    // no need to check existence of these oids, as owner is a FK pointing to RObject in RParentRef
    List<String> livingChildren = getChildren(oid, session);
    LOGGER.trace("Living children = {}", livingChildren);
    addChildrenEdges(oid, livingChildren, context, session);
    // all parents are "new", so we should just select which do really exist at this moment
    Collection<String> livingParents = retainExistingOids(parents, session);
    LOGGER.trace("Living parents = {} (parents = {})", livingParents, parents);
    if (livingParents.size() <= 1 && (livingChildren == null || livingChildren.isEmpty())) {
        String parent;
        if (livingParents.isEmpty()) {
            parent = null;
        } else {
            parent = livingParents.iterator().next();
        }
        addEdgeSimple(oid, parent, session);
    } else {
        addParentEdges(oid, livingParents, context, session);
    }
}
Also used : ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure)

Example 2 with ROrgClosure

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

the class OrgStructTest method test003modifyOrgStructDeleteRef.

@SuppressWarnings("unchecked")
@Test
public void test003modifyOrgStructDeleteRef() throws Exception {
    // test modification of org ref - delete org ref
    OperationResult opResult = new OperationResult("test003modifyOrgStructDeleteRef");
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_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_F003_OID, MODIFY_ORG_DELETE_REF_OID, session);
        AssertJUnit.assertEquals(1, orgClosure.size());
        session.getTransaction().commit();
        repositoryService.modifyObject(OrgType.class, MODIFY_ORG_DELETE_REF_OID, delta.getModifications(), opResult);
        session.clear();
        session.beginTransaction();
        LOGGER.info("==>after modify - delete<==");
        orgClosure = getOrgClosure(ORG_F003_OID, MODIFY_ORG_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)

Example 3 with ROrgClosure

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

the class OrgStructTest method test007searchOrgStructOrgDepth.

@Test
public void test007searchOrgStructOrgDepth() throws Exception {
    OperationResult parentResult = new OperationResult("test007searchOrgStructOrgDepth");
    Session session = open();
    try {
        List<ROrgClosure> orgClosure = getOrgClosure(SEARCH_ORG_OID_DEPTH1, SEARCH_ORG_OID_DEPTH1, session);
        LOGGER.info("==============CLOSURE TABLE==========");
        for (ROrgClosure o : orgClosure) {
            LOGGER.info("=> A: {}, D: {}", o.getAncestor(), o.getDescendant());
        }
        AssertJUnit.assertEquals(1, orgClosure.size());
        session.getTransaction().commit();
        session.close();
        ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext).isDirectChildOf(SEARCH_ORG_OID_DEPTH1).asc(ObjectType.F_NAME).build();
        List<PrismObject<ObjectType>> sOrgClosure = repositoryService.searchObjects(ObjectType.class, objectQuery, null, parentResult);
        for (PrismObject<ObjectType> u : sOrgClosure) {
            LOGGER.info("USER000 ======> {}", ObjectTypeUtil.toShortString(u.asObjectable()));
        }
        AssertJUnit.assertEquals(4, sOrgClosure.size());
    } finally {
        if (session.isOpen()) {
            close(session);
        }
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 4 with ROrgClosure

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

the class OrgStructTest method test002modifyOrgStructAddRefIncorrect.

@Test
public void test002modifyOrgStructAddRefIncorrect() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRefIncorrect");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_INCORRECT_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_INCORRECT_ADD_REF_OID, delta.getModifications(), opResult);
    Session session = open();
    try {
        List<ROrgClosure> orgClosure = getOrgClosureByDescendant(MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
        LOGGER.info("after modify incorrect - closure");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(5, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_INCORRECT_ADD_REF_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_INCORRECT_ADD_REF_OID, session);
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_INCORRECT_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } 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) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 5 with ROrgClosure

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

the class OrgStructTest method test002modifyOrgStructAddRef.

@Test
public void test002modifyOrgStructAddRef() throws Exception {
    OperationResult opResult = new OperationResult("test002modifyOrgStructAddRef");
    // test modification of org ref in another org type..
    ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(MODIFY_ORG_ADD_REF_FILENAME), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<OrgType> delta = DeltaConvertor.createObjectDelta(modification, OrgType.class, prismContext);
    Query query;
    List<ROrgClosure> orgClosure;
    Session session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("before modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(3, orgClosure.size());
    } finally {
        close(session);
    }
    repositoryService.modifyObject(OrgType.class, MODIFY_ORG_ADD_REF_OID, delta.getModifications(), opResult);
    session = open();
    try {
        orgClosure = getOrgClosureByDescendant(MODIFY_ORG_ADD_REF_OID, session);
        LOGGER.info("after modify");
        for (ROrgClosure c : orgClosure) {
            LOGGER.info("{}\t{}", new Object[] { c.getAncestor().getOid(), c.getDescendant().getOid() });
        }
        AssertJUnit.assertEquals(4, orgClosure.size());
        List<String> ancestors = new ArrayList<String>();
        ancestors.add(MODIFY_ORG_ADD_REF_OID);
        ancestors.add(ORG_F003_OID);
        ancestors.add(ORG_F001_OID);
        ancestors.add(ORG_F002_OID);
        for (String ancestorOid : ancestors) {
            orgClosure = getOrgClosure(ancestorOid, MODIFY_ORG_ADD_REF_OID, session);
            LOGGER.info("=> A: {}, D: {}", orgClosure.get(0).getAncestor(), orgClosure.get(0).getDescendant());
            AssertJUnit.assertEquals(1, orgClosure.size());
            AssertJUnit.assertEquals(ancestorOid, orgClosure.get(0).getAncestor().getOid());
            AssertJUnit.assertEquals(MODIFY_ORG_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
        }
    } finally {
        close(session);
    }
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Query(org.hibernate.Query) ROrgClosure(com.evolveum.midpoint.repo.sql.data.common.ROrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ArrayList(java.util.ArrayList) 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