Search in sources :

Example 1 with PagedLinksInformation

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;
}
Also used : DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) PagingSpecUrlBuilder(io.crnk.core.queryspec.pagingspec.PagingSpecUrlBuilder)

Example 2 with PagedLinksInformation

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());
}
Also used : PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 3 with PagedLinksInformation

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());
}
Also used : PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 4 with PagedLinksInformation

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());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 5 with PagedLinksInformation

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());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Aggregations

PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)11 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)10 Test (org.junit.Test)10 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)9 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)5 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)5 DefaultPagedLinksInformation (io.crnk.core.resource.links.DefaultPagedLinksInformation)2 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)1 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 Task (io.crnk.core.mock.models.Task)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 PagingSpecUrlBuilder (io.crnk.core.queryspec.pagingspec.PagingSpecUrlBuilder)1 DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)1 ResourceList (io.crnk.core.resource.list.ResourceList)1 DefaultPagedMetaInformation (io.crnk.core.resource.meta.DefaultPagedMetaInformation)1