Beispiel #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);
            }
        }
        public void ProcessActivityState(ActivityStateImpl activityState, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            // first set the flow-state to the activity-state
            FlowImpl flow = (FlowImpl) executionContext.GetFlow();

            log.Debug("processing activity-state '" + activityState + "' for flow '" + executionContext.GetFlow() + "'");

            // execute the actions scheduled for this assignment
            delegationService.RunActionsForEvent(EventType.BEFORE_ACTIVITYSTATE_ASSIGNMENT, activityState.Id, executionContext,dbSession);

            String actorId = null;
            String role = activityState.ActorRoleName;
            DelegationImpl assignmentDelegation = activityState.AssignmentDelegation;

            if (assignmentDelegation != null)
            {
                // delegate the assignment of the activity-state
                actorId = delegationHelper.DelegateAssignment(activityState.AssignmentDelegation, executionContext);
                if ((Object) actorId == null)
                {
                    throw new SystemException("invalid process definition : assigner of activity-state '" + activityState.Name + "' returned null instead of a valid actorId");
                }
                log.Debug("setting actor of flow " + flow + " to " + actorId);
            }
            else
            {
                // get the assigned actor from the specified attribute instance
                if ((Object) role != null)
                {
                    IActor actor = (IActor) executionContext.GetAttribute(role);
                    if (actor == null)
                    {
                        throw new SystemException("invalid process definition : activity-state must be assigned to role '" + role + "' but that attribute instance is null");
                    }
                    actorId = actor.Id;
                }
                else
                {
                    throw new SystemException("invalid process definition : activity-state '" + activityState.Name + "' does not have an assigner or a role");
                }
            }

            flow.ActorId = actorId;

            // If necessary, store the actor in the role
            if ((string.IsNullOrEmpty(role) == false) && (assignmentDelegation != null))
            {
                executionContext.StoreRole(actorId, activityState);
            }

            // the client of performActivity wants to be Informed of the people in charge of the process
            executionContext.AssignedFlows.Add(flow);

            // log the assignment
            executionContext.CreateLog(actorId, EventType.AFTER_ACTIVITYSTATE_ASSIGNMENT);
            executionContext.AddLogDetail(new ObjectReferenceImpl(activityState));

            // execute the actions scheduled for this assignment
            delegationService.RunActionsForEvent(EventType.AFTER_ACTIVITYSTATE_ASSIGNMENT, activityState.Id, executionContext,dbSession);
        }
Beispiel #3
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");
            }
        }
Beispiel #4
0
		public TransitionImpl DelegateDecision(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			TransitionImpl selectedTransition = null;

			try
			{
				IDecisionHandler decision = (IDecisionHandler) GetDelegate(delegation);
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				String transitionName = decision.Decide(executionContext);

				if ((Object) transitionName == null)
				{
					throw new SystemException("Decision-delegate for decision '" + executionContext.GetNode() + "' returned null instead of a transition-name : " + decision.GetType().FullName);
				}

				try
				{
					Object[] args = new Object[] {executionContext.GetNode().Id, transitionName};
					IType[] types = new IType[] {DbType.LONG, DbType.STRING};
					selectedTransition = (TransitionImpl) executionContext.DbSession.FindOne(queryFindLeavingTransitionByName, args, types);
				}
				catch (Exception t)
				{
					throw new SystemException("couldn't find transition '" + transitionName + "' that was selected by the decision-delegate of activity '" + executionContext.GetNode().Name + "' : " + t.Message);
				}
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}

			return selectedTransition;
		}
Beispiel #5
0
        public void ProcessActivityState(ActivityStateImpl activityState, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            // first set the flow-state to the activity-state
            FlowImpl flow = (FlowImpl)executionContext.GetFlow();

            log.Debug("processing activity-state '" + activityState + "' for flow '" + executionContext.GetFlow() + "'");

            // execute the actions scheduled for this assignment
            delegationService.RunActionsForEvent(EventType.BEFORE_ACTIVITYSTATE_ASSIGNMENT, activityState.Id, executionContext, dbSession);

            String         actorId = null;
            String         role    = activityState.ActorRoleName;
            DelegationImpl assignmentDelegation = activityState.AssignmentDelegation;

            if (assignmentDelegation != null)
            {
                // delegate the assignment of the activity-state
                actorId = delegationHelper.DelegateAssignment(activityState.AssignmentDelegation, executionContext);
                if ((Object)actorId == null)
                {
                    throw new SystemException("invalid process definition : assigner of activity-state '" + activityState.Name + "' returned null instead of a valid actorId");
                }
                log.Debug("setting actor of flow " + flow + " to " + actorId);
            }
            else
            {
                // get the assigned actor from the specified attribute instance
                if ((Object)role != null)
                {
                    IActor actor = (IActor)executionContext.GetAttribute(role);
                    if (actor == null)
                    {
                        throw new SystemException("invalid process definition : activity-state must be assigned to role '" + role + "' but that attribute instance is null");
                    }
                    actorId = actor.Id;
                }
                else
                {
                    throw new SystemException("invalid process definition : activity-state '" + activityState.Name + "' does not have an assigner or a role");
                }
            }

            flow.ActorId = actorId;

            // If necessary, store the actor in the role
            if ((string.IsNullOrEmpty(role) == false) && (assignmentDelegation != null))
            {
                executionContext.StoreRole(actorId, activityState);
            }

            // the client of performActivity wants to be Informed of the people in charge of the process
            executionContext.AssignedFlows.Add(flow);

            // log the assignment
            executionContext.CreateLog(actorId, EventType.AFTER_ACTIVITYSTATE_ASSIGNMENT);
            executionContext.AddLogDetail(new ObjectReferenceImpl(activityState));

            // execute the actions scheduled for this assignment
            delegationService.RunActionsForEvent(EventType.AFTER_ACTIVITYSTATE_ASSIGNMENT, activityState.Id, executionContext, dbSession);
        }
Beispiel #6
0
        public void SaveActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, DbSession dbSession, IOrganisationService organisationComponent)
        {
            // get the flow
            FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);
            // create the execution-context
            ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);

            executionContext.StoreAttributeValues(attributeValues);
        }
Beispiel #7
0
        public void ProcessDecision(DecisionImpl decision, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            // trigger actions, scheduled before the decision actually is made
            delegationService.RunActionsForEvent(EventType.BEFORE_DECISION, decision.Id, executionContext, dbSession);

            // delegate the decision
            TransitionImpl selectedTransition = delegationHelper.DelegateDecision(decision.DecisionDelegation, executionContext);

            // process the selected transition
            ProcessTransition(selectedTransition, executionContext, dbSession);

            // trigger actions, scheduled after the decision is made
            delegationService.RunActionsForEvent(EventType.AFTER_DECISION, decision.Id, executionContext, dbSession);
        }
Beispiel #8
0
		public void DelegateAction(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			try
			{
				executionContext.CreateLog(EventType.ACTION);
				executionContext.AddLogDetail(new DelegateCallImpl(delegation, typeof (IAction)));
				IActionHandler actionHandler = (IActionHandler) GetDelegate(delegation);
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				actionHandler.Run(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}
		}
Beispiel #9
0
        //private const String queryFindActionsByEventType = "select a from a in class NetBpm.Workflow.Definition.Impl.ActionImpl " +
        //    "where a.EventType = ? " +
        //    "  and a.DefinitionObjectId = ? ";

        //public void RunActionsForEvent(EventType eventType, Int64 definitionObjectId, ExecutionContextImpl executionContext)
        //{
        //    log.Debug("processing '" + eventType + "' events for executionContext " + executionContext);

        //    DbSession dbSession = executionContext.DbSession;

        //    // find all actions for definitionObject on the given eventType
        //    Object[] values = new Object[] {eventType, definitionObjectId};
        //    IType[] types = new IType[] {DbType.INTEGER, DbType.LONG};

        //    IList actions = dbSession.Find(queryFindActionsByEventType, values, types);
        //    IEnumerator iter = actions.GetEnumerator();
        //    log.Debug("list" + actions);
        //    while (iter.MoveNext())
        //    {
        //        ActionImpl action = (ActionImpl) iter.Current;
        //        log.Debug("action: " + action);
        //        delegationHelper.DelegateAction(action.ActionDelegation, executionContext);
        //    }
        //    log.Debug("ende runActionsForEvent!");
        //}

        public void ProcessTransition(TransitionImpl transition, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            log.Debug("processing transition '" + transition + "' for flow '" + executionContext.GetFlow() + "'");

            // trigger all the actions scheduled for this transition
            delegationService.RunActionsForEvent(EventType.TRANSITION, transition.Id, executionContext, dbSession);

            // first set the state of the execution context and the flow
            // to the node that is going to be processed
            FlowImpl flow        = (FlowImpl)executionContext.GetFlow();
            NodeImpl destination = (NodeImpl)transition.To;

            flow.Node = destination;
            executionContext.SetNode(destination);

            // note : I want to keep the engine methods grouped in this class, that is why I
            // didn't use inheritance but used an instanceof-switch instead.

            if (destination is ActivityStateImpl)
            {
                ProcessActivityState((ActivityStateImpl)destination, executionContext, dbSession);
            }
            else if (destination is ProcessStateImpl)
            {
                ProcessProcessState((ProcessStateImpl)destination, executionContext, dbSession);
            }
            else if (destination is DecisionImpl)
            {
                ProcessDecision((DecisionImpl)destination, executionContext, dbSession);
            }
            else if (destination is ForkImpl)
            {
                ProcessFork((ForkImpl)destination, executionContext, dbSession);
            }
            else if (destination is JoinImpl)
            {
                ProcessJoin((JoinImpl)destination, executionContext, dbSession);
            }
            else if (destination is EndStateImpl)
            {
                ProcessEndState((EndStateImpl)destination, executionContext, dbSession);
            }
            else
            {
                throw new SystemException("");
            }
        }
Beispiel #10
0
		public void ProcessTransition(TransitionImpl transition, ExecutionContextImpl executionContext)
		{
			log.Debug("processing transition '" + transition + "' for flow '" + executionContext.GetFlow() + "'");

			// trigger all the actions scheduled for this transition
			RunActionsForEvent(EventType.TRANSITION, transition.Id, executionContext);

			// first set the state of the execution context and the flow
			// to the node that is going to be processed 
			FlowImpl flow = (FlowImpl) executionContext.GetFlow();
			NodeImpl destination = (NodeImpl) transition.To;
			flow.Node = destination;
			executionContext.SetNode(destination);

			// note : I want to keep the engine methods grouped in this class, that is why I
			// didn't use inheritance but used an instanceof-switch instead.
			if (destination is ActivityStateImpl)
			{
				ProcessActivityState((ActivityStateImpl) destination, executionContext);
			}
			else if (destination is ProcessStateImpl)
			{
				ProcessProcessState((ProcessStateImpl) destination, executionContext);
			}
			else if (destination is DecisionImpl)
			{
				ProcessDecision((DecisionImpl) destination, executionContext);
			}
			else if (destination is ForkImpl)
			{
				ProcessFork((ForkImpl) destination, executionContext);
			}
			else if (destination is JoinImpl)
			{
				ProcessJoin((JoinImpl) destination, executionContext);
			}
			else if (destination is EndStateImpl)
			{
				ProcessEndState((EndStateImpl) destination, executionContext);
			}
			else
			{
				throw new SystemException("");
			}
		}
        public void RunActionsForEvent(EventType eventType, long definitionObjectId, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            log.Debug("processing '" + eventType + "' events for executionContext " + executionContext);

            // find all actions for definitionObject on the given eventType
            Object[] values = new Object[] { eventType, definitionObjectId };
            IType[] types = new IType[] { DbType.INTEGER, DbType.LONG };

            IList actions = dbSession.Find(queryFindActionsByEventType, values, types);
            IEnumerator iter = actions.GetEnumerator();
            log.Debug("list" + actions);
            while (iter.MoveNext())
            {
                ActionImpl action = (ActionImpl)iter.Current;
                log.Debug("action: " + action);
                delegationHelper.DelegateAction(action.ActionDelegation, executionContext);
            }
            log.Debug("ende runActionsForEvent!");
        }
Beispiel #12
0
		public void DelegateScheduledAction(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			try
			{
				/* can't add logs because of a integritiy constraint violation... 
				* can you find why ?
				*/
				if (executionContext.GetFlow() != null)
				{
					executionContext.CreateLog(EventType.ACTION);
					executionContext.AddLogDetail(new DelegateCallImpl(delegation, typeof (IAction)));
				}
				IActionHandler actionHandler = (IActionHandler) GetDelegate(delegation);
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				actionHandler.Run(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}
		}
Beispiel #13
0
        public IActivityForm GetActivityForm(String authenticatedActorId, Int64 flowId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            IActivityForm activityForm = null;

            // First check if the actor is allowed to get this form
            authorizationHelper.CheckGetActivityForm(authenticatedActorId, flowId, dbSession);

            FlowImpl  flow  = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);
            StateImpl state = (StateImpl)flow.Node;

            // create an executionContext for easy attributeValue retrieval
            ExecutionContextImpl executionContext = new ExecutionContextImpl(null, flow, dbSession, organisationComponent);

            // create a convenient map from the attribute-names to the fields
            IList       fields          = fieldRepository.FindFieldsByState(state.Id, dbSession);
            IDictionary attributeValues = new Hashtable();
            IEnumerator iter            = fields.GetEnumerator();

            while (iter.MoveNext())
            {
                FieldImpl field = (FieldImpl)iter.Current;
                if (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access))
                {
                    // activity form contains only readable or writeable fields
                    String attributeName = field.Attribute.Name;
                    if (executionContext.GetAttribute(attributeName) != null)
                    {
                        // attribute might not exist (this will cause a warning already being logged previusly)
                        attributeValues[attributeName] = executionContext.GetAttribute(attributeName);
                    }
                }
            }

            activityForm = new ActivityFormImpl(flow, fields, attributeValues);

            return(activityForm);
        }
Beispiel #14
0
        public void CancelFlow(String authenticatedActorId, Int64 flowId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            // first check if the actor is allowed to cancel this flow
            authorizationHelper.CheckCancelFlow(authenticatedActorId, flowId, dbSession);

            FlowImpl flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);

            log.Info("actor '" + authenticatedActorId + "' cancels flow '" + flowId + "'...");

            // only perform the cancel if this flow is not finished yet
            if (!flow.EndHasValue)
            {
                ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);
                executionContext.CreateLog(authenticatedActorId, EventType.FLOW_CANCEL);

                if (flow.IsRootFlow())
                {
                    // set the flow in the end-state
                    log.Debug("setting root flow to the end state...");
                    EndStateImpl endState = (EndStateImpl) flow.ProcessInstance.ProcessDefinition.EndState;
                    engine.ProcessEndState(endState, executionContext, dbSession);
                }
                else
                {
                    // set the flow in the join
                    ConcurrentBlockImpl concurrentBlock = (ConcurrentBlockImpl) flow.Node.ProcessBlock;
                    JoinImpl join = (JoinImpl) concurrentBlock.Join;
                    log.Debug("setting concurrent flow to join '" + join + "'");
                    engine.ProcessJoin(join, executionContext, dbSession);
                }

                // flush the updates to the db
                dbSession.Update(flow);
                dbSession.Flush();
            }
        }
Beispiel #15
0
        public void CancelFlow(String authenticatedActorId, Int64 flowId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            // first check if the actor is allowed to cancel this flow
            authorizationHelper.CheckCancelFlow(authenticatedActorId, flowId, dbSession);

            FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);

            log.Info("actor '" + authenticatedActorId + "' cancels flow '" + flowId + "'...");

            // only perform the cancel if this flow is not finished yet
            if (!flow.EndHasValue)
            {
                ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);
                executionContext.CreateLog(authenticatedActorId, EventType.FLOW_CANCEL);

                if (flow.IsRootFlow())
                {
                    // set the flow in the end-state
                    log.Debug("setting root flow to the end state...");
                    EndStateImpl endState = (EndStateImpl)flow.ProcessInstance.ProcessDefinition.EndState;
                    engine.ProcessEndState(endState, executionContext, dbSession);
                }
                else
                {
                    // set the flow in the join
                    ConcurrentBlockImpl concurrentBlock = (ConcurrentBlockImpl)flow.Node.ProcessBlock;
                    JoinImpl            join            = (JoinImpl)concurrentBlock.Join;
                    log.Debug("setting concurrent flow to join '" + join + "'");
                    engine.ProcessJoin(join, executionContext, dbSession);
                }

                // flush the updates to the db
                dbSession.Update(flow);
                dbSession.Flush();
            }
        }
Beispiel #16
0
		public Object[] DelegateProcessInvocation(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			Object[] invocationData = new Object[2];
			try
			{
				IProcessInvocationHandler processInvoker = (IProcessInvocationHandler) delegation.GetDelegate();
				log.Debug("requesting the attributeValues from the process invoker...");
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				invocationData[0] = processInvoker.GetStartTransitionName(executionContext);
				invocationData[1] = processInvoker.GetStartAttributeValues(executionContext);
				log.Debug("process invoker specified transition '" + invocationData[0] + "' and supplied attributeValues '" + invocationData[1] + "'");
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}
			return invocationData;
		}
        public void ProcessDecision(DecisionImpl decision, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            // trigger actions, scheduled before the decision actually is made
            delegationService.RunActionsForEvent(EventType.BEFORE_DECISION, decision.Id, executionContext,dbSession);

            // delegate the decision
            TransitionImpl selectedTransition = delegationHelper.DelegateDecision(decision.DecisionDelegation, executionContext);

            // process the selected transition
            ProcessTransition(selectedTransition, executionContext,dbSession);

            // trigger actions, scheduled after the decision is made
            delegationService.RunActionsForEvent(EventType.AFTER_DECISION, decision.Id, executionContext,dbSession);
        }
Beispiel #18
0
 public void SaveActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, DbSession dbSession, IOrganisationService organisationComponent)
 {
     // get the flow
     FlowImpl flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
     // create the execution-context
     ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);
     executionContext.StoreAttributeValues(attributeValues);
 }
Beispiel #19
0
        public IActivityForm GetActivityForm(String authenticatedActorId, Int64 flowId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            IActivityForm activityForm = null;

            // First check if the actor is allowed to get this form
            authorizationHelper.CheckGetActivityForm(authenticatedActorId, flowId, dbSession);

            FlowImpl flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
            StateImpl state = (StateImpl) flow.Node;

            // create an executionContext for easy attributeValue retrieval
            ExecutionContextImpl executionContext = new ExecutionContextImpl(null, flow, dbSession, organisationComponent);

            // create a convenient map from the attribute-names to the fields
            IList fields = fieldRepository.FindFieldsByState(state.Id,dbSession);
            IDictionary attributeValues = new Hashtable();
            IEnumerator iter = fields.GetEnumerator();
            while (iter.MoveNext())
            {
                FieldImpl field = (FieldImpl) iter.Current;
                if (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access))
                {
                    // activity form contains only readable or writeable fields
                    String attributeName = field.Attribute.Name;
                    if (executionContext.GetAttribute(attributeName) != null)
                    {
                        // attribute might not exist (this will cause a warning already being logged previusly)
                        attributeValues[attributeName] = executionContext.GetAttribute(attributeName);
                    }
                }
            }

            activityForm = new ActivityFormImpl(flow, fields, attributeValues);

            return activityForm;
        }
		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;
			}
		}
Beispiel #21
0
		private void HandleException(DelegationImpl delegation, ExecutionContextImpl executionContext, Exception exception)
		{
			log.Debug("handling delegation exception :", exception);

			String exceptionClassName = exception.GetType().FullName;
			String delegationClassName = delegation.ClassName;

			ExceptionHandlingType exceptionHandlingType = delegation.ExceptionHandlingType;

			if (exceptionHandlingType != 0)
			{
				if (exceptionHandlingType == ExceptionHandlingType.IGNORE)
				{
					log.Debug("ignoring '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message);
				}
				else if (exceptionHandlingType == ExceptionHandlingType.LOG)
				{
					log.Debug("logging '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message);
					executionContext.AddLogDetail(new ExceptionReportImpl(exception));
				}
				else if (exceptionHandlingType == ExceptionHandlingType.ROLLBACK)
				{
					log.Debug("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message);
					throw new SystemException("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message);
				}
				else
				{
					throw new SystemException("unknown exception handler '" + exceptionHandlingType + "' : " + exception.Message);
				}
			}
			else
			{
				log.Debug("'" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message);
				executionContext.AddLogDetail(new ExceptionReportImpl(exception));
			}
		}
Beispiel #22
0
		public bool DelegateJoin(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			bool reactivateParent = false;

			try
			{
				IJoinHandler joiner = (IJoinHandler) delegation.GetDelegate();
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				reactivateParent = joiner.Join(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}

			return reactivateParent;
		}
		public Object ResolveArgumentProcessInitiator(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			return executionContext.GetProcessInstance().GetInitiator();
		}
Beispiel #24
0
        public void ProcessFork(ForkImpl fork, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            log.Debug("forking flow " + executionContext.GetFlow());

            // First initialize the children of the flow to be forked
            FlowImpl flow = (FlowImpl)executionContext.GetFlow();

            flow.Children = new ListSet();

            // Then initialise the forked flows in the execution context
            executionContext.ForkedFlows = new ArrayList();

            DelegationImpl delegation = fork.ForkDelegation;

            if (delegation != null)
            {
                delegationHelper.DelegateFork(fork.ForkDelegation, executionContext);
            }
            else
            {
                // execute the default fork behaviour
                IEnumerator iter = fork.LeavingTransitions.GetEnumerator();
                while (iter.MoveNext())
                {
                    TransitionImpl transition = (TransitionImpl)iter.Current;
                    executionContext.ForkFlow(transition, null);
                }
            }

            // create the fork event & remember the parent flow
            FlowImpl parentFlow = (FlowImpl)executionContext.GetFlow();

            executionContext.CreateLog(EventType.FORK);

            // log the event
            executionContext.SetFlow(parentFlow);
            IList       forkedFlows = executionContext.ForkedFlows;
            IEnumerator iter2       = forkedFlows.GetEnumerator();

            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow)iter2.Current;
                log.Debug("adding object reference [" + forkedFlow.Flow + "] to flow [" + parentFlow + "]");
                executionContext.AddLogDetail(new ObjectReferenceImpl(forkedFlow.Flow));
            }

            // loop over all flows that were forked in the ForkHandler implementation
            iter2 = forkedFlows.GetEnumerator();
            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow)iter2.Current;

                // trigger actions, scheduled after the creation and setting of the attributeValues
                // but before the fork is being processed
                delegationService.RunActionsForEvent(EventType.FORK, fork.Id, executionContext, dbSession);

                // then process the forked flow transition
                executionContext.SetFlow(forkedFlow.Flow);
                ProcessTransition(forkedFlow.Transition, executionContext, dbSession);
            }
        }
        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 void ProcessJoin(JoinImpl join, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            // First set the state of the flow to finished
            FlowImpl joiningFlow = (FlowImpl) executionContext.GetFlow();
            joiningFlow.End = DateTime.Now;
            joiningFlow.ActorId = null;
            joiningFlow.Node = join; // setting the node is not necessary if this method is called
            // from processTransition, but it is necessary if this method is
            // called from cancelFlow in the component-impl.

            // if parent-reactivation of the flow is true, this means that the parent-flow
            // not yet has been reactivated.  In that case we have to see if it needs to be
            // reactivated.  In the other case (parent-reactivation is false) we don't
            // need to do anything because this means that the parent-flow was already
            // reactivated before.
            if (!false.Equals(joiningFlow.ParentReactivation))
            {
                // check if the parent needs to be reactivated
                bool parentReactivation = false;
                IList concurrentFlows = executionContext.GetOtherActiveConcurrentFlows();
                if (concurrentFlows.Count == 0)
                {
                    // if no concurrent flows are present any more, reactivation is forced
                    parentReactivation = true;
                }
                else
                {
                    // if other concurrent flows are present, the decision to reactivate is left
                    // to the join-delegation (if there is one specified)
                    DelegationImpl joinDelegation = join.JoinDelegation;
                    // if no joinDelegation was specified, parentReactivation remains false
                    // so the behaviour is like an and-join. (=sunchronizing merge)
                    if (joinDelegation != null)
                    {
                        parentReactivation = delegationHelper.DelegateJoin(join.JoinDelegation, executionContext);
                    }
                }

                if (parentReactivation)
                {
                    // make sure the other concurrent flows will not reactivate the
                    // parent again
                    IEnumerator iter = concurrentFlows.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        //UPGRADE_TODO: Methode "java.util.Iterator.next" wurde in 'IEnumerator.Current' konvertiert und weist ein anderes Verhalten auf. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilIteratornext"'
                        FlowImpl concurrentFlow = (FlowImpl) iter.Current;
                        concurrentFlow.ParentReactivation = false;
                    }

                    // reactivate the parent by first setting the parentflow into the executionContext
                    FlowImpl parentFlow = (FlowImpl) joiningFlow.Parent;
                    executionContext.SetFlow(parentFlow);
                    // and then process the (single, checked at process-archive-parsing-time) leaving transition.
                    ISet leavingTransitions = join.LeavingTransitions;
                    iter = leavingTransitions.GetEnumerator();
                    if (iter.MoveNext())
                    {
                        TransitionImpl leavingTransition = (TransitionImpl) iter.Current;
                        ProcessTransition(leavingTransition, executionContext,dbSession);
                    } else {
                        // no transition throw exception?
                    }
                }
            }
        }
        public void ProcessFork(ForkImpl fork, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            log.Debug("forking flow " + executionContext.GetFlow());

            // First initialize the children of the flow to be forked
            FlowImpl flow = (FlowImpl) executionContext.GetFlow();
            flow.Children = new ListSet();

            // Then initialise the forked flows in the execution context
            executionContext.ForkedFlows = new ArrayList();

            DelegationImpl delegation = fork.ForkDelegation;
            if (delegation != null)
            {
                delegationHelper.DelegateFork(fork.ForkDelegation, executionContext);
            }
            else
            {
                // execute the default fork behaviour
                IEnumerator iter = fork.LeavingTransitions.GetEnumerator();
                while (iter.MoveNext())
                {
                    TransitionImpl transition = (TransitionImpl) iter.Current;
                    executionContext.ForkFlow(transition, null);
                }
            }

            // create the fork event & remember the parent flow
            FlowImpl parentFlow = (FlowImpl) executionContext.GetFlow();
            executionContext.CreateLog(EventType.FORK);

            // log the event
            executionContext.SetFlow(parentFlow);
            IList forkedFlows = executionContext.ForkedFlows;
            IEnumerator iter2 = forkedFlows.GetEnumerator();
            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow) iter2.Current;
                log.Debug("adding object reference [" + forkedFlow.Flow + "] to flow [" + parentFlow + "]");
                executionContext.AddLogDetail(new ObjectReferenceImpl(forkedFlow.Flow));
            }

            // loop over all flows that were forked in the ForkHandler implementation
            iter2 = forkedFlows.GetEnumerator();
            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow) iter2.Current;

                // trigger actions, scheduled after the creation and setting of the attributeValues
                // but before the fork is being processed
                delegationService.RunActionsForEvent(EventType.FORK, fork.Id, executionContext,dbSession);

                // then process the forked flow transition
                executionContext.SetFlow(forkedFlow.Flow);
                ProcessTransition(forkedFlow.Transition, executionContext,dbSession);
            }
        }
        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);
            }
        }
Beispiel #29
0
		public Object[] DelegateProcessTermination(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			Object[] completionData = new Object[2];
			try
			{
				IProcessInvocationHandler processInvoker = (IProcessInvocationHandler) delegation.GetDelegate();
				log.Debug("collecting results from the sub-process...");
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				completionData[0] = processInvoker.CollectResults(executionContext);
				completionData[1] = processInvoker.GetCompletionTransitionName(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}
			return completionData;
		}
Beispiel #30
0
		public void DelegateFork(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			try
			{
				// delegate the fork
				IForkHandler forker = (IForkHandler) delegation.GetDelegate();
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				forker.Fork(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}
		}
Beispiel #31
0
        public IList PerformActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationService organisationComponent)
        {
            IList assignedFlows = null;
            // get the flow
            FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);

            dbSession.Lock(flow.ProcessInstance, LockMode.Upgrade);
            ActivityStateImpl activityState = (ActivityStateImpl)flow.Node;

            // TODO : check which part can move to the DefaultAuthorizationHandler
            if ((Object)flow.ActorId == null)
            {
                throw new SystemException("the flow on which you try to perform an activity is not assigned to an actor");
            }
            else
            {
                if ((Object)authenticatedActorId == null)
                {
                    throw new AuthorizationException("you can't perform an activity because you are not authenticated");
                }
                //		else if ( ! authenticatedActorId.equals( flow.getActorId() ) ) {
                //        throw new AuthorizationException( "activity '" + activityState.getName() + "' in flow " + flow.getId() + " is not assigned to the authenticated actor (" + authenticatedActorId + ") but to " + flow.getActorId() );
                //      }
            }

            // first check if the actor is allowed to perform this activity
            authorizationHelper.CheckPerformActivity(authenticatedActorId, flowId, attributeValues, transitionName, dbSession);

            log.Info("actor '" + authenticatedActorId + "' performs activity '" + activityState.Name + "'...");

            // create the execution-context
            ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);

            // if this activity has a role-name, save the actor in the corresponding attribute
            // attributeValues = state.addRoleAttributeValue( attributeValues, authenticatedActorId, organisationComponent );

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, activityState.Id, executionContext, dbSession);

            // store the supplied attribute values
            executionContext.CreateLog(authenticatedActorId, EventType.PERFORM_OF_ACTIVITY);
            executionContext.AddLogDetail(new ObjectReferenceImpl(activityState));
            executionContext.CheckAccess(attributeValues, activityState);
            executionContext.StoreAttributeValues(attributeValues);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.PERFORM_OF_ACTIVITY, activityState.Id, executionContext, dbSession);

            // from here on, we consider the actor as being the previous actor
            //因為繼續往下跑,ActorId就有可能轉換成下一關卡的處理人員
            //所以previousActorId就是現在的登入人員
            executionContext.SetActorAsPrevious();

            // select and process the transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, activityState, dbSession);

            engine.ProcessTransition(startTransition, executionContext, dbSession);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.AFTER_PERFORM_OF_ACTIVITY, activityState.Id, executionContext, dbSession);

            assignedFlows = executionContext.AssignedFlows;

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

            if (relations != null)
            {
                relations.Resolve(assignedFlows);
            }
            dbSession.Update(flow.ProcessInstance);
            return(assignedFlows);
        }
Beispiel #32
0
		public String DelegateAssignment(DelegationImpl delegation, ExecutionContextImpl executionContext)
		{
			String actorId = null;

			try
			{
				IAssignmentHandler assigner = (IAssignmentHandler) delegation.GetDelegate();
				executionContext.SetConfiguration(ParseConfiguration(delegation));
				actorId = assigner.SelectActor(executionContext);
			}
			catch (Exception t)
			{
				HandleException(delegation, executionContext, t);
			}

			return actorId;
		}
Beispiel #33
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();
        }
		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;
		}
Beispiel #35
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 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;
		}
		public Object ResolveArgumentParentGroup(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			if (parameters.Length != 0)
				throw new SystemException("argument parentGroup expects exactly zero parameters instead of " + parameters.Length);

			IGroup group = null;

			try
			{
				group = (IGroup) resolvedActor;
				group = group.Parent;
			}
			catch (InvalidCastException e)
			{
				throw new SystemException("can't resolve parentGroup-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e);
			}

			return group;
		}
Beispiel #38
0
        public IList PerformActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationService organisationComponent)
        {
            IList assignedFlows = null;
            // get the flow
            FlowImpl flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
            dbSession.Lock(flow.ProcessInstance, LockMode.Upgrade);
            ActivityStateImpl activityState = (ActivityStateImpl) flow.Node;

            // TODO : check which part can move to the DefaultAuthorizationHandler
            if ((Object) flow.ActorId == null)
            {
                throw new SystemException("the flow on which you try to perform an activity is not assigned to an actor");
            }
            else
            {
                if ((Object) authenticatedActorId == null)
                {
                    throw new AuthorizationException("you can't perform an activity because you are not authenticated");
                }
                //		else if ( ! authenticatedActorId.equals( flow.getActorId() ) ) {
                //        throw new AuthorizationException( "activity '" + activityState.getName() + "' in flow " + flow.getId() + " is not assigned to the authenticated actor (" + authenticatedActorId + ") but to " + flow.getActorId() );
                //      }
            }

            // first check if the actor is allowed to perform this activity
            authorizationHelper.CheckPerformActivity(authenticatedActorId, flowId, attributeValues, transitionName, dbSession);

            log.Info("actor '" + authenticatedActorId + "' performs activity '" + activityState.Name + "'...");

            // create the execution-context
            ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, flow, dbSession, organisationComponent);

            // if this activity has a role-name, save the actor in the corresponding attribute
            // attributeValues = state.addRoleAttributeValue( attributeValues, authenticatedActorId, organisationComponent );

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, activityState.Id, executionContext,dbSession);

            // store the supplied attribute values
            executionContext.CreateLog(authenticatedActorId, EventType.PERFORM_OF_ACTIVITY);
            executionContext.AddLogDetail(new ObjectReferenceImpl(activityState));
            executionContext.CheckAccess(attributeValues, activityState);
            executionContext.StoreAttributeValues(attributeValues);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.PERFORM_OF_ACTIVITY, activityState.Id, executionContext,dbSession);

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

            // select and process the transition
            TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, activityState, dbSession);
            engine.ProcessTransition(startTransition, executionContext, dbSession);

            // log event & trigger actions
            delegationService.RunActionsForEvent(EventType.AFTER_PERFORM_OF_ACTIVITY, activityState.Id, executionContext,dbSession);

            assignedFlows = executionContext.AssignedFlows;

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

            if (relations != null)
            {
                relations.Resolve(assignedFlows);
            }
            dbSession.Update(flow.ProcessInstance);
            return assignedFlows;
        }
		public long ExecuteTask(DbSession dbSession, IOrganisationSessionLocal organisationComponent)
		{
			long millisToWait = DEFAULT_INTERVAL;

			DateTime now = DateTime.Now;

			IEnumerator iter = dbSession.Iterate(queryFindJobsToBeExecuted, now, DbType.TIMESTAMP).GetEnumerator();
			if (iter.MoveNext())
			{
				JobImpl job = (JobImpl) iter.Current;

				try
				{
					log.Debug("executing activation '" + job.Id + "' scheduled for " + job.Date.ToString());
					log.Debug("activation's flow-context is :" + job.Context);

					String userId = job.UserId;

					DelegationImpl actionDelegation = job.ActionDelegation;

					ExecutionContextImpl executionContext = new ExecutionContextImpl(userId, dbSession, organisationComponent);
					IFlow context = job.Context;
					if (context != null)
					{
						executionContext.SetFlow(context);
						executionContext.SetProcessInstance(context.ProcessInstance);
						executionContext.SetProcessDefinition(context.ProcessInstance.ProcessDefinition);
					}
					else
					{
						executionContext.SetProcessDefinition(job.ProcessDefinition);
					}

					delegationHelper.DelegateScheduledAction(actionDelegation, executionContext);

				}
				catch (Exception t)
				{
					log.Error("scheduler-exception : couldn't perform task : " + t.Message, t);
				}

				dbSession.Delete(job);
				dbSession.Flush();
				if (iter.MoveNext())
				{
					return 0;
				}
			} 

			iter = dbSession.Iterate(queryFindJobsInTheFuture, now, DbType.TIMESTAMP).GetEnumerator();
			if (iter.MoveNext())
			{
				JobImpl activation = (JobImpl) iter.Current;
				long activationDate = activation.Date.Ticks;
				millisToWait = activationDate - now.Ticks;
				log.Debug("next activation is scheduled at " + activation.Date.ToString() + ", (in " + millisToWait + " millis)");
				if (millisToWait < 0)
					millisToWait = 0;
				if (millisToWait > DEFAULT_INTERVAL)
					millisToWait = DEFAULT_INTERVAL;
			}

			return millisToWait;
		}
Beispiel #40
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);
            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;
        }
Beispiel #41
0
        public void ProcessJoin(JoinImpl join, ExecutionContextImpl executionContext, DbSession dbSession)
        {
            // First set the state of the flow to finished
            FlowImpl joiningFlow = (FlowImpl)executionContext.GetFlow();

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

            // if parent-reactivation of the flow is true, this means that the parent-flow
            // not yet has been reactivated.  In that case we have to see if it needs to be
            // reactivated.  In the other case (parent-reactivation is false) we don't
            // need to do anything because this means that the parent-flow was already
            // reactivated before.
            if (!false.Equals(joiningFlow.ParentReactivation))
            {
                // check if the parent needs to be reactivated
                bool  parentReactivation = false;
                IList concurrentFlows    = executionContext.GetOtherActiveConcurrentFlows();
                if (concurrentFlows.Count == 0)
                {
                    // if no concurrent flows are present any more, reactivation is forced
                    parentReactivation = true;
                }
                else
                {
                    // if other concurrent flows are present, the decision to reactivate is left
                    // to the join-delegation (if there is one specified)
                    DelegationImpl joinDelegation = join.JoinDelegation;
                    // if no joinDelegation was specified, parentReactivation remains false
                    // so the behaviour is like an and-join. (=sunchronizing merge)
                    if (joinDelegation != null)
                    {
                        parentReactivation = delegationHelper.DelegateJoin(join.JoinDelegation, executionContext);
                    }
                }

                if (parentReactivation)
                {
                    // make sure the other concurrent flows will not reactivate the
                    // parent again
                    IEnumerator iter = concurrentFlows.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        //UPGRADE_TODO: Methode "java.util.Iterator.next" wurde in 'IEnumerator.Current' konvertiert und weist ein anderes Verhalten auf. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javautilIteratornext"'
                        FlowImpl concurrentFlow = (FlowImpl)iter.Current;
                        concurrentFlow.ParentReactivation = false;
                    }

                    // reactivate the parent by first setting the parentflow into the executionContext
                    FlowImpl parentFlow = (FlowImpl)joiningFlow.Parent;
                    executionContext.SetFlow(parentFlow);
                    // and then process the (single, checked at process-archive-parsing-time) leaving transition.
                    ISet leavingTransitions = join.LeavingTransitions;
                    iter = leavingTransitions.GetEnumerator();
                    if (iter.MoveNext())
                    {
                        TransitionImpl leavingTransition = (TransitionImpl)iter.Current;
                        ProcessTransition(leavingTransition, executionContext, dbSession);
                    }
                    else
                    {
                        // no transition throw exception?
                    }
                }
            }
        }
Beispiel #42
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");
            }
        }
		public Object ResolveArgumentPreviousActor(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext)
		{
			if (parameters.Length != 0)
				throw new SystemException("argument previousActor expects exactly zero parameters instead of " + parameters.Length);
			IActor actor = executionContext.GetPreviousActor();
			if (actor == null)
				throw new SystemException("argument previousActor could not be resolve because there is no previous actor");
			return actor;
		}