public IList FindProcessInstances(DateTime startedAfter, DateTime startedBefore, String initiatorActorId, String actorId, Int64 processDefinitionId, Relations relations, DbSession dbSession) { IList processInstances = null; String query = queryFindAllProcessInstances; ArrayList parameters = new ArrayList(); ArrayList types = new ArrayList(); if (startedAfter != DateTime.MinValue) { query += "and pi.StartNullable > ? "; parameters.Add(startedAfter); types.Add(DbType.DATE); } if (startedBefore != DateTime.MinValue) { query += "and pi.StartNullable < ? "; parameters.Add(startedBefore); types.Add(DbType.DATE); } if (initiatorActorId != null && initiatorActorId != "") { query += "and pi.InitiatorActorId = ? "; parameters.Add(initiatorActorId); types.Add(DbType.STRING); } if (actorId != null && actorId != "") { query += "and f.ActorId = ? "; parameters.Add(actorId); types.Add(DbType.STRING); } if (processDefinitionId != 0) { query += "and pi.ProcessDefinition.Id = ? "; parameters.Add(processDefinitionId); types.Add(DbType.LONG); } query += "order by pi.StartNullable desc"; log.Debug("query for searching process instances : '" + query + "'"); Object[] parameterArray = parameters.ToArray(); IType[] typeArray = (IType[]) types.ToArray(typeof (IType)); processInstances = dbSession.Find(query, parameterArray, typeArray); if (relations != null) { relations.Resolve(processInstances); } log.Debug("process instances : '" + processInstances + "'"); return processInstances; }
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 IList FindAttributeInstanceByName(string attributeName,long scopeId,DbSession dbSession) { Object[] values = new Object[] { attributeName, scopeId }; IType[] types = new IType[] { DbType.STRING, DbType.LONG }; return dbSession.Find(queryFindAttributeInstanceByName, values, types); }
/* package private */ internal virtual TransitionImpl GetTransition(String transitionName, StateImpl state, DbSession dbSession) { TransitionImpl transition = null; if ((Object)transitionName != null) { Object[] values = new Object[] { transitionName, state.Id }; IType[] types = new IType[] { DbType.STRING, DbType.LONG }; transition = (TransitionImpl)dbSession.FindOne(queryFindTransitionByName, values, types); } else { ISet leavingTransitions = state.LeavingTransitions; if (leavingTransitions.Count == 1) { IEnumerator transEnum = leavingTransitions.GetEnumerator(); transEnum.MoveNext(); transition = (TransitionImpl)transEnum.Current; } else { throw new SystemException("no transitionName was specified : this is only allowed if the state (" + state.Name + ") has exactly 1 leaving transition (" + leavingTransitions.Count + ")"); } } return transition; }
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); }
internal virtual TransitionImpl FindLeavingTransitionByName(long nodeId,string transitionName, DbSession dbSession) { Object[] values = new Object[] { nodeId, transitionName }; IType[] types = new IType[] { DbType.LONG, DbType.STRING }; return (TransitionImpl)dbSession.FindOne(queryFindLeavingTransitionByName, values, types); }
public AttributeInstanceImpl FindAttributeInstanceInScope(String attributeName, FlowImpl scope,DbSession dbSession) { AttributeInstanceImpl attributeInstance = null; while (attributeInstance == null) { IList attributes = this.FindAttributeInstanceByName(attributeName, scope.Id, dbSession); IEnumerator iter = attributes.GetEnumerator(); if (iter.MoveNext()) { attributeInstance = (AttributeInstanceImpl)iter.Current; if (iter.MoveNext()) { throw new NetBpm.Util.DB.DbException("duplicate value"); } } else { if (!scope.IsRootFlow()) { scope = (FlowImpl)scope.Parent; } else { log.Warn("couldn't find attribute-instance '" + attributeName + "' in scope of flow '" + scope + "'"); break; } } } return attributeInstance; }
public TransitionService(string previousActorId,DbSession session) { // TODO: Complete member initialization this.session = session; delegationService = new DelegationService(); actorExpressionResolverService = new ActorExpressionResolverService(previousActorId); }
public void CheckGetStartForm(String authenticatedActorId, Int64 processDefinitionId, DbSession dbSession) { IAuthorizationHandler authorizationHandler = GetHandlerFromProcessDefinitionId(processDefinitionId, dbSession); if (authorizationHandler != null) { authorizationHandler.CheckGetStartForm(authenticatedActorId, processDefinitionId); } }
public void CheckPerformActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, String transitionName, DbSession dbSession) { IAuthorizationHandler authorizationHandler = GetHandlerFromFlowId(flowId, dbSession); if (authorizationHandler != null) { authorizationHandler.CheckPerformActivity(authenticatedActorId, flowId, attributeValues, transitionName); } }
public void CheckDelegateActivity(String authenticatedActorId, Int64 flowId, String delegateActorId, DbSession dbSession) { IAuthorizationHandler authorizationHandler = GetHandlerFromFlowId(flowId, dbSession); if (authorizationHandler != null) { authorizationHandler.CheckDelegateActivity(authenticatedActorId, flowId, delegateActorId); } }
public void CheckCancelProcessInstance(String authenticatedActorId, Int64 processInstanceId, DbSession dbSession) { IAuthorizationHandler authorizationHandler = GetHandlerFromProcessInstanceId(processInstanceId, dbSession); if (authorizationHandler != null) { authorizationHandler.CheckCancelProcessInstance(authenticatedActorId, processInstanceId); } }
public void CheckStartProcessInstance(String authenticatedActorId, Int64 processDefinitionId, IDictionary attributeValues, String transitionName, DbSession dbSession) { IAuthorizationHandler authorizationHandler = GetHandlerFromProcessDefinitionId(processDefinitionId, dbSession); if (authorizationHandler != null) { authorizationHandler.CheckStartProcessInstance(authenticatedActorId, processDefinitionId, attributeValues, transitionName); } }
public void DeleteAccount(string bank, string costumer, DbSession dbSession) { log.Debug("DeleteAccount"); Object[] values = new Object[] {bank, costumer}; IType[] types = new IType[] {DbType.STRING, DbType.STRING}; dbSession.Delete(queryFindBankAccount,values,types); }
public ExecutionContextImpl(String actorId, ProcessInstanceImpl processInstance, DbSession dbSession, IOrganisationService organisationComponent) { this._actorId = actorId; this._processInstance = processInstance; this._processDefinition = (ProcessDefinitionImpl) processInstance.ProcessDefinition; this._dbSession = dbSession; this._organisationComponent = organisationComponent; this._assignedFlows = new ArrayList(); }
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 IProcessDefinition GetProcessDefinition(String processDefinitionName, Relations relations, DbSession dbSession) { ProcessDefinitionImpl processDefinition = null; processDefinition = (ProcessDefinitionImpl) dbSession.FindOne(queryFindProcessDefinitionByName, processDefinitionName, DbType.STRING); if (relations != null) { relations.Resolve(processDefinition); } return processDefinition; }
public IList GetProcessDefinitions(Relations relations, DbSession dbSession) { IList processDefinitions = null; processDefinitions = dbSession.Find(queryFindProcessDefinitions); if (relations != null) { relations.Resolve(processDefinitions); } return processDefinitions; }
public IList GetAllProcessDefinitions(Relations relations, DbSession dbSession) { IList processDefinitions = null; log.Debug("getting all process definitions..."); processDefinitions = dbSession.Find(queryFindAllProcessDefinitions); if (relations != null) { relations.Resolve(processDefinitions); } return processDefinitions; }
public BankAccount GetBankAccount(string bank, string costumer, DbSession dbSession) { log.Debug("GetBankAccount"); BankAccount bankAccount = null; Object[] values = new Object[] {bank, costumer}; IType[] types = new IType[] {DbType.STRING, DbType.STRING}; bankAccount = (BankAccount) dbSession.FindOne(queryFindBankAccount,values,types); return bankAccount; }
public void DeployProcessArchive(byte[] processArchiveBytes, DbSession dbSession) { try { Stream mstream = new MemoryStream(processArchiveBytes); DeployProcessArchive(mstream, dbSession); } catch (IOException e) { throw new NpdlException("couldn't deploy process archive, the processArchiveBytes do not seem to be a valid par-file : " + 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); } }
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); } }
public void DeployProcessArchive(byte[] processArchiveBytes) { ParFile parFile = new ParFile(processArchiveBytes); ProcessDefinitionBuildService buildService = new ProcessDefinitionBuildService(parFile.ProcessDefinition); ProcessDefinitionImpl processDefinition = buildService.BuildProcessDefinition(); using (ISession session = NHibernateHelper.OpenSession()) { DbSession nhSession = new DbSession(session); repository.Save(processDefinition, nhSession); } }
public void ProcessActivityState(ActivityStateImpl activityState, FlowImpl flow, DbSession dbSession) { String actorId = null; String role = activityState.ActorRoleName; DelegationImpl assignmentDelegation = activityState.AssignmentDelegation; if (assignmentDelegation != null) { var delegateParameters = activityState.AssignmentDelegation.ParseConfiguration(); actorExpressionResolverService.CurrentScope = flow; actorExpressionResolverService.DbSession = dbSession; actorId = actorExpressionResolverService.ResolveArgument(delegateParameters["expression"].ToString()).Id; if ((Object)actorId == null) { throw new SystemException("invalid process definition : assigner of activity-state '" + activityState.Name + "' returned null instead of a valid actorId"); } } else { if ((Object)role != null) { IActor actor = null; var attr = attributeRepository.FindAttributeInstanceInScope(role, flow, dbSession); if (attr != null) actor = (IActor)attr.GetValue(); 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); }
public IList GetTaskList(String authenticatedActorId, IList actorIds, Relations relations, DbSession dbSession, IOrganisationSessionLocal organisationComponent) { ArrayList tasks = null; IEnumerator actorIdsIterator = actorIds.GetEnumerator(); while (actorIdsIterator.MoveNext()) { String actorId = (String) actorIdsIterator.Current; if (tasks == null) { tasks = new ArrayList(); } tasks.AddRange(GetTaskList(authenticatedActorId, actorId, relations, dbSession, organisationComponent)); } return tasks; }
public IList GetTaskList(String actorId,Relations relations = null) { IList taskLists = null; IOrganisationService organisationComponent = null; try { using (ISession session = NHibernateHelper.OpenSession()) { DbSession dbSession = new DbSession(session); IActor actor = organisationService.FindActorById(actorId); taskLists = taskRepository.FindTasks(actorId, dbSession); } } finally { ServiceLocator.Instance.Release(organisationComponent); } return taskLists; }
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!"); }
public IList GetTaskList(String authenticatedActorId, String actorId, Relations relations, DbSession dbSession, IOrganisationSessionLocal organisationComponent) { IList tasks = null; IActor actor = organisationComponent.FindActorById(actorId); if (actor is IUser) { log.Debug("getting task lists for actor --> User : [" + actor + "]"); tasks = GetActorTaskList(actorId, dbSession); } else if (actor is IGroup) { log.Debug("getting task lists for actor --> Group : [" + actor + "]"); tasks = GetGroupTaskList(authenticatedActorId, null, actorId, dbSession, organisationComponent); } if (relations != null) { relations.Resolve(tasks); } return tasks; }
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(); } }