Search in sources :

Example 1 with ValidationCriterionDto

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());
}
Also used : ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto)

Example 2 with ValidationCriterionDto

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);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 3 with ValidationCriterionDto

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());
            }
        }
    }
}
Also used : ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto)

Example 4 with ValidationCriterionDto

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;
}
Also used : IdentityType(javax.jdo.annotations.IdentityType) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto)

Example 5 with ValidationCriterionDto

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);
}
Also used : FieldMetadata(org.motechproject.mds.domain.FieldMetadata) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldSetting(org.motechproject.mds.domain.FieldSetting) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) TypeValidation(org.motechproject.mds.domain.TypeValidation) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) TypeSetting(org.motechproject.mds.domain.TypeSetting) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) SettingDto(org.motechproject.mds.dto.SettingDto) FieldValidation(org.motechproject.mds.domain.FieldValidation)

Aggregations

ValidationCriterionDto (org.motechproject.mds.dto.ValidationCriterionDto)6 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)3 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)2 MetadataDto (org.motechproject.mds.dto.MetadataDto)2 TypeDto (org.motechproject.mds.dto.TypeDto)2 Annotation (java.lang.annotation.Annotation)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 IdentityType (javax.jdo.annotations.IdentityType)1 InSet (org.motechproject.mds.annotations.InSet)1 NotInSet (org.motechproject.mds.annotations.NotInSet)1 Field (org.motechproject.mds.domain.Field)1 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)1 FieldSetting (org.motechproject.mds.domain.FieldSetting)1 FieldValidation (org.motechproject.mds.domain.FieldValidation)1 Type (org.motechproject.mds.domain.Type)1 TypeSetting (org.motechproject.mds.domain.TypeSetting)1 TypeValidation (org.motechproject.mds.domain.TypeValidation)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 SettingDto (org.motechproject.mds.dto.SettingDto)1 TypeValidationDto (org.motechproject.mds.dto.TypeValidationDto)1