Search in sources :

Example 71 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AssignmentTablePanel method handleAssignmentDeltas.

public ContainerDelta handleAssignmentDeltas(ObjectDelta<T> userDelta, PrismContainerDefinition def, QName assignmentPath) throws SchemaException {
    ContainerDelta assDelta = new ContainerDelta(new ItemPath(), assignmentPath, def, // hoping that def contains a prism
    def.getPrismContext());
    // context!
    // PrismObject<OrgType> org =
    // (PrismObject<OrgType>)getModel().getObject().getAssignmentParent();
    // PrismObjectDefinition orgDef = org.getDefinition();
    // PrismContainerDefinition assignmentDef =
    // def.findContainerDefinition(assignmentPath);
    List<AssignmentEditorDto> assignments = getAssignmentModel().getObject();
    for (AssignmentEditorDto assDto : assignments) {
        PrismContainerValue newValue = assDto.getNewValue(getPageBase().getPrismContext());
        switch(assDto.getStatus()) {
            case ADD:
                newValue.applyDefinition(def, false);
                assDelta.addValueToAdd(newValue.clone());
                break;
            case DELETE:
                PrismContainerValue oldValue = assDto.getOldValue();
                oldValue.applyDefinition(def);
                assDelta.addValueToDelete(oldValue.clone());
                break;
            case MODIFY:
                if (!assDto.isModified(getPageBase().getPrismContext())) {
                    LOGGER.trace("Assignment '{}' not modified.", new Object[] { assDto.getName() });
                    continue;
                }
                handleModifyAssignmentDelta(assDto, def, newValue, userDelta);
                break;
            default:
                warn(getString("pageUser.message.illegalAssignmentState", assDto.getStatus()));
        }
    }
    if (!assDelta.isEmpty()) {
        assDelta = userDelta.addModification(assDelta);
    }
    // todo remove this block [lazyman] after model is updated - it has to
    // remove resource from accountConstruction
    Collection<PrismContainerValue> values = assDelta.getValues(PrismContainerValue.class);
    for (PrismContainerValue value : values) {
        AssignmentType ass = new AssignmentType();
        ass.setupContainerValue(value);
        removeResourceFromAccConstruction(ass);
    }
    return assDelta;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 72 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method registerObject.

protected void registerObject(ObjectType objectType, boolean registerChildrenLinks) {
    if (!(objectType instanceof OrgType)) {
        return;
    }
    String oid = objectType.getOid();
    LOGGER.info("Registering {} into memory graph", oid);
    registerVertexIfNeeded(oid);
    for (ObjectReferenceType ort : objectType.getParentOrgRef()) {
        registerVertexIfNeeded(ort.getOid());
        try {
            orgGraph.addEdge(oid, ort.getOid());
        } catch (RuntimeException e) {
            System.err.println("Couldn't add edge " + oid + " -> " + ort.getOid() + " into the graph");
            throw e;
        }
    }
    if (registerChildrenLinks) {
        // let's check for existing children
        List<String> children = getOrgChildren(oid);
        LOGGER.info("Registering children of {}: {} into memory graph", oid, children);
        for (String child : children) {
            registerVertexIfNeeded(child);
            orgGraph.addEdge(child, oid);
        }
    }
    LOGGER.info("Registration of {} done.", oid);
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)

Example 73 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method scanOrgStructure.

//    // todo better name
//    protected void prepareOrgStructureOids(int level, String parentOid, int[] orgChildrenInLevel, int[] userChildrenInLevel, int[] parentsInLevel, String oidPrefix,
//                                    OperationResult result) throws Exception {
//        if (level == orgChildrenInLevel.length) {
//            return;
//        }
//
//        List<String> orgsAtThisLevel = getOrgsAtThisLevelSafe(level);
//        for (int i = 0; i < orgChildrenInLevel[level]; i++) {
//            String newOidPrefix = getOidCharFor(i) + oidPrefix;
//            int numberOfParents = parentsInLevel==null ? (parentOid != null ? 1 : 0) : parentsInLevel[level];
//            PrismObject<OrgType> org = createOrg(generateParentsForLevel(parentOid, level, numberOfParents), newOidPrefix);
//            LOGGER.info("'Creating' {}, total {}; parents = {}", new Object[]{org, count, getParentsOids(org)});
//            String oid = org.getOid();
//            if (parentOid == null) {
//                rootOids.add(oid);
//            }
//            allOrgCreated.add(org.asObjectable());
//            registerObject(org.asObjectable(), false);
//            orgsAtThisLevel.add(oid);
//            count++;
//
//            prepareOrgStructureOids(level + 1, oid, orgChildrenInLevel, userChildrenInLevel, parentsInLevel, newOidPrefix, result);
//        }
//
//        if (parentOid != null) {
//
//            List<String> usersAtThisLevel = getUsersAtThisLevelSafe(level);
//
//            for (int u = 0; u < userChildrenInLevel[level]; u++) {
//                int numberOfParents = parentsInLevel==null ? 1 : parentsInLevel[level];
//                PrismObject<UserType> user = createUser(generateParentsForLevel(parentOid, level, numberOfParents), getOidCharFor(u) + ":" + oidPrefix);
//                LOGGER.info("'Creating' {}, total {}; parents = {}", new Object[]{user, count, getParentsOids(user)});
//                String uoid = user.getOid();
//                registerObject(user.asObjectable(), false);
//                usersAtThisLevel.add(uoid);
//                count++;
//            }
//        }
//
//    }
protected void scanOrgStructure(OperationResult opResult) throws SchemaException, ObjectNotFoundException {
    // determine rootOids
    for (int i = 0; ; i++) {
        String oid = "o" + createOid("" + getOidCharFor(i));
        try {
            System.out.println("Trying to find " + oid + " as a root");
            OrgType org = repositoryService.getObject(OrgType.class, oid, null, opResult).asObjectable();
            rootOids.add(org.getOid());
            allOrgCreated.add(org);
            registerOrgToLevels(0, org.getOid());
            registerObject(org, false);
            objectCount++;
        } catch (ObjectNotFoundException e) {
            break;
        }
    }
    for (String rootOid : rootOids) {
        scanChildren(0, rootOid, opResult);
    }
}
Also used : OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 74 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method removeObjectParent.

protected void removeObjectParent(ObjectType object, ObjectReferenceType parentOrgRef, boolean useReplace, OperationResult opResult) throws Exception {
    List<ItemDelta> modifications = new ArrayList<>();
    if (!useReplace) {
        // standard case
        PrismReferenceValue existingValue = parentOrgRef.asReferenceValue();
        ItemDelta removeParent = ReferenceDelta.createModificationDelete(object.getClass(), OrgType.F_PARENT_ORG_REF, prismContext, existingValue.clone());
        modifications.add(removeParent);
    } else {
        // using REPLACE modification
        List<PrismReferenceValue> newValues = new ArrayList<>();
        for (ObjectReferenceType ort : object.getParentOrgRef()) {
            if (!ort.getOid().equals(parentOrgRef.getOid())) {
                newValues.add(ort.asReferenceValue().clone());
            }
        }
        PrismObjectDefinition objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(object.getClass());
        ItemDelta replaceParent = ReferenceDelta.createModificationReplace(new ItemPath(OrgType.F_PARENT_ORG_REF), objectDefinition, newValues);
        modifications.add(replaceParent);
    }
    repositoryService.modifyObject(object.getClass(), object.getOid(), modifications, opResult);
    if (object instanceof OrgType) {
        orgGraph.removeEdge(object.getOid(), parentOrgRef.getOid());
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 75 with OrgType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType in project midpoint by Evolveum.

the class AbstractOrgClosureTest method checkOrgGraph.

// checks org graph w.r.t. real org/parentref situation in repo
protected void checkOrgGraph() throws SchemaException {
    OperationResult result = new OperationResult("temp");
    int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, new ObjectQuery(), result);
    info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size());
    assertTrue("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")", numberOfOrgsInRepo == orgGraph.vertexSet().size());
    for (String oid : orgGraph.vertexSet()) {
        //info("Checking " + oid);
        OrgType orgType = null;
        try {
            orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable();
        } catch (ObjectNotFoundException | SchemaException e) {
            throw new AssertionError("Couldn't fetch " + oid, e);
        }
        assertTrue(orgGraph.vertexSet().contains(orgType.getOid()));
        Set<String> parentOidsInRepo = new HashSet<>();
        for (ObjectReferenceType ort : orgType.getParentOrgRef()) {
            if (orgGraph.vertexSet().contains(ort.getOid())) {
                // i.e. the parent does exist
                parentOidsInRepo.add(ort.getOid());
            }
        }
        Set<String> parentOidsInGraph = new HashSet<>();
        for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) {
            parentOidsInGraph.add(orgGraph.getEdgeTarget(edge));
        }
        assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo);
    }
    info("Graph is OK w.r.t. repo");
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DefaultEdge(org.jgrapht.graph.DefaultEdge) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) HashSet(java.util.HashSet)

Aggregations

OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)123 Test (org.testng.annotations.Test)70 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)69 Task (com.evolveum.midpoint.task.api.Task)69 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)31 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)26 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)23 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)22 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ArrayList (java.util.ArrayList)13 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)11 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)11 Entry (org.opends.server.types.Entry)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)8 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)8 QName (javax.xml.namespace.QName)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)7