Search in sources :

Example 1 with WorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType 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 WorkItemType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType 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 WorkItemType

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

the class TestDelegation method test100CreateTask.

@Test
public void test100CreateTask() throws Exception {
    final String TEST_NAME = "test100CreateTask";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    userLead1 = getUser(userLead1Oid);
    userLead3 = getUser(userLead3Oid);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // should start approval process
    assignRole(userJackOid, roleRole1aOid, task, result);
    assertNotAssignedRole(userJackOid, roleRole1aOid, task, result);
    WorkItemType workItem = getWorkItem(task, result);
    workItemId = workItem.getExternalId();
    taskOid = WfContextUtil.getTask(workItem).getOid();
    display("work item", workItem);
    display("task", getObjectViaRepo(TaskType.class, taskOid));
    PrismAsserts.assertReferenceValues(ref(workItem.getAssigneeRef()), userLead1Oid);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType) Test(org.testng.annotations.Test)

Example 4 with WorkItemType

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

the class TestDelegation method test120DelegateToUser2.

@Test
public void test120DelegateToUser2() throws Exception {
    final String TEST_NAME = "test120DelegateToUser2";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userLead1);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    workflowService.delegateWorkItem(workItemId, Collections.singletonList(ort(userLead2Oid)), ADD_ASSIGNEES, result);
    result.computeStatus();
    assertSuccess(result);
    WorkItemType workItem = getWorkItem(task, result);
    display("work item", workItem);
    PrismObject<TaskType> wfTask = getObjectViaRepo(TaskType.class, taskOid);
    display("task", wfTask);
    PrismAsserts.assertReferenceValues(ref(workItem.getAssigneeRef()), userLead1Oid, userLead2Oid);
    assertRefEquals("Wrong originalAssigneeRef", ort(userLead1Oid), workItem.getOriginalAssigneeRef());
    org.activiti.engine.task.Task activitiTask = activitiEngine.getTaskService().createTaskQuery().taskId(workItem.getExternalId()).singleResult();
    System.out.println("Activiti task: " + activitiTask);
    assertEquals("Wrong activiti assignee", "UserType:" + userLead1Oid, activitiTask.getAssignee());
    List<String> assignees = getAssignees(activitiTask);
    assertEquals("Wrong midpoint-assignee values", new HashSet<>(Arrays.asList("UserType:" + userLead1Oid, "UserType:" + userLead2Oid)), new HashSet<>(assignees));
    List<WorkItemDelegationEventType> events = WfContextUtil.getWorkItemEvents(wfTask.asObjectable().getWorkflowContext(), workItemId, WorkItemDelegationEventType.class);
    assertEquals("Wrong # of delegation events", 1, events.size());
// TODO check content
}
Also used : Task(com.evolveum.midpoint.task.api.Task) WorkItemDelegationEventType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemDelegationEventType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType) Test(org.testng.annotations.Test)

Example 5 with WorkItemType

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

the class TestActivitiQuery method test100SearchByMoreAssignees.

@Test
public void test100SearchByMoreAssignees() throws Exception {
    final String TEST_NAME = "test100SearchByMoreAssignees";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // should start approval process
    assignRole(userJackOid, roleRole1aOid, task, result);
    assertNotAssignedRole(userJackOid, roleRole1aOid, task, result);
    {
        SearchResultList<WorkItemType> itemsAll = modelService.searchContainers(WorkItemType.class, null, null, task, result);
        assertEquals("Wrong # of total work items", 1, itemsAll.size());
    }
    {
        ObjectQuery query2 = QueryBuilder.queryFor(WorkItemType.class, prismContext).item(WorkItemType.F_ASSIGNEE_REF).ref(userLead1Oid).build();
        SearchResultList<WorkItemType> items2 = modelService.searchContainers(WorkItemType.class, query2, null, task, result);
        assertEquals("Wrong # of work items found using single-assignee query", 1, items2.size());
    }
    {
        List<PrismReferenceValue> refs = new ArrayList<>();
        refs.add(prv("oid-number-1"));
        refs.add(prv(userLead1Oid));
        refs.add(prv("oid-number-3"));
        ObjectQuery query3 = QueryBuilder.queryFor(WorkItemType.class, prismContext).item(WorkItemType.F_ASSIGNEE_REF).ref(refs).build();
        SearchResultList<WorkItemType> items3 = modelService.searchContainers(WorkItemType.class, query3, null, task, result);
        assertEquals("Wrong # of work items found using multi-assignee query", 1, items3.size());
    }
}
Also used : SearchResultList(com.evolveum.midpoint.schema.SearchResultList) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ArrayList(java.util.ArrayList) List(java.util.List) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType) Test(org.testng.annotations.Test)

Aggregations

WorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 Task (com.evolveum.midpoint.task.api.Task)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 Test (org.testng.annotations.Test)6 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)5 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)5 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)2 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)2 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 WorkItemDelegationEventType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemDelegationEventType)2 ArrayList (java.util.ArrayList)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ModelState (com.evolveum.midpoint.model.api.context.ModelState)1 AbstractModelImplementationIntegrationTest (com.evolveum.midpoint.model.impl.AbstractModelImplementationIntegrationTest)1 ModelOperationTaskHandler (com.evolveum.midpoint.model.impl.controller.ModelOperationTaskHandler)1