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