Properly handle associations in nested entities.
Nested entities that contain a reference to an aggregate root get a link to that attached to their representation. Previously, the creation of those links assumed that the reference is a materialized instance of the remote aggregate. That's now altered to be able to deal with associations, use identifiers directly or materialize to an intermediate aggregate instance to potentially use a custom lookup.
This commit is contained in:
@@ -829,8 +829,10 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SelfLinkProvider selfLinkProvider(PersistentEntities persistentEntities, RepositoryEntityLinks entityLinks) {
|
||||
return new DefaultSelfLinkProvider(persistentEntities, entityLinks, getEntityLookups());
|
||||
public SelfLinkProvider selfLinkProvider(PersistentEntities persistentEntities, RepositoryEntityLinks entityLinks,
|
||||
@Qualifier("mvcConversionService") ObjectProvider<ConversionService> conversionService) {
|
||||
return new DefaultSelfLinkProvider(persistentEntities, entityLinks, getEntityLookups(),
|
||||
conversionService.getIfUnique(() -> defaultConversionService));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -183,7 +183,7 @@ public class LinkCollector {
|
||||
private final SelfLinkProvider selfLinks;
|
||||
private final PersistentPropertyAccessor<?> accessor;
|
||||
private final Associations associations;
|
||||
private final List<Link> links = new ArrayList<Link>();
|
||||
private Links links = Links.NONE;
|
||||
|
||||
public NestedLinkCollectingAssociationHandler(SelfLinkProvider selfLinks,
|
||||
PersistentPropertyAccessor<?> accessor, Associations associations) {
|
||||
@@ -198,7 +198,7 @@ public class LinkCollector {
|
||||
}
|
||||
|
||||
public List<Link> getLinks() {
|
||||
return this.links;
|
||||
return this.links.toList();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -223,9 +223,10 @@ public class LinkCollector {
|
||||
ResourceMapping propertyMapping = metadata.getMappingFor(property);
|
||||
|
||||
for (Object element : asCollection(value)) {
|
||||
if (element != null) {
|
||||
links.add(getLinkFor(element, propertyMapping));
|
||||
}
|
||||
|
||||
links = links.andIf(element != null,
|
||||
() -> selfLinks.createSelfLinkFor(property.getAssociationTargetType(), element)
|
||||
.withRel(propertyMapping.getRel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user