Search in sources :

Example 16 with WorkItemType

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

Example 17 with WorkItemType

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

the class WorkItemProvider method taskExtractToWorkItem.

public WorkItemType taskExtractToWorkItem(TaskExtract task, boolean resolveTask, boolean resolveAssignee, boolean resolveCandidates, boolean fetchAllVariables, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(OPERATION_ACTIVITI_TASK_TO_WORK_ITEM);
    result.addParams(new String[] { "activitiTaskId", "resolveTask", "resolveAssignee", "resolveCandidates" }, task.getId(), resolveTask, resolveAssignee, resolveCandidates);
    try {
        WorkItemType wi = new WorkItemType(prismContext);
        final Map<String, Object> variables = task.getVariables();
        wi.setExternalId(task.getId());
        wi.setName(task.getName());
        wi.setCreateTimestamp(XmlTypeConverter.createXMLGregorianCalendar(task.getCreateTime()));
        wi.setDeadline(XmlTypeConverter.createXMLGregorianCalendar(task.getDueDate()));
        String taskOid = ActivitiUtil.getRequiredVariable(variables, CommonProcessVariableNames.VARIABLE_MIDPOINT_TASK_OID, String.class, null);
        com.evolveum.midpoint.task.api.Task mpTask = null;
        try {
            mpTask = taskManager.getTask(taskOid, result);
        } catch (ObjectNotFoundException | SchemaException e) {
            // TODO more gentle treatment
            throw new SystemException("Couldn't retrieve owning task for " + wi + ": " + e.getMessage(), e);
        }
        if (mpTask.getWorkflowContext() == null) {
            throw new IllegalStateException("No workflow context in task " + mpTask + " that owns " + wi);
        }
        mpTask.getWorkflowContext().getWorkItem().add(wi);
        // assignees
        wi.getAssigneeRef().addAll(getMidpointAssignees(task));
        String originalAssigneeString = ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_ORIGINAL_ASSIGNEE, String.class, prismContext);
        if (originalAssigneeString != null) {
            wi.setOriginalAssigneeRef(MiscDataUtil.stringToRef(originalAssigneeString));
        }
        if (resolveAssignee) {
            miscDataUtil.resolveAndStoreObjectReferences(wi.getAssigneeRef(), result);
            miscDataUtil.resolveAndStoreObjectReference(wi.getOriginalAssigneeRef(), result);
        }
        // candidates
        task.getCandidateUsers().forEach(s -> wi.getCandidateRef().add(createObjectRef(s, USER)));
        task.getCandidateGroups().forEach(s -> wi.getCandidateRef().add(MiscDataUtil.stringToRef(s)));
        if (resolveCandidates) {
            miscDataUtil.resolveAndStoreObjectReferences(wi.getCandidateRef(), result);
        }
        // other
        ProcessMidPointInterface pmi = processInterfaceFinder.getProcessInterface(variables);
        wi.setOutput(pmi.extractWorkItemResult(variables));
        String completedBy = ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_WORK_ITEM_COMPLETED_BY, String.class, prismContext);
        if (completedBy != null) {
            wi.setPerformerRef(ObjectTypeUtil.createObjectRef(completedBy, ObjectTypes.USER));
        }
        wi.setStageNumber(pmi.getStageNumber(variables));
        wi.setEscalationLevel(WfContextUtil.createEscalationLevel(pmi.getEscalationLevelNumber(variables), pmi.getEscalationLevelName(variables), pmi.getEscalationLevelDisplayName(variables)));
        // This is just because 'variables' switches in task query DO NOT fetch all required variables...
        if (fetchAllVariables) {
            // TODO can we do this e.g. in the task completion listener?
            Map<String, Object> allVariables = activitiEngine.getTaskService().getVariables(task.getId());
            wi.setProcessSpecificPart(pmi.extractProcessSpecificWorkItemPart(allVariables));
            wi.getAdditionalInformation().addAll(pmi.getAdditionalInformation(allVariables));
        }
        return wi;
    } catch (RuntimeException e) {
        result.recordFatalError("Couldn't convert activiti task " + task.getId() + " to midPoint WorkItem: " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProcessMidPointInterface(com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) WorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)

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