Search in sources :

Example 1 with LookupWrongFieldNameException

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);
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) LookupFieldType(org.motechproject.mds.dto.LookupFieldType) LookupWrongFieldNameException(org.motechproject.mds.exception.lookup.LookupWrongFieldNameException) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Aggregations

ArrayList (java.util.ArrayList)1 LookupDto (org.motechproject.mds.dto.LookupDto)1 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)1 LookupFieldType (org.motechproject.mds.dto.LookupFieldType)1 LookupWrongFieldNameException (org.motechproject.mds.exception.lookup.LookupWrongFieldNameException)1