コード例 #1
0
 public WalkConditionAnonymousInnerClass2(AbstractInstantiationCmd outerInstance, ProcessDefinitionImpl processDefinition, ActivityExecutionTreeMapping mapping, ExecutionEntity ancestorScopeExecution, PvmScope ancestorScope)
 {
     this.outerInstance          = outerInstance;
     this.processDefinition      = processDefinition;
     this.mapping                = mapping;
     this.ancestorScopeExecution = ancestorScopeExecution;
     this.ancestorScope          = ancestorScope;
 }
コード例 #2
0
 public MigratingInstanceParseContext(MigratingInstanceParser parser, MigrationPlan migrationPlan, ExecutionEntity processInstance, ProcessDefinitionEntity targetProcessDefinition)
 {
     this.parser = parser;
     this.sourceProcessDefinition  = processInstance.getProcessDefinition();
     this.targetProcessDefinition  = targetProcessDefinition;
     this.migratingProcessInstance = new MigratingProcessInstance(processInstance.Id, sourceProcessDefinition, targetProcessDefinition);
     this.mapping = new ActivityExecutionTreeMapping(Context.CommandContext, processInstance.Id);
     this.instructionsBySourceScope = organizeInstructionsBySourceScope(migrationPlan);
 }
コード例 #3
0
 public MigratingInstanceParseContext(MigratingInstanceParser parser, IMigrationPlan migrationPlan,
                                      ExecutionEntity processInstance, ProcessDefinitionEntity targetProcessDefinition)
 {
     this.Parser                  = parser;
     sourceProcessDefinition      = processInstance.GetProcessDefinition();//.ProcessDefinition;
     this.targetProcessDefinition = targetProcessDefinition;
     migratingProcessInstance     = new MigratingProcessInstance(processInstance.Id, sourceProcessDefinition,
                                                                 targetProcessDefinition);
     mapping = new ActivityExecutionTreeMapping(context.Impl.Context.CommandContext, processInstance.Id);
     InstructionsBySourceScope = OrganizeInstructionsBySourceScope(migrationPlan);
 }
コード例 #4
0
        protected internal virtual ExecutionEntity GetSingleExecutionForScope(ActivityExecutionTreeMapping mapping,
                                                                              ScopeImpl scope)
        {
            var executions = mapping.GetExecutions(scope);

            if (executions.Count > 0)
            {
                if (executions.Count > 1)
                {
                    throw new ProcessEngineException("Executions for activity " + scope + " ambiguous");
                }
            }
            return(null);
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: protected org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity determineSourceInstanceExecution(final org.camunda.bpm.engine.impl.interceptor.CommandContext commandContext)
        protected internal override ExecutionEntity determineSourceInstanceExecution(CommandContext commandContext)
        {
            ExecutionEntity processInstance = commandContext.ExecutionManager.findExecutionById(processInstanceId);

            // rebuild the mapping because the execution tree changes with every iteration
            ActivityExecutionTreeMapping mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);

            ActivityInstance instance = commandContext.runWithoutAuthorization(new CallableAnonymousInnerClass(this, commandContext));

            ActivityInstance instanceToCancel = findActivityInstance(instance, activityInstanceId);

            EnsureUtil.ensureNotNull(typeof(NotValidException), describeFailure("Activity instance '" + activityInstanceId + "' does not exist"), "activityInstance", instanceToCancel);
            ExecutionEntity scopeExecution = getScopeExecutionForActivityInstance(processInstance, mapping, instanceToCancel);

            return(scopeExecution);
        }
コード例 #6
0
        protected internal override ExecutionEntity DetermineSourceInstanceExecution(CommandContext commandContext)
        {
            ExecutionEntity processInstance = commandContext.ExecutionManager.FindExecutionById(processInstanceId);

            // rebuild the mapping because the execution tree changes with every iteration
            var mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);

            IActivityInstance instance = commandContext.RunWithoutAuthorization(() => (new GetActivityInstanceCmd(processInstanceId)).Execute(commandContext));

            IActivityInstance instanceToCancel = FindActivityInstance(instance, ActivityInstanceId);

            EnsureUtil.EnsureNotNull(typeof(NotValidException), DescribeFailure("Activity instance '" + ActivityInstanceId + "' does not exist"), "activityInstance", instanceToCancel);
            ExecutionEntity scopeExecution = GetScopeExecutionForActivityInstance(processInstance, mapping, instanceToCancel);

            return(scopeExecution);
            //return new ExecutionEntity();
        }
コード例 #7
0
        protected internal virtual ExecutionEntity getSingleExecutionForScope(ActivityExecutionTreeMapping mapping, ScopeImpl scope)
        {
            ISet <ExecutionEntity> executions = mapping.getExecutions(scope);

            if (executions.Count > 0)
            {
                if (executions.Count > 1)
                {
                    throw new ProcessEngineException("Executions for activity " + scope + " ambiguous");
                }

                return(executions.GetEnumerator().next());
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
        protected internal virtual ExecutionEntity GetScopeExecutionForActivityInstance(ExecutionEntity processInstance,
                                                                                        ActivityExecutionTreeMapping mapping, IActivityInstance activityInstance)
        {
            EnsureUtil.EnsureNotNull("activityInstance", activityInstance);

            ProcessDefinitionImpl processDefinition = processInstance.ProcessDefinition;
            ScopeImpl             scope             = GetScopeForActivityInstance(processDefinition, activityInstance);

            ISet <ExecutionEntity> executions = mapping.GetExecutions(scope);
            ISet <string>          activityInstanceExecutions = new HashSet <string>(activityInstance.ExecutionIds);

            // TODO: this is a hack around the activity instance tree
            // remove with fix of CAM-3574
            foreach (var activityInstanceExecutionId in activityInstance.ExecutionIds)
            {
                ExecutionEntity execution = context.Impl.Context.CommandContext.ExecutionManager.FindExecutionById(activityInstanceExecutionId);
                if (execution.IsConcurrent && execution.HasChildren())
                {
                    // concurrent executions have at most one child
                    IActivityExecution child = execution.executions.First();//.Executions[0];
                    activityInstanceExecutions.Add(child.Id);
                }
            }

            // find the scope execution for the given activity instance
            ISet <ExecutionEntity> retainedExecutionsForInstance = new HashSet <ExecutionEntity>();

            foreach (ExecutionEntity execution in executions)
            {
                if (activityInstanceExecutions.Contains(execution.Id))
                {
                    retainedExecutionsForInstance.Add(execution);
                }
            }

            if (retainedExecutionsForInstance.Count != 1)
            {
                throw new ProcessEngineException("There are " + retainedExecutionsForInstance.Count +
                                                 " (!= 1) executions for activity instance " + activityInstance.Id);
            }

            return(retainedExecutionsForInstance.GetEnumerator().Current);
        }
コード例 #9
0
        public override object Execute(CommandContext commandContext)
        {
            ExecutionEntity processInstance = commandContext.ExecutionManager.FindExecutionById(processInstanceId);

            ProcessDefinitionImpl processDefinition = processInstance.GetProcessDefinition();

            CoreModelElement elementToInstantiate = GetTargetElement(processDefinition);

            EnsureUtil.EnsureNotNull(typeof(NotValidException), DescribeFailure("Element '" + TargetElementId + "' does not exist in process '" + processDefinition.Id + "'"), "element", elementToInstantiate);

            // rebuild the mapping because the execution tree changes with every iteration
            var mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);

            // before instantiating an activity, two things have to be determined:
            //
            // activityStack:
            // For the activity to instantiate, we build a stack of parent flow scopes
            // for which no executions exist yet and that have to be instantiated
            //
            // scopeExecution:
            // This is typically the execution under which a new sub tree has to be created.
            // if an explicit ancestor activity instance is set:
            //   - this is the scope execution for that ancestor activity instance
            //   - throws exception if that scope execution is not in the parent hierarchy
            //     of the activity to be started
            // if no explicit ancestor activity instance is set:
            //   - this is the execution of the first parent/ancestor flow scope that has an execution
            //   - throws an exception if there is more than one such execution

            var targetFlowScope = GetTargetFlowScope(processDefinition);

            // prepare to walk up the flow scope hierarchy and collect the flow scope activities
            var stackCollector = new ActivityStackCollector();
            var walker         = new FlowScopeWalker(targetFlowScope);

            walker.AddPreVisitor(stackCollector);

            ExecutionEntity scopeExecution = null;

            // if no explicit ancestor activity instance is set
            if (ReferenceEquals(AncestorActivityInstanceId, null))
            {
                // walk until a scope is reached for which executions exist
                walker.WalkWhile((element) => mapping.GetExecutions(element)
                                 .Count > 0 || element == processDefinition);

                var flowScopeExecutions = mapping.GetExecutions(walker.CurrentElement);

                if (flowScopeExecutions.Count > 1)
                {
                    throw new ProcessEngineException("Ancestor activity execution is ambiguous for activity " +
                                                     targetFlowScope);
                }

                //scopeExecution = flowScopeExecutions.GetEnumerator().Next();
                scopeExecution = flowScopeExecutions.First();
            }

            var activitiesToInstantiate = stackCollector.ActivityStack;

            activitiesToInstantiate.Reverse();

            // We have to make a distinction between
            // - "regular" activities for which the activity stack can be instantiated and started
            //   right away
            // - interrupting or cancelling activities for which we have to ensure that
            //   the interruption and cancellation takes place before we instantiate the activity stack
            ActivityImpl topMostActivity = null;
            ScopeImpl    flowScope       = null;

            if (activitiesToInstantiate.Count > 0)
            {
                topMostActivity = (ActivityImpl)activitiesToInstantiate[0];
                flowScope       = topMostActivity.FlowScope;
            }
            else if (elementToInstantiate is ActivityImpl)
            {
                topMostActivity = (ActivityImpl)elementToInstantiate;
                flowScope       = topMostActivity.FlowScope;
            }
            else if (elementToInstantiate is TransitionImpl)
            {
                var transitionToInstantiate = (TransitionImpl)elementToInstantiate;
                flowScope = transitionToInstantiate.Source.FlowScope;
            }

            if (!SupportsConcurrentChildInstantiation(flowScope))
            {
                throw new ProcessEngineException("Concurrent instantiation not possible for " + "activities in scope " +
                                                 flowScope.Id);
            }

            var startBehavior = ActivityStartBehavior.ConcurrentInFlowScope;

            if (topMostActivity != null)
            {
                startBehavior = topMostActivity.ActivityStartBehavior;

                if (activitiesToInstantiate.Count > 0)
                {
                    // this is in BPMN relevant if there is an interrupting event sub process.
                    // we have to distinguish between instantiation of the start event and any other activity.
                    // instantiation of the start event means interrupting behavior; instantiation
                    // of any other ITask means no interruption.
                    IPvmActivity initialActivity       = topMostActivity.Properties.Get(BpmnProperties.InitialActivity);
                    IPvmActivity secondTopMostActivity = null;
                    if (activitiesToInstantiate.Count > 1)
                    {
                        secondTopMostActivity = activitiesToInstantiate[1];
                    }
                    else if (elementToInstantiate.GetType().IsSubclassOf(typeof(ActivityImpl)))
                    {
                        secondTopMostActivity = (IPvmActivity)elementToInstantiate;
                    }

                    if (initialActivity != secondTopMostActivity)
                    {
                        startBehavior = ActivityStartBehavior.ConcurrentInFlowScope;
                    }
                }
            }
            //throw new Exception("startBehavior值:"+(int)startBehavior);//2
            switch (startBehavior)
            {
            case ActivityStartBehavior.CancelEventScope:
            {
                ScopeImpl scopeToCancel     = (ScopeImpl)topMostActivity.EventScope;
                var       executionToCancel = GetSingleExecutionForScope(mapping, scopeToCancel);
                if (executionToCancel != null)
                {
                    executionToCancel.DeleteCascade("Cancelling activity " + topMostActivity + " executed.",
                                                    skipCustomListeners, skipIoMappings);
                    Instantiate(executionToCancel.Parent, activitiesToInstantiate, elementToInstantiate);
                }
                else
                {
                    var flowScopeExecution = GetSingleExecutionForScope(mapping, topMostActivity.FlowScope);
                    InstantiateConcurrent(flowScopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                break;
            }

            case ActivityStartBehavior.InterruptEventScope:
            {
                ScopeImpl scopeToCancel     = (ScopeImpl)topMostActivity.EventScope;
                var       executionToCancel = GetSingleExecutionForScope(mapping, scopeToCancel);
                executionToCancel.Interrupt("Interrupting activity " + topMostActivity + " executed.",
                                            skipCustomListeners, skipIoMappings);
                executionToCancel.SetActivity(null);
                executionToCancel.LeaveActivityInstance();
                Instantiate(executionToCancel, activitiesToInstantiate, elementToInstantiate);
                break;
            }

            case ActivityStartBehavior.InterruptFlowScope:
            {
                var scopeToCancel     = topMostActivity.FlowScope;
                var executionToCancel = GetSingleExecutionForScope(mapping, scopeToCancel);
                executionToCancel.Interrupt("Interrupting activity " + topMostActivity + " executed.",
                                            skipCustomListeners, skipIoMappings);
                executionToCancel.SetActivity(null);
                executionToCancel.LeaveActivityInstance();
                Instantiate(executionToCancel, activitiesToInstantiate, elementToInstantiate);
                break;
            }

            default:
            {
                // if all child executions have been cancelled
                // or this execution has ended executing its scope, it can be reused
                if (!scopeExecution.HasChildren() && (scopeExecution.GetActivity() == null || scopeExecution.IsEnded))
                {
                    // reuse the scope execution
                    Instantiate(scopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                else
                {
                    // if the activity is not cancelling/interrupting, it can simply be instantiated as
                    // a concurrent child of the scopeExecution
                    InstantiateConcurrent(scopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                break;
            }
            }

            return(null);
        }
コード例 #10
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public Void execute(final org.camunda.bpm.engine.impl.interceptor.CommandContext commandContext)
        public override Void execute(CommandContext commandContext)
        {
            ExecutionEntity processInstance = commandContext.ExecutionManager.findExecutionById(processInstanceId);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl processDefinition = processInstance.getProcessDefinition();
            ProcessDefinitionImpl processDefinition = processInstance.getProcessDefinition();

            CoreModelElement elementToInstantiate = getTargetElement(processDefinition);

            EnsureUtil.ensureNotNull(typeof(NotValidException), describeFailure("Element '" + TargetElementId + "' does not exist in process '" + processDefinition.Id + "'"), "element", elementToInstantiate);

            // rebuild the mapping because the execution tree changes with every iteration
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.ActivityExecutionTreeMapping mapping = new org.camunda.bpm.engine.impl.ActivityExecutionTreeMapping(commandContext, processInstanceId);
            ActivityExecutionTreeMapping mapping = new ActivityExecutionTreeMapping(commandContext, processInstanceId);

            // before instantiating an activity, two things have to be determined:
            //
            // activityStack:
            // For the activity to instantiate, we build a stack of parent flow scopes
            // for which no executions exist yet and that have to be instantiated
            //
            // scopeExecution:
            // This is typically the execution under which a new sub tree has to be created.
            // if an explicit ancestor activity instance is set:
            //   - this is the scope execution for that ancestor activity instance
            //   - throws exception if that scope execution is not in the parent hierarchy
            //     of the activity to be started
            // if no explicit ancestor activity instance is set:
            //   - this is the execution of the first parent/ancestor flow scope that has an execution
            //   - throws an exception if there is more than one such execution

            ScopeImpl targetFlowScope = getTargetFlowScope(processDefinition);

            // prepare to walk up the flow scope hierarchy and collect the flow scope activities
            ActivityStackCollector stackCollector = new ActivityStackCollector();
            FlowScopeWalker        walker         = new FlowScopeWalker(targetFlowScope);

            walker.addPreVisitor(stackCollector);

            ExecutionEntity scopeExecution = null;

            // if no explicit ancestor activity instance is set
            if (string.ReferenceEquals(ancestorActivityInstanceId, null))
            {
                // walk until a scope is reached for which executions exist
                walker.walkWhile(new WalkConditionAnonymousInnerClass(this, processDefinition, mapping));

                ISet <ExecutionEntity> flowScopeExecutions = mapping.getExecutions(walker.CurrentElement);

                if (flowScopeExecutions.Count > 1)
                {
                    throw new ProcessEngineException("Ancestor activity execution is ambiguous for activity " + targetFlowScope);
                }

                scopeExecution = flowScopeExecutions.GetEnumerator().next();
            }
            else
            {
                ActivityInstance tree = commandContext.runWithoutAuthorization(new CallableAnonymousInnerClass(this, commandContext));

                ActivityInstance ancestorInstance = findActivityInstance(tree, ancestorActivityInstanceId);
                EnsureUtil.ensureNotNull(typeof(NotValidException), describeFailure("Ancestor activity instance '" + ancestorActivityInstanceId + "' does not exist"), "ancestorInstance", ancestorInstance);

                // determine ancestor activity scope execution and activity
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity ancestorScopeExecution = getScopeExecutionForActivityInstance(processInstance, mapping, ancestorInstance);
                ExecutionEntity ancestorScopeExecution = getScopeExecutionForActivityInstance(processInstance, mapping, ancestorInstance);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.impl.pvm.PvmScope ancestorScope = getScopeForActivityInstance(processDefinition, ancestorInstance);
                PvmScope ancestorScope = getScopeForActivityInstance(processDefinition, ancestorInstance);

                // walk until the scope of the ancestor scope execution is reached
                walker.walkWhile(new WalkConditionAnonymousInnerClass2(this, processDefinition, mapping, ancestorScopeExecution, ancestorScope));

                ISet <ExecutionEntity> flowScopeExecutions = mapping.getExecutions(walker.CurrentElement);

                if (!flowScopeExecutions.Contains(ancestorScopeExecution))
                {
                    throw new NotValidException(describeFailure("Scope execution for '" + ancestorActivityInstanceId + "' cannot be found in parent hierarchy of flow element '" + elementToInstantiate.Id + "'"));
                }

                scopeExecution = ancestorScopeExecution;
            }

            IList <PvmActivity> activitiesToInstantiate = stackCollector.ActivityStack;

            activitiesToInstantiate.Reverse();

            // We have to make a distinction between
            // - "regular" activities for which the activity stack can be instantiated and started
            //   right away
            // - interrupting or cancelling activities for which we have to ensure that
            //   the interruption and cancellation takes place before we instantiate the activity stack
            ActivityImpl topMostActivity = null;
            ScopeImpl    flowScope       = null;

            if (activitiesToInstantiate.Count > 0)
            {
                topMostActivity = (ActivityImpl)activitiesToInstantiate[0];
                flowScope       = topMostActivity.FlowScope;
            }
            else if (elementToInstantiate.GetType().IsAssignableFrom(typeof(ActivityImpl)))
            {
                topMostActivity = (ActivityImpl)elementToInstantiate;
                flowScope       = topMostActivity.FlowScope;
            }
            else if (elementToInstantiate.GetType().IsAssignableFrom(typeof(TransitionImpl)))
            {
                TransitionImpl transitionToInstantiate = (TransitionImpl)elementToInstantiate;
                flowScope = transitionToInstantiate.Source.FlowScope;
            }

            if (!supportsConcurrentChildInstantiation(flowScope))
            {
                throw new ProcessEngineException("Concurrent instantiation not possible for " + "activities in scope " + flowScope.Id);
            }

            ActivityStartBehavior startBehavior = ActivityStartBehavior.CONCURRENT_IN_FLOW_SCOPE;

            if (topMostActivity != null)
            {
                startBehavior = topMostActivity.ActivityStartBehavior;

                if (activitiesToInstantiate.Count > 0)
                {
                    // this is in BPMN relevant if there is an interrupting event sub process.
                    // we have to distinguish between instantiation of the start event and any other activity.
                    // instantiation of the start event means interrupting behavior; instantiation
                    // of any other task means no interruption.
                    PvmActivity initialActivity       = topMostActivity.Properties.get(BpmnProperties.INITIAL_ACTIVITY);
                    PvmActivity secondTopMostActivity = null;
                    if (activitiesToInstantiate.Count > 1)
                    {
                        secondTopMostActivity = activitiesToInstantiate[1];
                    }
                    else if (elementToInstantiate.GetType().IsAssignableFrom(typeof(ActivityImpl)))
                    {
                        secondTopMostActivity = (PvmActivity)elementToInstantiate;
                    }

                    if (initialActivity != secondTopMostActivity)
                    {
                        startBehavior = ActivityStartBehavior.CONCURRENT_IN_FLOW_SCOPE;
                    }
                }
            }

            switch (startBehavior)
            {
            case ActivityStartBehavior.CANCEL_EVENT_SCOPE:
            {
                ScopeImpl       scopeToCancel     = topMostActivity.EventScope;
                ExecutionEntity executionToCancel = getSingleExecutionForScope(mapping, scopeToCancel);
                if (executionToCancel != null)
                {
                    executionToCancel.deleteCascade("Cancelling activity " + topMostActivity + " executed.", skipCustomListeners, skipIoMappings);
                    instantiate(executionToCancel.Parent, activitiesToInstantiate, elementToInstantiate);
                }
                else
                {
                    ExecutionEntity flowScopeExecution = getSingleExecutionForScope(mapping, topMostActivity.FlowScope);
                    instantiateConcurrent(flowScopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                break;
            }

            case ActivityStartBehavior.INTERRUPT_EVENT_SCOPE:
            {
                ScopeImpl       scopeToCancel     = topMostActivity.EventScope;
                ExecutionEntity executionToCancel = getSingleExecutionForScope(mapping, scopeToCancel);
                executionToCancel.interrupt("Interrupting activity " + topMostActivity + " executed.", skipCustomListeners, skipIoMappings);
                executionToCancel.setActivity(null);
                executionToCancel.leaveActivityInstance();
                instantiate(executionToCancel, activitiesToInstantiate, elementToInstantiate);
                break;
            }

            case ActivityStartBehavior.INTERRUPT_FLOW_SCOPE:
            {
                ScopeImpl       scopeToCancel     = topMostActivity.FlowScope;
                ExecutionEntity executionToCancel = getSingleExecutionForScope(mapping, scopeToCancel);
                executionToCancel.interrupt("Interrupting activity " + topMostActivity + " executed.", skipCustomListeners, skipIoMappings);
                executionToCancel.setActivity(null);
                executionToCancel.leaveActivityInstance();
                instantiate(executionToCancel, activitiesToInstantiate, elementToInstantiate);
                break;
            }

            default:
            {
                // if all child executions have been cancelled
                // or this execution has ended executing its scope, it can be reused
                if (!scopeExecution.hasChildren() && (scopeExecution.getActivity() == null || scopeExecution.Ended))
                {
                    // reuse the scope execution
                    instantiate(scopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                else
                {
                    // if the activity is not cancelling/interrupting, it can simply be instantiated as
                    // a concurrent child of the scopeExecution
                    instantiateConcurrent(scopeExecution, activitiesToInstantiate, elementToInstantiate);
                }
                break;
            }
            }

            return(null);
        }
コード例 #11
0
 public WalkConditionAnonymousInnerClass(AbstractInstantiationCmd outerInstance, ProcessDefinitionImpl processDefinition, ActivityExecutionTreeMapping mapping)
 {
     this.outerInstance     = outerInstance;
     this.processDefinition = processDefinition;
     this.mapping           = mapping;
 }