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 void CheckAccess(IDictionary attributeValues, StateImpl state) { IDictionary fields = new Hashtable(); // first we check if a value is supplied for all required fields IEnumerator iter = state.Fields.GetEnumerator(); log.Debug(iter); while (iter.MoveNext()) { FieldImpl field = (FieldImpl)iter.Current; String attributeName = field.Attribute.Name; fields[attributeName] = field; // if a field is found required and no attribute value is supplied throw // RequiredFieldException log.Debug(field); log.Debug(field.Access); if ((FieldAccessHelper.IsRequired(field.Access)) && (attributeValues == null)) { throw new RequiredFieldException(field); } // OR // if field is found required and attribute value of it is not available // throw RequiredFieldException if ((FieldAccessHelper.IsRequired(field.Access)) && (attributeValues != null) && (!attributeValues.Contains(attributeName))) { throw new RequiredFieldException(field); } } // then we check if the access of all supplied values is writable IList attributeNamesToBeRemoved = new ArrayList(); // store attribute name of attribute to be removed if (attributeValues != null) { iter = attributeValues.GetEnumerator(); while (iter.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)iter.Current; String attributeName = (String)entry.Key; FieldImpl field = (FieldImpl)fields[attributeName]; if ((field != null) && (!FieldAccessHelper.IsWritable(field.Access))) { log.Warn("ignoring attributeValue for unwritable attribute '" + attributeName + "'"); // commented out cause will result in ConcurrentModificationException // instead copy its attribute name and remove later OR do a deep copy of the // attributeValues so there is one set that gets iterated and another that //gets deleted??? //attributeValues.remove( attributeName ); attributeNamesToBeRemoved.Add(attributeName); } } // now removed collected to be removed attribute IEnumerator itr = attributeNamesToBeRemoved.GetEnumerator(); while (itr.MoveNext()) { String an = (String)itr.Current; attributeValues.Remove(an); } } }
//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); }