Exemple #1
0
        public virtual ProcessInstanceWithVariables execute(CommandContext commandContext)
        {
            ProcessDefinitionEntity processDefinition = (new GetDeployedProcessDefinitionCmd(instantiationBuilder, false)).execute(commandContext);

            foreach (CommandChecker checker in commandContext.ProcessEngineConfiguration.CommandCheckers)
            {
                checker.checkCreateProcessInstance(processDefinition);
            }

            ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.ModificationBuilder;

            ensureNotEmpty("At least one instantiation instruction required (e.g. by invoking startBefore(..), startAfter(..) or startTransition(..))", "instructions", modificationBuilder.ModificationOperations);

            // instantiate the process
            ActivityImpl initialActivity = determineFirstActivity(processDefinition, modificationBuilder);

            ExecutionEntity processInstance = processDefinition.createProcessInstance(instantiationBuilder.BusinessKey, instantiationBuilder.CaseInstanceId, initialActivity);

            if (!string.ReferenceEquals(instantiationBuilder.TenantId, null))
            {
                processInstance.TenantId = instantiationBuilder.TenantId;
            }

            processInstance.SkipCustomListeners = modificationBuilder.SkipCustomListeners;
            VariableMap variables = modificationBuilder.ProcessVariables;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver variablesListener = new org.camunda.bpm.engine.impl.persistence.entity.ExecutionVariableSnapshotObserver(processInstance);
            ExecutionVariableSnapshotObserver variablesListener = new ExecutionVariableSnapshotObserver(processInstance);

            processInstance.startWithoutExecuting(variables);

            // prevent ending of the process instance between instructions
            processInstance.PreserveScope = true;

            // apply modifications
            IList <AbstractProcessInstanceModificationCommand> instructions = modificationBuilder.ModificationOperations;

            for (int i = 0; i < instructions.Count; i++)
            {
                AbstractProcessInstanceModificationCommand instruction = instructions[i];
                LOG.debugStartingInstruction(processInstance.Id, i, instruction.describe());

                instruction.ProcessInstanceId   = processInstance.Id;
                instruction.SkipCustomListeners = modificationBuilder.SkipCustomListeners;
                instruction.SkipIoMappings      = modificationBuilder.SkipIoMappings;
                instruction.execute(commandContext);
            }

            if (!processInstance.hasChildren() && processInstance.Ended)
            {
                // process instance has ended regularly but this has not been propagated yet
                // due to preserveScope setting
                processInstance.propagateEnd();
            }

            commandContext.OperationLogManager.logProcessInstanceOperation(org.camunda.bpm.engine.history.UserOperationLogEntry_Fields.OPERATION_TYPE_CREATE, processInstance.Id, processInstance.ProcessDefinitionId, processInstance.getProcessDefinition().Key, Collections.singletonList(PropertyChange.EMPTY_CHANGE));

            return(new ProcessInstanceWithVariablesImpl(processInstance, variablesListener.Variables));
        }
Exemple #2
0
        public virtual Void execute(CommandContext commandContext)
        {
            string processInstanceId = builder.ProcessInstanceId;

            ExecutionManager executionManager = commandContext.ExecutionManager;
            ExecutionEntity  processInstance  = executionManager.findExecutionById(processInstanceId);

            ensureProcessInstanceExist(processInstanceId, processInstance);

            checkUpdateProcessInstance(processInstance, commandContext);

            processInstance.PreserveScope = true;

            IList <AbstractProcessInstanceModificationCommand> instructions = builder.ModificationOperations;

            checkCancellation(commandContext);
            for (int i = 0; i < instructions.Count; i++)
            {
                AbstractProcessInstanceModificationCommand instruction = instructions[i];
                LOG.debugModificationInstruction(processInstanceId, i + 1, instruction.describe());

                instruction.SkipCustomListeners = builder.SkipCustomListeners;
                instruction.SkipIoMappings      = builder.SkipIoMappings;
                instruction.execute(commandContext);
            }

            processInstance = executionManager.findExecutionById(processInstanceId);

            if (!processInstance.hasChildren())
            {
                if (processInstance.getActivity() == null)
                {
                    // process instance was cancelled
                    checkDeleteProcessInstance(processInstance, commandContext);
                    deletePropagate(processInstance, builder.ModificationReason, builder.SkipCustomListeners, builder.SkipIoMappings);
                }
                else if (processInstance.Ended)
                {
                    // process instance has ended regularly
                    processInstance.propagateEnd();
                }
            }

            if (writeOperationLog)
            {
                commandContext.OperationLogManager.logProcessInstanceOperation(LogEntryOperation, processInstanceId, null, null, Collections.singletonList(PropertyChange.EMPTY_CHANGE));
            }

            return(null);
        }