Search in sources :

Example 6 with TypeSetting

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

the class AllTypesContextIT method assertType.

private void assertType(String displayName, String description, String className, List<String> settings, List<String> validations) {
    Type type = allTypes.retrieveByClassName(className);
    assertNotNull("Not found type with class name: " + className, type);
    assertNotNull("Type should have id", type.getId());
    assertEquals(displayName, type.getDisplayName());
    assertEquals(description, type.getDescription());
    assertEquals(className, type.getTypeClassName());
    assertEquals("Field " + displayName + " settings: ", null != settings, type.hasSettings());
    assertEquals("Field " + displayName + " validations: ", null != validations, type.hasValidation());
    if (null != settings) {
        List<TypeSetting> typeSettings = type.getSettings();
        List<String> strings = new ArrayList<>();
        for (TypeSetting typeSetting : typeSettings) {
            strings.add(typeSetting.getName());
        }
        Collections.sort(settings);
        Collections.sort(strings);
        assertEquals(settings, strings);
    }
    if (null != validations) {
        List<TypeValidation> typeValidations = type.getValidations();
        List<String> strings = new ArrayList<>();
        for (TypeValidation typeValidation : typeValidations) {
            strings.add(typeValidation.getDisplayName());
        }
        Collections.sort(validations);
        Collections.sort(strings);
        assertEquals(validations, strings);
    }
}
Also used : Type(org.motechproject.mds.domain.Type) TypeValidation(org.motechproject.mds.domain.TypeValidation) TypeSetting(org.motechproject.mds.domain.TypeSetting) ArrayList(java.util.ArrayList)

Example 7 with TypeSetting

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

the class AllTypeSettingsContextIT method assertTypeSetting.

private void assertTypeSetting(List<TypeSetting> typeSettings, String name, List<String> typeSettingOptions, Class<?> typeClass, String defaultValue) {
    TypeSetting typeSetting = retrieveByName(typeSettings, name);
    assertNotNull("Not found type setting with name: " + name, typeSetting);
    assertNotNull("Type setting should have id", typeSetting.getId());
    assertEquals(name, typeSetting.getName());
    List<TypeSettingOption> options = typeSetting.getTypeSettingOptions();
    List<String> optionsNames = new ArrayList<>();
    for (TypeSettingOption option : options) {
        optionsNames.add(option.getName());
    }
    assertEquals(typeSettingOptions, optionsNames);
    assertEquals(typeClass, typeSetting.getValueType().getTypeClass());
    assertEquals(defaultValue, typeSetting.getDefaultValue());
}
Also used : TypeSettingOption(org.motechproject.mds.domain.TypeSettingOption) TypeSetting(org.motechproject.mds.domain.TypeSetting) ArrayList(java.util.ArrayList)

Example 8 with TypeSetting

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

TypeSetting (org.motechproject.mds.domain.TypeSetting)8 Type (org.motechproject.mds.domain.Type)7 Field (org.motechproject.mds.domain.Field)6 FieldSetting (org.motechproject.mds.domain.FieldSetting)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)3 Entity (org.motechproject.mds.domain.Entity)3 Lookup (org.motechproject.mds.domain.Lookup)3 TypeValidation (org.motechproject.mds.domain.TypeValidation)3 ArrayList (java.util.ArrayList)2 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)2 FieldValidation (org.motechproject.mds.domain.FieldValidation)2 Range (org.motechproject.commons.api.Range)1 ClassData (org.motechproject.mds.domain.ClassData)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 EntityDraft (org.motechproject.mds.domain.EntityDraft)1 MdsEntity (org.motechproject.mds.domain.MdsEntity)1 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)1 TypeSettingOption (org.motechproject.mds.domain.TypeSettingOption)1 DraftData (org.motechproject.mds.dto.DraftData)1