use of org.motechproject.mds.dto.ValidationCriterionDto in project motech by motech.
the class FieldProcessor method createValidation.
private FieldValidationDto createValidation(AccessibleObject ac, TypeDto type) {
FieldValidationDto validationDto = null;
for (Annotation annotation : ac.getAnnotations()) {
List<TypeValidationDto> validations = getSchemaHolder().findValidations(type.getTypeClass(), annotation.annotationType());
for (TypeValidationDto validation : validations) {
String displayName = validation.getDisplayName();
TypeDto valueType = getSchemaHolder().getType(validation.getValueType());
if (null == valueType) {
throw new IllegalStateException("The valueType is not set in: " + validation);
}
String valueAsString = getValidationValue(displayName, annotation);
if (InSet.class.isAssignableFrom(annotation.annotationType()) || NotInSet.class.isAssignableFrom(annotation.annotationType())) {
valueAsString = valueAsString.replaceAll("(\\{|\\})", "");
}
Object value = TypeHelper.parse(valueAsString, valueType.getClassObjectForType());
ValidationCriterionDto dto = new ValidationCriterionDto();
dto.setDisplayName(displayName);
dto.setType(valueType);
dto.setEnabled(true);
dto.setValue(value);
if (null == validationDto) {
validationDto = new FieldValidationDto();
}
validationDto.addCriterion(dto);
}
}
return validationDto;
}
Aggregations