use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class RepositoryRequestSpecImpl method getQuerySpec.
@Override
public QuerySpec getQuerySpec(ResourceInformation targetResourceInformation) {
if (queryAdapter instanceof QuerySpecAdapter) {
QuerySpec querySpec = ((QuerySpecAdapter) queryAdapter).getQuerySpec();
return querySpec.getOrCreateQuerySpec(targetResourceInformation);
}
Class<?> targetResourceClass = targetResourceInformation.getResourceClass();
QueryParams queryParams = getQueryParams();
DefaultQuerySpecConverter converter = new DefaultQuerySpecConverter(moduleRegistry);
return converter.fromParams(targetResourceClass, queryParams);
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class ResponseRepositoryAdapter method enrichLinksInformation.
private LinksInformation enrichLinksInformation(LinksInformation linksInformation, Iterable<?> resources, RepositoryRequestSpec requestSpec) {
QueryAdapter queryAdapter = requestSpec.getQueryAdapter();
LinksInformation enrichedLinksInformation = linksInformation;
if (queryAdapter instanceof QuerySpecAdapter && resources instanceof ResourceList && requestSpec.getResponseResourceInformation().getPagingBehavior() != null && requestSpec.getResponseResourceInformation().getPagingBehavior().isRequired(queryAdapter.getPagingSpec())) {
enrichedLinksInformation = enrichPageLinksInformation(enrichedLinksInformation, (ResourceList<?>) resources, queryAdapter, requestSpec);
}
return enrichedLinksInformation;
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class TotalBasedPagedLinksInformationTest method testPaging.
@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(2L, 2L), resourceRegistry);
PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getFirst());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2&page[offset]=4", 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.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class TotalBasedPagedLinksInformationTest method testInvalidPaging.
@Test(expected = BadRequestException.class)
public void testInvalidPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(1L, 3L), resourceRegistry);
adapter.findAll(querySpec).getLinksInformation();
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class TotalBasedPagedLinksInformationTest method testPagingNoContents.
@Test
public void testPagingNoContents() throws InstantiationException, IllegalAccessException {
TotalResourceCountTestRepository.clear();
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 2L), resourceRegistry);
PagedLinksInformation linksInformation = (PagedLinksInformation) adapter.findAll(querySpec).getLinksInformation();
Assert.assertNull(linksInformation.getFirst());
Assert.assertNull(linksInformation.getLast());
Assert.assertNull(linksInformation.getPrev());
Assert.assertNull(linksInformation.getNext());
}
Aggregations