Search in sources :

Example 16 with F_WORK_ITEM

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

the class TestUserChangeApprovalLegacy method assertWfContextAfterRootTaskFinishes.

protected void assertWfContextAfterRootTaskFinishes(Task rootTask, List<Task> subtasks, OperationResult result, String... processNames) throws Exception {
    final Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), createRetrieve());
    Task opTask = taskManager.createTaskInstance();
    TaskType rootTaskType = modelService.getObject(TaskType.class, rootTask.getOid(), options, opTask, result).asObjectable();
    assertTrue("unexpected process instance id in root task", rootTaskType.getWorkflowContext() == null || rootTaskType.getWorkflowContext().getProcessInstanceId() == null);
    assertEquals("Wrong # of wf subtasks w.r.t processNames (" + Arrays.asList(processNames) + ")", processNames.length, subtasks.size());
    int i = 0;
    for (Task subtask : subtasks) {
        TaskType subtaskType = modelService.getObject(TaskType.class, subtask.getOid(), options, opTask, result).asObjectable();
        display("Subtask #" + (i + 1) + ": ", subtaskType);
        assertNull("Unexpected fetch result in wf subtask: " + subtask, subtaskType.getFetchResult());
        WfContextType wfc = subtaskType.getWorkflowContext();
        assertNotNull("Missing workflow context in wf subtask: " + subtask, wfc);
        assertNotNull("No process ID in wf subtask: " + subtask, wfc.getProcessInstanceId());
        assertEquals("Wrong process ID name in subtask: " + subtask, processNames[i++], wfc.getProcessInstanceName());
        assertNotNull("Missing process start time in subtask: " + subtask, wfc.getStartTimestamp());
        assertNotNull("Missing process end time in subtask: " + subtask, wfc.getEndTimestamp());
        assertEquals("Wrong outcome", SchemaConstants.MODEL_APPROVAL_OUTCOME_APPROVE, wfc.getOutcome());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) WfContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 17 with F_WORK_ITEM

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

the class AccCertCaseOperationsHelper method getDeltasToAdvanceCases.

List<ItemDelta<?, ?>> getDeltasToAdvanceCases(AccessCertificationCampaignType campaign, AccessCertificationStageType stage, Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {
    LOGGER.trace("Advancing reviewers and timestamps for cases in {}", toShortString(campaign));
    List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaign.getOid(), null, null, result);
    List<ItemDelta<?, ?>> rv = new ArrayList<>(caseList.size());
    int stageToBe = campaign.getStageNumber() + 1;
    List<AccessCertificationResponseType> outcomesToStopOn = computationHelper.getOutcomesToStopOn(campaign);
    AccessCertificationReviewerSpecificationType reviewerSpec = reviewersHelper.findReviewersSpecification(campaign, stageToBe, task, result);
    for (AccessCertificationCaseType _case : caseList) {
        if (!computationHelper.computeEnabled(campaign, _case, outcomesToStopOn)) {
            continue;
        }
        Long caseId = _case.asPrismContainerValue().getId();
        assert caseId != null;
        List<ObjectReferenceType> reviewers = reviewersHelper.getReviewersForCase(_case, campaign, reviewerSpec, task, result);
        List<AccessCertificationWorkItemType> workItems = createWorkItems(reviewers, stageToBe);
        _case.getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
        AccessCertificationResponseType currentOutcome = computationHelper.computeOutcomeForStage(_case, campaign, stageToBe);
        AccessCertificationResponseType overallOutcome = computationHelper.computeOverallOutcome(_case, campaign, currentOutcome);
        rv.addAll(DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, prismContext).item(F_CASE, caseId, F_WORK_ITEM).add(PrismContainerValue.toPcvList(workItems)).item(F_CASE, caseId, F_CURRENT_STAGE_CREATE_TIMESTAMP).replace(stage.getStartTimestamp()).item(F_CASE, caseId, F_CURRENT_STAGE_DEADLINE).replace(stage.getDeadline()).item(F_CASE, caseId, F_CURRENT_STAGE_OUTCOME).replace(OutcomeUtils.toUri(currentOutcome)).item(F_CASE, caseId, F_OUTCOME).replace(OutcomeUtils.toUri(overallOutcome)).item(F_CASE, caseId, F_STAGE_NUMBER).replace(stageToBe).asItemDeltas());
    }
    LOGGER.debug("Created {} deltas to advance {} cases for campaign {}", rv.size(), caseList.size(), toShortString(campaign));
    return rv;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 18 with F_WORK_ITEM

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

the class ProcessInstanceProvider method augmentTaskObject.

// doesn't throw any exceptions - these are logged and stored into the operation result
public <T extends ObjectType> void augmentTaskObject(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Task opTask, OperationResult parentResult) {
    final OperationResult result = parentResult.createSubresult(OPERATION_AUGMENT_TASK_OBJECT);
    result.addParam("object", ObjectTypeUtil.toShortString(object));
    result.addCollectionOfSerializablesAsParam("options", options);
    if (!(object.asObjectable() instanceof TaskType)) {
        result.recordNotApplicableIfUnknown();
        return;
    }
    final TaskType taskType = (TaskType) object.asObjectable();
    try {
        if (taskType.getWorkflowContext() == null) {
            return;
        }
        final String instanceId = taskType.getWorkflowContext().getProcessInstanceId();
        if (instanceId == null) {
            return;
        }
        final boolean retrieveWorkItems = SelectorOptions.hasToLoadPath(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), options);
        if (!retrieveWorkItems) {
            // We assume that everything (except work items) is already stored in repo.
            return;
        }
        final List<WorkItemType> workItems = workItemProvider.getWorkItemsForProcessInstanceId(instanceId, result);
        taskType.getWorkflowContext().getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
    } catch (RuntimeException e) {
        result.recordFatalError(e.getMessage(), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare wf-related information for {}", e, ObjectTypeUtil.toShortString(object));
    } finally {
        result.computeStatusIfUnknown();
    }
    if (!result.isSuccess()) {
        taskType.setFetchResult(result.createOperationResultType());
    }
}
Also used : TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

Aggregations

Test (org.testng.annotations.Test)12 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 AccessCertificationWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 Session (org.hibernate.Session)5 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 Task (com.evolveum.midpoint.task.api.Task)3 WorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)1 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)1 WfContextType (com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1