Search in sources :

Example 1 with OffsetLimitPagingSpec

use of io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec in project crnk-framework by crnk-project.

the class RepositoryFilterTest method prepare.

@Before
public void prepare() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addRepositoryFilter(filter);
    boot.addModule(filterModule);
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    querySpec = new QuerySpec(User.class);
    querySpec.setPagingSpec(new OffsetLimitPagingSpec());
    queryAdapter = new QuerySpecAdapter(querySpec, resourceRegistry);
    scheduleInfo = resourceRegistry.getEntry(Schedule.class).getResourceInformation();
    RegistryEntry userEntry = resourceRegistry.getEntry(User.class);
    resourceAdapter = userEntry.getResourceRepository(null);
    projectRelationAdapter = userEntry.getRelationshipRepository("assignedProjects", null);
    taskRelationAdapter = userEntry.getRelationshipRepository("assignedTasks", null);
    userInfo = userEntry.getResourceInformation();
    UserRepository resourceRepository = (UserRepository) resourceAdapter.getResourceRepository();
    user1 = new User();
    user1.setId(1L);
    resourceRepository.save(user1);
    user2 = new User();
    user2.setId(2L);
    resourceRepository.save(user2);
    UserToProjectRepository userProjectRepository = (UserToProjectRepository) ((AnnotatedRelationshipRepositoryAdapter<?, ?, ?, ?>) projectRelationAdapter.getRelationshipRepository()).getImplementationObject();
    userProjectRepository.setRelation(user1, 11L, "assignedProjects");
    UserToTaskRepository userTaskRepository = new UserToTaskRepository();
    userTaskRepository.addRelations(user1, Arrays.asList(21L), "assignedTasks");
    userTaskRepository.addRelations(user2, Arrays.asList(22L), "assignedTasks");
    assignedTasksField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedTasks");
    assignedProjectsField = resourceRegistry.getEntry(User.class).getResourceInformation().findRelationshipFieldByName("assignedProjects");
}
Also used : UserToProjectRepository(io.crnk.core.mock.repository.UserToProjectRepository) CrnkBoot(io.crnk.core.boot.CrnkBoot) User(io.crnk.core.mock.models.User) UserRepository(io.crnk.core.mock.repository.UserRepository) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) UserToTaskRepository(io.crnk.core.mock.repository.UserToTaskRepository) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) QuerySpec(io.crnk.core.queryspec.QuerySpec) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 2 with OffsetLimitPagingSpec

use of io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecConverter method fromParams.

@Override
public QuerySpec fromParams(Class<?> rootType, QueryParams params) {
    QuerySpec querySpec = new QuerySpec(rootType);
    querySpec.setPagingSpec(new OffsetLimitPagingSpec());
    applyIncludedFields(querySpec, params);
    applySorting(querySpec, params);
    applyFiltering(querySpec, params);
    applyRelatedFields(querySpec, params);
    applyPaging(querySpec, params);
    return querySpec;
}
Also used : OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec)

Example 3 with OffsetLimitPagingSpec

use of io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec in project crnk-framework by crnk-project.

the class DefaultQuerySpecDeserializerTestBase method testPaging.

@Test
public void testPaging() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.setPagingSpec(new OffsetLimitPagingSpec(1L, 2L));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "page[offset]", "1");
    add(params, "page[limit]", "2");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 4 with OffsetLimitPagingSpec

use of io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec in project crnk-framework by crnk-project.

the class QuerySpecTest method checkToString.

@Test
public void checkToString() {
    QuerySpec spec = new QuerySpec("projects");
    Assert.assertEquals("QuerySpec{resourceType=projects, paging=OffsetLimitPagingSpec{offset=0}}", spec.toString());
    spec = new QuerySpec(Project.class);
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=0}}", spec.toString());
    spec.addFilter(new FilterSpec(Arrays.asList("filterAttr"), FilterOperator.EQ, "test"));
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=0}, filters=[filterAttr EQ test]}", spec.toString());
    spec.addSort(new SortSpec(Arrays.asList("sortAttr"), Direction.ASC));
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=0}, filters=[filterAttr EQ test], sort=[sortAttr ASC]}", spec.toString());
    spec.includeField(Arrays.asList("includedField"));
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=0}, filters=[filterAttr EQ test], sort=[sortAttr ASC], " + "includedFields=[includedField]}", spec.toString());
    spec.includeRelation(Arrays.asList("includedRelation"));
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=0}, filters=[filterAttr EQ test], sort=[sortAttr ASC], " + "includedFields=[includedField], includedRelations=[includedRelation]}", spec.toString());
    spec.setPagingSpec(new OffsetLimitPagingSpec(12L, 13L));
    Assert.assertEquals("QuerySpec{resourceClass=io.crnk.core.mock.models.Project, paging=OffsetLimitPagingSpec{offset=12, limit=13}, filters=[filterAttr EQ test], " + "sort=[sortAttr ASC], includedFields=[includedField], includedRelations=[includedRelation]}", spec.toString());
}
Also used : Project(io.crnk.core.mock.models.Project) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) Test(org.junit.Test)

Example 5 with OffsetLimitPagingSpec

use of io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec in project crnk-framework by crnk-project.

the class QuerySpecAdapterTest method test.

@Test
public void test() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
    resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
    QuerySpec spec = new QuerySpec(Task.class);
    spec.includeField(Arrays.asList("test"));
    spec.includeRelation(Arrays.asList("relation"));
    QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
    Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
    Assert.assertEquals(spec, adapter.getQuerySpec());
    TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
    IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
    Assert.assertEquals(1, includedFieldsParams.getParams().size());
    Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
    TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
    IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
    Assert.assertEquals(1, includedRelationsParams.getParams().size());
    Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
    Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) Test(org.junit.Test)

Aggregations

OffsetLimitPagingSpec (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec)7 Test (org.junit.Test)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3 QuerySpec (io.crnk.core.queryspec.QuerySpec)3 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)3 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)1 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 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 Project (io.crnk.core.mock.models.Project)1 Schedule (io.crnk.core.mock.models.Schedule)1 User (io.crnk.core.mock.models.User)1 UserRepository (io.crnk.core.mock.repository.UserRepository)1 UserToProjectRepository (io.crnk.core.mock.repository.UserToProjectRepository)1 UserToTaskRepository (io.crnk.core.mock.repository.UserToTaskRepository)1 ModuleRegistry (io.crnk.core.module.ModuleRegistry)1