use of org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl in project camunda-bpm-platform by camunda.
the class RestartProcessInstancesCmd method execute.
@Override
public Void execute(final CommandContext commandContext) {
final Collection<String> processInstanceIds = collectProcessInstanceIds();
final List<AbstractProcessInstanceModificationCommand> instructions = builder.getInstructions();
ensureNotEmpty(BadUserRequestException.class, "Restart instructions cannot be empty", "instructions", instructions);
ensureNotEmpty(BadUserRequestException.class, "Process instance ids cannot be empty", "Process instance ids", processInstanceIds);
ensureNotContainsNull(BadUserRequestException.class, "Process instance ids cannot be null", "Process instance ids", processInstanceIds);
final ProcessDefinitionEntity processDefinition = getProcessDefinition(commandContext, builder.getProcessDefinitionId());
ensureNotNull("Process definition cannot be found", "processDefinition", processDefinition);
checkAuthorization(commandContext, processDefinition);
if (writeUserOperationLog) {
writeUserOperationLog(commandContext, processDefinition, processInstanceIds.size(), false);
}
final String processDefinitionId = builder.getProcessDefinitionId();
Runnable runnable = new Runnable() {
@Override
public void run() {
for (String processInstanceId : processInstanceIds) {
HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(commandContext, processInstanceId);
ensureNotNull(BadUserRequestException.class, "Historic process instance cannot be found", "historicProcessInstanceId", historicProcessInstance);
ensureHistoricProcessInstanceNotActive(historicProcessInstance);
ensureSameProcessDefinition(historicProcessInstance, processDefinitionId);
ProcessInstantiationBuilderImpl instantiationBuilder = getProcessInstantiationBuilder(commandExecutor, processDefinitionId);
applyProperties(instantiationBuilder, processDefinition, historicProcessInstance);
ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
modificationBuilder.setModificationOperations(instructions);
VariableMap variables = collectVariables(commandContext, historicProcessInstance);
instantiationBuilder.setVariables(variables);
instantiationBuilder.execute(builder.isSkipCustomListeners(), builder.isSkipIoMappings());
}
}
};
ProcessApplicationContextUtil.doContextSwitch(runnable, processDefinition);
return null;
}
Aggregations