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