use of org.motechproject.mds.dto.SettingDto in project motech by motech.
the class FieldSetting method toDto.
public SettingDto toDto() {
List<SettingOptions> options = new ArrayList<>();
if (details.getTypeSettingOptions() != null) {
for (TypeSettingOption option : details.getTypeSettingOptions()) {
options.add(SettingOptions.valueOf(option.getName()));
}
}
Type valueType = details.getValueType();
SettingDto dto = new SettingDto();
dto.setType(valueType.toDto());
dto.setValue(valueType.parse(value));
dto.setName(details.getName());
dto.setOptions(options);
return dto;
}
use of org.motechproject.mds.dto.SettingDto 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);
}
use of org.motechproject.mds.dto.SettingDto in project motech by motech.
the class EntityBuilderTest method shouldBuildAnEntityWithFields.
@Test
public void shouldBuildAnEntityWithFields() throws Exception {
FieldDto enumListField = fieldDto("enumList", List.class);
enumListField.addMetadata(new MetadataDto(Constants.MetadataKeys.ENUM_CLASS_NAME, FieldEnum.class.getName()));
enumListField.getType().setDisplayName("mds.field.combobox");
enumListField.addSetting(new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, "true"));
fields.addAll(asList(fieldDto("count", Integer.class), fieldDto("time", Time.class), fieldDto("str", String.class), fieldDto("dec", Double.class), fieldDto("bool", Boolean.class), fieldDto("date", Date.class), fieldDto("dt", DateTime.class), fieldDto("ld", LocalDate.class), fieldDto("locale", Locale.class), enumListField, fieldDto("CapitalizedName", String.class), fieldDto("jd", java.time.LocalDate.class), fieldDto("jdt", LocalDateTime.class), fieldDto("blob", Byte[].class.getName())));
Class<?> clazz = buildClass();
assertNotNull(clazz);
assertField(clazz, "count", Integer.class);
assertField(clazz, "time", Time.class);
assertField(clazz, "str", String.class);
assertField(clazz, "dec", Double.class);
assertField(clazz, "bool", Boolean.class);
assertField(clazz, "date", Date.class);
assertField(clazz, "dt", DateTime.class);
assertField(clazz, "ld", LocalDate.class);
assertField(clazz, "locale", Locale.class);
assertField(clazz, "jd", java.time.LocalDate.class);
assertField(clazz, "jdt", LocalDateTime.class);
assertField(clazz, "blob", Byte[].class);
// should use uncapitalized version
assertField(clazz, "capitalizedName", String.class);
}
use of org.motechproject.mds.dto.SettingDto in project motech by motech.
the class EntityBuilderTest method shouldBuildEnumListFieldProperly.
@Test
public void shouldBuildEnumListFieldProperly() throws Exception {
FieldDto enumListField = fieldDto("enumList", Collection.class);
enumListField.addMetadata(new MetadataDto(Constants.MetadataKeys.ENUM_CLASS_NAME, FieldEnum.class.getName()));
enumListField.addSetting(new SettingDto(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS, "true"));
fields.add(enumListField);
Class<?> clazz = buildClass();
assertNotNull(clazz);
assertField(clazz, "enumList", List.class);
// verify that getters and setters have correct generic signatures
Method setter = clazz.getDeclaredMethod("setEnumList", List.class);
assertNotNull(setter);
ParameterizedType pType = (ParameterizedType) setter.getGenericParameterTypes()[0];
assertEquals(FieldEnum.class, pType.getActualTypeArguments()[0]);
Method getter = clazz.getDeclaredMethod("getEnumList");
assertNotNull(getter);
pType = (ParameterizedType) getter.getGenericReturnType();
assertEquals(FieldEnum.class, pType.getActualTypeArguments()[0]);
}
use of org.motechproject.mds.dto.SettingDto in project motech by motech.
the class FieldProcessorTest method shouldReadMaxLengthForStringField.
@Test
public void shouldReadMaxLengthForStringField() {
Method getLength400 = getAccessibleMethod(Sample.class, "getLength400", new Class[0]);
processor.process(getLength400);
Collection<FieldDto> fields = processor.getElements();
assertEquals(1, fields.size());
FieldDto field = fields.iterator().next();
assertEquals("length400", field.getBasic().getName());
SettingDto lengthSetting = field.getSetting(Constants.Settings.STRING_MAX_LENGTH);
assertNotNull(lengthSetting);
assertEquals(400, lengthSetting.getValue());
}
Aggregations