@Test public void testGetLinksOnSecondPage() throws Exception { String dspaceBaseURL = "http: String dspaceURL = dspaceBaseURL + "?page=1&size=10"; PageRequest pageRequest = PageRequest.of(1, 10); Page page = new PageImpl<>(new ArrayList<>(), pageRequest, 50); EmbeddedPageHeader embeddedPageHeader = new EmbeddedPageHeader(dspaceURL, page, true); Map<String,Object> links = embeddedPageHeader.getLinks(); assertEquals(dspaceURL, ((EmbeddedPageHeader.Href) links.get("self")).getHref()); assertEquals(dspaceBaseURL + "?page=0&size=10", ((EmbeddedPageHeader.Href) links.get("first")).getHref()); assertEquals(dspaceBaseURL + "?page=0&size=10", ((EmbeddedPageHeader.Href) links.get("prev")).getHref()); assertEquals(dspaceBaseURL + "?page=2&size=10", ((EmbeddedPageHeader.Href) links.get("next")).getHref()); assertEquals(dspaceBaseURL + "?page=4&size=10", ((EmbeddedPageHeader.Href) links.get("last")).getHref()); }
@JsonProperty(value = "_links") public Map<String, Object> getLinks() { Map<String, Object> links = new HashMap<>(); if (!page.isFirst()) { links.put("first", _link(page.getSort(), 0, page.getSize())); links.put("self", _link(page.getSort(), page.getNumber(), page.getSize())); } else { links.put("self", _link(page.getSort(), null, page.getSize())); } if (!page.isLast() && totalElementsIsKnown) { links.put("last", _link(page.getSort(), page.getTotalPages() - 1, page.getSize())); } if (page.hasPrevious()) { links.put("prev", _link(page.getSort(), page.getNumber() - 1, page.getSize())); } if (page.hasNext()) { links.put("next", _link(page.getSort(), page.getNumber() + 1, page.getSize())); } return links; }
EmbeddedPageHeader { @JsonProperty(value = "_links") public Map<String, Object> getLinks() { Map<String, Object> links = new HashMap<>(); if (!page.isFirst()) { links.put("first", _link(page.getSort(), 0, page.getSize())); links.put("self", _link(page.getSort(), page.getNumber(), page.getSize())); } else { links.put("self", _link(page.getSort(), null, page.getSize())); } if (!page.isLast() && totalElementsIsKnown) { links.put("last", _link(page.getSort(), page.getTotalPages() - 1, page.getSize())); } if (page.hasPrevious()) { links.put("prev", _link(page.getSort(), page.getNumber() - 1, page.getSize())); } if (page.hasNext()) { links.put("next", _link(page.getSort(), page.getNumber() + 1, page.getSize())); } return links; } }
EmbeddedPageHeader { @JsonProperty(value = "_links") public Map<String, Object> getLinks() { Map<String, Object> links = new HashMap<>(); if (!page.isFirst()) { links.put("first", _link(page.getSort(), 0, page.getSize())); links.put("self", _link(page.getSort(), page.getNumber(), page.getSize())); } else { links.put("self", _link(page.getSort(), null, page.getSize())); } if (!page.isLast() && totalElementsIsKnown) { links.put("last", _link(page.getSort(), page.getTotalPages() - 1, page.getSize())); } if (page.hasPrevious()) { links.put("prev", _link(page.getSort(), page.getNumber() - 1, page.getSize())); } if (page.hasNext()) { links.put("next", _link(page.getSort(), page.getNumber() + 1, page.getSize())); } return links; } EmbeddedPageHeader(UriComponentsBuilder self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(String self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(UriComponentsBuilder self, Page page); }
EmbeddedPageHeader { @JsonProperty(value = "_links") public Map<String, Object> getLinks() { Map<String, Object> links = new HashMap<>(); if (!page.isFirst()) { links.put("first", _link(page.getSort(), 0, page.getSize())); links.put("self", _link(page.getSort(), page.getNumber(), page.getSize())); } else { links.put("self", _link(page.getSort(), null, page.getSize())); } if (!page.isLast() && totalElementsIsKnown) { links.put("last", _link(page.getSort(), page.getTotalPages() - 1, page.getSize())); } if (page.hasPrevious()) { links.put("prev", _link(page.getSort(), page.getNumber() - 1, page.getSize())); } if (page.hasNext()) { links.put("next", _link(page.getSort(), page.getNumber() + 1, page.getSize())); } return links; } EmbeddedPageHeader(UriComponentsBuilder self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(String self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(UriComponentsBuilder self, Page page); @JsonProperty(value = "page") Map<String, Long> getPageInfo(); @JsonProperty(value = "_links") Map<String, Object> getLinks(); }
EmbeddedPageHeader { @JsonProperty(value = "_links") public Map<String, Object> getLinks() { Map<String, Object> links = new HashMap<>(); if (!page.isFirst()) { links.put("first", _link(page.getSort(), 0, page.getSize())); links.put("self", _link(page.getSort(), page.getNumber(), page.getSize())); } else { links.put("self", _link(page.getSort(), null, page.getSize())); } if (!page.isLast() && totalElementsIsKnown) { links.put("last", _link(page.getSort(), page.getTotalPages() - 1, page.getSize())); } if (page.hasPrevious()) { links.put("prev", _link(page.getSort(), page.getNumber() - 1, page.getSize())); } if (page.hasNext()) { links.put("next", _link(page.getSort(), page.getNumber() + 1, page.getSize())); } return links; } EmbeddedPageHeader(UriComponentsBuilder self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(String self, Page page, boolean totalElementsIsKnown);  EmbeddedPageHeader(UriComponentsBuilder self, Page page); @JsonProperty(value = "page") Map<String, Long> getPageInfo(); @JsonProperty(value = "_links") Map<String, Object> getLinks();  }