@Override public OptionalInt getPage(Pagination<?> page) { return page.getFirstPage(); } },
@Override public OptionalInt getPage(Pagination<?> page) { return page.getLastPage(); } },
@Override public OptionalInt getPage(Pagination<?> page) { return page.getNextPage(); } },
generator.writeNumberField("currentPage", pages.getPage()); generator.writeNumberField("rowsPerPage", pages.getPerPage()); generator.writeNumberField("numberOfResults", pages.getNumResults()); generator.writeEndObject(); generator.writeEndObject();
/** * Getter for dimension rows. * * @return Set of dimension rows the Search Provider has in it's indexes * */ default Set<DimensionRow> findAllDimensionRows() { return new LinkedHashSet<>( findAllDimensionRowsPaged(PaginationParameters.EVERYTHING_IN_ONE_PAGE).getPageOfData() ); }
/** * Adds the specified link to the headers and body of the response. * * @param link The type of the link being added * @param pages The paginated set of results containing the pages being linked to. * @param uriBuilder The builder for creating the pagination links. * @param bodyLinks The map of links that will be added to the body of the response */ public static void addLink( PaginationLink link, Pagination<?> pages, UriBuilder uriBuilder, Map<String, URI> bodyLinks ) { link.getPage(pages).ifPresent(page -> addLink(link, page, pages.getPerPage(), uriBuilder, bodyLinks)); }
@Override public OptionalInt getPage(Pagination<?> page) { return page.getPreviousPage(); } };
/** * Determine if any rows match these filters. * * @param filters ApiFilters to use for finding matching dimension rows * * @return true if at least one row is returned. */ default boolean hasAnyRows(Set<ApiFilter> filters) { return findFilteredDimensionRowsPaged(filters, PaginationParameters.ONE_RESULT).getNumResults() > 0; }
generator.writeNumberField("currentPage", pagination.getPage()); generator.writeNumberField("rowsPerPage", pagination.getPerPage()); generator.writeNumberField("numberOfResults", pagination.getNumResults());
/** * Get a set of dimension row(s) given a set of ApiFilters. * * @param filters ApiFilters to use for finding matching dimension rows * * @return set of dimension row(s) * */ default TreeSet<DimensionRow> findFilteredDimensionRows(Set<ApiFilter> filters) { return new TreeSet<>( findFilteredDimensionRowsPaged(filters, PaginationParameters.EVERYTHING_IN_ONE_PAGE).getPageOfData() ); }
/** * Adds the specified link to the headers and body of the response. * * @param link The type of the link being added * @param pages The paginated set of results containing the pages being linked to. * @param uriBuilder The uri builder to build the links * @param responseProcessor The response processor whose links are being built * @param bodyLinks The map of links that will be added to the body of the response */ public static void addLink( PaginationLink link, Pagination<?> pages, UriBuilder uriBuilder, MappingResponseProcessor responseProcessor, Map<String, URI> bodyLinks ) { link.getPage(pages).ifPresent( page -> addLink(link, page, pages.getPerPage(), uriBuilder, responseProcessor, bodyLinks) ); }
/** * Add links to the response builder and return a stream with the requested page from the raw data. * * @param <T> The type of the collection elements * @param pagination The pagination object * @param responseBuilder The builder for the http response * @param uriInfo The context object desribing the requested uri * * @return A stream from the subcollection of the data collection corresponding to the page described */ public static <T> Stream<T> paginate( Response.ResponseBuilder responseBuilder, Pagination<T> pagination, UriInfo uriInfo ) { Arrays.stream(PaginationLink.values()) .forEachOrdered(link -> addPageLink(responseBuilder, link, uriInfo, pagination)); return pagination.getPageOfData().stream(); } }
uriInfo.getRequestUriBuilder() .replaceQueryParam(PAGE, pair.getRight()) .replaceQueryParam(PER_PAGE, pages.getPerPage())
/** * Cuts the result set down to just the page requested. * * @param resultSet The result set to be cut down. * * @return The page of results desired. */ @Override public ResultSet map(ResultSet resultSet) { Pagination<Result> pages = new AllPagesPagination<>(resultSet, paginationParameters); AbstractResponse.addLinks(pages, uriBuilder, responseProcessor); //uses map for additional flexibility and robustness, even though it is currently a no-op. return new ResultSet(map(resultSet.getSchema()), pages.getPageOfData()); }