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;
}
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");
}
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"));
}
Aggregations