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());
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations