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); }
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); }
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); }
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; }
public Object ResolveArgumentRole(IActor resolvedActor, String[] parameters, ExecutionContextImpl executionContext) { if (parameters.Length != 1) throw new SystemException("argument role expects exactly one parameter (role-name) instead of " + parameters.Length); IActor actor = null; if (resolvedActor == null) { try { actor = (IActor) executionContext.GetAttribute(parameters[0]); } catch (InvalidCastException e) { throw new SystemException("argument attribute(" + parameters[0] + ") does not contain an actor : " + executionContext.GetAttribute(parameters[0]).GetType().FullName, e); } } else { String roleName = parameters[0].Trim(); try { IList users = executionContext.GetOrganisationComponent().FindUsersByGroupAndRole(resolvedActor.Id, roleName); if (users.Count < 1) throw new SystemException("no users have role " + roleName + " for group " + resolvedActor.Id); actor = (IUser) users[0]; // TODO : create a new group if more then one user is returned on the query... } catch (InvalidCastException e) { throw new SystemException("can't resolve role-argument : a role must be calculated from a Group, not a " + resolvedActor.GetType().FullName, e); } catch (OrganisationRuntimeException e) { throw new SystemException("can't resolve role-argument : can't find the users that perform role " + roleName + " for group " + resolvedActor.Id + " : " + e.Message); } } return actor; }