use of org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationCmd method createProcessInstanceModificationBuilder.
protected ProcessInstanceModificationBuilderImpl createProcessInstanceModificationBuilder(final String processInstanceId, final CommandContext commandContext) {
ProcessInstanceModificationBuilderImpl processInstanceModificationBuilder = new ProcessInstanceModificationBuilderImpl(commandContext, processInstanceId);
List<AbstractProcessInstanceModificationCommand> operations = processInstanceModificationBuilder.getModificationOperations();
ActivityInstance activityInstanceTree = null;
for (AbstractProcessInstanceModificationCommand instruction : builder.getInstructions()) {
instruction.setProcessInstanceId(processInstanceId);
if (!(instruction instanceof ActivityCancellationCmd) || !((ActivityCancellationCmd) instruction).isCancelCurrentActiveActivityInstances()) {
operations.add(instruction);
} else {
if (activityInstanceTree == null) {
activityInstanceTree = commandContext.runWithoutAuthorization(new Callable<ActivityInstance>() {
@Override
public ActivityInstance call() throws Exception {
return new GetActivityInstanceCmd(processInstanceId).execute(commandContext);
}
});
}
ActivityCancellationCmd cancellationInstruction = (ActivityCancellationCmd) instruction;
List<AbstractInstanceCancellationCmd> cmds = cancellationInstruction.createActivityInstanceCancellations(activityInstanceTree, commandContext);
operations.addAll(cmds);
}
}
return processInstanceModificationBuilder;
}
use of org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl in project camunda-bpm-platform by camunda.
the class AbstractDeleteProcessInstanceCmd method deleteProcessInstance.
protected void deleteProcessInstance(final CommandContext commandContext, String processInstanceId, final String deleteReason, final boolean skipCustomListeners, boolean externallyTerminated, final boolean skipIoMappings, boolean skipSubprocesses) {
ensureNotNull(BadUserRequestException.class, "processInstanceId is null", "processInstanceId", processInstanceId);
// fetch process instance
ExecutionManager executionManager = commandContext.getExecutionManager();
final ExecutionEntity execution = executionManager.findExecutionById(processInstanceId);
ensureNotNull(BadUserRequestException.class, "No process instance found for id '" + processInstanceId + "'", "processInstance", execution);
checkDeleteProcessInstance(execution, commandContext);
// delete process instance
commandContext.getExecutionManager().deleteProcessInstance(processInstanceId, deleteReason, false, skipCustomListeners, externallyTerminated, skipIoMappings, skipSubprocesses);
if (skipSubprocesses) {
List<ProcessInstance> superProcesslist = commandContext.getProcessEngineConfiguration().getRuntimeService().createProcessInstanceQuery().superProcessInstanceId(processInstanceId).list();
triggerHistoryEvent(superProcesslist);
}
final ExecutionEntity superExecution = execution.getSuperExecution();
if (superExecution != null) {
commandContext.runWithoutAuthorization(new Callable<Void>() {
public Void call() {
ProcessInstanceModificationBuilderImpl builder = (ProcessInstanceModificationBuilderImpl) new ProcessInstanceModificationBuilderImpl(commandContext, superExecution.getProcessInstanceId(), deleteReason).cancelActivityInstance(superExecution.getActivityInstanceId());
builder.execute(false, skipCustomListeners, skipIoMappings);
return null;
}
});
}
// create user operation log
commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_DELETE, processInstanceId, null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
}
use of org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl in project camunda-bpm-platform by camunda.
the class ProcessInstanceModificationCmd method execute.
@Override
public Void execute(final CommandContext commandContext) {
List<AbstractProcessInstanceModificationCommand> instructions = builder.getInstructions();
final Collection<String> processInstanceIds = collectProcessInstanceIds(commandContext);
ensureNotEmpty(BadUserRequestException.class, "Modification instructions cannot be empty", 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);
ProcessDefinitionEntity processDefinition = getProcessDefinition(commandContext, builder.getProcessDefinitionId());
ensureNotNull(BadUserRequestException.class, "Process definition id cannot be null", processDefinition);
if (writeUserOperationLog) {
writeUserOperationLog(commandContext, processDefinition, processInstanceIds.size(), false);
}
boolean skipCustomListeners = builder.isSkipCustomListeners();
boolean skipIoMappings = builder.isSkipIoMappings();
for (String processInstanceId : processInstanceIds) {
ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
ensureProcessInstanceExist(processInstanceId, processInstance);
ensureSameProcessDefinition(processInstance, processDefinition.getId());
ProcessInstanceModificationBuilderImpl builder = createProcessInstanceModificationBuilder(processInstanceId, commandContext);
builder.execute(false, skipCustomListeners, skipIoMappings);
}
return null;
}
use of org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl 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;
}
use of org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl 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