use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.
the class ResponseRepositoryAdapter method enrichPageLinksInformation.
private LinksInformation enrichPageLinksInformation(LinksInformation linksInformation, ResourceList<?> resources, QueryAdapter queryAdapter, RepositoryRequestSpec requestSpec) {
if (linksInformation == null) {
// use default implementation if no link information
// provided by resource
linksInformation = new DefaultPagedLinksInformation();
}
if (linksInformation instanceof PagedLinksInformation) {
PagingSpecUrlBuilder urlBuilder = new PagingSpecUrlBuilder(moduleRegistry.getResourceRegistry(), requestSpec);
requestSpec.getResponseResourceInformation().getPagingBehavior().build((PagedLinksInformation) linksInformation, resources, queryAdapter, urlBuilder);
}
return linksInformation;
}
use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.
the class TotalBasedPagedLinksInformationTest method testPagingFirst.
@Test
public void testPagingFirst() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 3L), resourceRegistry);
PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=3", linksInformation.getFirst());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=3&page[offset]=3", linksInformation.getLast());
Assert.assertNull(linksInformation.getPrev());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=3&page[offset]=3", linksInformation.getNext());
}
use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.
the class TotalBasedPagedLinksInformationTest method testPagingLast.
@Test
public void testPagingLast() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(4L, 4L), resourceRegistry);
PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=4", linksInformation.getFirst());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=4&page[offset]=4", linksInformation.getLast());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=4", linksInformation.getFirst());
Assert.assertNull(linksInformation.getNext());
}
use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testPaging.
@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(2L, 2L), resourceRegistry);
JsonApiResponse results = adapter.findAll(querySpec);
HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
Assert.assertTrue(metaInformation.getHasMoreResources());
PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getFirst());
Assert.assertNull(linksInformation.getLast());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getPrev());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2&page[offset]=4", linksInformation.getNext());
}
use of io.crnk.core.resource.links.PagedLinksInformation in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testPagingNoContents.
@Test
public void testPagingNoContents() throws InstantiationException, IllegalAccessException {
HasNextPageTestRepository.clear();
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 2L), resourceRegistry);
JsonApiResponse results = adapter.findAll(querySpec);
HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
Assert.assertFalse(metaInformation.getHasMoreResources());
PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
Assert.assertNull(linksInformation.getFirst());
Assert.assertNull(linksInformation.getLast());
Assert.assertNull(linksInformation.getPrev());
Assert.assertNull(linksInformation.getNext());
}
Aggregations