Search in sources :

Example 1 with OptionsField

use of cern.modesti.schema.field.OptionsField in project modesti by jlsalmon.

the class CoreValidationService method isValidValue.

private boolean isValidValue(Object value, Point point, Field field) {
    // If the value is empty, it's technically not invalid.
    if (value == null || value.equals("")) {
        return true;
    }
    // If we have an options field, check that the value is in the list of options
    if (field.getType().equals("options")) {
        OptionsField optionsField = (OptionsField) field;
        List<Object> options = (List<Object>) optionsField.getOptions();
        if (options != null) {
            for (Object option : options) {
                option = option instanceof Map ? mapper.convertValue(option, Option.class).getValue() : option;
                if ((option instanceof Number) && (NumberUtils.isNumber(value.toString()))) {
                    if (new Double(option.toString()).equals(new Double(value.toString()))) {
                        return true;
                    }
                } else if (option.equals(value)) {
                    return true;
                }
            }
        }
        return false;
    } else // Otherwise, if we have an autocomplete field, make a call to the backend to see if this value returns any results
    if (field.getType().equals("autocomplete")) {
        String url = ((AutocompleteField) field).getUrl();
        return true;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Option(cern.modesti.schema.field.Option) OptionsField(cern.modesti.schema.field.OptionsField) Map(java.util.Map)

Aggregations

Option (cern.modesti.schema.field.Option)1 OptionsField (cern.modesti.schema.field.OptionsField)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1