Search in sources :

Example 1 with ResourceFieldContributor

use of io.crnk.core.engine.information.contributor.ResourceFieldContributor 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)

Aggregations

InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 ResourceFieldContributor (io.crnk.core.engine.information.contributor.ResourceFieldContributor)1 ResourceFieldContributorContext (io.crnk.core.engine.information.contributor.ResourceFieldContributorContext)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 ArrayList (java.util.ArrayList)1