use of org.motechproject.mds.dto.FieldValidationDto in project motech by motech.
the class Field method toDto.
public FieldDto toDto() {
FieldBasicDto basic = new FieldBasicDto(displayName, name, required, unique, parseDefaultValue(), tooltip, placeholder);
TypeDto typeDto = null;
List<MetadataDto> metaDto = new ArrayList<>();
for (FieldMetadata meta : metadata) {
metaDto.add(meta.toDto());
}
FieldValidationDto validationDto = null;
if (CollectionUtils.isNotEmpty(validations)) {
validationDto = new FieldValidationDto();
for (FieldValidation validation : validations) {
validationDto.addCriterion(validation.toDto());
}
}
List<SettingDto> settingsDto = new ArrayList<>();
for (FieldSetting setting : settings) {
settingsDto.add(setting.toDto());
}
List<LookupDto> lookupDtos = new ArrayList<>();
for (Lookup lookup : getLookups()) {
lookupDtos.add(lookup.toDto());
}
if (typeDto == null && type != null) {
typeDto = type.toDto();
}
return new FieldDto(id, entity == null ? null : entity.getId(), typeDto, basic, readOnly, nonEditable, nonDisplayable, uiFilterable, uiChanged, metaDto, validationDto, settingsDto, lookupDtos);
}
use of org.motechproject.mds.dto.FieldValidationDto in project motech by motech.
the class FieldHelperTest method fieldDto.
private FieldDto fieldDto() {
TypeDto type = new TypeDto("typeDispName", "typeDesc", "typeDefaultName", "typeClass");
FieldBasicDto basic = new FieldBasicDto("fieldDispName", "fieldName", true, false, "defVal", "tooltip", "placeholder");
MetadataDto metadata = new MetadataDto("key", "val");
ValidationCriterionDto criterion = new ValidationCriterionDto("criterionDispName", type);
FieldValidationDto validation = new FieldValidationDto(criterion);
return new FieldDto(1L, 100L, type, basic, false, new ArrayList<>(asList(metadata)), validation, null, null);
}
use of org.motechproject.mds.dto.FieldValidationDto in project motech by motech.
the class EntityServiceImpl method addField.
private void addField(Entity entity, FieldDto fieldDto) {
FieldBasicDto basic = fieldDto.getBasic();
String typeClass = fieldDto.getType().getTypeClass();
Type type = allTypes.retrieveByClassName(typeClass);
Field field = new Field(entity, basic.getName(), basic.getDisplayName(), basic.isRequired(), basic.isUnique(), fieldDto.isReadOnly(), fieldDto.isNonEditable(), fieldDto.isNonDisplayable(), (String) basic.getDefaultValue(), basic.getTooltip(), basic.getPlaceholder(), null);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
SettingDto settingDto = fieldDto.getSetting(setting.getName());
FieldSetting fieldSetting = new FieldSetting(field, setting);
if (null != settingDto) {
fieldSetting.setValue(settingDto.getValueAsString());
}
field.addSetting(fieldSetting);
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
FieldValidation fieldValidation = new FieldValidation(field, validation);
FieldValidationDto validationDto = fieldDto.getValidation();
if (null != validationDto) {
ValidationCriterionDto criterion = validationDto.getCriterion(validation.getDisplayName());
if (null != criterion) {
fieldValidation.setValue(criterion.valueAsString());
fieldValidation.setEnabled(criterion.isEnabled());
}
}
field.addValidation(fieldValidation);
}
}
for (MetadataDto metadata : fieldDto.getMetadata()) {
field.addMetadata(new FieldMetadata(metadata));
}
entity.addField(field);
}
use of org.motechproject.mds.dto.FieldValidationDto 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