Search in sources :

Example 1 with FieldValidation

use of org.motechproject.mds.domain.FieldValidation in project motech by motech.

the class FieldReader method readValidations.

private void readValidations(Field field) throws IOException {
    objectReader.expect("validations");
    jsonReader.beginArray();
    while (jsonReader.hasNext()) {
        FieldValidation validation = new FieldValidation();
        validation.setField(field);
        jsonReader.beginObject();
        validation.setDetails(getTypeValidation(field.getType(), objectReader.readString("key")));
        validation.setValue(objectReader.readString("value"));
        validation.setEnabled(objectReader.readBoolean("enabled"));
        jsonReader.endObject();
        field.addValidation(validation);
    }
    jsonReader.endArray();
}
Also used : FieldValidation(org.motechproject.mds.domain.FieldValidation)

Example 2 with FieldValidation

use of org.motechproject.mds.domain.FieldValidation in project motech by motech.

the class FieldWriter method writeValidations.

private void writeValidations(List<FieldValidation> validations) throws IOException {
    jsonWriter.name("validations");
    jsonWriter.beginArray();
    for (FieldValidation validation : validations) {
        jsonWriter.beginObject();
        jsonWriter.name("key").value(validation.getDetails().getDisplayName());
        jsonWriter.name("value").value(validation.getValue());
        jsonWriter.name("enabled").value(validation.isEnabled());
        jsonWriter.endObject();
    }
    jsonWriter.endArray();
}
Also used : FieldValidation(org.motechproject.mds.domain.FieldValidation)

Example 3 with FieldValidation

use of org.motechproject.mds.domain.FieldValidation in project motech by motech.

the class EntityServiceImpl method createFieldForDraft.

private void createFieldForDraft(EntityDraft draft, DraftData draftData) {
    String typeClass = draftData.getValue(DraftData.TYPE_CLASS).toString();
    String displayName = draftData.getValue(DraftData.DISPLAY_NAME).toString();
    String name = draftData.getValue(DraftData.NAME).toString();
    Type type = ("textArea".equalsIgnoreCase(typeClass)) ? allTypes.retrieveByClassName("java.lang.String") : allTypes.retrieveByClassName(typeClass);
    if (type == null) {
        throw new NoSuchTypeException(typeClass);
    }
    Set<Lookup> fieldLookups = new HashSet<>();
    Field field = new Field(draft, name, displayName, fieldLookups);
    field.setType(type);
    if (type.hasSettings()) {
        for (TypeSetting setting : type.getSettings()) {
            field.addSetting(new FieldSetting(field, setting));
        }
    }
    if (type.hasValidation()) {
        for (TypeValidation validation : type.getValidations()) {
            field.addValidation(new FieldValidation(field, validation));
        }
    }
    if (TypeDto.BLOB.getTypeClass().equals(typeClass)) {
        field.setUIDisplayable(false);
    } else {
        field.setUIDisplayable(true);
        field.setUIDisplayPosition((long) draft.getFields().size());
    }
    if ("textArea".equalsIgnoreCase(typeClass)) {
        setSettingForTextArea(field);
    }
    FieldHelper.addMetadataForRelationship(typeClass, field);
    FieldHelper.addOrUpdateMetadataForCombobox(field);
    draft.addField(field);
    allEntityDrafts.update(draft);
}
Also used : FieldSetting(org.motechproject.mds.domain.FieldSetting) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) TypeValidation(org.motechproject.mds.domain.TypeValidation) NoSuchTypeException(org.motechproject.mds.exception.type.NoSuchTypeException) TypeSetting(org.motechproject.mds.domain.TypeSetting) Lookup(org.motechproject.mds.domain.Lookup) FieldValidation(org.motechproject.mds.domain.FieldValidation) HashSet(java.util.HashSet)

Example 4 with FieldValidation

use of org.motechproject.mds.domain.FieldValidation 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

FieldValidation (org.motechproject.mds.domain.FieldValidation)4 Field (org.motechproject.mds.domain.Field)2 FieldSetting (org.motechproject.mds.domain.FieldSetting)2 Type (org.motechproject.mds.domain.Type)2 TypeSetting (org.motechproject.mds.domain.TypeSetting)2 TypeValidation (org.motechproject.mds.domain.TypeValidation)2 HashSet (java.util.HashSet)1 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)1 Lookup (org.motechproject.mds.domain.Lookup)1 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)1 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)1 MetadataDto (org.motechproject.mds.dto.MetadataDto)1 SettingDto (org.motechproject.mds.dto.SettingDto)1 ValidationCriterionDto (org.motechproject.mds.dto.ValidationCriterionDto)1 NoSuchTypeException (org.motechproject.mds.exception.type.NoSuchTypeException)1