Ejemplo n.º 1
0
        public void  CheckPerformActivity(String authenticatedActorId, Int64 flowId, IDictionary attributeValues, String transitionName)
        {
            //only actor assigned for that activity can perform an activity
            IExecutionApplicationService executionComponent = (IExecutionApplicationService)serviceLocator.GetService(typeof(IExecutionApplicationService));

            try
            {
                IFlow flow = executionComponent.GetFlow(flowId);
                if (flow.GetActor().Id.Equals(authenticatedActorId) == false)
                {
                    throw new AuthorizationException("only actor assigned for that activity can perform an activity");
                }
            }
            catch (ExecutionException e)
            {
                log.Error("failed doing authorization : ", e);
                throw new System.SystemException("failed doing authorization : " + e.Message);
            }
            finally
            {
                serviceLocator.Release(executionComponent);
            }
        }
Ejemplo n.º 2
0
        public ActionResult ActivityForm(string aa)
        {
            IDictionary   userInputFields = new Hashtable();
            IActivityForm activityForm    = (IActivityForm)HttpContext.Session["activityForm"];
            IList         fields          = activityForm.Fields;
            IEnumerator   fildEnumer      = fields.GetEnumerator();

            while (fildEnumer.MoveNext())
            {
                IField field = (IField)fildEnumer.Current;
                // Construct a meaningfull name that is http-compliant
                String attributeName  = field.Attribute.Name;
                String parameterName  = convertToHttpCompliant(attributeName);
                String parameterValue = HttpContext.Request.Params[parameterName];

                if (FieldAccessHelper.IsRequired(field.Access) && (parameterValue == null || "".Equals(parameterValue)))
                {
                    //AddMessage("Field "+field.Name+" is required. Please, provide a value");
                }
                else
                {
                    try
                    {
                        Object         parsedParameter = null;
                        IHtmlFormatter htmlFormatter   = field.GetHtmlFormatter();
                        if (htmlFormatter != null)
                        {
                            // TODO: Test if there is the possibility to simplify the interface, see null
                            parsedParameter = htmlFormatter.ParseHttpParameter(parameterValue, null);

                            if (parsedParameter != null)
                            {
                                userInputFields.Add(attributeName, parsedParameter);
                            }
                        }
                        else
                        {
                            //log.Warn("No htmlformatter defined for field:"+field.Name);
                        }
                    }
                    catch (Exception ex)
                    {
                        //log.Debug( "error parsing user-input-field " + field.Name + " : " + parameterValue,ex);
                        //AddMessage("error parsing user-input-field " + field.Name + " with value: " + parameterValue);
                    }
                }
            }

            if (false)
            {
                //log.Debug( "submitted activity-form has messages, redirecting to activityFormPage..." );
                HttpContext.Session.Add("userInputFields", userInputFields);
                if (activityForm.Flow == null)
                {
                    return(RedirectToAction("ActivityForm", "Form",
                                            new RouteValueDictionary()
                    {
                        { "flowId", activityForm.ProcessDefinition.Id }
                    }));
                    //StartProcessInstance(activityForm.ProcessDefinition.Id);
                }
                else
                {
                    return(RedirectToAction("ActivityForm", "Form", new RouteValueDictionary()));
                    //ShowActivityForm(activityForm.Flow.Id);
                }
            }
            else
            {
                // remove the old inputvalues
                HttpContext.Session.Remove("userInputFields");
                //log.Debug( "submitting the form..." );
                IList activatedFlows = null;
                IFlow flow           = activityForm.Flow;
                // if there is no flow in the activityForm
                IExecutionSessionLocal executionComponent = null;
                try
                {
                    executionComponent = ServiceLocator.Instance.GetService(typeof(IExecutionSessionLocal)) as IExecutionSessionLocal;
                    if (flow == null)
                    {
                        // this means that it is a start-activity being performed so we have to
                        // start a new process instance
                        IProcessDefinition processDefinition = activityForm.ProcessDefinition;
                        IProcessInstance   processInstance   = executionComponent.StartProcessInstance(processDefinition.Id, userInputFields);
                        activatedFlows = new ArrayList();
                        //AddAllActiveFlows(processInstance.RootFlow,activatedFlows);
                        //activatedFlows.Add(processInstance.RootFlow);
                    }
                    else
                    {
                        activatedFlows = executionComponent.PerformActivity(flow.Id, userInputFields);
                    }
                }
                finally
                {
                    ServiceLocator.Instance.Release(executionComponent);
                }
                if (activatedFlows.Count > 0)
                {
                    System.Text.StringBuilder feedbackBuffer = new System.Text.StringBuilder();
                    for (int i = 0; i < activatedFlows.Count; ++i)
                    {
                        IFlow activatedFlow = (IFlow)activatedFlows[i];

                        if (activatedFlow.GetActor() != null)
                        {
                            feedbackBuffer.Append(activatedFlow.GetActor().Name);
                        }
                        else
                        {
                            // when flow's node is start-state no actor is assigned to it, this is to handle the NPE thrown
                            feedbackBuffer.Append("Nobody");
                        }
                        if (i + 1 < activatedFlows.Count)
                        {
                            feedbackBuffer.Append(", ");
                        }
                    }

                    if (activatedFlows.Count > 1)
                    {
                        //AddMessage("Now, following people are handling this process :"+feedbackBuffer.ToString());
                    }
                    else
                    {
                        //AddMessage("Now, "+  feedbackBuffer.ToString() +" is handling this process");
                    }
                    return(Redirect("/User/ShowHome"));
                }
                else
                {
                    //AddMessage("This flow in the process finished");
                    return(Redirect("/User/ShowHome"));
                }
            }
        }