RepositoryResourceMappings now processes all entities to detect repository mappings.

We now consider all registered PersistentEntity instances and try to detect repository metadata for them. A case we didn't cover before was that a repository was declared for an aggregate super type but the actual child aggregate class didn't have a dedicated repository declared. While this is a perfectly valid scenario, the mapping information was broken as it fell back on the plain domain type information and produced paths and relation names derived from that, even if there's a super type repository available.

Thus, solely traversing the aggregate types we have repositories registered for is not enough. We now traverse all known PersistentEntity types and also register repository metadata for all types that are assignable to a known domain type. The latter is actually implemented in Spring Data Commons' Repositories via spring-projects/spring-data-commons#2406.
This commit is contained in:
Oliver Drotbohm
2021-07-07 16:20:09 +02:00
parent 29f0fd1a98
commit c682ebbd1d

View File

@@ -61,16 +61,21 @@ public class RepositoryResourceMappings extends PersistentEntitiesResourceMappin
this.repositories = repositories;
this.configuration = configuration;
this.populateCache(repositories, configuration);
this.populateCache(entities, configuration);
}
private void populateCache(Repositories repositories, RepositoryRestConfiguration configuration) {
private void populateCache(PersistentEntities entities, RepositoryRestConfiguration configuration) {
for (Class<?> type : repositories) {
for (PersistentEntity<?, ? extends PersistentProperty<?>> entity : entities) {
Class<?> type = entity.getType();
if (!repositories.hasRepositoryFor(type)) {
continue;
}
RepositoryInformation repositoryInformation = repositories.getRequiredRepositoryInformation(type);
Class<?> repositoryInterface = repositoryInformation.getRepositoryInterface();
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(type);
RepositoryDetectionStrategy strategy = configuration.getRepositoryDetectionStrategy();
LinkRelationProvider provider = configuration.getRelProvider();