use of org.motechproject.mds.dto.ValidationCriterionDto in project motech by motech.
the class FieldProcessorTest method assertCriterion.
private void assertCriterion(FieldDto field, String displayName, String value) {
ValidationCriterionDto dto = field.getValidation().getCriterion(displayName);
assertNotNull("Criterion " + displayName + " should exists", dto);
assertEquals(value, String.valueOf(dto.getValue()));
assertTrue("The validation criterion should be enabled", dto.isEnabled());
}
use of org.motechproject.mds.dto.ValidationCriterionDto 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.ValidationCriterionDto in project motech by motech.
the class Field method updateValidation.
private void updateValidation(FieldValidationDto validationDto) {
if (null != validationDto) {
for (ValidationCriterionDto criterionDto : validationDto.getCriteria()) {
FieldValidation validation = getValidationByName(criterionDto.getDisplayName());
if (null != validation) {
validation.setEnabled(criterionDto.isEnabled());
validation.setValue(criterionDto.valueAsString());
}
}
}
}
use of org.motechproject.mds.dto.ValidationCriterionDto in project motech by motech.
the class FieldValidation method toDto.
public ValidationCriterionDto toDto() {
Type valueType = details.getValueType();
ValidationCriterionDto dto = new ValidationCriterionDto();
dto.setDisplayName(details.getDisplayName());
dto.setType(valueType.toDto());
dto.setEnabled(enabled);
dto.setValue(valueType.parse(value));
return dto;
}
use of org.motechproject.mds.dto.ValidationCriterionDto 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);
}
Aggregations