Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
		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;
		}
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
		public void CancelTasks(String reference, DbSession dbSession)
		{
			dbSession.Delete(queryFindByReference, reference, DbType.STRING);
			dbSession.Flush();
		}
Ejemplo n.º 8
0
		public void ScheduleTask(Job job, String reference, DbSession dbSession)
		{
			JobImpl jobImpl = new JobImpl(job, reference);
			dbSession.Save(jobImpl);
			dbSession.Flush();
		}
Ejemplo n.º 9
0
        public void ProcessProcessState(ProcessStateImpl processState, ExecutionContextImpl executionContext,DbSession dbSession)
        {
            // TODO : try to group similarities between this method and ExecutionComponentImpl.startProcessInstance and
            //        group them in a common method

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            // flush the updates to the db
            dbSession.Update(subProcessInstance);
            dbSession.Flush();
        }
Ejemplo n.º 10
0
		public void DeployProcessArchive(Stream processArchiveStream, DbSession dbSession)
		{
			log.Debug("reading process archive...");
			try
			{
				IDictionary entries = null;
				// construct an empty process definition
				ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
				try
				{
					entries = ReadEntries(processArchiveStream);
				}
				catch (IOException e)
				{
					throw new NpdlException("couldn't deploy process archive, the processArchiveBytes do not seem to be a valid jar-file : " + e.Message, e);
				}

				// Then save the process definition
				// This is done so hibernate will assign an id to this object.
				dbSession.Save(processDefinition);
				CreationContext creationContext = new CreationContext(processDefinition, entries, dbSession);
				try
				{
					// parse the  processdefinition.xml
					XmlElement xmlElement = GetXmlElementForEntry("processdefinition.xml", entries, creationContext);
					// build the object model from the xml
					creationContext.PushScope("in processdefinition.xml");
					processDefinition.ReadProcessData(xmlElement, creationContext);
					creationContext.PopScope();
					// resolve all forward references
					creationContext.ResolveReferences();

					processDefinition.Validate(creationContext);

					if (creationContext.HasErrors())
					{
						throw new NpdlException(creationContext.Errors);
					}
					// read the optional web-interface information
					if (entries.Contains("web/webinterface.xml"))
					{
						log.Debug("processing webinterface.xml...");
						xmlElement = GetXmlElementForEntry("web/webinterface.xml", entries, creationContext);
						creationContext.PushScope("in webinterface.xml");
						processDefinition.ReadWebData(xmlElement, creationContext);
						creationContext.PopScope();
					}
					else
					{
						log.Debug("no web/webinterface.xml was supplied");
					}

				}
				catch (SystemException e)
				{
					log.Error("xml parsing error :", e);
					creationContext.AddError(e.GetType().FullName + " : " + e.Message);
					creationContext.AddError("couldn't continue to parse the process archive");
					throw new NpdlException(creationContext.Errors);
				}

				// flush the changes to the database
				dbSession.SaveOrUpdate(processDefinition);
				dbSession.Flush();
			}
			catch (DbException e)
			{
				throw new NpdlException("couldn't deploy process archive due to a database exception : " + e.Message, e);
			}
		}
 public void Save(ProcessDefinitionImpl processDefinition,DbSession dbSession) 
 {
     try
     {
         dbSession.SaveOrUpdate(processDefinition);
         dbSession.Flush();
     }
     catch (DbException e)
     {
         throw new NpdlException("couldn't deploy process archive due to a database exception : " + e.Message, e);
     }
 }