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());
}
}
}
}
}
Aggregations