Exemple #1
0
        protected internal virtual void parseValidation(Element formField, FormFieldHandler formFieldHandler, BpmnParse bpmnParse, ExpressionManager expressionManager)
        {
            Element validationElement = formField.elementNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "validation");

            if (validationElement != null)
            {
                IList <Element> constraintElements = validationElement.elementsNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "constraint");

                foreach (Element property in constraintElements)
                {
                    FormFieldValidator validator = Context.ProcessEngineConfiguration.FormValidators.createValidator(property, bpmnParse, expressionManager);

                    string validatorName   = property.attribute("name");
                    string validatorConfig = property.attribute("config");

                    if (validator != null)
                    {
                        FormFieldValidationConstraintHandler handler = new FormFieldValidationConstraintHandler();
                        handler.Name      = validatorName;
                        handler.Config    = validatorConfig;
                        handler.Validator = validator;
                        formFieldHandler.ValidationHandlers.Add(handler);
                    }
                }
            }
        }
Exemple #2
0
 public DefaultFormFieldValidatorContext(VariableScope variableScope, string configuration, VariableMap submittedValues, FormFieldHandler formFieldHandler) : base()
 {
     this.variableScope    = variableScope;
     this.configuration    = configuration;
     this.submittedValues  = submittedValues;
     this.formFieldHandler = formFieldHandler;
 }
Exemple #3
0
        protected internal virtual void parseFormField(Element formField, BpmnParse bpmnParse, ExpressionManager expressionManager)
        {
            FormFieldHandler formFieldHandler = new FormFieldHandler();

            // parse Id
            string id = formField.attribute("id");

            if (string.ReferenceEquals(id, null) || id.Length == 0)
            {
                bpmnParse.addError("attribute id must be set for FormFieldGroup and must have a non-empty value", formField);
            }
            else
            {
                formFieldHandler.Id = id;
            }

            if (id.Equals(businessKeyFieldId))
            {
                formFieldHandler.BusinessKey = true;
            }

            // parse name
            string name = formField.attribute("label");

            if (!string.ReferenceEquals(name, null))
            {
                Expression nameExpression = expressionManager.createExpression(name);
                formFieldHandler.Label = nameExpression;
            }

            // parse properties
            parseProperties(formField, formFieldHandler, bpmnParse, expressionManager);

            // parse validation
            parseValidation(formField, formFieldHandler, bpmnParse, expressionManager);

            // parse type
            FormTypes             formTypes = FormTypes;
            AbstractFormFieldType formType  = formTypes.parseFormPropertyType(formField, bpmnParse);

            formFieldHandler.setType(formType);

            // parse default value
            string defaultValue = formField.attribute("defaultValue");

            if (!string.ReferenceEquals(defaultValue, null))
            {
                Expression defaultValueExpression = expressionManager.createExpression(defaultValue);
                formFieldHandler.DefaultValueExpression = defaultValueExpression;
            }

            formFieldHandlers.Add(formFieldHandler);
        }
Exemple #4
0
        protected internal virtual void parseProperties(Element formField, FormFieldHandler formFieldHandler, BpmnParse bpmnParse, ExpressionManager expressionManager)
        {
            Element propertiesElement = formField.elementNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "properties");

            if (propertiesElement != null)
            {
                IList <Element> propertyElements = propertiesElement.elementsNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, "property");

                // use linked hash map to preserve item ordering as provided in XML
                IDictionary <string, string> propertyMap = new LinkedHashMap <string, string>();
                foreach (Element property in propertyElements)
                {
                    string id    = property.attribute("id");
                    string value = property.attribute("value");
                    propertyMap[id] = value;
                }

                formFieldHandler.Properties = propertyMap;
            }
        }
Exemple #5
0
        // submit /////////////////////////////////

        public virtual void validate(object submittedValue, VariableMap submittedValues, FormFieldHandler formFieldHandler, VariableScope variableScope)
        {
            try
            {
                FormFieldValidatorContext context = new DefaultFormFieldValidatorContext(variableScope, config, submittedValues, formFieldHandler);
                if (!validator.validate(submittedValue, context))
                {
                    throw new FormFieldValidatorException(formFieldHandler.Id, name, config, submittedValue, "Invalid value submitted for form field '" + formFieldHandler.Id + "': validation of " + this + " failed.");
                }
            }
            catch (FormFieldValidationException e)
            {
                throw new FormFieldValidatorException(formFieldHandler.Id, name, config, submittedValue, "Invalid value submitted for form field '" + formFieldHandler.Id + "': validation of " + this + " failed.", e);
            }
        }