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