use of com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor.ExecutionMode in project midpoint by Evolveum.
the class PrimaryChangeProcessor method submitTasks.
private HookOperationMode submitTasks(List<PcpChildWfTaskCreationInstruction> instructions, final ModelContext context, final ObjectTreeDeltas changesWithoutApproval, Task taskFromModel, WfConfigurationType wfConfigurationType, OperationResult result) {
try {
ExecutionMode executionMode = determineExecutionMode(instructions);
// prepare root task and task0
WfTask rootWfTask = submitRootTask(context, changesWithoutApproval, taskFromModel, executionMode, wfConfigurationType, result);
WfTask wfTask0 = submitTask0(context, changesWithoutApproval, rootWfTask, executionMode, wfConfigurationType, result);
// start the jobs
List<WfTask> wfTasks = new ArrayList<>(instructions.size());
for (PcpChildWfTaskCreationInstruction instruction : instructions) {
if (instruction.startsWorkflowProcess() && instruction.isExecuteApprovedChangeImmediately()) {
// if we want to execute approved changes immediately in this instruction, we have to wait for
// task0 (if there is any) and then to update our model context with the results (if there are any)
// TODO CONSIDER THIS... when OID is no longer transferred
instruction.addHandlersAfterWfProcessAtEnd(WfTaskUtil.WAIT_FOR_TASKS_HANDLER_URI, WfPrepareChildOperationTaskHandler.HANDLER_URI);
}
WfTask wfTask = wfTaskController.submitWfTask(instruction, rootWfTask.getTask(), wfConfigurationType, null, result);
wfTasks.add(wfTask);
}
// all jobs depend on job0 (if there is one)
if (wfTask0 != null) {
for (WfTask wfTask : wfTasks) {
wfTask0.addDependent(wfTask);
}
wfTask0.commitChanges(result);
}
baseModelInvocationProcessingHelper.logJobsBeforeStart(rootWfTask, result);
rootWfTask.startWaitingForSubtasks(result);
return HookOperationMode.BACKGROUND;
} catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | RuntimeException | ExpressionEvaluationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Workflow process(es) could not be started", e);
result.recordFatalError("Workflow process(es) could not be started: " + e, e);
return HookOperationMode.ERROR;
// todo rollback - at least close open tasks, maybe stop workflow process instances
}
}
Aggregations