/** * Add the paging parameters to the request. * * @param request * @param pagingInfo */ protected void applyPagingParams(JsonObject request, PagingParameters pagingInfo) { long page = pagingInfo.getPage() - 1; Long perPage = pagingInfo.getPerPage(); if (perPage != null) { long low = page * perPage; request.put("from", low); request.put("size", pagingInfo.getPerPage()); } }
/** * Return the sort by parameter value. * * @return Field to be sorted by * @deprecated not yet implemented */ @Deprecated default String getSortBy() { return getParameter(SORT_BY_PARAMETER_KEY); }
/** * Set the order by parameter. * * @param orderBy * @return * @deprecated not yet implemented */ @Deprecated default PagingParameters setOrderBy(String orderBy) { setParameter(SORT_BY_PARAMETER_KEY, orderBy); return this; }
/** * Load the paging parameters from the provided {@link DataFetchingEnvironment}. * * @param env * @return Loaded paging parameters */ protected PagingParameters getPagingInfo(DataFetchingEnvironment env) { PagingParameters parameters = new PagingParametersImpl(); Long page = env.getArgument("page"); if (page != null) { parameters.setPage(page); } Long perPage = env.getArgument("perPage"); if (perPage != null) { parameters.setPerPage(perPage); } parameters.validate(); return parameters; }
public AbstractDynamicPage(PagingParameters pagingInfo) { if (pagingInfo.getPage() < 1) { throw new GenericRestException(BAD_REQUEST, "error_page_parameter_must_be_positive", String.valueOf(pagingInfo.getPage())); } if (pagingInfo.getPerPage() != null && pagingInfo.getPerPage() < 0) { throw new GenericRestException(BAD_REQUEST, "error_pagesize_parameter", String.valueOf(pagingInfo.getPerPage())); } this.pageNumber = pagingInfo.getPage(); this.perPage = pagingInfo.getPerPage(); if (perPage == null) { this.lowerBound = null; } else if (perPage == 0) { this.lowerBound = 0L; } else { this.lowerBound = (pageNumber - 1) * perPage; } }
/** * Return the current page. * * @return Current page number */ default int getPage() { return NumberUtils.toInt(getParameter(PAGE_PARAMETER_KEY), DEFAULT_PAGE); }
/** * Set the current page. * * @param page * Current page number * @return Fluent API */ default PagingParameters setPage(long page) { setParameter(PAGE_PARAMETER_KEY, String.valueOf(page)); return this; }
/** * Extract the total count and hit count from the info object and return the populated paging object. < * * * @param info * @param pagingInfo * @return */ protected PagingMetaInfo extractMetaInfo(JsonObject info, PagingParameters pagingInfo) { PagingMetaInfo metaInfo = new PagingMetaInfo(); long total = info.getLong("total"); metaInfo.setTotalCount(total); int totalPages = 0; Long perPage = pagingInfo.getPerPage(); if (perPage != null && perPage != 0) { totalPages = (int) Math.ceil(total / (double) perPage); } // Cap totalpages to 1 totalPages = totalPages == 0 ? 1 : totalPages; metaInfo.setCurrentPage(pagingInfo.getPage()); metaInfo.setPageCount(totalPages); metaInfo.setPerPage(perPage); return metaInfo; }
/** * Return the per page count. * * @return Per page count */ default Long getPerPage() { return NumberUtils.toLong(getParameter(PER_PAGE_PARAMETER_KEY), null); }
/** * Set the used sort order. * * @param sortBy * Sort order * @return Fluent API * @deprecated not yet implemented * */ @Deprecated default PagingParameters setSortOrder(String sortBy) { setParameter(SORT_BY_PARAMETER_KEY, sortBy); return this; }
return new PageImpl<>(elementList, info.getTotalCount(), pagingInfo.getPage(), info.getPageCount(), pagingInfo.getPerPage()); }); });
/** * Return the sortorder. * * @return * @deprecated not yet implemented */ @Deprecated default SortOrder getOrder() { return SortOrder.valueOfName(getParameter(SORT_ORDER_PARAMETER_KEY)); }
/** * Set the per page count. * * @param perPage * Per page count * @return Fluent API */ default PagingParameters setPerPage(Long perPage) { if (perPage != null) { setParameter(PER_PAGE_PARAMETER_KEY, String.valueOf(perPage)); } return this; }
if (pagingInfo.getPage() < 1) { throw new InvalidArgumentException("The page must always be positive"); Long perPage = pagingInfo.getPerPage(); if (perPage != null && perPage < 0) { throw new InvalidArgumentException("The pageSize must always be zero or greater than zero");
return new PageImpl<>(elementList, info.getTotalCount(), pagingInfo.getPage(), info.getPageCount(), pagingInfo.getPerPage()); }); return page;