001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.ws.server.provider;
015
016import org.gbif.api.model.common.paging.Pageable;
017
018import org.springframework.core.MethodParameter;
019import org.springframework.web.bind.support.WebDataBinderFactory;
020import org.springframework.web.context.request.NativeWebRequest;
021import org.springframework.web.method.support.HandlerMethodArgumentResolver;
022import org.springframework.web.method.support.ModelAndViewContainer;
023
024@SuppressWarnings("NullableProblems")
025public class PageableHandlerMethodArgumentResolver extends PageableProvider
026    implements HandlerMethodArgumentResolver {
027
028  public PageableHandlerMethodArgumentResolver() {}
029
030  public PageableHandlerMethodArgumentResolver(Integer maxPageSize) {
031    super(maxPageSize);
032  }
033
034  @Override
035  public boolean supportsParameter(MethodParameter parameter) {
036    return Pageable.class.equals(parameter.getParameterType());
037  }
038
039  @Override
040  public Object resolveArgument(
041      MethodParameter parameter,
042      ModelAndViewContainer mavContainer,
043      NativeWebRequest webRequest,
044      WebDataBinderFactory binderFactory) {
045    return getValue(webRequest);
046  }
047}