Search in sources :

Example 1 with F_ASSIGNEE_REF

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

the class WorkItemDtoProvider method internalIterator.

@Override
public Iterator<? extends WorkItemDto> internalIterator(long first, long count) {
    getAvailableData().clear();
    Task task = getTaskManager().createTaskInstance();
    OperationResult result = new OperationResult(OPERATION_LIST_ITEMS);
    try {
        ObjectQuery query = createQuery(first, count, result);
        Collection<SelectorOptions<GetOperationOptions>> options = GetOperationOptions.resolveItemsNamed(new ItemPath(F_ASSIGNEE_REF), new ItemPath(T_PARENT, WfContextType.F_OBJECT_REF), new ItemPath(T_PARENT, WfContextType.F_TARGET_REF));
        List<WorkItemType> items = getModel().searchContainers(WorkItemType.class, query, options, task, result);
        for (WorkItemType item : items) {
            try {
                getAvailableData().add(new WorkItemDto(item));
            } catch (Exception e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing work item {}", e, item);
                result.recordFatalError("Couldn't list work item.", e);
            }
        }
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | ConfigurationException | RuntimeException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing work items", ex);
        result.recordFatalError("Couldn't list work items.", ex);
    }
    if (result.isUnknown()) {
        result.computeStatus();
    }
    return getAvailableData().iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

Example 2 with F_ASSIGNEE_REF

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

the class AbstractWfTestPolicy method executeTest.

protected <F extends FocusType> void executeTest(String testName, TestDetails testDetails, int expectedSubTaskCount) throws Exception {
    // GIVEN
    prepareNotifications();
    dummyAuditService.clear();
    Task modelTask = taskManager.createTaskInstance(AbstractWfTestPolicy.class.getName() + "." + testName);
    modelTask.setOwner(userAdministrator);
    OperationResult result = new OperationResult("execution");
    LensContext<F> modelContext = testDetails.createModelContext(result);
    display("Model context at test start", modelContext);
    // this has problems with deleting assignments by ID
    //assertFocusModificationSanity(modelContext);
    // WHEN
    HookOperationMode mode = clockwork.run(modelContext, modelTask, result);
    // THEN
    display("Model context after first clockwork.run", modelContext);
    assertEquals("Unexpected state of the context", ModelState.PRIMARY, modelContext.getState());
    assertEquals("Wrong mode after clockwork.run in " + modelContext.getState(), HookOperationMode.BACKGROUND, mode);
    modelTask.refresh(result);
    display("Model task after first clockwork.run", modelTask);
    String rootTaskOid = wfTaskUtil.getRootTaskOid(modelTask);
    assertNotNull("Root task OID is not set in model task", rootTaskOid);
    Task rootTask = taskManager.getTask(rootTaskOid, result);
    assertTrue("Root task is not persistent", rootTask.isPersistent());
    UriStack uriStack = rootTask.getOtherHandlersUriStack();
    if (!testDetails.executeImmediately()) {
        assertEquals("Invalid handler at stack position 0", ModelOperationTaskHandler.MODEL_OPERATION_TASK_URI, uriStack.getUriStackEntry().get(0).getHandlerUri());
    } else {
        assertTrue("There should be no handlers for root tasks with immediate execution mode", uriStack == null || uriStack.getUriStackEntry().isEmpty());
    }
    ModelContext rootModelContext = testDetails.executeImmediately() ? null : wfTaskUtil.getModelContext(rootTask, result);
    if (!testDetails.executeImmediately()) {
        assertNotNull("Model context is not present in root task", rootModelContext);
    } else {
        assertNull("Model context is present in root task (execution mode = immediate)", rootModelContext);
    }
    List<Task> subtasks = rootTask.listSubtasks(result);
    Task task0 = findAndRemoveTask0(subtasks, testDetails);
    assertEquals("Incorrect number of subtasks", expectedSubTaskCount, subtasks.size());
    final Collection<SelectorOptions<GetOperationOptions>> options1 = resolveItemsNamed(new ItemPath(T_PARENT, F_OBJECT_REF), new ItemPath(T_PARENT, F_TARGET_REF), F_ASSIGNEE_REF, F_ORIGINAL_ASSIGNEE_REF, new ItemPath(T_PARENT, F_REQUESTER_REF));
    List<WorkItemType> workItems = modelService.searchContainers(WorkItemType.class, null, options1, modelTask, result);
    testDetails.afterFirstClockworkRun(rootTask, subtasks, workItems, result);
    if (testDetails.executeImmediately()) {
        if (task0 != null) {
            waitForTaskClose(task0, 20000);
        }
        testDetails.afterTask0Finishes(rootTask, result);
    }
    for (int i = 0; i < subtasks.size(); i++) {
        Task subtask = subtasks.get(i);
        PrismProperty<ObjectTreeDeltasType> deltas = subtask.getTaskPrismObject().findProperty(new ItemPath(F_WORKFLOW_CONTEXT, F_PROCESSOR_SPECIFIC_STATE, F_DELTAS_TO_PROCESS));
        assertNotNull("There are no modifications in subtask #" + i + ": " + subtask, deltas);
        assertEquals("Incorrect number of modifications in subtask #" + i + ": " + subtask, 1, deltas.getRealValues().size());
        // todo check correctness of the modification?
        // now check the workflow state
        String pid = wfTaskUtil.getProcessId(subtask);
        assertNotNull("Workflow process instance id not present in subtask " + subtask, pid);
        List<org.activiti.engine.task.Task> tasks = activitiEngine.getTaskService().createTaskQuery().processInstanceId(pid).list();
        assertFalse("activiti task not found", tasks.isEmpty());
        for (org.activiti.engine.task.Task task : tasks) {
            String executionId = task.getExecutionId();
            display("Execution id = " + executionId);
            Boolean approve = testDetails.decideOnApproval(executionId, task);
            if (approve != null) {
                workflowManager.completeWorkItem(task.getId(), approve, null, null, null, result);
                login(userAdministrator);
                break;
            }
        }
    }
    // alternative way of approvals executions
    if (CollectionUtils.isNotEmpty(testDetails.getApprovalSequence())) {
        List<ApprovalInstruction> instructions = new ArrayList<>(testDetails.getApprovalSequence());
        while (!instructions.isEmpty()) {
            List<WorkItemType> currentWorkItems = modelService.searchContainers(WorkItemType.class, null, options1, modelTask, result);
            boolean matched = false;
            main: for (ApprovalInstruction approvalInstruction : instructions) {
                for (WorkItemType workItem : currentWorkItems) {
                    if (approvalInstruction.matches(workItem)) {
                        if (approvalInstruction.beforeApproval != null) {
                            approvalInstruction.beforeApproval.run();
                        }
                        login(getUserFromRepo(approvalInstruction.approverOid));
                        workflowManager.completeWorkItem(workItem.getExternalId(), approvalInstruction.approval, null, null, null, result);
                        if (approvalInstruction.afterApproval != null) {
                            approvalInstruction.afterApproval.run();
                        }
                        login(userAdministrator);
                        matched = true;
                        instructions.remove(approvalInstruction);
                        break main;
                    }
                }
            }
            if (!matched) {
                fail("None of approval instructions " + instructions + " matched any of current work items: " + currentWorkItems);
            }
        }
    }
    waitForTaskClose(rootTask, 60000);
    subtasks = rootTask.listSubtasks(result);
    findAndRemoveTask0(subtasks, testDetails);
    testDetails.afterRootTaskFinishes(rootTask, subtasks, result);
    notificationManager.setDisabled(true);
    // Check audit
    display("Audit", dummyAuditService);
    display("Output context", modelContext);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with F_ASSIGNEE_REF

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

the class QueryInterpreter2Test method test920DecisionsNotAnswered.

@Test
public void test920DecisionsNotAnswered() throws Exception {
    Session session = open();
    try {
        /*
             * ### AccCertCase: Exists (decision: assigneeRef = XYZ and stage = ../stage and response is null or response = NO_RESPONSE)
             */
        ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).exists(F_WORK_ITEM).block().item(F_ASSIGNEE_REF).ref("123456").and().item(F_STAGE_NUMBER).eq().item(T_PARENT, AccessCertificationCaseType.F_STAGE_NUMBER).and().item(F_OUTPUT, AbstractWorkItemOutputType.F_OUTCOME).isNull().endBlock().build();
        String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
        String expected = "select\n" + "  a.ownerOid, a.id, a.fullObject\n" + "from\n" + "  RAccessCertificationCase a\n" + "    left join a.workItems w\n" + "    left join w.assigneeRef a2\n" + "where\n" + "  (\n" + "    (\n" + "      a2.targetOid = :targetOid and\n" + "      a2.relation in (:relation)\n" + "    ) and\n" + "    (\n" + "      w.stageNumber = a.stageNumber or\n" + "      (\n" + "        w.stageNumber is null and\n" + "        a.stageNumber is null\n" + "      )\n" + "    ) and\n" + "      w.outcome is null\n" + "  )\n";
        assertEqualsIgnoreWhitespace(expected, real);
    } finally {
        close(session);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 4 with F_ASSIGNEE_REF

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

the class QueryInterpreter2Test method test745QueryCertCaseReviewerAndEnabledByDeadlineAndOidAsc.

@Test
public void test745QueryCertCaseReviewerAndEnabledByDeadlineAndOidAsc() throws Exception {
    Session session = open();
    try {
        PrismReferenceValue assigneeRef = ObjectTypeUtil.createObjectRef("1234567890", ObjectTypes.USER).asReferenceValue();
        ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(F_WORK_ITEM, F_ASSIGNEE_REF).ref(assigneeRef).and().item(AccessCertificationCaseType.F_STAGE_NUMBER).eq().item(T_PARENT, AccessCertificationCampaignType.F_STAGE_NUMBER).asc(F_CURRENT_STAGE_DEADLINE).asc(T_ID).build();
        String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
        String expected = "select\n" + "  a.ownerOid, a.id, a.fullObject\n" + "from\n" + "  RAccessCertificationCase a\n" + "    left join a.workItems w\n" + "    left join w.assigneeRef a2\n" + "    left join a.owner o\n" + "where\n" + "  (\n" + "    (\n" + "      a2.targetOid = :targetOid and\n" + "      a2.relation in (:relation) and\n" + "      a2.type = :type\n" + "    ) and\n" + "    (\n" + "      a.stageNumber = o.stageNumber or\n" + "      (\n" + "        a.stageNumber is null and\n" + "        o.stageNumber is null\n" + "      )\n" + "    )\n" + "  )\n" + "order by a.reviewDeadline asc, a.id asc\n";
        assertEqualsIgnoreWhitespace(expected, real);
    } finally {
        close(session);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 5 with F_ASSIGNEE_REF

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

the class QueryInterpreter2Test method test730QueryCertCaseReviewer.

@Test
public void test730QueryCertCaseReviewer() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(F_WORK_ITEM, F_ASSIGNEE_REF).ref("1234567890").build();
        String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query, false);
        String expected = "select\n" + "  a.ownerOid, a.id, a.fullObject\n" + "from\n" + "  RAccessCertificationCase a\n" + "    left join a.workItems w\n" + "    left join w.assigneeRef a2\n" + "where\n" + "  (\n" + "    a2.targetOid = :targetOid and\n" + "    a2.relation in (:relation)\n" + "  )\n";
        assertEqualsIgnoreWhitespace(expected, real);
    } finally {
        close(session);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

Session (org.hibernate.Session)12 Test (org.testng.annotations.Test)12 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)10 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)4 Task (com.evolveum.midpoint.task.api.Task)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 WorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)3 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 AccessCertificationWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 CaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType)1 F_ASSIGNEE_REF (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ASSIGNEE_REF)1 F_ORIGINAL_ASSIGNEE_REF (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseWorkItemType.F_ORIGINAL_ASSIGNEE_REF)1