public IProcessInstance StartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName, Relations relations, DbSession dbSession, IOrganisationService organisationComponent) { ProcessInstanceImpl processInstance = null; // First check if the actor is allowed to start this instance authorizationHelper.CheckStartProcessInstance(authenticatedActorId, processDefinitionId, attributeValues, transitionName, dbSession); // get the process-definition and its start-state ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)definitionRepository.GetProcessDefinition(processDefinitionId, null, dbSession); StartStateImpl startState = (StartStateImpl) processDefinition.StartState; log.Info("actor '" + authenticatedActorId + "' starts an instance of process '" + processDefinition.Name + "'..."); processInstance = new ProcessInstanceImpl(authenticatedActorId, processDefinition); FlowImpl rootFlow = (FlowImpl) processInstance.RootFlow; ExecutionContextImpl executionContext = new ExecutionContextImpl(authenticatedActorId, rootFlow, dbSession, organisationComponent); MyExecutionContext myExecutionContext = new MyExecutionContext(); // save the process instance to allow hibernate queries dbSession.Save(processInstance); //dbSession.Lock(processInstance,LockMode.Upgrade); delegationService.RunActionsForEvent(EventType.BEFORE_PERFORM_OF_ACTIVITY, startState.Id, executionContext,dbSession); // store the attributes executionContext.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START); //LogImpl logImpl = rootFlow.CreateLog(authenticatedActorId, EventType.PROCESS_INSTANCE_START);//new add executionContext.CheckAccess(attributeValues, startState); //startState.CheckAccess(attributeValues); //�ݨӤ]�䤣��AttributeInstance executionContext.StoreAttributeValues(attributeValues); // if this activity has a role-name, save the actor in the corresponding attribute executionContext.StoreRole(authenticatedActorId, startState); // run the actions delegationService.RunActionsForEvent(EventType.PROCESS_INSTANCE_START, processDefinitionId, executionContext,dbSession); // from here on, we consider the actor as being the previous actor executionContext.SetActorAsPrevious(); // process the start-transition TransitionImpl startTransition = transitionRepository.GetTransition(transitionName, startState, dbSession); engine.ProcessTransition(startTransition, executionContext, dbSession); // run the actions delegationService.RunActionsForEvent(EventType.AFTER_PERFORM_OF_ACTIVITY, startState.Id, executionContext,dbSession); // flush the updates to the db dbSession.Update(processInstance); dbSession.Flush(); //@portme /* if (relations != null) { relations.resolve(processInstance); } */ return processInstance; }
public IProcessInstance StartProcessInstance(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 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 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); }