Search in sources :

Example 1 with SettingDto

use of org.motechproject.mds.dto.SettingDto in project motech by motech.

the class FieldRecordTest method shouldHandleSingleSelectComboBoxes.

@Test
public void shouldHandleSingleSelectComboBoxes() {
    FieldDto fieldDto = FieldTestHelper.fieldDto(1L, "name", List.class.getName(), "disp", "[one, two]");
    fieldDto.setSettings(asList(new SettingDto(COMBOBOX_VALUES, asList("one", "two", "three"), null, null)));
    FieldRecord fieldRecord = new FieldRecord(fieldDto);
    fieldRecord.setValue("[two]");
    assertEquals("two", fieldRecord.getValue());
    fieldRecord.setValue("test");
    assertEquals("test", fieldRecord.getValue());
    // test with enum
    fieldRecord.setValue(TestEnum.TWO);
    assertEquals("TWO", fieldRecord.getValue());
    fieldRecord.setValue(asList(TestEnum.ONE));
    assertEquals("ONE", fieldRecord.getValue());
    fieldRecord.setValue(null);
    assertNull(fieldRecord.getValue());
}
Also used : List(java.util.List) Arrays.asList(java.util.Arrays.asList) SettingDto(org.motechproject.mds.dto.SettingDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 2 with SettingDto

use of org.motechproject.mds.dto.SettingDto in project motech by motech.

the class FieldProcessor method createRelationshipSettings.

private List<SettingDto> createRelationshipSettings(AccessibleObject ac) {
    Cascade cascade = ReflectionsUtil.getAnnotationSelfOrAccessor(ac, Cascade.class);
    boolean persist = parseBoolean(getAnnotationValue(cascade, PERSIST, TRUE.toString()));
    boolean update = parseBoolean(getAnnotationValue(cascade, UPDATE, TRUE.toString()));
    boolean delete = parseBoolean(getAnnotationValue(cascade, DELETE, FALSE.toString()));
    List<SettingDto> list = new ArrayList<>();
    list.add(new SettingDto(Constants.Settings.CASCADE_PERSIST, persist));
    list.add(new SettingDto(Constants.Settings.CASCADE_UPDATE, update));
    list.add(new SettingDto(Constants.Settings.CASCADE_DELETE, delete));
    return list;
}
Also used : ArrayList(java.util.ArrayList) SettingDto(org.motechproject.mds.dto.SettingDto) Cascade(org.motechproject.mds.annotations.Cascade)

Example 3 with SettingDto

use of org.motechproject.mds.dto.SettingDto in project motech by motech.

the class EntityMetadataBuilderImpl method addColumnMetadata.

private void addColumnMetadata(FieldMetadata fmd, FieldDto field, Value valueAnnotation) {
    SettingDto maxLengthSetting = field.getSetting(Constants.Settings.STRING_MAX_LENGTH);
    ColumnMetadata colMd = fmd.newColumnMetadata();
    // text(clob) fields don't have length
    if (maxLengthSetting != null && !isClob(field)) {
        colMd.setLength(Integer.parseInt(maxLengthSetting.getValueAsString()));
    }
    // if TextArea then change length
    if (field.getSetting(Constants.Settings.STRING_TEXT_AREA) != null && "true".equalsIgnoreCase(field.getSetting(Constants.Settings.STRING_TEXT_AREA).getValueAsString())) {
        fmd.setIndexed(false);
        colMd.setSQLType("CLOB");
    }
    if (field.getMetadata(DATABASE_COLUMN_NAME) != null) {
        colMd.setName(field.getMetadata(DATABASE_COLUMN_NAME).getValue());
    }
    if (valueAnnotation != null) {
        copyParametersFromValueAnnotation(fmd, valueAnnotation);
    }
}
Also used : ColumnMetadata(javax.jdo.metadata.ColumnMetadata) SettingDto(org.motechproject.mds.dto.SettingDto)

Example 4 with SettingDto

use of org.motechproject.mds.dto.SettingDto 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);
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) SettingDto(org.motechproject.mds.dto.SettingDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 5 with SettingDto

use of org.motechproject.mds.dto.SettingDto in project motech by motech.

the class MdsBundleIT method createEntityForPreferencesTest.

private EntityDto createEntityForPreferencesTest() {
    EntityDto entityDto = new EntityDto(null, FOO);
    entityDto = entityService.createEntity(entityDto);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    List<FieldDto> fields = new ArrayList<>();
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString"), false, false, false, false, false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Some Integer", "someInteger"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Other Integer", "otherInteger"), false, false, false, false, false, null, null, null, null));
    entityService.addFields(entityDto, fields);
    Map<String, Long> displayedFields = new HashMap<>();
    displayedFields.put("someInteger", 1L);
    displayedFields.put("someBoolean", 2L);
    displayedFields.put("someString", 3L);
    entityService.addDisplayedFields(entityDto, displayedFields);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    return entityDto;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

SettingDto (org.motechproject.mds.dto.SettingDto)19 FieldDto (org.motechproject.mds.dto.FieldDto)11 ArrayList (java.util.ArrayList)8 MetadataDto (org.motechproject.mds.dto.MetadataDto)6 Test (org.junit.Test)5 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)4 Method (java.lang.reflect.Method)3 List (java.util.List)3 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)3 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 EntityDto (org.motechproject.mds.dto.EntityDto)2 FieldValidationDto (org.motechproject.mds.dto.FieldValidationDto)2 LookupDto (org.motechproject.mds.dto.LookupDto)2 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)2 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1