Example #1
0
 /// <summary>
 /// Gets corresponding validator for specific validation rule.
 /// </summary>
 /// <param name="rule">specific validation rule</param>
 /// <returns>corresponding validator</returns>
 public AFValidator getValidator(AFValidationRule rule)
 {
     if (rule.getValidationType().Equals(SupportedValidations.REQUIRED) && Utils.TryToConvertIntoBoolean(rule.getValue()))
     {
         return new RequiredValidator();
     }
     if (rule.getValidationType().Equals(SupportedValidations.MAXLENGTH))
     {
         return new MaxCharsValidator();
     }
     if (rule.getValidationType().Equals(SupportedValidations.MAX))
     {
         return new MaxValueValidator();
     }
     if (rule.getValidationType().Equals(SupportedValidations.MIN))
     {
         return new MinValueValidator();
     }
     if (rule.getValidationType().Equals(SupportedValidations.LESSTHAN))
     {
         return new LessThanValidator();
     }
     if (rule.getValidationType().Equals(SupportedValidations.NUMBER))
     {
         return new NumberValidator();
     }
     //not found
     return null;
 }
Example #2
0
 public void addRule(AFValidationRule rule)
 {
     if (rules == null)
     {
         rules = new List<AFValidationRule>();
     }
     rules.Add(rule);
 }
Example #3
0
        /// <summary>
        /// Parses information about one field in component.
        /// Exception thrown if there war error during parsing field info.
        /// </summary>
        /// <param name="field">field information wrapped in JSONObject</param>
        /// <returns>field info wrapped in AFFieldInfo object</returns>
        private AFFieldInfo parseFieldInfo(JsonObject field)
        {
            Debug.WriteLine("PARSING FIELD " + Utils.TryToGetValueFromJson(field[Constants.ID]));
            AFFieldInfo fieldInfo = new AFFieldInfo();
            try
            {
                fieldInfo.setWidgetType(Utils.ValueOf<SupportedWidgets>(typeof(SupportedWidgets), (String) Utils.TryToGetValueFromJson(field[Constants.WIDGET_TYPE])));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            fieldInfo.setId((String) Utils.TryToGetValueFromJson(field[Constants.ID]));

            fieldInfo.setLabelText((String) Utils.TryToGetValueFromJson(field[Constants.LABEL]));
            fieldInfo.setIsClass((Boolean) Utils.TryToGetValueFromJson(field[Constants.CLASS_TYPE]));
            fieldInfo.setVisible((Boolean) Utils.TryToGetValueFromJson(field[Constants.VISIBLE]));
            fieldInfo.setReadOnly((Boolean) Utils.TryToGetValueFromJson(field[Constants.READ_ONLY]));
            //field layout
            fieldInfo.setLayout(createLayoutProperties((JsonObject) Utils.TryToGetValueFromJson(field[Constants.LAYOUT])));
            //rules)
            JsonArray rules = (JsonArray) Utils.TryToGetValueFromJson(field[Constants.RULES]);
            if (rules != null)
            {
                for (int i = 0; i < rules.Count; i++)
                {
                    fieldInfo.addRule(createRule((JsonObject) Utils.TryToGetValueFromJson(rules[i])));
                }
            }
            //add number rule - it is not among others in json 
            try
            {
                if (fieldInfo.getWidgetType().Equals(SupportedWidgets.NUMBERFIELD) || fieldInfo.getWidgetType().Equals(SupportedWidgets.NUMBERDOUBLEFIELD))
                {
                    AFValidationRule numberRule = new AFValidationRule();
                    numberRule.setValidationType(SupportedValidations.NUMBER);
                    numberRule.setValue("");
                    fieldInfo.addRule(numberRule);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            //options
            JsonArray options = (JsonArray) Utils.TryToGetValueFromJson(field[Constants.OPTIONS]);
            if (options != null)
            {
                for (int i = 0; i < options.Count; i++)
                {
                    fieldInfo.addOption(createOption((JsonObject) Utils.TryToGetValueFromJson(options[i])));
                }
            }

            return fieldInfo;
        }
Example #4
0
 /// <summary>
 /// Parses and creates validation rule.
 /// Exception thrown if any error happened during parsing validation rule
 /// </summary>
 /// <param name="ruleJson">JSON object which contains info about validation rule</param>
 /// <returns>created validation rule</returns>
 private AFValidationRule createRule(JsonObject ruleJson)
 {
     AFValidationRule rule = new AFValidationRule();
     rule.setValidationType(Utils.ValueOf<SupportedValidations>(typeof(SupportedValidations), (String) Utils.TryToGetValueFromJson(ruleJson[Constants.VALIDATION_TYPE])));
     rule.setValue((String) Utils.TryToGetValueFromJson(ruleJson[Constants.VALUE]));
     return rule;
 }