Exemple #1
0
        public virtual void CheckReadProcessInstance(ExecutionEntity execution)
        {
            var processDefinition = (ProcessDefinitionEntity)execution.GetProcessDefinition();

            // necessary permissions:
            // - READ on PROCESS_INSTANCE

            var firstCheck = new PermissionCheck();

            firstCheck.Permission = Permissions.Read;
            firstCheck.Resource   = Resources.ProcessInstance;
            firstCheck.ResourceId = execution.ProcessInstanceId;

            // ... OR ...

            // - READ_INSTANCE on PROCESS_DEFINITION
            var secondCheck = new PermissionCheck();

            secondCheck.Permission = Permissions.ReadInstance;
            secondCheck.Resource   = Resources.ProcessDefinition;
            secondCheck.ResourceId = processDefinition.Key;
            secondCheck.AuthorizationNotFoundReturnValue = 0L;

            AuthorizationManager.CheckAuthorization(firstCheck, secondCheck);
        }
        // form Properties ///////////////////////////

        public virtual HistoryEvent CreateFormPropertyUpdateEvt(ExecutionEntity execution, string propertyId, string propertyValue, string taskId)
        {
            IDGenerator idGenerator = Context.ProcessEngineConfiguration.IdGenerator;

            HistoricFormPropertyEventEntity historicFormPropertyEntity = NewHistoricFormPropertyEvent();

            historicFormPropertyEntity.Id                  = idGenerator.NewGuid();//.NextId;
            historicFormPropertyEntity.EventType           = HistoryEventTypes.FormPropertyUpdate.EventName;
            historicFormPropertyEntity.TimeStamp           = ClockUtil.CurrentTime;
            historicFormPropertyEntity.ActivityInstanceId  = execution.ActivityInstanceId;
            historicFormPropertyEntity.ExecutionId         = execution.Id;
            historicFormPropertyEntity.ProcessDefinitionId = execution.ProcessDefinitionId;
            historicFormPropertyEntity.ProcessInstanceId   = execution.ProcessInstanceId;
            historicFormPropertyEntity.PropertyId          = propertyId;
            historicFormPropertyEntity.PropertyValue       = propertyValue;
            historicFormPropertyEntity.TaskId              = taskId;
            historicFormPropertyEntity.TenantId            = execution.TenantId;

            ProcessDefinitionEntity definition = execution.GetProcessDefinition();

            if (definition != null)
            {
                historicFormPropertyEntity.ProcessDefinitionKey = definition.Key;
            }

            // initialize sequence counter
            InitSequenceCounter(execution, historicFormPropertyEntity);

            return(historicFormPropertyEntity);
        }
Exemple #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);
 }
        protected internal virtual void InitHistoricVariableUpdateEvt(HistoricVariableUpdateEventEntity evt, VariableInstanceEntity variableInstance, IHistoryEventType eventType)
        {
            // init properties
            evt.EventType          = eventType.EventName;
            evt.TimeStamp          = ClockUtil.CurrentTime;
            evt.VariableInstanceId = variableInstance.Id;
            evt.ProcessInstanceId  = variableInstance.ProcessInstanceId;
            evt.ExecutionId        = variableInstance.ExecutionId;
            evt.CaseInstanceId     = variableInstance.CaseInstanceId;
            evt.CaseExecutionId    = variableInstance.CaseExecutionId;
            evt.TaskId             = variableInstance.TaskId;
            evt.Revision           = variableInstance.Revision;
            evt.VariableName       = variableInstance.Name;
            evt.SerializerName     = variableInstance.SerializerName;
            evt.TenantId           = variableInstance.TenantId;

            ExecutionEntity execution = variableInstance.Execution;

            if (execution != null)
            {
                ProcessDefinitionEntity definition = execution.GetProcessDefinition();
                if (definition != null)
                {
                    evt.ProcessDefinitionId  = definition.Id;
                    evt.ProcessDefinitionKey = definition.Key;
                }
            }

            //CaseExecutionEntity caseExecution = variableInstance.CaseExecution;
            //if (caseExecution != null)
            //{
            //    CaseDefinitionEntity definition = (CaseDefinitionEntity)caseExecution.CaseDefinition;
            //    if (definition != null)
            //    {
            //        evt.CaseDefinitionId = definition.Id;
            //        evt.CaseDefinitionKey = definition.Key;
            //    }
            //}

            // copy value
            evt.TextValue   = variableInstance.TextValue;
            evt.TextValue2  = variableInstance.TextValue2;
            evt.DoubleValue = variableInstance.DoubleValue;
            evt.LongValue   = variableInstance.LongValue;
            if (variableInstance.ByteArrayId != null)
            {
                evt.ByteValue = variableInstance.ByteArrayValue;
                //evt.Value = variableInstance.Value;
                //evt.ByteArrayValue = variableInstance.ByteArrayValue;
                var r = evt.Value;
            }
        }
Exemple #5
0
        protected internal virtual void Initialize()
        {
            ExecutionEntity processInstance = CommandContext.ExecutionManager.FindExecutionById(ProcessInstanceId);

            this.ProcessDefinition = processInstance.GetProcessDefinition();

            IList <IActivityExecution> executions = FetchExecutionsForProcessInstance(processInstance);

            executions.Add(processInstance);

            IList <IActivityExecution> leaves = FindLeaves(executions);

            AssignExecutionsToActivities(leaves);
        }
Exemple #6
0
        public virtual void CheckUpdateTask(TaskEntity task)
        {
            var taskId = task.Id;

            var executionId = task.ExecutionId;

            if (!ReferenceEquals(executionId, null))
            {
                // if ITask exists in context of a process instance
                // then check the following permissions:
                // - UPDATE on ITask
                // - UPDATE_TASK on PROCESS_DEFINITION

                ExecutionEntity execution         = task.GetExecution();
                var             processDefinition = (ProcessDefinitionEntity)execution.GetProcessDefinition();

                var updatePermissionCheck = new PermissionCheck();
                updatePermissionCheck.Permission = Permissions.Update;
                updatePermissionCheck.Resource   = Resources.Task;
                updatePermissionCheck.ResourceId = taskId;

                var updateTaskPermissionCheck = new PermissionCheck();
                updateTaskPermissionCheck.Permission = Permissions.UpdateTask;
                updateTaskPermissionCheck.Resource   = Resources.ProcessDefinition;
                updateTaskPermissionCheck.ResourceId = processDefinition.Key;
                updateTaskPermissionCheck.AuthorizationNotFoundReturnValue = 0L;

                AuthorizationManager.CheckAuthorization(updatePermissionCheck, updateTaskPermissionCheck);
            }
            else
            {
                // if ITask does not exist in context of process
                // instance, then it is either a (a) standalone ITask
                // or (b) it exists in context of a case instance.

                // (a) standalone ITask: check following permission
                // - READ on ITask
                // (b) ITask in context of a case instance, in this
                // case it is not necessary to check any permission,
                // because such tasks can always be updated

                var caseExecutionId = task.CaseExecutionId;
                if (ReferenceEquals(caseExecutionId, null))
                {
                    // standalone ITask
                    AuthorizationManager.CheckAuthorization(Permissions.Update, Resources.Task, taskId);
                }
            }
        }
Exemple #7
0
        /// <summary>
        ///     Creates and inserts a subscription entity depending on the message type of this declaration.
        /// </summary>
        public virtual EventSubscriptionEntity CreateSubscriptionForExecution(ExecutionEntity execution)
        {
            var eventSubscriptionEntity = new EventSubscriptionEntity(execution, eventType);

            eventSubscriptionEntity.EventName = ResolveExpressionOfEventName(execution);
            if (activityId != null)
            {
                ActivityImpl activity = execution.GetProcessDefinition().FindActivity(activityId) as ActivityImpl;
                eventSubscriptionEntity.Activity = activity;
            }

            eventSubscriptionEntity.Insert();
            LegacyBehavior.RemoveLegacySubscriptionOnParent(execution, eventSubscriptionEntity);

            return(eventSubscriptionEntity);
            //return null;
        }
        public static IProcessApplicationReference GetTargetProcessApplication(ExecutionEntity execution)
        {
            if (execution == null)
            {
                return(null);
            }

            IProcessApplicationReference processApplicationForDeployment =
                GetTargetProcessApplication(execution.GetProcessDefinition());

            //logg application context switch details
            if (Log.ContextSwitchLoggable && processApplicationForDeployment == null)
            {
                //打印 ENGINE-07023 no target process application found for...
                LoggContextSwitchDetails(execution);
            }

            return(processApplicationForDeployment);
        }
        protected internal virtual void InitActivityInstanceEvent(HistoricActivityInstanceEventEntity evt, ExecutionEntity execution, IPvmScope eventSource, string activityInstanceId, string parentActivityInstanceId, IHistoryEventType eventType)
        {
            evt.Id                       = activityInstanceId;
            evt.EventType                = eventType.EventName;
            evt.ActivityInstanceId       = activityInstanceId;
            evt.ParentActivityInstanceId = parentActivityInstanceId;
            evt.ProcessDefinitionId      = execution.ProcessDefinitionId;
            evt.ProcessInstanceId        = execution.ProcessInstanceId;
            evt.ExecutionId              = execution.Id;
            evt.TenantId                 = execution.TenantId;

            ProcessDefinitionEntity definition = execution.GetProcessDefinition();

            if (definition != null)
            {
                evt.ProcessDefinitionKey = definition.Key;
            }

            evt.ActivityId   = eventSource.Id;
            evt.ActivityName = (string)eventSource.GetProperty("name");
            evt.ActivityType = (string)eventSource.GetProperty("type");

            // update sub process reference
            ExecutionEntity subProcessInstance = execution.GetSubProcessInstance();

            if (subProcessInstance != null)
            {
                evt.CalledProcessInstanceId = subProcessInstance.Id;
            }

            // update sub case reference
            //CaseExecutionEntity subCaseInstance = execution.GetSubCaseInstance();
            //if (subCaseInstance != null)
            //{
            //    evt.CalledCaseInstanceId = subCaseInstance.Id;
            //}
        }
        protected internal virtual void InitProcessInstanceEvent(HistoricProcessInstanceEventEntity evt, ExecutionEntity execution, IHistoryEventType eventType)
        {
            string processDefinitionId = execution.ProcessDefinitionId;
            string processInstanceId   = execution.ProcessInstanceId;
            string executionId         = execution.Id;
            // the given execution is the process instance!
            string caseInstanceId = execution.CaseInstanceId;
            string tenantId       = execution.TenantId;

            ProcessDefinitionEntity definition = execution.GetProcessDefinition();
            string processDefinitionKey        = null;

            if (definition != null)
            {
                processDefinitionKey = definition.Key;
            }

            evt.Id                   = processInstanceId;
            evt.EventType            = eventType.EventName;
            evt.ProcessDefinitionKey = processDefinitionKey;
            evt.ProcessDefinitionId  = processDefinitionId;
            evt.ProcessInstanceId    = processInstanceId;
            evt.ExecutionId          = executionId;
            evt.BusinessKey          = execution.ProcessBusinessKey;
            evt.CaseInstanceId       = caseInstanceId;
            evt.TenantId             = tenantId;

            //if (execution.GetSuperCaseExecution() != null)
            //{
            //    evt.SuperCaseInstanceId = execution.GetSuperCaseExecution().CaseInstanceId;
            //}
            if (execution.SuperExecution != null)
            {
                evt.SuperProcessInstanceId = execution.SuperExecution.ProcessInstanceId;
            }
        }
Exemple #11
0
        public override void Execute(IJobHandlerConfiguration _configuration, ExecutionEntity execution,
                                     CommandContext commandContext, string tenantId)
        {
            TimerJobConfiguration configuration    = _configuration as TimerJobConfiguration;
            var          activityId                = configuration.TimerElementKey;
            ActivityImpl intermediateEventActivity = execution.GetProcessDefinition().FindActivity(activityId) as ActivityImpl;

            EnsureUtil.EnsureNotNull(
                "Error while firing timer: intermediate event activity " + configuration + " not found",
                "intermediateEventActivity", intermediateEventActivity);

            try
            {
                if (activityId.Equals(execution.ActivityId))
                {
                    // Regular Intermediate timer catch
                    execution.Signal("signal", null);
                }
            }
            catch (System.Exception e)
            {
                throw new ProcessEngineException("exception during timer execution: " + e.Message, e);
            }
        }
        public override void Execute(IJobHandlerConfiguration _configuration, ExecutionEntity execution,
                                     CommandContext commandContext, string tenantId)
        {
            TimerJobConfiguration configuration = _configuration as TimerJobConfiguration;
            var          activityId             = configuration.TimerElementKey;
            ActivityImpl activity = execution.GetProcessDefinition().FindActivity(activityId) as ActivityImpl;

            EnsureUtil.EnsureNotNull(
                "Error while firing timer: boundary event activity " + configuration + " not found",
                "boundary event activity", activity);

            try
            {
                execution.ExecuteEventHandlerActivity(activity);
            }
            //catch (Exception e)
            //{
            //    throw e;
            //}
            catch (System.Exception e)
            {
                throw new ProcessEngineException("exception during timer execution: " + e.Message, e);
            }
        }
Exemple #13
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);
        }
Exemple #14
0
 protected internal override long?GetProcessDefinitionPriority(ExecutionEntity execution,
                                                               ExternalTaskActivityBehavior param)
 {
     return(GetProcessDefinedPriority(execution.GetProcessDefinition(), BpmnParse.PropertynameTaskPriority, execution, ""));
 }
Exemple #15
0
        protected internal virtual string GetProcessDefinitionTenantId(ExecutionEntity execution)
        {
            var processDefinition = execution.GetProcessDefinition();

            return(processDefinition.TenantId);
        }