for (final FieldMetadata field : finderDetails
.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"), StringUtils
.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)) {
final AnnotationMetadata annotation = MemberFindingUtils
.getAnnotationOfType(field.getAnnotations(),
DATE_TIME_FORMAT);
if (annotation != null) {
annotations.add(annotation);
}
}
parameterNames.add(fieldName);
parameterTypes.add(new AnnotatedJavaType(field.getFieldType(),
annotations));
if (field.getFieldType().equals(JavaType.BOOLEAN_OBJECT)) {
methodParams.append(field.getFieldName()
+ " == null ? Boolean.FALSE : " + field.getFieldName()
+ ", ");
}
else {
methodParams.append(field.getFieldName() + ", ");
}
}
if (methodParams.length() > 0) {
methodParams.delete(methodParams.length() - 2,
methodParams.length());
}
final List<JavaSymbolName> newParamNames = new ArrayList<JavaSymbolName>();
newParamNames.addAll(parameterNames);
final List<AnnotationAttributeValue<?>> requestMappingAttributes = new ArrayList<AnnotationAttributeValue<?>>();
requestMappingAttributes.add(new StringAttributeValue(
new JavaSymbolName("params"), "find="
+ finderDetails.getFinderMethodMetadata()
.getMethodName().getSymbolName()
.replaceFirst("find" + plural, "")));
requestMappingAttributes.add(new StringAttributeValue(
new JavaSymbolName("headers"), "Accept=application/json"));
final AnnotationMetadataBuilder requestMapping = new AnnotationMetadataBuilder(
REQUEST_MAPPING, requestMappingAttributes);
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(requestMapping);