use of org.motechproject.mds.exception.lookup.LookupNotFoundException 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;
}
Aggregations