Search in sources :

Example 6 with InformationBuilder

use of io.crnk.core.engine.information.InformationBuilder in project crnk-framework by crnk-project.

the class JsonApiQueryParamsParserTest method parseQueryParams.

private QueryParams parseQueryParams() {
    TestResourceInformationProvider infoBuilder = new TestResourceInformationProvider();
    infoBuilder.init(new ResourceInformationProviderContext() {

        @Override
        public String getResourceType(Class<?> clazz) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean accept(Class<?> type) {
            throw new UnsupportedOperationException();
        }

        @Override
        public TypeParser getTypeParser() {
            return new TypeParser();
        }

        @Override
        public InformationBuilder getInformationBuilder() {
            throw new UnsupportedOperationException();
        }

        @Override
        public ObjectMapper getObjectMapper() {
            throw new UnsupportedOperationException();
        }
    });
    return parser.parse(new SimpleQueryParamsParserContext(queryParams, infoBuilder.build(TestResource.class)));
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) SimpleQueryParamsParserContext(io.crnk.legacy.queryParams.context.SimpleQueryParamsParserContext) TypeParser(io.crnk.core.engine.parser.TypeParser) ResourceInformationProviderContext(io.crnk.core.engine.information.resource.ResourceInformationProviderContext) TestResourceInformationProvider(io.crnk.core.module.TestResourceInformationProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with InformationBuilder

use of io.crnk.core.engine.information.InformationBuilder in project crnk-framework by crnk-project.

the class JaxrsModuleTest method setup.

@Before
public void setup() {
    final ModuleRegistry moduleRegistry = new ModuleRegistry();
    builder = new JaxrsModule.JaxrsResourceRepositoryInformationProvider();
    final ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(moduleRegistry.getPropertiesProvider(), ImmutableList.<PagingBehavior>of(new OffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    resourceInformationProvider.init(new DefaultResourceInformationProviderContext(resourceInformationProvider, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
    context = new RepositoryInformationProviderContext() {

        @Override
        public ResourceInformationProvider getResourceInformationBuilder() {
            return resourceInformationProvider;
        }

        @Override
        public TypeParser getTypeParser() {
            return moduleRegistry.getTypeParser();
        }

        @Override
        public InformationBuilder builder() {
            return new DefaultInformationBuilder(moduleRegistry.getTypeParser());
        }
    };
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) TypeParser(io.crnk.core.engine.parser.TypeParser) ModuleRegistry(io.crnk.core.module.ModuleRegistry) JaxrsModule(io.crnk.rs.internal.JaxrsModule) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) RepositoryInformationProviderContext(io.crnk.core.engine.information.repository.RepositoryInformationProviderContext) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Example 8 with InformationBuilder

use of io.crnk.core.engine.information.InformationBuilder in project crnk-framework by crnk-project.

the class AbstractQuerySpecTest method setup.

@Before
public void setup() {
    ResourceInformationProvider resourceInformationProvider = new DefaultResourceInformationProvider(new NullPropertiesProvider(), ImmutableList.of(new OffsetLimitPagingBehavior(), new CustomOffsetLimitPagingBehavior()), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider()) {

        @Override
        protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
            List<ResourceField> fields = super.getResourceFields(resourceClass);
            if (resourceClass == Task.class) {
                // add additional field that is not defined on the class
                String name = "computedAttribute";
                ResourceFieldAccess access = new ResourceFieldAccess(true, true, true, true, true);
                InformationBuilder informationBuilder = new DefaultInformationBuilder(new TypeParser());
                InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
                fieldBuilder.type(Integer.class);
                fieldBuilder.jsonName(name);
                fieldBuilder.underlyingName(name);
                fieldBuilder.access(access);
                fieldBuilder.accessor(new ResourceFieldAccessor() {

                    public Object getValue(Object resource) {
                        return 13;
                    }

                    public void setValue(Object resource, Object fieldValue) {
                    }
                });
                fields.add(fieldBuilder.build());
            }
            return fields;
        }
    };
    SimpleModule testModule = new SimpleModule("test");
    testModule.addResourceInformationProvider(resourceInformationProvider);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://127.0.0.1"));
    boot.addModule(testModule);
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(getResourceSearchPackage()));
    boot.boot();
    moduleRegistry = boot.getModuleRegistry();
    querySpecConverter = new DefaultQuerySpecConverter(moduleRegistry);
    resourceRegistry = boot.getResourceRegistry();
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) TypeParser(io.crnk.core.engine.parser.TypeParser) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultQuerySpecConverter(io.crnk.legacy.internal.DefaultQuerySpecConverter) ResourceFieldAccess(io.crnk.core.engine.information.resource.ResourceFieldAccess) CustomOffsetLimitPagingBehavior(io.crnk.core.queryspec.repository.CustomOffsetLimitPagingBehavior) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldAccessor(io.crnk.core.engine.information.resource.ResourceFieldAccessor) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) SimpleModule(io.crnk.core.module.SimpleModule) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Before(org.junit.Before)

Aggregations

InformationBuilder (io.crnk.core.engine.information.InformationBuilder)8 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TypeParser (io.crnk.core.engine.parser.TypeParser)4 ResourceField (io.crnk.core.engine.information.resource.ResourceField)3 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)3 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)3 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 DefaultResourceInformationProviderContext (io.crnk.legacy.registry.DefaultResourceInformationProviderContext)3 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)2 ResourceInformationProviderContext (io.crnk.core.engine.information.resource.ResourceInformationProviderContext)2 TestResourceInformationProvider (io.crnk.core.module.TestResourceInformationProvider)2 SimpleQueryParamsParserContext (io.crnk.legacy.queryParams.context.SimpleQueryParamsParserContext)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 BeanAttributeInformation (io.crnk.core.engine.information.bean.BeanAttributeInformation)1 BeanInformation (io.crnk.core.engine.information.bean.BeanInformation)1 ResourceFieldContributor (io.crnk.core.engine.information.contributor.ResourceFieldContributor)1