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 void SetUp() { simpleSingleChainRelations1 = new Relations("singleReturn"); simpleSingleChainRelations2 = new Relations("singleReturn.singleReturn"); singleChainRelations = new Relations("singleReturn.singleReturn.singleReturn.singleReturn"); resultSimpleSingleChainRelations1 = new String[] {"singleReturn"}; resultSimpleSingleChainRelations2 = new String[] {"singleReturn", "singleReturn"}; resultSingleChainRelations = new String[] {"singleReturn", "singleReturn", "singleReturn", "singleReturn"}; simpleCollectionChainRelations1 = new Relations("collectionReturn"); simpleCollectionChainRelations2 = new Relations("collectionReturn.singleReturn"); collectionChainRelations = new Relations("collectionReturn.collectionReturn.collectionReturn.singleReturn"); resultSimpleCollectionChainRelations1 = new String[] {"collectionReturn"}; resultSimpleCollectionChainRelations2 = new String[] {"collectionReturn", "singleReturn"}; resultCollectionChainRelations = new String[] {"collectionReturn", "collectionReturn", "collectionReturn", "singleReturn"}; simpleArrayChainRelations1 = new Relations("arrayReturn"); simpleArrayChainRelations2 = new Relations("arrayReturn.singleReturn"); arrayChainRelations = new Relations("arrayReturn.arrayReturn.arrayReturn.singleReturn"); resultSimpleArrayChainRelations1 = new String[] {"arrayReturn"}; resultSimpleArrayChainRelations2 = new String[] {"arrayReturn", "singleReturn"}; resultArrayChainRelations = new String[] {"arrayReturn", "arrayReturn", "arrayReturn", "singleReturn"}; }
public virtual IList GetProcessDefinitions(Relations relations) { IList processDefinitions = null; DbSession dbSession = null; dbSession = OpenSession(); processDefinitions = implementation.GetProcessDefinitions(relations, dbSession); return processDefinitions; }
public virtual IList FindAllUsers(Relations relations) { IList users = null; DbSession dbSession = null; dbSession = OpenSession(); users = implementation.FindAllUsers(relations, dbSession); return users; }
public virtual IProcessInstance GetProcessInstance(Int64 processInstanceId, Relations relations) { ProcessInstanceImpl processInstance = null; DbSession dbSession = null; dbSession = OpenSession(); processInstance = implementation.GetProcessInstance(processInstanceId, relations, dbSession); return processInstance; }
public virtual IFlow GetFlow(Int64 flowId, Relations relations) { FlowImpl flow = null; DbSession dbSession = null; dbSession = OpenSession(); flow = implementation.GetFlow(flowId, relations, dbSession); return flow; }
public virtual IList FindProcessInstances(DateTime startedAfter, DateTime startedBefore, String initiatorUserName, String actorUserName, Int64 processDefinitionId, Relations relations) { IList processInstances = null; DbSession dbSession = null; dbSession = OpenSession(); processInstances = implementation.FindProcessInstances(startedAfter, startedBefore, initiatorUserName, actorUserName, processDefinitionId, relations, dbSession); return processInstances; }
public virtual IProcessDefinition GetProcessDefinition(Int64 processDefinitionId, Relations relations) { IProcessDefinition processDefinition = null; DbSession dbSession = null; dbSession = OpenSession(); processDefinition = implementation.GetProcessDefinition(processDefinitionId, relations, dbSession); return processDefinition; }
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 IList GetProcessDefinitions(Relations relations, DbSession dbSession) { IList processDefinitions = null; processDefinitions = dbSession.Find(queryFindProcessDefinitions); if (relations != null) { relations.Resolve(processDefinitions); } return processDefinitions; }
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 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 virtual IActor FindActorById(String actorId, Relations relations) { IActor actor = null; DbSession dbSession = null; try { dbSession = OpenSession(); actor = implementation.FindActorById(actorId, relations, dbSession); } catch (Exception t) { log.Error("error when finding actor by id " + actorId, t); } return actor; }
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 virtual IList GetTaskList(IList actorIds, Relations relations) { DbSession dbSession = null; IList taskLists = null; IOrganisationSessionLocal organisationComponent = null; try { dbSession = OpenSession(); organisationComponent = (IOrganisationSessionLocal) ServiceLocator.Instance.GetService(typeof (IOrganisationSessionLocal)); taskLists = implementation.GetTaskList(ActorId, actorIds, relations, dbSession, organisationComponent); } finally { ServiceLocator.Instance.Release(organisationComponent); } return taskLists; }
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 IList PerformActivity(long flowId, IDictionary attributeValues = null, String transitionName=null, Relations relations=null) { if (string.IsNullOrEmpty(ActorId)) { throw new AuthorizationException("you can't perform an activity because you are not authenticated"); } IList flows = null; try { using (ISession session = NHibernateHelper.OpenSession()) { DbSession dbSession = new DbSession(session); FlowImpl flow = flowRepository.GetFlow(flowId,dbSession); ActivityStateImpl activityState = (ActivityStateImpl)flow.Node; ExecutionContext executionContext = new ExecutionContext(); activityState.CheckAccess(attributeValues); attributeService = new AttributeService(flow,dbSession); attributeService.StoreAttributeValue(attributeValues); transitionService = new TransitionService(ActorId, dbSession); TransitionImpl transitionTo = transitionService.GetTransition(transitionName, activityState, dbSession); transitionService.ProcessTransition(transitionTo, flow, dbSession); session.Flush(); } } catch (ExecutionException e) { throw e; } catch (Exception e) { throw new SystemException("uncaught exception : " + e.Message, e); } finally { //ServiceLocator.Instance.Release(organisationComponent); } return flows; }
private static void ResolveObject(Object persistentObject, IDictionary relationsMap) { if (relationsMap == null) { return; } IEnumerator iter = relationsMap.GetEnumerator(); while (iter.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)iter.Current; String propertyName = (String)entry.Key; IDictionary rest = null; Relations relations = (Relations)entry.Value; if (relations != null) { rest = relations._relationsMap; } try { String getterName = propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1); System.Reflection.PropertyInfo prop = persistentObject.GetType().GetProperty(getterName); // Type type=persistentObject.GetType(); Object agreggatedObject = prop.GetValue(persistentObject, null); // log.Debug( "agreggatedObject: " + agreggatedObject ); if (agreggatedObject != null) { Resolve(agreggatedObject, rest); } } catch (System.Exception e) { log.Error("can't resolve property " + propertyName + " for object " + persistentObject + " : " + e.Message, e); } } }
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 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; }
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; }
private void Add(String fullyQualifiedProperty) { String atomicProperty = null; String subProperty = null; int dotIndex = fullyQualifiedProperty.IndexOf('.'); if (dotIndex != - 1) { atomicProperty = fullyQualifiedProperty.Substring(0, dotIndex); subProperty = fullyQualifiedProperty.Substring(dotIndex + 1); } else { atomicProperty = fullyQualifiedProperty; } Relations subRelation = (Relations) _relationsMap[atomicProperty]; if (subRelation != null) { subRelation.Add(subProperty); } else { if ((Object) subProperty != null) { subRelation = new Relations(subProperty); } } _relationsMap[atomicProperty] = subRelation; }
private void Resolve(FlowImpl flow, Relations relations, DbSession dbSession) { // resolve the flow if (relations != null) { log.Debug("resolving relations : '" + relations + "' on flow '" + flow + "'"); relations.Resolve(flow); } // resolve the flow-details IEnumerator iter = flow.Logs.GetEnumerator(); while (iter.MoveNext()) { LogImpl logImpl = (LogImpl) iter.Current; IEnumerator detailsIter = logImpl.Details.GetEnumerator(); while (detailsIter.MoveNext()) { LogDetailImpl LogDetailImpl = (LogDetailImpl) detailsIter.Current; LogDetailImpl.Resolve(dbSession); } } // resolve the attribute values iter = flow.AttributeInstances.GetEnumerator(); while (iter.MoveNext()) { AttributeInstanceImpl attributeInstance = (AttributeInstanceImpl) iter.Current; log.Debug("resolving attribute instance : " + attributeInstance.GetValue()); } // resolve the child-flows iter = flow.Children.GetEnumerator(); while (iter.MoveNext()) { FlowImpl subFlow = (FlowImpl) iter.Current; Resolve(subFlow, relations, dbSession); } // resolve the sub-process-flows IProcessInstance subProcessInstance = flow.GetSubProcessInstance(); if (subProcessInstance != null) { Resolve((FlowImpl) subProcessInstance.RootFlow, relations, dbSession); } }
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; }
public IGroup FindGroupByMembership(String userId, String membershipType, Relations relations, DbSession dbSession) { IGroup group = null; try { Object[] args = new Object[] {userId, membershipType}; IType[] types = new IType[] {DbType.STRING, DbType.STRING}; group = (IGroup) dbSession.FindOne(queryFindGroupByMembership, args, types); if (relations != null) relations.Resolve(group); } catch (Exception t) { throw new OrganisationRuntimeException("organisation-exception : coudn't find group by membership by user '" + userId + "' and membership-type '" + membershipType + "' : " + t.Message); } return group; }
public IProcessInstance StartProcessInstance(long processDefinitionId, IDictionary attributeValues = null, string transitionName = null, Relations relations = null) { ProcessInstanceImpl processInstance = null; IOrganisationService organisationService = null; using (ISession session = NHibernateHelper.OpenSession()) { using (var tran = session.BeginTransaction()) { DbSession dbSession = new DbSession(session); ProcessDefinitionImpl processDefinition = myProcessDefinitionService.GetProcessDefinition(processDefinitionId, dbSession); processInstance = new ProcessInstanceImpl(ActorId, processDefinition); processInstanceRepository.Save(processInstance, dbSession);//到這裏應該存了ProcessInstance,RootFlow ExecutionContext executionContext = new ExecutionContext(); //logRepository.CreateLog(); processDefinition.StartState.CheckAccess(attributeValues); attributeService = new AttributeService((FlowImpl)processInstance.RootFlow, dbSession); attributeService.StoreAttributeValue(attributeValues);//儲存傳入的欄位值 attributeService.StoreRole(organisationService.FindActorById(ActorId), (ActivityStateImpl)processDefinition.StartState); //flow的node推進到下一關卡 //flow的actor=解析出來的actor.Id transitionService = new TransitionService(ActorId, dbSession); TransitionImpl transitionTo = transitionService.GetTransition(transitionName, processDefinition.StartState, dbSession); transitionService.ProcessTransition(transitionTo, (FlowImpl)processInstance.RootFlow, dbSession); session.Flush(); tran.Commit(); } } return processInstance; }
public IGroup CreateGroup(String groupId, ICollection userIds, Relations relations, DbSession dbSession) { //Group group = null; throw new NotSupportedException("in the organisation-component, the method createGroup is not yet implemented"); // return group; }
// method implementations //////////////////////////////////////////// public IActor FindActorById(String actorName, Relations relations, DbSession dbSession) { IActor actor = null; try { actor = (IActor) dbSession.FindOne(queryFindActorById, actorName, DbType.STRING); if (relations != null) relations.Resolve(actor); } catch (Exception t) { throw new OrganisationRuntimeException("organisation-exception : coudn't find actor '" + actorName + "' by name : " + t.Message); } return actor; }
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 FindMembershipsByUserAndGroup(String userId, String groupId, Relations relations, DbSession dbSession) { IList memberships = null; try { Object[] args = new Object[] {userId, groupId}; IType[] types = new IType[] {DbType.STRING, DbType.STRING}; log.Debug("findMembershipsByUserAndGroup(" + userId + "," + groupId + "): !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + memberships); memberships = dbSession.Find(queryFindMembershipsByUserAndGroup, args, types); log.Debug("findMembershipsByUserAndGroup(" + userId + "," + groupId + "): " + memberships); if (relations != null) relations.Resolve(memberships); } catch (Exception t) { throw new OrganisationRuntimeException("organisation-exception : coudn't find memberships by user '" + userId + "' and group '" + groupId + "' : " + t.Message); } return memberships; }