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 WebQuery on the controller method. Sorting is only allowed on fields explicitly annotated with Sortable. Alias mappings from WebQuery.fieldMappings() are also applied so API-facing sort names can be rewritten to entity field paths.

If a requested sort field is not annotated as Sortable, a QueryValidationException 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. Resolve WebQuery metadata from the controller method.
      3. Validate each requested Sort.Order against the entity's sortable fields. If a field is not annotated with Sortable, a QueryValidationException is thrown.
      4. Rewrite alias sort properties to real entity field paths using field mappings.
      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, validated sort information, and mapped sort field paths
      Throws:
      QueryValidationException - if any requested sort field is not marked as Sortable
      QueryConfigurationException - if resolver metadata or alias configuration cannot be processed