Search in sources :

Example 1 with ApprovalInstruction

use of com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction in project midpoint by Evolveum.

the class TestAssignmentsWithDifferentMetaroles method executeUnassignRoles123ToJack.

private void executeUnassignRoles123ToJack(String TEST_NAME, boolean immediate, boolean approve, boolean byId, boolean has1and2) throws Exception {
    PrismObject<UserType> jack = getUser(userJackOid);
    AssignmentType a1 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole21Oid) : null;
    AssignmentType a2 = has1and2 ? findAssignmentByTargetRequired(jack, roleRole22Oid) : null;
    AssignmentType a3 = findAssignmentByTargetRequired(jack, roleRole23Oid);
    AssignmentType del1 = toDelete(a1, byId);
    AssignmentType del2 = toDelete(a2, byId);
    AssignmentType del3 = toDelete(a3, byId);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole1Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del1).asObjectDelta(userJackOid) : null;
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole2Delta = has1and2 ? (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del2).asObjectDelta(userJackOid) : null;
    @SuppressWarnings("unchecked") ObjectDelta<UserType> deleteRole3Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).delete(del3).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace(TEST_NAME).asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta, deleteRole3Delta);
    ObjectDelta<UserType> delta0 = ObjectDelta.summarize(changeDescriptionDelta, deleteRole1Delta, deleteRole2Delta);
    String originalDescription = getUser(userJackOid).asObjectable().getDescription();
    executeTest2(TEST_NAME, new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 1;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Arrays.asList(approve);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Arrays.asList(deleteRole3Delta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return delta0.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Arrays.asList(new ExpectedTask(roleRole23Oid, "Unassigning Role23 from jack"));
        }

        // after first step
        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> tasks = getExpectedTasks();
            return Arrays.asList(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task rootTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, TEST_NAME);
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    if (yes || !has1and2) {
                        assertNotAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
                        assertNotAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole21Oid, rootTask, result);
                        assertAssignedRole(userJackOid, roleRole22Oid, rootTask, result);
                    }
                    break;
                case 1:
                    if (yes) {
                        assertNotAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
                    } else {
                        assertAssignedRole(userJackOid, roleRole23Oid, rootTask, result);
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Unexpected delta number: " + number);
            }
        }

        @Override
        protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
            // ignore this way of approving
            return null;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ExpectedTask> tasks = getExpectedTasks();
            List<ApprovalInstruction> instructions = new ArrayList<>();
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(0)), approve, userSecurityApproverOid));
            return instructions;
        }
    }, 1, immediate);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ApprovalInstruction(com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 2 with ApprovalInstruction

use of com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction in project midpoint by Evolveum.

the class TestAssignmentsWithDifferentMetaroles method executeAssignRoles123ToJack.

private void executeAssignRoles123ToJack(String TEST_NAME, boolean immediate, boolean approve1, boolean approve2, boolean approve3a, boolean approve3b, boolean securityDeputy) throws Exception {
    Task task = createTask("executeAssignRoles123ToJack");
    PrismObject<UserType> jack = getUser(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> addRole1Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole21Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> addRole2Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole22Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> addRole3Delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(roleRole23Oid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    @SuppressWarnings("unchecked") ObjectDelta<UserType> changeDescriptionDelta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_DESCRIPTION).replace(TEST_NAME).asObjectDelta(userJackOid);
    ObjectDelta<UserType> primaryDelta = ObjectDelta.summarize(addRole1Delta, addRole2Delta, addRole3Delta, changeDescriptionDelta);
    ObjectDelta<UserType> delta0 = changeDescriptionDelta.clone();
    String originalDescription = getUser(userJackOid).asObjectable().getDescription();
    executeTest2(TEST_NAME, new TestDetails2<UserType>() {

        @Override
        protected PrismObject<UserType> getFocus(OperationResult result) throws Exception {
            return jack.clone();
        }

        @Override
        protected ObjectDelta<UserType> getFocusDelta() throws SchemaException {
            return primaryDelta.clone();
        }

        @Override
        protected int getNumberOfDeltasToApprove() {
            return 3;
        }

        @Override
        protected List<Boolean> getApprovals() {
            return Arrays.asList(approve1, approve2, approve3a && approve3b);
        }

        @Override
        protected List<ObjectDelta<UserType>> getExpectedDeltasToApprove() {
            return Arrays.asList(addRole1Delta.clone(), addRole2Delta.clone(), addRole3Delta.clone());
        }

        @Override
        protected ObjectDelta<UserType> getExpectedDelta0() {
            return delta0.clone();
        }

        @Override
        protected String getObjectOid() {
            return jack.getOid();
        }

        @Override
        protected List<ExpectedTask> getExpectedTasks() {
            return Arrays.asList(new ExpectedTask(roleRole21Oid, "Assigning Role21 to jack"), new ExpectedTask(roleRole22Oid, "Assigning Role22 to jack"), new ExpectedTask(roleRole23Oid, "Assigning Role23 to jack"));
        }

        // after first step
        @Override
        protected List<ExpectedWorkItem> getExpectedWorkItems() {
            List<ExpectedTask> tasks = getExpectedTasks();
            return Arrays.asList(new ExpectedWorkItem(userLead21Oid, roleRole21Oid, tasks.get(0)), new ExpectedWorkItem(userLead22Oid, roleRole22Oid, tasks.get(1)), new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)));
        }

        @Override
        protected void assertDeltaExecuted(int number, boolean yes, Task rootTask, OperationResult result) throws Exception {
            switch(number) {
                case 0:
                    if (yes) {
                        assertUserProperty(userJackOid, UserType.F_DESCRIPTION, TEST_NAME);
                    } else {
                        if (originalDescription != null) {
                            assertUserProperty(userJackOid, UserType.F_DESCRIPTION, originalDescription);
                        } else {
                            assertUserNoProperty(userJackOid, UserType.F_DESCRIPTION);
                        }
                    }
                    break;
                case 1:
                case 2:
                case 3:
                    String[] oids = { roleRole21Oid, roleRole22Oid, roleRole23Oid };
                    if (yes) {
                        assertAssignedRole(userJackOid, oids[number - 1], rootTask, result);
                    } else {
                        assertNotAssignedRole(userJackOid, oids[number - 1], rootTask, result);
                    }
                    break;
            }
        }

        @Override
        protected Boolean decideOnApproval(String executionId, org.activiti.engine.task.Task task) throws Exception {
            // ignore this way of approving
            return null;
        }

        @Override
        public List<ApprovalInstruction> getApprovalSequence() {
            List<ExpectedTask> tasks = getExpectedTasks();
            List<ApprovalInstruction> instructions = new ArrayList<>();
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead21Oid, roleRole21Oid, tasks.get(0)), approve1, userLead21Oid));
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead22Oid, roleRole22Oid, tasks.get(1)), approve2, userLead22Oid));
            instructions.add(new ApprovalInstruction(new ExpectedWorkItem(userLead23Oid, roleRole23Oid, tasks.get(2)), approve3a, userLead23Oid));
            if (approve3a) {
                ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userSecurityApproverOid, roleRole23Oid, tasks.get(2));
                ApprovalInstruction.CheckedRunnable before = () -> {
                    login(getUserFromRepo(userSecurityApproverOid));
                    checkVisibleWorkItem(expectedWorkItem, 1, task, task.getResult());
                    login(getUserFromRepo(userSecurityApproverDeputyOid));
                    checkVisibleWorkItem(expectedWorkItem, 1, task, task.getResult());
                    login(getUserFromRepo(userSecurityApproverDeputyLimitedOid));
                    checkVisibleWorkItem(null, 0, task, task.getResult());
                };
                instructions.add(new ApprovalInstruction(expectedWorkItem, approve3b, securityDeputy ? userSecurityApproverDeputyOid : userSecurityApproverOid, before, null));
            }
            return instructions;
        }
    }, 3, immediate);
}
Also used : ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) ApprovalInstruction(com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction) ArrayList(java.util.ArrayList) List(java.util.List) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ExpectedTask(com.evolveum.midpoint.wf.impl.policy.ExpectedTask) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpectedWorkItem(com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ApprovalInstruction (com.evolveum.midpoint.wf.impl.policy.ApprovalInstruction)2 ExpectedTask (com.evolveum.midpoint.wf.impl.policy.ExpectedTask)2 ExpectedWorkItem (com.evolveum.midpoint.wf.impl.policy.ExpectedWorkItem)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)1