use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver in project camunda-bpm-platform by camunda.
the class StartProcessInstanceCmd method execute.
public ProcessInstanceWithVariables execute(CommandContext commandContext) {
ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkCreateProcessInstance(processDefinition);
}
// Start the process instance
ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId());
if (instantiationBuilder.getTenantId() != null) {
processInstance.setTenantId(instantiationBuilder.getTenantId());
}
final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);
processInstance.start(instantiationBuilder.getVariables());
return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver in project camunda-bpm-platform by camunda.
the class StartProcessInstanceAtActivitiesCmd method execute.
public ProcessInstanceWithVariables execute(CommandContext commandContext) {
ProcessDefinitionEntity processDefinition = new GetDeployedProcessDefinitionCmd(instantiationBuilder, false).execute(commandContext);
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkCreateProcessInstance(processDefinition);
}
ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
ensureNotEmpty("At least one instantiation instruction required (e.g. by invoking startBefore(..), startAfter(..) or startTransition(..))", "instructions", modificationBuilder.getModificationOperations());
// instantiate the process
ActivityImpl initialActivity = determineFirstActivity(processDefinition, modificationBuilder);
ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.getBusinessKey(), instantiationBuilder.getCaseInstanceId(), initialActivity);
if (instantiationBuilder.getTenantId() != null) {
processInstance.setTenantId(instantiationBuilder.getTenantId());
}
processInstance.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
VariableMap variables = modificationBuilder.getProcessVariables();
final ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);
processInstance.startWithoutExecuting(variables);
// prevent ending of the process instance between instructions
processInstance.setPreserveScope(true);
// apply modifications
List<AbstractProcessInstanceModificationCommand> instructions = modificationBuilder.getModificationOperations();
for (int i = 0; i < instructions.size(); i++) {
AbstractProcessInstanceModificationCommand instruction = instructions.get(i);
LOG.debugStartingInstruction(processInstance.getId(), i, instruction.describe());
instruction.setProcessInstanceId(processInstance.getId());
instruction.setSkipCustomListeners(modificationBuilder.isSkipCustomListeners());
instruction.setSkipIoMappings(modificationBuilder.isSkipIoMappings());
instruction.execute(commandContext);
}
if (!processInstance.hasChildren() && processInstance.isEnded()) {
// process instance has ended regularly but this has not been propagated yet
// due to preserveScope setting
processInstance.propagateEnd();
}
return new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.getVariables());
}
Aggregations