public void ShowActivityForm(long flowId) { if (log.IsDebugEnabled) { log.Debug("ShowActivityForm flowId:" + flowId); } IExecutionSessionLocal executionComponent = null; try { executionComponent = ServiceLocator.Instance.GetService(typeof(IExecutionSessionLocal)) as IExecutionSessionLocal; IFlow flow = executionComponent.GetFlow(flowId); Context.Flash["activity"] = flow.Node; Context.Flash["processDefinition"] = flow.ProcessInstance.ProcessDefinition; Context.Flash["preview"] = "activity"; AddImageCoordinates((IState)flow.Node); //create Form IActivityForm activityForm = executionComponent.GetActivityForm(flowId); AddFormData(activityForm); } finally { ServiceLocator.Instance.Release(executionComponent); } RenderView("activityForm"); }
// // GET: /Form/ public ActionResult ActivityForm(long flowId) { IExecutionSessionLocal executionComponent = null; try { executionComponent = ServiceLocator.Instance.GetService(typeof(IExecutionSessionLocal)) as IExecutionSessionLocal; IFlow flow = executionComponent.GetFlow(flowId); ViewData["activity"] = flow.Node; ViewData["processDefinition"] = flow.ProcessInstance.ProcessDefinition; ViewData["preview"] = "activity"; //AddImageCoordinates((IState)flow.Node); //create Form IActivityForm activityForm = executionComponent.GetActivityForm(flowId); AddFormData(activityForm); } finally { ServiceLocator.Instance.Release(executionComponent); } return(View()); }
public void TestNotAccessibleAttributeInActivityState() { IProcessInstance processInstance = StartAttributeTestProcessInstance("ae", CreateNormalAttributeValues()); IActivityForm activityForm = executionComponent.GetActivityForm(processInstance.RootFlow.Id); //attribute values from activity state activity form should not contain not-accessible field attribute Assert.IsFalse(activityForm.AttributeValues.Contains("field not accessible")); /// Test when a read-only attribute is supplied to process definition's /// activity state. This read-only attribute should be available in the activity /// form obtained from activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field read only")); /// Test when a write-only attribute is supplied to process definition's /// activity state. This write-only attribute should be available in the activity /// form obtained from activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field write only")); /// Test when a write-only-required attribute is supplied to process definition's /// activity state. This write-only-required attribute should be available in the /// activity form obtained from activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field write only required")); /// Test when a read-write attribute is supplied to process definition's /// activity state. This read-write attribute should be available in the /// activity form obtained from activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field read write")); /// Test when a read-write-required attribute is supplied to process definition's /// activity state. This read-write-required should be available in the activity form /// obtained from activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field read write required")); }
public void StartProcessInstance(long processDefinitionId) { if (log.IsDebugEnabled) { log.Debug("StartProcessInstance processDefinitionId:" + processDefinitionId); } IExecutionSessionLocal executionComponent = null; IDefinitionSessionLocal definitionComponent = null; try { executionComponent = ServiceLocator.Instance.GetService(typeof(IExecutionSessionLocal)) as IExecutionSessionLocal; definitionComponent = ServiceLocator.Instance.GetService(typeof(IDefinitionSessionLocal)) as IDefinitionSessionLocal; IProcessDefinition processDefinition = definitionComponent.GetProcessDefinition(processDefinitionId); Context.Flash["activity"] = processDefinition.StartState; Context.Flash["processDefinition"] = processDefinition; Context.Flash["preview"] = "activity"; AddImageCoordinates(processDefinition.StartState); //create Form IActivityForm activityForm = executionComponent.GetStartForm(processDefinitionId); AddFormData(activityForm); RenderView("activityForm"); } finally { ServiceLocator.Instance.Release(executionComponent); ServiceLocator.Instance.Release(definitionComponent); } }
public void TestNotAccessibleAttributeInStartState() { IProcessDefinition processDefinition = definitionComponent.GetProcessDefinition("attribute test"); IActivityForm startActivityForm = executionComponent.GetStartForm(processDefinition.Id); IDictionary startActivityFormAttributeValues = startActivityForm.AttributeValues; //attribute values from start state activity form should not contain not accessible field attribute Assert.IsFalse(startActivityFormAttributeValues.Contains("field not accessible")); Assert.IsTrue(startActivityFormAttributeValues.Contains("field read only")); Assert.IsTrue(startActivityFormAttributeValues.Contains("field write only")); Assert.IsTrue(startActivityFormAttributeValues.Contains("field write only required")); Assert.IsTrue(startActivityFormAttributeValues.Contains("field read write")); Assert.IsTrue(startActivityFormAttributeValues.Contains("field read write required")); }
private void AddFormData(IActivityForm activityForm) { IDictionary userInputFields = (IDictionary)HttpContext.Session["userInputFields"]; if (userInputFields == null) { userInputFields = new Hashtable(); } HttpContext.Session.Add("activityForm", activityForm); IList fields = activityForm.Fields; IEnumerator fildEnumer = fields.GetEnumerator(); IList formRows = new ArrayList(); 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); IHtmlFormatter htmlFormatter = field.GetHtmlFormatter(); if (htmlFormatter != null) { Object objectToFormat = null; if (userInputFields.Contains(attributeName)) { objectToFormat = userInputFields[attributeName]; } else { objectToFormat = activityForm.AttributeValues[field.Attribute.Name]; } // TODO: Test if there is the possibility to simplify the interface, see null String html = htmlFormatter.ObjectToHtml(objectToFormat, parameterName, null); FormRow formRow = new FormRow(field, html); formRows.Add(formRow); } else { //log.Warn("skipping field for attribute '" + attributeName + "' because it doesn't have a HtmlFormatter"); } } ViewData["formRows"] = formRows; }
public virtual IActivityForm GetActivityForm(Int64 flowId) { IActivityForm activityForm = null; DbSession dbSession = null; IOrganisationService organisationComponent = null; try { dbSession = OpenSession(); organisationComponent = (IOrganisationService)ServiceLocator.Instance.GetService(typeof(IOrganisationService)); activityForm = implementation.GetActivityForm(ActorId, flowId, dbSession, organisationComponent); ServiceLocator.Instance.Release(organisationComponent); } finally { ServiceLocator.Instance.Release(organisationComponent); } return(activityForm); }
public void TestNotAccessibleAttributeInConcurrentBlock() { IProcessInstance processInstance = StartAttributeTestProcessInstance("ae", CreateNormalAttributeValues()); IList flows = testUtil.PerformActivity("ae", processInstance.RootFlow.Id, 0, CreateNormalAttributeValues(), executionComponent); // get the first flow (should be enough) Maybe test the second flow as well??? IEnumerator flowEnum = flows.GetEnumerator(); while (flowEnum.MoveNext()) { IFlow flow = (IFlow)flowEnum.Current; IActivityForm activityForm = executionComponent.GetActivityForm(flow.Id); //attribute values from concurrent block activity state activity form should not contain not-accessible field attribute Assert.IsFalse(activityForm.AttributeValues.Contains("field not accessible")); /// Test when a read-only attribute is supplied to process definition's /// concurrent-block's activity state. This read-only attribute should be available /// in the activity form obtained from concurrent-block's activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field read only")); /// Test when a write-only attribute is supplied to process definition's /// concurrent-block's activity state. This write-only attribute should be available /// in the activity form obtained from concurrent-block's activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field write only")); /// Test when a write-only-required attribute is supplied to process definition's /// concurrent-block's activity state. This write-only-required attribute should be /// available in the activity form obtained from concurrent-block's activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field write only required")); /// Test when a read-write attribute is supplied to process definition's /// concurrent-block's activity state. This read-write attribute should be /// available in the activity form obtained form concurrent-block's activity state Assert.IsTrue(activityForm.AttributeValues.Contains("field read write")); /// Test when a read-write-required is supplied to process definition's /// concurrent-block's activity state. This read-write-required attribute should be /// available in the activity form obtained from concurrent-block's activity state. Assert.IsTrue(activityForm.AttributeValues.Contains("field read write required")); } }
//private const String queryFieldsByState = "select f from f in class NetBpm.Workflow.Definition.Impl.FieldImpl " + // "where f.State.Id = ? " + // "order by f.Index"; public IActivityForm GetStartForm(String authenticatedActorId, Int64 processDefinitionId, DbSession dbSession, IOrganisationService organisationComponent) { IActivityForm activityForm = null; // First check if the actor is allowed to get this form authorizationHelper.CheckGetStartForm(authenticatedActorId, processDefinitionId, dbSession); ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)dbSession.Load(typeof(ProcessDefinitionImpl), processDefinitionId); StartStateImpl startState = (StartStateImpl)processDefinition.StartState; // create a convenient map from the attribute-names to the fields IList fields = fieldRepository.FindFieldsByState(startState.Id, dbSession); IDictionary attributeValues = new Hashtable(); IEnumerator iter = fields.GetEnumerator(); while (iter.MoveNext()) { FieldImpl field = (FieldImpl)iter.Current; // if the attribute has an initial value AttributeImpl attribute = (AttributeImpl)field.Attribute; String attributeName = attribute.Name; String initialValue = attribute.InitialValue; if ((Object)initialValue != null && (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access))) { // start form contains only fields that are readable or writable // get it and store it in the attributeValues AttributeInstanceImpl attributeInstance = new AttributeInstanceImpl(); attributeInstance.Attribute = attribute; attributeInstance.ValueText = initialValue; attributeValues[attributeName] = attributeInstance.GetValue(); } } activityForm = new ActivityFormImpl(processDefinition, 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 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")); } } }
private void AddFormData(IActivityForm activityForm) { IDictionary userInputFields = (IDictionary)Context.Session["userInputFields"]; if (userInputFields == null) { userInputFields = new Hashtable(); } Context.Session.Add("activityForm",activityForm); IList fields = activityForm.Fields; IEnumerator fildEnumer = fields.GetEnumerator(); IList formRows = new ArrayList(); 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); IHtmlFormatter htmlFormatter = field.GetHtmlFormatter(); if (htmlFormatter != null) { Object objectToFormat = null; if (userInputFields.Contains(attributeName)) { objectToFormat = userInputFields[attributeName]; } else { objectToFormat = activityForm.AttributeValues[field.Attribute.Name]; } // TODO: Test if there is the possibility to simplify the interface, see null String html = htmlFormatter.ObjectToHtml( objectToFormat, parameterName, null); FormRow formRow = new FormRow(field,html); formRows.Add(formRow); } else { log.Warn( "skipping field for attribute '" + attributeName + "' because it doesn't have a HtmlFormatter" ); } } Context.Flash["formRows"] = formRows; }