Example #1
0
		public IProcessInstance StartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationSessionLocal 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) dbSession.Load(typeof (ProcessDefinitionImpl), processDefinitionId);
			StartStateImpl startState = (StartStateImpl) processDefinition.StartState;

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

			// create the process-instance
			processInstance = new ProcessInstanceImpl(authenticatedActorId, processDefinition);
			FlowImpl rootFlow = (FlowImpl) processInstance.RootFlow;

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

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

			// run the actions 
			engine.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, startState.Id, executionContext);

			// store the attributes
			executionContext.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);
			executionContext.CheckAccess(attributeValues, startState);
			executionContext.StoreAttributeValues(attributeValues);

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

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

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

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

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

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

			//@portme
/*			if (relations != null)
			{
				relations.resolve(processInstance);
			}
*/
			return processInstance;
		}
		public IProcessDefinition GetProcessDefinition(Int64 processDefinitionId, Relations relations, DbSession dbSession)
		{
			ProcessDefinitionImpl processDefinition = null;
			processDefinition = (ProcessDefinitionImpl) dbSession.Load(typeof (ProcessDefinitionImpl), processDefinitionId);
			if (relations != null)
			{
				relations.Resolve(processDefinition);
			}
			return processDefinition;
		}
 public override void Resolve(DbSession dbSession)
 {
     try
     {
         log.Debug("resolving object reference : " + _referenceId + " : " + _className);
         Type clazz = Type.GetType(_className);
         _object = dbSession.Load(clazz, _referenceId);
     }
     catch (System.Exception e)
     {
         log.Error("error resolving object reference :", e);
     }
 }
Example #4
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();
            }
        }
Example #5
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");
            }
        }
Example #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);
 }
Example #7
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;
        }
Example #8
0
        //private const String queryFieldsByState = "select f from f in class NetBpm.Workflow.Definition.Impl.FieldImpl " +
        //    "where f.State.Id = ? " +
        //    "order by f.Index";
        public IActivityForm GetStartForm(String authenticatedActorId, Int64 processDefinitionId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            IActivityForm activityForm = null;

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

            ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) dbSession.Load(typeof (ProcessDefinitionImpl), processDefinitionId);
            StartStateImpl startState = (StartStateImpl) processDefinition.StartState;

            // create a convenient map from the attribute-names to the fields
            IList fields = fieldRepository.FindFieldsByState(startState.Id, dbSession);
            IDictionary attributeValues = new Hashtable();
            IEnumerator iter = fields.GetEnumerator();
            while (iter.MoveNext())
            {
                FieldImpl field = (FieldImpl) iter.Current;

                // if the attribute has an initial value
                AttributeImpl attribute = (AttributeImpl) field.Attribute;
                String attributeName = attribute.Name;
                String initialValue = attribute.InitialValue;
                if ((Object) initialValue != null && (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access)))
                {
                    // start form contains only fields that are readable or writable

                    // get it and store it in the attributeValues
                    AttributeInstanceImpl attributeInstance = new AttributeInstanceImpl();
                    attributeInstance.Attribute = attribute;
                    attributeInstance.ValueText = initialValue;
                    attributeValues[attributeName] = attributeInstance.GetValue();
                }
            }

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

            return activityForm;
        }
Example #9
0
        public IFlow GetFlow(String authenticatedActorId, Int64 flowId, Relations relations, DbSession dbSession)
        {
            // first check if the actor is allowed to get this flow
            authorizationHelper.CheckGetFlow(authenticatedActorId, flowId, dbSession);

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

            if (relations != null)
            {
                relations.Resolve(flow);
            }

            return flow;
        }
Example #10
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;
        }
Example #11
0
        //@todo delete parameter organisationComponent
        public void DelegateActivity(String authenticatedActorId, Int64 flowId, String delegateActorId, DbSession dbSession, IOrganisationService organisationComponent)
        {
            // first check if the actor is allowed to delegate this activity
            authorizationHelper.CheckDelegateActivity(authenticatedActorId, flowId, delegateActorId, dbSession);

            // reassign the flow
            FlowImpl flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
            flow.ActorId = delegateActorId;

            // flush the updates to the db
            dbSession.Update(flow);
            dbSession.Flush();
        }
Example #12
0
		public ProcessInstanceImpl GetProcessInstance(Int64 processInstanceId, Relations relations, DbSession dbSession)
		{
			ProcessInstanceImpl processInstance = null;
			log.Debug("searching for process instances...");
			processInstance = (ProcessInstanceImpl) dbSession.Load(typeof (ProcessInstanceImpl), processInstanceId);
			Resolve((FlowImpl) processInstance.RootFlow, relations, dbSession);
			return processInstance;
		}
Example #13
0
		public FlowImpl GetFlow(Int64 flowId, Relations relations, DbSession dbSession)
		{
			FlowImpl flow = null;
			log.Debug("searching for flow '" + flowId + "'...");
			flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
			Resolve(flow, relations, dbSession);
			return flow;
		}
Example #14
0
		private IAuthorizationHandler GetHandlerFromFlowId(Int64 flowId, DbSession dbSession)
		{
			FlowImpl flow = null;
			;
			try
			{
				flow = (FlowImpl) dbSession.Load(typeof (FlowImpl), flowId);
			}
			catch (ObjectNotFoundException e)
			{
				throw new ArgumentException("couldn't check authorization : flow with id '" + flowId + "' does not exist : " + e.Message);
			}
			return GetAuthorizationHandler((ProcessDefinitionImpl) flow.ProcessInstance.ProcessDefinition);
		}
Example #15
0
		private IAuthorizationHandler GetHandlerFromProcessInstanceId(Int64 processInstanceId, DbSession dbSession)
		{
			ProcessInstanceImpl processInstance = null;
			;
			try
			{
				processInstance = (ProcessInstanceImpl) dbSession.Load(typeof (ProcessInstanceImpl), processInstanceId);
			}
			catch (ObjectNotFoundException e)
			{
				throw new ArgumentException("couldn't check authorization : process instance with id '" + processInstanceId + "' does not exist : " + e.Message);
			}
			return GetAuthorizationHandler((ProcessDefinitionImpl) processInstance.ProcessDefinition);
		}
Example #16
0
        public FlowImpl GetFlow(long flowId,DbSession dbSession)
        {
            FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);

            return flow;
        }