Search in sources :

Example 1 with ProcessInstanceModificationBuilderImpl

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;
}
Also used : ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) Callable(java.util.concurrent.Callable)

Example 2 with ProcessInstanceModificationBuilderImpl

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));
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)

Example 3 with ProcessInstanceModificationBuilderImpl

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

Example 4 with ProcessInstanceModificationBuilderImpl

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;
}
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)

Example 5 with ProcessInstanceModificationBuilderImpl

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());
}
Also used : ExecutionVariableSnapshotObserver(org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ProcessInstanceWithVariablesImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessInstanceModificationBuilderImpl(org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Aggregations

ProcessInstanceModificationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstanceModificationBuilderImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)3 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 Callable (java.util.concurrent.Callable)1 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)1 ProcessInstantiationBuilderImpl (org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1 ExecutionManager (org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager)1 ExecutionVariableSnapshotObserver (org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver)1 ProcessInstanceWithVariablesImpl (org.camunda.bpm.engine.impl.persistence.entity.ProcessInstanceWithVariablesImpl)1 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)1 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1