Search in sources :

Example 1 with LookupWrongParameterTypeException

use of org.motechproject.mds.exception.lookup.LookupWrongParameterTypeException in project motech by motech.

the class LookupProcessor method verifyLookupParameters.

private void verifyLookupParameters(Method method, String entityClassName, String lookupName, List<LookupFieldDto> lookupFields, Class<?>[] parameterTypes) {
    List<String> parametersNames = findParametersNames(method);
    for (LookupFieldDto lookupFieldDto : lookupFields) {
        if (lookupFieldDto.getType() == LookupFieldType.VALUE) {
            FieldDto fieldDto = findEntityFieldByName(entityClassName, lookupFieldDto.getLookupFieldName());
            int position = parametersNames.indexOf(lookupFieldDto.getLookupFieldName());
            if (fieldDto != null && fieldDto.getType() != null) {
                TypeDto type = fieldDto.getType();
                // check if field is a Combobox or a TextArea
                if (type.isCombobox() || (type.isTextArea() && "java.lang.String".equals(parameterTypes[position].getName()))) {
                    continue;
                }
                if (!parameterTypes[position].getName().equals(type.getTypeClass())) {
                    StringBuilder sb = new StringBuilder("Wrong type of argument ");
                    sb.append(position).append(" \"").append(parametersNames.get(position));
                    sb.append("\" in lookup \"").append(lookupName);
                    sb.append("\" - should be ").append(type.getTypeClass());
                    sb.append(" but is ").append(parameterTypes[position].getName());
                    throw new LookupWrongParameterTypeException(sb.toString());
                }
            }
        }
    }
}
Also used : LookupWrongParameterTypeException(org.motechproject.mds.exception.lookup.LookupWrongParameterTypeException) TypeDto(org.motechproject.mds.dto.TypeDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)1 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)1 TypeDto (org.motechproject.mds.dto.TypeDto)1 LookupWrongParameterTypeException (org.motechproject.mds.exception.lookup.LookupWrongParameterTypeException)1