@Test public void shouldGenerateHeaderLinksFirstPage() throws URISyntaxException { final ResteasyUriInfo uriInfo = getUriInfo(); final LinkHeader linkHeader = endpoint.getLinkHeader(0, 3, uriInfo); assertThat(findLinkByRel(linkHeader, "prev")).isNull(); final Link next = findLinkByRel(linkHeader, "next"); assertThat(next).isNotNull(); assertThat(next.getHref()).isEqualTo("/?page=1"); assertThat(findLinkByRel(linkHeader, "first")).isNull(); }
static LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) { LinkHeader header = new LinkHeader(); if (page != 0) { header.addLink(buildLink("prev", page - 1, uri)); header.addLink(buildLink("first", 0, uri)); } if (page < totalPages) { header.addLink(buildLink("next", page + 1, uri)); header.addLink(buildLink("last", totalPages, uri)); } return header; }
InstallationManagementEndpoint { static LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) { LinkHeader header = new LinkHeader(); if (page != 0) { header.addLink(buildLink("prev", page - 1, uri)); header.addLink(buildLink("first", 0, uri)); } if (page < totalPages) { header.addLink(buildLink("next", page + 1, uri)); header.addLink(buildLink("last", totalPages, uri)); } return header; } }
InstallationManagementEndpoint { static LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) { LinkHeader header = new LinkHeader(); if (page != 0) { header.addLink(buildLink("prev", page - 1, uri)); header.addLink(buildLink("first", 0, uri)); } if (page < totalPages) { header.addLink(buildLink("next", page + 1, uri)); header.addLink(buildLink("last", totalPages, uri)); } return header; }  }
InstallationManagementEndpoint { static LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) { LinkHeader header = new LinkHeader(); if (page != 0) { header.addLink(buildLink("prev", page - 1, uri)); header.addLink(buildLink("first", 0, uri)); } if (page < totalPages) { header.addLink(buildLink("next", page + 1, uri)); header.addLink(buildLink("last", totalPages, uri)); } return header; }  @GET @Produces(MediaType.APPLICATION_JSON) Response findInstallations(@PathParam("variantID") String variantId,
                                      @QueryParam("page") Integer page,
                                      @QueryParam("per_page") Integer pageSize,
                                      @QueryParam("search") String search,
                                      @Context UriInfo uri); @GET @Path("/{installationID}") @Produces(MediaType.APPLICATION_JSON) Response findInstallation(@PathParam("variantID") String variantId, @PathParam("installationID") String installationId); @PUT @Path("/{installationID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateInstallation(Installation entity, @PathParam("variantID") String variantId, @PathParam("installationID") String installationId); @DELETE @Path("/{installationID}") @Produces(MediaType.APPLICATION_JSON) Response removeInstallation(@PathParam("variantID") String variantId, @PathParam("installationID") String installationId); }
InstallationManagementEndpoint { static LinkHeader getLinkHeader(Integer page, long totalPages, UriInfo uri) { LinkHeader header = new LinkHeader(); if (page != 0) { header.addLink(buildLink("prev", page - 1, uri)); header.addLink(buildLink("first", 0, uri)); } if (page < totalPages) { header.addLink(buildLink("next", page + 1, uri)); header.addLink(buildLink("last", totalPages, uri)); } return header; }  @GET @Produces(MediaType.APPLICATION_JSON) Response findInstallations(@PathParam("variantID") String variantId,
                                      @QueryParam("page") Integer page,
                                      @QueryParam("per_page") Integer pageSize,
                                      @QueryParam("search") String search,
                                      @Context UriInfo uri); @GET @Path("/{installationID}") @Produces(MediaType.APPLICATION_JSON) Response findInstallation(@PathParam("variantID") String variantId, @PathParam("installationID") String installationId); @PUT @Path("/{installationID}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response updateInstallation(Installation entity, @PathParam("variantID") String variantId, @PathParam("installationID") String installationId); @DELETE @Path("/{installationID}") @Produces(MediaType.APPLICATION_JSON) Response removeInstallation(@PathParam("variantID") String variantId, @PathParam("installationID") String installationId);  }