use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class MDSConstructorImpl method buildClasses.
private Map<String, ClassData> buildClasses(List<EntityDto> entities, SchemaHolder schemaHolder) {
Map<String, ClassData> classDataMap = new LinkedHashMap<>();
// We build classes for all entities
for (EntityDto entity : entities) {
List<FieldDto> fields = schemaHolder.getFields(entity);
ClassData classData = buildClass(entity, fields);
ClassData historyClassData = null;
if (entity.isRecordHistory()) {
historyClassData = entityBuilder.buildHistory(entity, fields);
}
ClassData trashClassData = entityBuilder.buildTrash(entity, fields);
String className = entity.getClassName();
classDataMap.put(className, classData);
if (historyClassData != null) {
classDataMap.put(ClassName.getHistoryClassName(className), historyClassData);
}
classDataMap.put(ClassName.getTrashClassName(className), trashClassData);
}
return classDataMap;
}
use of org.motechproject.mds.dto.FieldDto 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.FieldDto in project motech by motech.
the class EntityServiceImpl method getLookupFieldsMapping.
@Override
@Transactional
public Map<String, FieldDto> getLookupFieldsMapping(Long entityId, String lookupName) {
Entity entity = allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
Lookup lookup = entity.getLookupByName(lookupName);
if (lookup == null) {
throw new LookupNotFoundException(entity.getName(), lookupName);
}
Map<String, FieldDto> fieldMap = new HashMap<>();
for (String lookupFieldName : lookup.getFieldsOrder()) {
Field field = lookup.getLookupFieldByName(LookupName.getFieldName(lookupFieldName));
if (lookupFieldName.contains(".")) {
Entity relatedEntity = allEntities.retrieveByClassName(field.getMetadata(Constants.MetadataKeys.RELATED_CLASS).getValue());
field = relatedEntity.getField(LookupName.getRelatedFieldName(lookupFieldName));
}
fieldMap.put(lookupFieldName, field.toDto());
}
return fieldMap;
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class EntityServiceImpl method removeFields.
private void removeFields(Entity entity, Collection<FieldDto> fields) {
Iterator<Field> iterator = entity.getFields().iterator();
while (iterator.hasNext()) {
Field field = iterator.next();
// don't remove user defined fields
if (!field.isReadOnly() || field.getMetadata(AUTO_GENERATED) != null || field.getMetadata(AUTO_GENERATED_EDITABLE) != null) {
continue;
}
boolean found = false;
for (FieldDto fieldDto : fields) {
if (field.getName().equalsIgnoreCase(fieldDto.getBasic().getName())) {
found = true;
break;
}
}
if (!found) {
iterator.remove();
}
}
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class EntityServiceImpl method getFields.
private List<FieldDto> getFields(Long entityId, boolean forDraft, boolean forUi) {
Entity entity = (forDraft) ? getEntityDraft(entityId) : allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
// the returned collection is unmodifiable
List<Field> fields = new ArrayList<>(entity.getFields());
// for data browser purposes, we sort the fields by their ui display order
if (!forDraft) {
Collections.sort(fields, new UIDisplayFieldComparator());
}
// if it's for the UI, then we add combobox options
List<FieldDto> fieldDtos = toFieldDtos(entity, fields, forUi);
return addNonPersistentFieldsData(fieldDtos, entity);
}
Aggregations