Search in sources :

Example 36 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class AutoAssignMappingCollector method collectAutoassignMappings.

<AH extends AssignmentHolderType> void collectAutoassignMappings(LensContext<AH> context, List<FocalMappingEvaluationRequest<?, ?>> mappings, OperationResult result) throws SchemaException {
    if (!autoassignEnabled(context.getSystemConfiguration())) {
        return;
    }
    ObjectQuery query = prismContext.queryFor(AbstractRoleType.class).item(SchemaConstants.PATH_AUTOASSIGN_ENABLED).eq(true).build();
    ResultHandler<AbstractRoleType> handler = (role, objectResult) -> {
        AutoassignSpecificationType autoassign = role.asObjectable().getAutoassign();
        if (autoassign == null) {
            return true;
        }
        if (!isTrue(autoassign.isEnabled())) {
            return true;
        }
        FocalAutoassignSpecificationType focalAutoassignSpec = autoassign.getFocus();
        if (focalAutoassignSpec == null) {
            return true;
        }
        if (!isApplicableFor(focalAutoassignSpec.getSelector(), context.getFocusContext(), objectResult)) {
            return true;
        }
        for (AutoassignMappingType autoMapping : focalAutoassignSpec.getMapping()) {
            AutoassignMappingType mapping = LensUtil.setMappingTarget(autoMapping, new ItemPathType(SchemaConstants.PATH_ASSIGNMENT));
            mappings.add(new AutoassignRoleMappingEvaluationRequest(mapping, role.asObjectable()));
            LOGGER.trace("Collected autoassign mapping {} from {}", mapping.getName(), role);
        }
        return true;
    };
    cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, createReadOnlyCollection(), true, result);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) AutoassignRoleMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.AutoassignRoleMappingEvaluationRequest) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) PrismObject(com.evolveum.midpoint.prism.PrismObject) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) BooleanUtils.isTrue(org.apache.commons.lang.BooleanUtils.isTrue) Component(org.springframework.stereotype.Component) List(java.util.List) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) FocalMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.FocalMappingEvaluationRequest) PrismContext(com.evolveum.midpoint.prism.PrismContext) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AutoassignRoleMappingEvaluationRequest(com.evolveum.midpoint.model.impl.lens.projector.mappings.AutoassignRoleMappingEvaluationRequest)

Example 37 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class AbstractTestObjectLifecycleApproval method createObject.

private void createObject(ObjectType object, boolean immediate, boolean approve, String assigneeOid) throws Exception {
    // noinspection unchecked
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta((PrismObject<RoleType>) object.asPrismObject());
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            // noinspection unchecked
            LensContext<RoleType> lensContext = createLensContext((Class) object.getClass());
            addFocusDeltaToContext(lensContext, addObjectDelta);
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
            if (!immediate) {
                // ModelContext taskModelContext = temporaryHelper.getModelContext(rootCase, opTask, result);
                // ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta();
                // assertTrue("Non-empty primary focus delta: " + realDelta0.debugDump(), realDelta0.isEmpty());
                assertNoObject(object);
                ExpectedTask expectedTask = new ExpectedTask(null, "Adding role \"" + object.getName().getOrig() + "\"");
                ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(assigneeOid, null, expectedTask);
                assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
            }
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
            assertNoObject(object);
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
            if (approve) {
                assertObject(object);
            } else {
                assertNoObject(object);
            }
        }

        @Override
        protected boolean executeImmediately() {
            return immediate;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            return singletonList(new ApprovalInstruction(null, true, USER_JUPITER_OID, "creation comment"));
        }
    }, 1);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask)

Example 38 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class TestObjectLifecycleApprovalGlobal method test510AddInducementsToJudge.

@Test
public void test510AddInducementsToJudge() throws Exception {
    login(userAdministrator);
    ObjectDelta<RoleType> judgeDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).add(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext), createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext)).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDeltaCast(roleJudgeOid);
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, judgeDelta);
            lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
        // nothing here
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
        // nothing here
        }

        @Override
        protected boolean executeImmediately() {
            return true;
        }

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 1 in 1st inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in 1st inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in 2nd inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in 2nd inducement part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 1 in main part (owner)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUDGE_OWNER_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 3);
    // TODO some more asserts
    PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
    display("Judge role", judgeAfter);
    assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
    assertEquals("Wrong description", "hi", judgeAfter.asObjectable().getDescription());
    assertInducedRoles(judgeAfter, OID1, OID2);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 39 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class TestObjectLifecycleApprovalGlobal method test520DeleteRoleJudge.

// MID-4372
@Test
public void test520DeleteRoleJudge() throws Exception {
    login(userAdministrator);
    deleteObject(UserType.class, USER_JUDGE_OWNER_OID);
    ObjectDelta<RoleType> deleteDelta = prismContext.deltaFactory().object().createDeleteDelta(RoleType.class, roleJudgeOid);
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, deleteDelta);
            lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
            assertObjectExists(RoleType.class, roleJudgeOid);
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
            assertObjectDoesntExist(RoleType.class, roleJudgeOid);
        }

        @Override
        protected boolean executeImmediately() {
            return true;
        }

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 2 in main part (first step is owner that is skipped as the owner was already deleted)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Deleting role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 1);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Example 40 with LensContext

use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.

the class TestObjectLifecycleApprovalGlobal method test500CreateRoleJudge.

@Test
public void test500CreateRoleJudge() throws Exception {
    login(userAdministrator);
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    RoleType judge = new RoleType(prismContext).name("judge").riskLevel("high");
    ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(judge.asPrismObject());
    executeTest(new TestDetails() {

        @Override
        protected LensContext createModelContext(OperationResult result) throws Exception {
            LensContext<RoleType> lensContext = createLensContext(RoleType.class);
            addFocusDeltaToContext(lensContext, addObjectDelta);
            lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
            return lensContext;
        }

        @Override
        protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
            display("subtasks", subcases);
            display("work items", workItems);
        // todo some asserts here
        }

        @Override
        protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
            assertNoObject(judge);
        }

        @Override
        protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
            assertObject(judge);
        }

        @Override
        protected boolean executeImmediately() {
            return true;
        }

        @Override
        public boolean strictlySequentialApprovals() {
            return true;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ApprovalInstruction> instructions = new ArrayList<>();
            // this is step 2 in riskLevel part (first step is owner that is skipped)
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in riskLevel part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_PETER_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 2 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            // this is step 3 in main part
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
            return instructions;
        }
    }, 2);
    // TODO some more asserts
    PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
    roleJudgeOid = judgeAfter.getOid();
    PrismReferenceValue judgeOwner = getPrismContext().itemFactory().createReferenceValue(roleJudgeOid, RoleType.COMPLEX_TYPE);
    judgeOwner.setRelation(SchemaConstants.ORG_OWNER);
    executeChanges(prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(judgeAfter, SchemaConstants.ORG_OWNER)).asObjectDeltaCast(USER_JUDGE_OWNER_OID), null, task, result);
    display("Judge role", judgeAfter);
    display("Judge owner", getUser(USER_JUDGE_OWNER_OID));
    assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.ExpectedWorkItem) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ApprovalInstruction(com.evolveum.midpoint.wf.impl.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ExpectedTask(com.evolveum.midpoint.wf.impl.ExpectedTask) Test(org.testng.annotations.Test)

Aggregations

LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)44 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 Task (com.evolveum.midpoint.task.api.Task)32 Test (org.testng.annotations.Test)24 ExpectedTask (com.evolveum.midpoint.wf.impl.ExpectedTask)12 List (java.util.List)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.ExpectedWorkItem)10 ArrayList (java.util.ArrayList)10 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)9 ApprovalInstruction (com.evolveum.midpoint.wf.impl.ApprovalInstruction)8 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 IOException (java.io.IOException)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 JAXBException (javax.xml.bind.JAXBException)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 AbstractUninitializedCertificationTest (com.evolveum.midpoint.certification.test.AbstractUninitializedCertificationTest)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5