Exemple #1
0
        public void CancelProcessInstance(String authenticatedActorId, Int64 processInstanceId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            // first check if the actor is allowed to cancel this process instance
            authorizationHelper.CheckCancelProcessInstance(authenticatedActorId, processInstanceId, dbSession);

            ProcessInstanceImpl processInstance = (ProcessInstanceImpl)dbSession.Load(typeof(ProcessInstanceImpl), processInstanceId);

            log.Info("actor '" + authenticatedActorId + "' cancels processInstance '" + processInstanceId + "'...");

            if (!processInstance.EndHasValue)
            {
                CancelFlowRecursive((FlowImpl)processInstance.RootFlow, DateTime.Now);
                ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, (FlowImpl)processInstance.RootFlow, dbSession, organisationComponent);
                executionContext.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_CANCEL);
                EndStateImpl endState = (EndStateImpl)processInstance.ProcessDefinition.EndState;
                engine.ProcessEndState(endState, executionContext, dbSession);
                processInstance.End = DateTime.Now;

                // flush the updates to the db
                dbSession.Update(processInstance);
                dbSession.Flush();
            }
            else
            {
                throw new SystemException("couldn't cancel process instance : process instance '" + processInstanceId + "' was already finished");
            }
        }
Exemple #2
0
        public void ProcessEndState(EndStateImpl endState, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_END, endState.ProcessDefinition.Id, executionContext, dbSession);
            executionContext.CreateLog(EventType.PROCESS_INSTANCE_END);

            FlowImpl rootFlow = (FlowImpl)executionContext.GetFlow();

            rootFlow.ActorId = null;
            rootFlow.End     = DateTime.Now;
            rootFlow.Node    = endState;          // setting the node is not necessary if this method is called
            // from processTransition, but it is necessary if this method is
            // called from cancelProcessInstance in the component-impl.

            ProcessInstanceImpl processInstance  = (ProcessInstanceImpl)executionContext.GetProcessInstance();
            FlowImpl            superProcessFlow = (FlowImpl)processInstance.SuperProcessFlow;

            if (superProcessFlow != null)
            {
                log.Debug("reactivating the super process...");

                // create the execution context for the parent-process
                ExecutionContextImpl superExecutionContext = new ExecutionContextImpl(executionContext.PreviousActorId, superProcessFlow, executionContext.DbSession, executionContext.GetOrganisationComponent());
                superExecutionContext.SetInvokedProcessContext(executionContext);

                // delegate the attributeValues
                ProcessStateImpl processState    = (ProcessStateImpl)superProcessFlow.Node;
                Object[]         completionData  = delegationHelper.DelegateProcessTermination(processState.ProcessInvokerDelegation, superExecutionContext);
                IDictionary      attributeValues = (IDictionary)completionData[0];
                String           transitionName  = (String)completionData[1];
                TransitionImpl   transition      = transitionRepository.GetTransition(transitionName, processState, executionContext.DbSession);

                // process the super process transition
                ProcessTransition(transition, superExecutionContext, dbSession);
            }
        }
Exemple #3
0
 public ExecutionContextImpl(String actorId, ProcessInstanceImpl processInstance, DbSession dbSession, IOrganisationService organisationComponent)
 {
     this._actorId               = actorId;
     this._processInstance       = processInstance;
     this._processDefinition     = (ProcessDefinitionImpl)processInstance.ProcessDefinition;
     this._dbSession             = dbSession;
     this._organisationComponent = organisationComponent;
     this._assignedFlows         = new ArrayList();
 }
 public ExecutionContextImpl(String actorId, ProcessInstanceImpl processInstance, DbSession dbSession, IOrganisationService organisationComponent)
 {
     this._actorId = actorId;
     this._processInstance = processInstance;
     this._processDefinition = (ProcessDefinitionImpl) processInstance.ProcessDefinition;
     this._dbSession = dbSession;
     this._organisationComponent = organisationComponent;
     this._assignedFlows = new ArrayList();
 }
Exemple #5
0
 public FlowImpl(String actorId, ProcessInstanceImpl processInstance)
 {
     ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) processInstance.ProcessDefinition;
     this._name = "root";
     this._actorId = actorId;
     this._start = DateTime.Now;
     this._node = processDefinition.StartState;
     this._processInstance = processInstance;
     this._subProcessInstances = null;
     this._parent = null;
     this._children = null;
     this._logs = new ListSet();
     this._parentReactivation = true;
     CreateAttributeInstances(processDefinition.Attributes);
 }
Exemple #6
0
        public FlowImpl(String actorId, ProcessInstanceImpl processInstance)
        {
            ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)processInstance.ProcessDefinition;

            this._name                = "root";
            this._actorId             = actorId;
            this._start               = DateTime.Now;
            this._node                = processDefinition.StartState;
            this._processInstance     = processInstance;
            this._subProcessInstances = null;
            this._parent              = null;
            this._children            = null;
            this._logs                = new ListSet();
            this._parentReactivation  = true;
            CreateAttributeInstances(processDefinition.Attributes);
        }
Exemple #7
0
 public void SetProcessInstance(IProcessInstance processInstance)
 {
     this._processInstance = (ProcessInstanceImpl)processInstance;
 }
        public IProcessInstance StartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationService organisationComponent)
        {
            ProcessInstanceImpl processInstance = null;

            // First check if the actor is allowed to start this instance
            authorizationHelper.CheckStartProcessInstance(authenticatedActorId, processDefinitionId, attributeValues, transitionName, dbSession);

            // get the process-definition and its start-state
            ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)definitionRepository.GetProcessDefinition(processDefinitionId, null, dbSession);
            StartStateImpl startState = (StartStateImpl) processDefinition.StartState;

            log.Info("actor '" + authenticatedActorId + "' starts an instance of process '" + processDefinition.Name + "'...");

            processInstance = new ProcessInstanceImpl(authenticatedActorId, processDefinition);
            FlowImpl rootFlow = (FlowImpl) processInstance.RootFlow;

            ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, rootFlow, dbSession, organisationComponent);
            MyExecutionContext myExecutionContext = new MyExecutionContext();

            // save the process instance to allow hibernate queries
            dbSession.Save(processInstance);
            //dbSession.Lock(processInstance,LockMode.Upgrade);

            delegationService.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, startState.Id, executionContext,dbSession);

            // store the attributes
            executionContext.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);
            //LogImpl logImpl = rootFlow.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);//new add
            executionContext.CheckAccess(attributeValues, startState);
            //startState.CheckAccess(attributeValues);
            //�ݨӤ]�䤣��AttributeInstance
            executionContext.StoreAttributeValues(attributeValues);

            // if this activity has a role-name, save the actor in the corresponding attribute
            executionContext.StoreRole(authenticatedActorId, startState);

            // run the actions
            delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_START, processDefinitionId, executionContext,dbSession);

            // from here on, we consider the actor as being the previous actor
            executionContext.SetActorAsPrevious();

            // process the start-transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, startState, dbSession);
            engine.ProcessTransition(startTransition, executionContext, dbSession);

            // run the actions
            delegationService.RunActionsForEvent(EventType.AFTER_PERFORM_OF_ACTIVITY, startState.Id, executionContext,dbSession);

            // flush the updates to the db
            dbSession.Update(processInstance);
            dbSession.Flush();

            //@portme
            /*			if (relations != null)
            {
                relations.resolve(processInstance);
            }
            */
            return processInstance;
        }
        public IProcessInstance StartProcessInstance(long processDefinitionId, IDictionary attributeValues = null, string transitionName = null, Relations relations = null)
        {
            ProcessInstanceImpl processInstance = null;
            IOrganisationService organisationService = null;

            using (ISession session = NHibernateHelper.OpenSession())
            {
                using (var tran = session.BeginTransaction())
                {
                    DbSession dbSession = new DbSession(session);
                    ProcessDefinitionImpl processDefinition = myProcessDefinitionService.GetProcessDefinition(processDefinitionId, dbSession);
                    processInstance = new ProcessInstanceImpl(ActorId, processDefinition);
                    processInstanceRepository.Save(processInstance, dbSession);//到這裏應該存了ProcessInstance,RootFlow

                    ExecutionContext executionContext = new ExecutionContext();
                    //logRepository.CreateLog();
                    processDefinition.StartState.CheckAccess(attributeValues);

                    attributeService = new AttributeService((FlowImpl)processInstance.RootFlow, dbSession);
                    attributeService.StoreAttributeValue(attributeValues);//儲存傳入的欄位值
                    attributeService.StoreRole(organisationService.FindActorById(ActorId), (ActivityStateImpl)processDefinition.StartState);

                    //flow的node推進到下一關卡
                    //flow的actor=解析出來的actor.Id
                    transitionService = new TransitionService(ActorId, dbSession);
                    TransitionImpl transitionTo = transitionService.GetTransition(transitionName, processDefinition.StartState, dbSession);
                    transitionService.ProcessTransition(transitionTo, (FlowImpl)processInstance.RootFlow, dbSession);

                    session.Flush();
                    tran.Commit();
                }
            }

            return processInstance;
        }
 public void Save(ProcessInstanceImpl processInstance,DbSession dbSession)
 {
     dbSession.Save(processInstance);
 }
 public void SetProcessInstance(IProcessInstance processInstance)
 {
     this._processInstance = (ProcessInstanceImpl) processInstance;
 }
Exemple #12
0
        public IProcessInstance StartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationService organisationComponent)
        {
            ProcessInstanceImpl processInstance = null;

            // First check if the actor is allowed to start this instance
            authorizationHelper.CheckStartProcessInstance(authenticatedActorId, processDefinitionId, attributeValues, transitionName, dbSession);

            // get the process-definition and its start-state
            ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)definitionRepository.GetProcessDefinition(processDefinitionId, null, dbSession);
            StartStateImpl        startState        = (StartStateImpl)processDefinition.StartState;

            log.Info("actor '" + authenticatedActorId + "' starts an instance of process '" + processDefinition.Name + "'...");

            processInstance = new ProcessInstanceImpl(authenticatedActorId, processDefinition);
            FlowImpl rootFlow = (FlowImpl)processInstance.RootFlow;

            ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, rootFlow, dbSession, organisationComponent);

            // save the process instance to allow hibernate queries
            dbSession.Save(processInstance);
            //dbSession.Lock(processInstance,LockMode.Upgrade);

            delegationService.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, startState.Id, executionContext, dbSession);

            // store the attributes
            executionContext.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);
            //LogImpl logImpl = rootFlow.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);//new add
            executionContext.CheckAccess(attributeValues, startState);
            //startState.CheckAccess(attributeValues);
            //看來也找不到AttributeInstance
            executionContext.StoreAttributeValues(attributeValues);

            // if this activity has a role-name, save the actor in the corresponding attribute
            executionContext.StoreRole(authenticatedActorId, startState);

            // run the actions
            delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_START, processDefinitionId, executionContext, dbSession);

            // from here on, we consider the actor as being the previous actor
            executionContext.SetActorAsPrevious();

            // process the start-transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, startState, dbSession);

            engine.ProcessTransition(startTransition, executionContext, dbSession);

            // run the actions
            delegationService.RunActionsForEvent(EventType.AFTER_PERFORM_OF_ACTIVITY, startState.Id, executionContext, dbSession);

            // flush the updates to the db
            dbSession.Update(processInstance);
            dbSession.Flush();

            //@portme

/*			if (relations != null)
 *                      {
 *                              relations.resolve(processInstance);
 *                      }
 */
            return(processInstance);
        }
        public void ProcessProcessState(ProcessStateImpl processState, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            // TODO : try to group similarities between this method and ExecutionComponentImpl.startProcessInstance and
            //        group them in a common method

            // provide a convenient local var for the database session
            //DbSession dbSession = executionContext.DbSession;

            // get the sub-process-definition and its start-state
            ProcessDefinitionImpl subProcessDefinition = (ProcessDefinitionImpl) processState.SubProcess;
            StartStateImpl startState = (StartStateImpl) subProcessDefinition.StartState;

            log.Info("processState '" + processState.Name + "' starts an instance of process '" + subProcessDefinition.Name + "'...");

            // get the actor that is supposed to start this process instance
            IActor subProcessStarter = actorExpressionResolver.ResolveArgument(processState.ActorExpression, executionContext);
            String subProcessStarterId = subProcessStarter.Id;

            // create the process-instance
            ProcessInstanceImpl subProcessInstance = new ProcessInstanceImpl(subProcessStarterId, subProcessDefinition);
            FlowImpl rootFlow = (FlowImpl) subProcessInstance.RootFlow;

            // attach the subProcesInstance to the parentFlow
            FlowImpl superProcessFlow = (FlowImpl) executionContext.GetFlow();
            superProcessFlow.SetSubProcessInstance(subProcessInstance);
            subProcessInstance.SuperProcessFlow = superProcessFlow;

            // create the execution context for the sub-process
            ExecutionContextImpl subExecutionContext = new ExecutionContextImpl(subProcessStarterId, rootFlow, dbSession, executionContext.GetOrganisationComponent());

            // save the process instance to allow hibernate queries
            dbSession.Save(subProcessInstance);

            // add the log
            executionContext.CreateLog(EventType.SUB_PROCESS_INSTANCE_START);
            executionContext.AddLogDetail(new ObjectReferenceImpl(subProcessInstance));

            // delegate the attributeValues
            Object[] processInvocationData = delegationHelper.DelegateProcessInvocation(processState.ProcessInvokerDelegation, subExecutionContext);
            String transitionName = (String) processInvocationData[0];
            IDictionary attributeValues = (IDictionary) processInvocationData[1];

            // store the attributes
            subExecutionContext.CreateLog(subProcessStarterId, EventType.PROCESS_INSTANCE_START);
            subExecutionContext.StoreAttributeValues(attributeValues);
            subExecutionContext.StoreRole(subProcessStarterId, startState);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.SUB_PROCESS_INSTANCE_START, processState.Id, subExecutionContext,dbSession);
            delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_START, subProcessDefinition.Id, subExecutionContext,dbSession);

            // from here on, we consider the actor as being the previous actor
            subExecutionContext.SetActorAsPrevious();

            // process the start-transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, startState, dbSession);
            ProcessTransition(startTransition, subExecutionContext,dbSession);

            // add the assigned flows of the subContext to the parentContext
            executionContext.AssignedFlows.AddRange(subExecutionContext.AssignedFlows);

            // flush the updates to the db
            dbSession.Update(subProcessInstance);
            dbSession.Flush();
        }
		public ExecutionContextImpl(String actorId, FlowImpl flow, DbSession dbSession, IOrganisationSessionLocal organisationComponent)
		{
			this._actorId = actorId;
			this._flow = flow;
			this._processInstance = (ProcessInstanceImpl) flow.ProcessInstance;
			this._processDefinition = (ProcessDefinitionImpl) _processInstance.ProcessDefinition;
			this._dbSession = dbSession;
			this._organisationComponent = organisationComponent;
			this._assignedFlows = new ArrayList();
		}
Exemple #15
0
        public void ProcessProcessState(ProcessStateImpl processState, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            // TODO : try to group similarities between this method and ExecutionComponentImpl.startProcessInstance and
            //        group them in a common method

            // provide a convenient local var for the database session
            //DbSession dbSession = executionContext.DbSession;

            // get the sub-process-definition and its start-state
            ProcessDefinitionImpl subProcessDefinition = (ProcessDefinitionImpl)processState.SubProcess;
            StartStateImpl        startState           = (StartStateImpl)subProcessDefinition.StartState;

            log.Info("processState '" + processState.Name + "' starts an instance of process '" + subProcessDefinition.Name + "'...");

            // get the actor that is supposed to start this process instance
            IActor subProcessStarter   = actorExpressionResolver.ResolveArgument(processState.ActorExpression, executionContext);
            String subProcessStarterId = subProcessStarter.Id;

            // create the process-instance
            ProcessInstanceImpl subProcessInstance = new ProcessInstanceImpl(subProcessStarterId, subProcessDefinition);
            FlowImpl            rootFlow           = (FlowImpl)subProcessInstance.RootFlow;

            // attach the subProcesInstance to the parentFlow
            FlowImpl superProcessFlow = (FlowImpl)executionContext.GetFlow();

            superProcessFlow.SetSubProcessInstance(subProcessInstance);
            subProcessInstance.SuperProcessFlow = superProcessFlow;

            // create the execution context for the sub-process
            ExecutionContextImpl subExecutionContext = new ExecutionContextImpl(subProcessStarterId, rootFlow, dbSession, executionContext.GetOrganisationComponent());

            // save the process instance to allow hibernate queries
            dbSession.Save(subProcessInstance);

            // add the log
            executionContext.CreateLog(EventType.SUB_PROCESS_INSTANCE_START);
            executionContext.AddLogDetail(new ObjectReferenceImpl(subProcessInstance));

            // delegate the attributeValues
            Object[]    processInvocationData = delegationHelper.DelegateProcessInvocation(processState.ProcessInvokerDelegation, subExecutionContext);
            String      transitionName        = (String)processInvocationData[0];
            IDictionary attributeValues       = (IDictionary)processInvocationData[1];

            // store the attributes
            subExecutionContext.CreateLog(subProcessStarterId, EventType.PROCESS_INSTANCE_START);
            subExecutionContext.StoreAttributeValues(attributeValues);
            subExecutionContext.StoreRole(subProcessStarterId, startState);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.SUB_PROCESS_INSTANCE_START, processState.Id, subExecutionContext, dbSession);
            delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_START, subProcessDefinition.Id, subExecutionContext, dbSession);

            // from here on, we consider the actor as being the previous actor
            subExecutionContext.SetActorAsPrevious();

            // process the start-transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, startState, dbSession);

            ProcessTransition(startTransition, subExecutionContext, dbSession);

            // add the assigned flows of the subContext to the parentContext
            executionContext.AssignedFlows.AddRange(subExecutionContext.AssignedFlows);

            // flush the updates to the db
            dbSession.Update(subProcessInstance);
            dbSession.Flush();
        }