for (final FieldMetadata field : finderMetadataDetails
.getFinderMethodParamFields()) {
final JavaSymbolName fieldName = field.getFieldName();
final List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
attributes.add(new StringAttributeValue(
new JavaSymbolName("value"), uncapitalize(fieldName
.getSymbolName())));
if (field.getFieldType().equals(JavaType.BOOLEAN_PRIMITIVE)
|| field.getFieldType().equals(JavaType.BOOLEAN_OBJECT)) {
attributes.add(new BooleanAttributeValue(new JavaSymbolName(
"required"), false));
}
final AnnotationMetadataBuilder requestParamAnnotation = new AnnotationMetadataBuilder(
REQUEST_PARAM, attributes);
annotations.add(requestParamAnnotation.build());
if (field.getFieldType().equals(DATE)
|| field.getFieldType().equals(CALENDAR)) {
dateFieldPresent = true;
final AnnotationMetadata annotation = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(),
DATE_TIME_FORMAT);
if (annotation != null) {
getShortName(DATE_TIME_FORMAT);
annotations.add(annotation);
}
}
parameterNames.add(fieldName);
parameterTypes.add(new AnnotatedJavaType(field.getFieldType(),
annotations));
if (field.getFieldType().equals(JavaType.BOOLEAN_OBJECT)) {
methodParams.append(fieldName + " == null ? Boolean.FALSE : "
+ fieldName + ", ");
}
else {
methodParams.append(fieldName + ", ");
}
}
if (methodParams.length() > 0) {
methodParams.delete(methodParams.length() - 2,
methodParams.length());
}
final List<AnnotationAttributeValue<?>> firstResultAttributes = new ArrayList<AnnotationAttributeValue<?>>();
firstResultAttributes.add(new StringAttributeValue(new JavaSymbolName(
"value"), "page"));
firstResultAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
"required"), false));
final AnnotationMetadataBuilder firstResultAnnotation = new AnnotationMetadataBuilder(
REQUEST_PARAM, firstResultAttributes);
final List<AnnotationAttributeValue<?>> maxResultsAttributes = new ArrayList<AnnotationAttributeValue<?>>();
maxResultsAttributes.add(new StringAttributeValue(new JavaSymbolName(
"value"), "size"));
maxResultsAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
"required"), false));
final AnnotationMetadataBuilder maxResultAnnotation = new AnnotationMetadataBuilder(
REQUEST_PARAM, maxResultsAttributes);
final List<AnnotationAttributeValue<?>> sortFieldNameAttributes = new ArrayList<AnnotationAttributeValue<?>>();
sortFieldNameAttributes.add(new StringAttributeValue(new JavaSymbolName(
"value"), "sortFieldName"));
sortFieldNameAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
"required"), false));
final AnnotationMetadataBuilder sortFieldNameAnnotation = new AnnotationMetadataBuilder(
REQUEST_PARAM, sortFieldNameAttributes);
final List<AnnotationAttributeValue<?>> sortOrderAttributes = new ArrayList<AnnotationAttributeValue<?>>();
sortOrderAttributes.add(new StringAttributeValue(new JavaSymbolName(
"value"), "sortOrder"));
sortOrderAttributes.add(new BooleanAttributeValue(new JavaSymbolName(
"required"), false));
final AnnotationMetadataBuilder sortOrderAnnotation = new AnnotationMetadataBuilder(
REQUEST_PARAM, sortOrderAttributes);
parameterTypes.add(new AnnotatedJavaType(
new JavaType(Integer.class.getName()),
firstResultAnnotation.build()));
parameterTypes.add(new AnnotatedJavaType(
new JavaType(Integer.class.getName()),
maxResultAnnotation.build()));
parameterTypes.add(new AnnotatedJavaType(
new JavaType(String.class.getName()),
sortFieldNameAnnotation.build()));
parameterTypes.add(new AnnotatedJavaType(
new JavaType(String.class.getName()),
sortOrderAnnotation.build()));
parameterTypes.add(new AnnotatedJavaType(MODEL));
if (getGovernorMethod(finderMethodName,
AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes)) != null) {
return null;
}
final List<JavaSymbolName> newParamNames = new ArrayList<JavaSymbolName>();
newParamNames.addAll(parameterNames);
newParamNames.add(new JavaSymbolName("page"));
newParamNames.add(new JavaSymbolName("size"));
newParamNames.add(new JavaSymbolName("sortFieldName"));
newParamNames.add(new JavaSymbolName("sortOrder"));
newParamNames.add(new JavaSymbolName("uiModel"));
final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
requestMappingAttributes.add(new StringAttributeValue(
new JavaSymbolName("params"), "find="
+ finderMetadataDetails
.getFinderMethodMetadata()
.getMethodName()
.getSymbolName()