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;
}
Aggregations