Search in sources :

Example 26 with QuerySpecAdapter

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);
}
Also used : QueryParams(io.crnk.legacy.queryParams.QueryParams) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter)

Example 27 with QuerySpecAdapter

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;
}
Also used : ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) LinksInformation(io.crnk.core.resource.links.LinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter)

Example 28 with QuerySpecAdapter

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());
}
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 29 with QuerySpecAdapter

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

Example 30 with QuerySpecAdapter

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());
}
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)

Aggregations

QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)48 QuerySpec (io.crnk.core.queryspec.QuerySpec)32 Test (org.junit.Test)25 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)15 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)13 Task (io.crnk.core.mock.models.Task)11 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)11 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)11 Document (io.crnk.core.engine.document.Document)10 Resource (io.crnk.core.engine.document.Resource)8 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)8 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)7 Before (org.junit.Before)7 Relationship (io.crnk.core.engine.document.Relationship)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 Project (io.crnk.core.mock.models.Project)6 HasMoreResourcesMetaInformation (io.crnk.core.resource.meta.HasMoreResourcesMetaInformation)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 Response (io.crnk.core.engine.dispatcher.Response)4 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4