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);
}
}
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();
}
}
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);
}
Aggregations