Exemplo n.º 1
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;
        }