Search in sources :

Example 1 with DefaultPagedMetaInformation

use of io.crnk.core.resource.meta.DefaultPagedMetaInformation in project crnk-framework by crnk-project.

the class QuerySpec method apply.

/**
 * Evaluates this querySpec against the provided list in memory. It supports
 * sorting, filter and paging.
 * <p>
 * TODO currently ignores relations and inclusions, has room for
 * improvements
 *
 * @param <T> the type of resources in this Iterable
 * @param resources resources
 * @return sorted, filtered list.
 */
public <T> DefaultResourceList<T> apply(Iterable<T> resources) {
    DefaultResourceList<T> resultList = new DefaultResourceList<>();
    resultList.setMeta(new DefaultPagedMetaInformation());
    apply(resources, resultList);
    return resultList;
}
Also used : DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList)

Example 2 with DefaultPagedMetaInformation

use of io.crnk.core.resource.meta.DefaultPagedMetaInformation 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

DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)2 DefaultPagedMetaInformation (io.crnk.core.resource.meta.DefaultPagedMetaInformation)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 DefaultPagedLinksInformation (io.crnk.core.resource.links.DefaultPagedLinksInformation)1 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)1 ResourceList (io.crnk.core.resource.list.ResourceList)1 Test (org.junit.Test)1