Search in sources :

Example 1 with ProcessMidPointInterface

use of com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface in project midpoint by Evolveum.

the class WfTaskController method onProcessEvent.

public void onProcessEvent(ProcessEvent event, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException {
    WfTask wfTask = recreateWfTask(task);
    LOGGER.trace("Updating instance state and activiti process instance ID in task {}", task);
    if (wfTask.getProcessInstanceId() == null) {
        wfTask.setWfProcessId(event.getPid());
    }
    Map<String, Object> variables = event.getVariables();
    // update state description
    ProcessMidPointInterface pmi = processInterfaceFinder.getProcessInterface(variables);
    wfTask.setProcessInstanceStageInformation(pmi.getStageNumber(variables), pmi.getStageCount(variables), pmi.getStageName(variables), pmi.getStageDisplayName(variables));
    wfTask.commitChanges(result);
    if (event instanceof ProcessFinishedEvent || !event.isRunning()) {
        onProcessFinishedEvent(event, wfTask, result);
    }
}
Also used : ProcessMidPointInterface(com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface) PcpWfTask(com.evolveum.midpoint.wf.impl.processors.primary.PcpWfTask)

Example 2 with ProcessMidPointInterface

use of com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface 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)

Example 3 with ProcessMidPointInterface

use of com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface in project midpoint by Evolveum.

the class ProcessEvent method computeOutcome.

private void computeOutcome(ProcessInterfaceFinder processInterfaceFinder) {
    ProcessMidPointInterface pmi = processInterfaceFinder.getProcessInterface(variables);
    outcome = pmi.getOutcome(variables);
}
Also used : ProcessMidPointInterface(com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface)

Aggregations

ProcessMidPointInterface (com.evolveum.midpoint.wf.impl.processes.ProcessMidPointInterface)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 PcpWfTask (com.evolveum.midpoint.wf.impl.processors.primary.PcpWfTask)1 WorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType)1