use of org.motechproject.mds.exception.lookup.LookupWrongFieldNameException in project motech by motech.
the class Lookup method toDto.
public LookupDto toDto() {
List<LookupFieldDto> lookupFields = new ArrayList<>();
for (String lookupFieldName : getFieldsOrder()) {
Field field = getLookupFieldByName(LookupName.getFieldName(lookupFieldName));
LookupFieldType lookupFieldType = LookupFieldType.VALUE;
if (isRangeParam(lookupFieldName)) {
lookupFieldType = LookupFieldType.RANGE;
} else if (isSetParam(lookupFieldName)) {
lookupFieldType = LookupFieldType.SET;
}
String customOperator = getCustomOperators().get(lookupFieldName);
boolean useGenericParam = toBoolean(getUseGenericParams().get(lookupFieldName));
if (field != null) {
LookupFieldDto lookupField = new LookupFieldDto(field.getId(), field.getName(), lookupFieldType, customOperator, useGenericParam, LookupName.getRelatedFieldName(lookupFieldName));
lookupFields.add(lookupField);
} else {
throw new LookupWrongFieldNameException(String.format("Can't create LookupFieldDto. Field with given name %s does not exist in %s lookup", lookupFieldName, lookupName));
}
}
return new LookupDto(id, lookupName, singleObjectReturn, exposedViaRest, lookupFields, readOnly, methodName, fieldsOrder, indexRequired);
}
Aggregations