Search in sources :

Example 11 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.

the class InMemoryEvaluatorTest method testNextPageMetaInformationIsTrue.

@Test
public void testNextPageMetaInformationIsTrue() {
    QuerySpec spec = new QuerySpec(Task.class);
    DefaultResourceList<Task> results = new DefaultResourceList<>();
    results.setMeta(new DefaultHasMoreResourcesMetaInformation());
    spec.setLimit(2L);
    spec.apply(tasks, results);
    Assert.assertEquals(2, results.size());
    HasMoreResourcesMetaInformation meta = results.getMeta(HasMoreResourcesMetaInformation.class);
    Assert.assertTrue(meta.getHasMoreResources());
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) Test(org.junit.Test)

Example 12 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.

the class InMemoryEvaluatorTest method testNextPageMetaInformationIsFalse.

@Test
public void testNextPageMetaInformationIsFalse() {
    QuerySpec spec = new QuerySpec(Task.class);
    DefaultResourceList<Task> results = new DefaultResourceList<>();
    results.setMeta(new DefaultHasMoreResourcesMetaInformation());
    spec.setLimit(5L);
    spec.apply(tasks, results);
    HasMoreResourcesMetaInformation meta = results.getMeta(HasMoreResourcesMetaInformation.class);
    Assert.assertEquals(5, results.size());
    Assert.assertFalse(meta.getHasMoreResources());
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) DefaultHasMoreResourcesMetaInformation(io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation) Test(org.junit.Test)

Example 13 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.

the class ResponseRepositoryAdapter method doGetLinksInformation.

@SuppressWarnings({ "unchecked", "rawtypes" })
private LinksInformation doGetLinksInformation(Object repository, Iterable<?> resources, RepositoryRequestSpec requestSpec) {
    if (resources instanceof ResourceList) {
        ResourceList<?> resourceList = (ResourceList<?>) resources;
        boolean createLinksInformation = resourceList instanceof DefaultResourceList;
        LinksInformation newLinksInfo = enrichLinksInformation(resourceList.getLinks(), resources, requestSpec);
        if (createLinksInformation) {
            ((DefaultResourceList) resources).setLinks(newLinksInfo);
        }
        return resourceList.getLinks();
    }
    LinksInformation linksInformation = null;
    if (repository instanceof AnnotatedRepositoryAdapter) {
        if (((AnnotatedRepositoryAdapter) repository).linksRepositoryAvailable()) {
            linksInformation = ((LinksRepository) repository).getLinksInformation(resources, requestSpec.getQueryParams());
        }
    } else if (repository instanceof LinksRepositoryV2) {
        linksInformation = ((LinksRepositoryV2) repository).getLinksInformation(resources, requestSpec.getResponseQuerySpec());
    } else if (repository instanceof LinksRepository) {
        linksInformation = ((LinksRepository) repository).getLinksInformation(resources, requestSpec.getQueryParams());
    }
    // everything deprecated anyway
    return enrichLinksInformation(linksInformation, resources, requestSpec);
}
Also used : 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) LinksInformation(io.crnk.core.resource.links.LinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) AnnotatedRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRepositoryAdapter) LinksRepositoryV2(io.crnk.core.repository.LinksRepositoryV2) LinksRepository(io.crnk.legacy.repository.LinksRepository)

Example 14 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.

the class RegistryEntry method toResources.

private ResourceList toResources(JsonApiResponse response) {
    Collection elements = (Collection) toResource(response);
    DefaultResourceList result = new DefaultResourceList();
    result.addAll(elements);
    result.setMeta(response.getMetaInformation());
    result.setLinks(response.getLinksInformation());
    return result;
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) Collection(java.util.Collection)

Example 15 with DefaultResourceList

use of io.crnk.core.resource.list.DefaultResourceList in project crnk-framework by crnk-project.

the class HistoryResourceRepository method findAll.

@Override
public ResourceList<History> findAll(Iterable<UUID> ids, QuerySpec querySpec) {
    DefaultResourceList list = new DefaultResourceList();
    for (UUID id : ids) {
        History history = new History();
        history.setId(id);
        history.setName("test");
        list.add(history);
    }
    return list;
}
Also used : DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) UUID(java.util.UUID) History(io.crnk.example.springboot.domain.model.History)

Aggregations

DefaultResourceList (io.crnk.core.resource.list.DefaultResourceList)26 Task (io.crnk.core.mock.models.Task)7 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)5 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)4 DefaultHasMoreResourcesMetaInformation (io.crnk.core.resource.meta.DefaultHasMoreResourcesMetaInformation)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Test (org.junit.Test)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)3 ResourceList (io.crnk.core.resource.list.ResourceList)3 JsonLinksInformation (io.crnk.client.response.JsonLinksInformation)2 JsonMetaInformation (io.crnk.client.response.JsonMetaInformation)2 Resource (io.crnk.core.engine.document.Resource)2 ModuleRegistry (io.crnk.core.module.ModuleRegistry)2 FilterSpec (io.crnk.core.queryspec.FilterSpec)2