use of org.motechproject.mds.domain.TypeValidation in project motech by motech.
the class EntityServiceImpl method createFieldForDraft.
private void createFieldForDraft(EntityDraft draft, DraftData draftData) {
String typeClass = draftData.getValue(DraftData.TYPE_CLASS).toString();
String displayName = draftData.getValue(DraftData.DISPLAY_NAME).toString();
String name = draftData.getValue(DraftData.NAME).toString();
Type type = ("textArea".equalsIgnoreCase(typeClass)) ? allTypes.retrieveByClassName("java.lang.String") : allTypes.retrieveByClassName(typeClass);
if (type == null) {
throw new NoSuchTypeException(typeClass);
}
Set<Lookup> fieldLookups = new HashSet<>();
Field field = new Field(draft, name, displayName, fieldLookups);
field.setType(type);
if (type.hasSettings()) {
for (TypeSetting setting : type.getSettings()) {
field.addSetting(new FieldSetting(field, setting));
}
}
if (type.hasValidation()) {
for (TypeValidation validation : type.getValidations()) {
field.addValidation(new FieldValidation(field, validation));
}
}
if (TypeDto.BLOB.getTypeClass().equals(typeClass)) {
field.setUIDisplayable(false);
} else {
field.setUIDisplayable(true);
field.setUIDisplayPosition((long) draft.getFields().size());
}
if ("textArea".equalsIgnoreCase(typeClass)) {
setSettingForTextArea(field);
}
FieldHelper.addMetadataForRelationship(typeClass, field);
FieldHelper.addOrUpdateMetadataForCombobox(field);
draft.addField(field);
allEntityDrafts.update(draft);
}
use of org.motechproject.mds.domain.TypeValidation 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.TypeValidation in project motech by motech.
the class TypeServiceImpl method findValidations.
@Override
@Transactional
public List<TypeValidation> findValidations(TypeDto type, Class<? extends Annotation> aClass) {
Type typeSource = allTypes.retrieveByClassName(type.getTypeClass());
List<TypeValidation> list = null == typeSource ? new ArrayList<>() : typeSource.getValidations();
List<TypeValidation> validations = new ArrayList<>();
for (TypeValidation validation : list) {
if (validation.getAnnotations().contains(aClass)) {
validations.add(validation);
}
}
return validations;
}
use of org.motechproject.mds.domain.TypeValidation 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