Skip to content

Commit

Permalink
RepositoryResourceMappings now processes all entities to detect repos…
Browse files Browse the repository at this point in the history
…itory 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.
  • Loading branch information
odrotbohm committed Jul 7, 2021
1 parent ab00721 commit 940a676
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ public RepositoryResourceMappings(Repositories repositories, PersistentEntities

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.getLinkRelationProvider();
Expand Down

0 comments on commit 940a676

Please sign in to comment.