Search in sources :

Example 1 with DefaultPagedLinksInformation

use of io.crnk.core.resource.links.DefaultPagedLinksInformation 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 DefaultPagedLinksInformation

use of io.crnk.core.resource.links.DefaultPagedLinksInformation in project crnk-framework by crnk-project.

the class LinksInformationSerializerTest method setup.

@Before
public void setup() {
    selfLink = new TestSelfLinksInformation("/self");
    pagedLink = new DefaultPagedLinksInformation();
    pagedLink.setFirst("/first");
    pagedLink.setLast("/last");
    // not setting previous -> first page
    pagedLink.setNext("/next");
    customLink = new TestCustomLinksInformation("http://www.imdb.com");
}
Also used : DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) Before(org.junit.Before)

Example 3 with DefaultPagedLinksInformation

use of io.crnk.core.resource.links.DefaultPagedLinksInformation in project crnk-framework by crnk-project.

the class OffsetLimitPagingBehaviorTest method testBuild.

@Test
public void testBuild() {
    PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
    OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QuerySpec spec = new QuerySpec(Task.class);
    QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
    querySpecAdapter.setPagingSpec(pagingSpec);
    PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
    when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
    DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
    pagedMetaInformation.setTotalResourceCount(30L);
    ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
    for (int i = 0; i < 30; i++) {
        resourceList.add(new Task());
    }
    PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
    pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
    assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
    assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
    assertNull(pagedLinksInformation.getPrev());
    assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

DefaultPagedLinksInformation (io.crnk.core.resource.links.DefaultPagedLinksInformation)3 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)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 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)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 Before (org.junit.Before)1 Test (org.junit.Test)1