Search in sources :

Example 1 with ProcessInstantiationBuilderImpl

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;
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstantiationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Aggregations

HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 ProcessInstanceModificationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)1 ProcessInstantiationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl)1 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1