Search in sources :

Example 6 with OffsetLimitPagingBehavior

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

the class CrnkBoot method setupPagingBehavior.

private void setupPagingBehavior() {
    if (moduleRegistry.getPagingBehaviors().isEmpty()) {
        setupServiceDiscovery();
        moduleRegistry.addAllPagingBehaviors(serviceDiscovery.getInstancesByType(PagingBehavior.class));
        if (moduleRegistry.getPagingBehaviors().isEmpty()) {
            moduleRegistry.addPagingBehavior(new OffsetLimitPagingBehavior());
        }
    }
    for (PagingBehavior pagingBehavior : moduleRegistry.getPagingBehaviors()) {
        if (pagingBehavior instanceof OffsetLimitPagingBehavior) {
            if (defaultPageLimit != null) {
                ((OffsetLimitPagingBehavior) pagingBehavior).setDefaultLimit(defaultPageLimit);
            }
            if (maxPageLimit != null) {
                ((OffsetLimitPagingBehavior) pagingBehavior).setMaxPageLimit(maxPageLimit);
            }
        }
    }
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) PagingBehavior(io.crnk.core.queryspec.pagingspec.PagingBehavior)

Example 7 with OffsetLimitPagingBehavior

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

the class TestResourceInformationProvider method build.

@Override
public ResourceInformation build(Class<?> resourceClass) {
    ResourceField idField = new ResourceFieldImpl("testId", "id", ResourceFieldType.ID, Integer.class, null, null);
    List<ResourceField> fields = Arrays.asList(idField);
    TypeParser typeParser = context.getTypeParser();
    ResourceInformation info = new ResourceInformation(typeParser, resourceClass, resourceClass.getSimpleName(), null, fields, new OffsetLimitPagingBehavior());
    return info;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceFieldImpl(io.crnk.core.engine.internal.information.resource.ResourceFieldImpl) TypeParser(io.crnk.core.engine.parser.TypeParser)

Example 8 with OffsetLimitPagingBehavior

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

the class DefaultResourceInformationProviderTest method getResourceInformationProviderWithProperty.

private ResourceInformationProvider getResourceInformationProviderWithProperty(String key, String value) {
    PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
    Mockito.when(propertiesProvider.getProperty(Mockito.eq(key))).thenReturn(value);
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(propertiesProvider, new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    resourceInformationProvider.init(context);
    return resourceInformationProvider;
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)

Example 9 with OffsetLimitPagingBehavior

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

the class QueryParamsAdapterTest method test.

@Test
public void test() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QueryParams params = new QueryParams();
    DefaultResourceInformationProvider builder = new DefaultResourceInformationProvider(new NullPropertiesProvider(), new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
    ResourceInformation info = builder.build(Task.class);
    QueryParamsAdapter adapter = new QueryParamsAdapter(info, params, moduleRegistry);
    Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
    Assert.assertEquals(resourceRegistry, adapter.getResourceRegistry());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Test(org.junit.Test)

Example 10 with OffsetLimitPagingBehavior

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

the class ResourceInformationTest method setup.

@Before
public void setup() throws NoSuchFieldException {
    ResourceField idField = new ResourceFieldImpl("id", "id", ResourceFieldType.ID, Long.class, Long.class, null);
    ResourceField valueField = new ResourceFieldImpl("value", "value", ResourceFieldType.RELATIONSHIP, String.class, String.class, "projects");
    TypeParser typeParser = new TypeParser();
    sut = new ResourceInformation(typeParser, Task.class, "tasks", null, Arrays.asList(idField, valueField), new OffsetLimitPagingBehavior());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Task(io.crnk.core.mock.models.Task) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceFieldImpl(io.crnk.core.engine.internal.information.resource.ResourceFieldImpl) TypeParser(io.crnk.core.engine.parser.TypeParser) Before(org.junit.Before)

Aggregations

OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)15 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)5 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)5 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)5 TypeParser (io.crnk.core.engine.parser.TypeParser)5 Before (org.junit.Before)5 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)4 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)4 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)4 ModuleRegistry (io.crnk.core.module.ModuleRegistry)4 Test (org.junit.Test)4 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)3 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)3 ResourceFieldImpl (io.crnk.core.engine.internal.information.resource.ResourceFieldImpl)3 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)3