Search in sources :

Example 1 with InformationBuilder

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

the class ModuleRegistry method getResourceInformationBuilder.

/**
 * Returns a {@link ResourceInformationProvider} instance that combines all
 * instances registered by modules.
 *
 * @return resource information builder
 */
public ResourceInformationProvider getResourceInformationBuilder() {
    if (resourceInformationProvider == null) {
        resourceInformationProvider = new CombinedResourceInformationProvider(aggregatedModule.getResourceInformationProviders());
        InformationBuilder informationBuilder = new DefaultInformationBuilder(typeParser);
        DefaultResourceInformationProviderContext context = new DefaultResourceInformationProviderContext(resourceInformationProvider, informationBuilder, typeParser, objectMapper);
        resourceInformationProvider.init(context);
    }
    return resourceInformationProvider;
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext)

Example 2 with InformationBuilder

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

the class MetaModule method registerInformationBuilder.

protected DefaultResourceInformationProvider registerInformationBuilder(PropertiesProvider propertiesProvider) {
    InformationBuilder informationBuilder = new DefaultInformationBuilder(context.getTypeParser());
    DefaultResourceInformationProvider informationProvider = new DefaultResourceInformationProvider(propertiesProvider, new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    informationProvider.init(new DefaultResourceInformationProviderContext(informationProvider, informationBuilder, context.getTypeParser(), null) {

        @Override
        public ObjectMapper getObjectMapper() {
            return context.getObjectMapper();
        }
    });
    return informationProvider;
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)

Example 3 with InformationBuilder

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

the class DefaultRegistryEntryBuilder method contributeFields.

private void contributeFields(ResourceInformation resourceInformation) {
    // TODO make service discovery the primary target to resolve all objects => wrapped it with module
    List<ResourceFieldContributor> contributors = new ArrayList<>();
    contributors.addAll(moduleRegistry.getServiceDiscovery().getInstancesByType(ResourceFieldContributor.class));
    for (Object repo : moduleRegistry.getRepositories()) {
        if (repo instanceof ResourceFieldContributor && !contributors.contains(repo)) {
            contributors.add((ResourceFieldContributor) repo);
        }
    }
    for (ResourceFieldContributor contributor : contributors) {
        List<ResourceField> contributedFields = contributor.getResourceFields(new ResourceFieldContributorContext() {

            @Override
            public ResourceInformation getResourceInformation() {
                return resourceInformation;
            }

            @Override
            public InformationBuilder getInformationBuilder() {
                return new DefaultInformationBuilder(moduleRegistry.getTypeParser());
            }
        });
        List<ResourceField> fields = new ArrayList<>();
        fields.addAll(resourceInformation.getFields());
        fields.addAll(contributedFields);
        resourceInformation.setFields(fields);
    }
}
Also used : InformationBuilder(io.crnk.core.engine.information.InformationBuilder) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) ResourceFieldContributor(io.crnk.core.engine.information.contributor.ResourceFieldContributor) ArrayList(java.util.ArrayList) ResourceFieldContributorContext(io.crnk.core.engine.information.contributor.ResourceFieldContributorContext)

Example 4 with InformationBuilder

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

the class ResourceInformationProviderBase method getResourceFields.

protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
    BeanInformation beanDesc = BeanInformation.get(resourceClass);
    List<String> attributeNames = beanDesc.getAttributeNames();
    List<ResourceField> fields = new ArrayList<>();
    Set<String> relationIdFields = new HashSet<>();
    for (String attributeName : attributeNames) {
        BeanAttributeInformation attributeDesc = beanDesc.getAttribute(attributeName);
        if (!isIgnored(attributeDesc)) {
            InformationBuilder informationBuilder = context.getInformationBuilder();
            InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
            buildResourceField(beanDesc, attributeDesc, fieldBuilder);
            fields.add(fieldBuilder.build());
        } else if (attributeDesc.getAnnotation(JsonApiRelationId.class).isPresent()) {
            relationIdFields.add(attributeDesc.getName());
        }
    }
    verifyRelationIdFields(resourceClass, relationIdFields, fields);
    return fields;
}
Also used : BeanInformation(io.crnk.core.engine.information.bean.BeanInformation) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ArrayList(java.util.ArrayList) BeanAttributeInformation(io.crnk.core.engine.information.bean.BeanAttributeInformation) HashSet(java.util.HashSet)

Example 5 with InformationBuilder

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

the class DefaultQueryParamsParserTest 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)

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