Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
		public Object ResolveArgumentRole(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			if (parameters.Length != 1)
				throw new SystemException("argument role expects exactly one parameter (role-name) instead of " + parameters.Length);

			IActor actor = null;

			if (resolvedActor == null)
			{
				try
				{
					actor = (IActor) executionContext.GetAttribute(parameters[0]);
				}
				catch (InvalidCastException e)
				{
					throw new SystemException("argument attribute(" + parameters[0] + ") does not contain an actor : " + executionContext.GetAttribute(parameters[0]).GetType().FullName, e);
				}
			}
			else
			{
				String roleName = parameters[0].Trim();

				try
				{
					IList users = executionContext.GetOrganisationComponent().FindUsersByGroupAndRole(resolvedActor.Id, roleName);
					if (users.Count < 1)
						throw new SystemException("no users have role " + roleName + " for group " + resolvedActor.Id);
					actor = (IUser) users[0];

					// TODO : create a new group if more then one user is returned on the query...
				}
				catch (InvalidCastException e)
				{
					throw new SystemException("can't resolve role-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e);
				}
				catch (OrganisationRuntimeException e)
				{
					throw new SystemException("can't resolve role-argument : can't find the users that perform role " + roleName + " for group " + resolvedActor.Id + " : " + e.Message);
				}
			}

			return actor;
		}
Ejemplo n.º 6
0
		public Object ResolveArgumentGroup(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			log.Debug("resolvedActor inside resolveArgumentGroup: " + resolvedActor);

			if (resolvedActor == null)
			{
				if (parameters.Length != 1)
					throw new SystemException("argument group expects exactly one parameter instead of " + parameters.Length);

				String groupId = parameters[0];
				IGroup group = null;
				try
				{
					group = executionContext.GetOrganisationComponent().FindGroupById(groupId);
				}
				catch (OrganisationRuntimeException e)
				{
					throw new SystemException("can't resolve group-argument with parameter " + groupId + " : " + e.Message);
				}

				return group;
			}
			else
			{
				if (parameters.Length != 1)
					throw new SystemException("argument group expects exactly one parameter (membership-type) instead of " + parameters.Length);

				IUser user = null;
				IGroup group = null;
				String membershipType = parameters[0];

				try
				{
					group = executionContext.GetOrganisationComponent().FindGroupByMembership(resolvedActor.Id, membershipType);
				}
				catch (InvalidCastException e)
				{
					throw new SystemException("can't resolve group-argument : a group must be calculated from a User, not a " + resolvedActor.GetType().FullName, e);
				}
				catch (OrganisationRuntimeException e)
				{
					throw new SystemException("can't resolve group-argument : can't find the hierarchy-memberschip of User " + user.Id + " and membership-type " + membershipType + " : " + e.Message, e);
				}

				return group;
			}
		}
Ejemplo n.º 7
0
		public Object ResolveArgumentActor(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			if (parameters.Length != 1)
				throw new SystemException("argument actor expects exactly one (the actor-id) parameter instead of " + parameters.Length);

			IActor actor = null;
			try
			{
				actor = executionContext.GetOrganisationComponent().FindActorById(parameters[0]);
			}
			catch (OrganisationRuntimeException e)
			{
				throw new SystemException("can't resolve actor-argument with parameter " + parameters[0], e);
			}

			return actor;
		}