Search in sources :

Example 1 with ResponseRelationshipEntry

use of io.crnk.core.engine.registry.ResponseRelationshipEntry in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method findRelationshipMatch.

private ResponseRelationshipEntry findRelationshipMatch(ResourceField relationshipField) {
    Collection<Object> repositories = moduleRegistry.getRepositories();
    RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
    ResponseRelationshipEntry matchedEntry = null;
    for (Object repository : repositories) {
        RepositoryInformation repositoryInformation = repositoryInformationBuilder.build(repository, new DefaultRepositoryInformationProviderContext(moduleRegistry));
        if (repositoryInformation instanceof RelationshipRepositoryInformation) {
            RelationshipRepositoryInformation relationshipRepositoryInformation = (RelationshipRepositoryInformation) repositoryInformation;
            RelationshipMatcher matcher = relationshipRepositoryInformation.getMatcher();
            if (matcher.matches(relationshipField)) {
                if (matchedEntry != null) {
                    throw new IllegalStateException("multiple repositories for " + relationshipField + ": " + repository + ", " + matchedEntry);
                }
                matcher.matches(relationshipField);
                matchedEntry = setupRelationship(relationshipField, relationshipRepositoryInformation, repository);
            }
        }
    }
    return matchedEntry;
}
Also used : RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) DefaultRepositoryInformationProviderContext(io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext) RepositoryInformationProvider(io.crnk.core.engine.information.repository.RepositoryInformationProvider) RelationshipMatcher(io.crnk.core.repository.RelationshipMatcher) ResourceRepositoryInformation(io.crnk.core.engine.information.repository.ResourceRepositoryInformation) RepositoryInformation(io.crnk.core.engine.information.repository.RepositoryInformation) RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)

Example 2 with ResponseRelationshipEntry

use of io.crnk.core.engine.registry.ResponseRelationshipEntry in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method buildRelationships.

private Map<ResourceField, ResponseRelationshipEntry> buildRelationships(ResourceInformation resourceInformation) {
    for (String relationshipName : relationshipRepositoryMap.keySet()) {
        if (resourceInformation.findFieldByUnderlyingName(relationshipName) == null) {
            throw new ResourceFieldNotFoundException("failed to find relationship field '" + relationshipName + "' to setup " + "registered relationship repository");
        }
    }
    Map<ResourceField, ResponseRelationshipEntry> map = new HashMap<>();
    for (ResourceField relationshipField : resourceInformation.getRelationshipFields()) {
        ResponseRelationshipEntry relationshipEntry = null;
        // check for local definition
        DefaultRelationshipRepository repository = relationshipRepositoryMap.get(relationshipField.getUnderlyingName());
        if (repository != null) {
            RelationshipRepositoryInformation relationshipInformation = repository.information.build();
            relationshipEntry = setupRelationship(relationshipField, relationshipInformation, repository.instance);
        }
        // check for match
        if (relationshipEntry == null) {
            relationshipEntry = findRelationshipMatch(relationshipField);
        }
        // check for implicit
        if (relationshipEntry == null) {
            relationshipEntry = setupImplicitRelationshipRepository(relationshipField);
        }
        if (relationshipEntry != null) {
            map.put(relationshipField, relationshipEntry);
        } else {
            LOGGER.warn("no relationship repository found for " + resourceInformation.getResourceType() + "." + relationshipField.getUnderlyingName());
        }
    }
    return map;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation) ResourceFieldNotFoundException(io.crnk.core.exception.ResourceFieldNotFoundException) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) HashMap(java.util.HashMap)

Example 3 with ResponseRelationshipEntry

use of io.crnk.core.engine.registry.ResponseRelationshipEntry in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method build.

@Override
public RegistryEntry build() {
    ResourceInformation resourceInformation = buildResource();
    ResourceEntry resourceEntry = buildResourceRepository(resourceInformation);
    Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = buildRelationships(resourceInformation);
    RegistryEntry entry = new RegistryEntry(resourceEntry, relationshipEntries);
    entry.initialize(moduleRegistry);
    return entry;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) ResourceEntry(io.crnk.core.engine.registry.ResourceEntry) AnnotatedResourceEntry(io.crnk.legacy.registry.AnnotatedResourceEntry) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

ResponseRelationshipEntry (io.crnk.core.engine.registry.ResponseRelationshipEntry)3 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)3 RelationshipRepositoryInformation (io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)2 RepositoryInformation (io.crnk.core.engine.information.repository.RepositoryInformation)1 RepositoryInformationProvider (io.crnk.core.engine.information.repository.RepositoryInformationProvider)1 ResourceRepositoryInformation (io.crnk.core.engine.information.repository.ResourceRepositoryInformation)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 ResourceEntry (io.crnk.core.engine.registry.ResourceEntry)1 ResourceFieldNotFoundException (io.crnk.core.exception.ResourceFieldNotFoundException)1 DefaultRepositoryInformationProviderContext (io.crnk.core.module.internal.DefaultRepositoryInformationProviderContext)1 RelationshipMatcher (io.crnk.core.repository.RelationshipMatcher)1 DirectResponseResourceEntry (io.crnk.legacy.internal.DirectResponseResourceEntry)1 AnnotatedResourceEntry (io.crnk.legacy.registry.AnnotatedResourceEntry)1 HashMap (java.util.HashMap)1