Class RestrictedPageableArgumentResolver

java.lang.Object
in.co.akshitbansal.springwebquery.RestrictedPageableArgumentResolver
All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver

public class RestrictedPageableArgumentResolver extends Object implements org.springframework.web.method.support.HandlerMethodArgumentResolver
A custom HandlerMethodArgumentResolver that wraps a standard PageableHandlerMethodArgumentResolver to enforce restrictions on pageable sorting fields based on entity metadata.

This resolver only supports controller method parameters that:

The resolver delegates the initial parsing of page, size, and sort parameters to Spring's PageableHandlerMethodArgumentResolver. It then validates each requested Sort.Order against the target entity class specified in the RestrictedPageable annotation. Sorting is only allowed on fields explicitly annotated with Sortable.

If a requested sort field is not annotated as Sortable, a QueryException is thrown.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.data.domain.Pageable
    resolveArgument(@NonNull org.springframework.core.MethodParameter methodParameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, @NonNull org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
    Resolves the given Pageable argument from the web request.
    boolean
    supportsParameter(org.springframework.core.MethodParameter parameter)
    Determines whether the given method parameter is supported by this resolver.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RestrictedPageableArgumentResolver

      public RestrictedPageableArgumentResolver()
  • Method Details

    • supportsParameter

      public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
      Determines whether the given method parameter is supported by this resolver.

      Supported parameters must:

      Specified by:
      supportsParameter in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
      Parameters:
      parameter - the method parameter to check
      Returns:
      true if the parameter is supported, false otherwise
    • resolveArgument

      public org.springframework.data.domain.Pageable resolveArgument(@NonNull @NonNull org.springframework.core.MethodParameter methodParameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, @NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
      Resolves the given Pageable argument from the web request.

      The process is as follows:

      1. Delegate parsing of page, size, and sort parameters to delegate.
      2. Retrieve the target entity class from the RestrictedPageable annotation.
      3. Validate each requested Sort.Order against the entity's sortable fields. If a field is not annotated with Sortable, a QueryException is thrown.
      Specified by:
      resolveArgument in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
      Parameters:
      methodParameter - the method parameter for which the value should be resolved
      mavContainer - the ModelAndViewContainer (can be null)
      webRequest - the current request
      binderFactory - a factory for creating WebDataBinder instances (can be null)
      Returns:
      a Pageable object containing page, size, and validated sort information
      Throws:
      QueryException - if any requested sort field is not marked as Sortable