use of org.springframework.hateoas.PagedResources in project taskana by Taskana.
the class TaskControllerIntTest method testGetAllTasksWithAdminRole.
@Test
public void testGetAllTasksWithAdminRole() {
RestTemplate template = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
// Role Admin
headers.add("Authorization", "Basic YWRtaW46YWRtaW4=");
HttpEntity<String> request = new HttpEntity<String>(headers);
ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/tasks", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
});
assertNotNull(response.getBody().getLink(Link.REL_SELF));
assertEquals(70, response.getBody().getContent().size());
}
use of org.springframework.hateoas.PagedResources in project taskana by Taskana.
the class TaskControllerIntTest method testGetLastPageSortedByDue.
@Test
@Ignore
public void testGetLastPageSortedByDue() {
RestTemplate template = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
// Role Admin
headers.add("Authorization", "Basic YWRtaW46YWRtaW4=");
HttpEntity<String> request = new HttpEntity<String>(headers);
ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/tasks?sortBy=due&order=desc&page=14&pageSize=5", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
});
assertEquals(5, response.getBody().getContent().size());
assertTrue(response.getBody().getLink(Link.REL_LAST).getHref().contains("page=14"));
assertEquals("TKI:000000000000000000000000000000000004", response.getBody().getContent().iterator().next().getTaskId());
assertNotNull(response.getBody().getLink(Link.REL_SELF));
assertTrue(response.getBody().getLink(Link.REL_SELF).getHref().endsWith("/v1/tasks?sortBy=due&order=desc&page=14&pageSize=5"));
assertNotNull(response.getBody().getLink("allTasks"));
assertTrue(response.getBody().getLink("allTasks").getHref().endsWith("/v1/tasks"));
assertNotNull(response.getBody().getLink(Link.REL_FIRST));
assertNotNull(response.getBody().getLink(Link.REL_LAST));
assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
}
use of org.springframework.hateoas.PagedResources in project taskana by Taskana.
the class WorkbasketSummaryResourcesAssembler method toResources.
public PagedResources<WorkbasketSummaryResource> toResources(List<WorkbasketSummary> workbasketSummaries, PageMetadata pageMetadata) {
WorkbasketSummaryResourceAssembler assembler = new WorkbasketSummaryResourceAssembler();
List<WorkbasketSummaryResource> resources = assembler.toResources(workbasketSummaries);
PagedResources<WorkbasketSummaryResource> pagedResources = new PagedResources<WorkbasketSummaryResource>(resources, pageMetadata);
UriComponentsBuilder original = getBuilderForOriginalUri();
pagedResources.add(new Link(original.toUriString()).withSelfRel());
if (pageMetadata != null) {
pagedResources.add(linkTo(WorkbasketController.class).withRel("allWorkbaskets"));
pagedResources.add(new Link(original.replaceQueryParam("page", 1).toUriString()).withRel(Link.REL_FIRST));
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getTotalPages()).toUriString()).withRel(Link.REL_LAST));
if (pageMetadata.getNumber() > 1) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() - 1).toUriString()).withRel(Link.REL_PREVIOUS));
}
if (pageMetadata.getNumber() < pageMetadata.getTotalPages()) {
pagedResources.add(new Link(original.replaceQueryParam("page", pageMetadata.getNumber() + 1).toUriString()).withRel(Link.REL_NEXT));
}
}
return pagedResources;
}
use of org.springframework.hateoas.PagedResources in project spring-data-commons by spring-projects.
the class PagedResourcesAssembler method addPaginationLinks.
private <R> PagedResources<R> addPaginationLinks(PagedResources<R> resources, Page<?> page, Optional<Link> link) {
UriTemplate base = getUriTemplate(link);
boolean isNavigable = page.hasPrevious() || page.hasNext();
if (isNavigable || forceFirstAndLastRels) {
resources.add(createLink(base, PageRequest.of(0, page.getSize(), page.getSort()), Link.REL_FIRST));
}
if (page.hasPrevious()) {
resources.add(createLink(base, page.previousPageable(), Link.REL_PREVIOUS));
}
Link selfLink = //
link.map(it -> it.withSelfRel()).orElseGet(() -> createLink(base, page.getPageable(), Link.REL_SELF));
resources.add(selfLink);
if (page.hasNext()) {
resources.add(createLink(base, page.nextPageable(), Link.REL_NEXT));
}
if (isNavigable || forceFirstAndLastRels) {
int lastIndex = page.getTotalPages() == 0 ? 0 : page.getTotalPages() - 1;
resources.add(createLink(base, PageRequest.of(lastIndex, page.getSize(), page.getSort()), Link.REL_LAST));
}
return resources;
}
use of org.springframework.hateoas.PagedResources in project taskana by Taskana.
the class WorkbasketControllerIntTest method testGetSecondPageSortedByKey.
@Test
public void testGetSecondPageSortedByKey() {
RestTemplate template = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
HttpEntity<String> request = new HttpEntity<String>(headers);
ResponseEntity<PagedResources<WorkbasketSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/workbaskets?sortBy=key&order=desc&page=2&pagesize=5", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<WorkbasketSummaryResource>>() {
});
assertEquals(5, response.getBody().getContent().size());
assertEquals("USER_1_1", response.getBody().getContent().iterator().next().key);
assertNotNull(response.getBody().getLink(Link.REL_SELF));
assertTrue(response.getBody().getLink(Link.REL_SELF).getHref().endsWith("/v1/workbaskets?sortBy=key&order=desc&page=2&pagesize=5"));
assertNotNull(response.getBody().getLink("allWorkbaskets"));
assertTrue(response.getBody().getLink("allWorkbaskets").getHref().endsWith("/v1/workbaskets"));
assertNotNull(response.getBody().getLink(Link.REL_FIRST));
assertNotNull(response.getBody().getLink(Link.REL_LAST));
assertNotNull(response.getBody().getLink(Link.REL_NEXT));
assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
}
Aggregations