use of org.springframework.hateoas.core.MethodParameters in project spring-data-commons by spring-projects.
the class PagedResourcesAssemblerArgumentResolver method findMatchingPageableParameter.
/**
* Returns finds the {@link MethodParameter} for a {@link Pageable} instance matching the given
* {@link MethodParameter} requesting a {@link PagedResourcesAssembler}.
*
* @param parameter must not be {@literal null}.
* @return
*/
@Nullable
private static MethodParameter findMatchingPageableParameter(MethodParameter parameter) {
MethodParameters parameters = new MethodParameters(parameter.getMethod());
List<MethodParameter> pageableParameters = parameters.getParametersOfType(Pageable.class);
Qualifier assemblerQualifier = parameter.getParameterAnnotation(Qualifier.class);
if (pageableParameters.isEmpty()) {
return null;
}
if (pageableParameters.size() == 1) {
MethodParameter pageableParameter = pageableParameters.get(0);
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
if (matchingParameter == null) {
LOGGER.info(SUPERFLOUS_QUALIFIER, PagedResourcesAssembler.class.getSimpleName(), Pageable.class.getName());
}
return pageableParameter;
}
if (assemblerQualifier == null) {
throw new IllegalStateException(PARAMETER_AMBIGUITY);
}
for (MethodParameter pageableParameter : pageableParameters) {
MethodParameter matchingParameter = returnIfQualifiersMatch(pageableParameter, assemblerQualifier);
if (matchingParameter != null) {
return matchingParameter;
}
}
throw new IllegalStateException(PARAMETER_AMBIGUITY);
}
Aggregations