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