Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow scoping ContentGridLinkCollector to specific entities #303

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@RequiredArgsConstructor
class AggregateLinkCollector implements LinkCollector {
private final LinkCollector delegate;
private final Iterable<ContentGridLinkCollector> collectors;
private final Iterable<ContentGridLinkCollector<?>> collectors;

@Override
public Links getLinksFor(Object object) {
Expand All @@ -18,7 +18,10 @@ public Links getLinksFor(Object object) {
public Links getLinksFor(Object object, Links existing) {
existing = delegate.getLinksFor(object, existing);
for (var collector : collectors) {
existing = collector.getLinksFor(object, existing);
final Links finalExisting = existing;
existing = LambdaSafe.callback(ContentGridLinkCollector.class, collector, object, finalExisting)
.invokeAnd(c -> c.getLinksFor(object, finalExisting))
.get(finalExisting);
}
return existing;
}
Expand All @@ -27,7 +30,10 @@ public Links getLinksFor(Object object, Links existing) {
public Links getLinksForNested(Object object, Links existing) {
existing = delegate.getLinksForNested(object, existing);
for (var collector : collectors) {
existing = collector.getLinksForNested(object, existing);
final Links finalExisting = existing;
existing = LambdaSafe.callback(ContentGridLinkCollector.class, collector, object, finalExisting)
.invokeAnd(c -> c.getLinksForNested(object, finalExisting))
.get(finalExisting);
}
return existing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.springframework.hateoas.Links;

public interface ContentGridLinkCollector {
public interface ContentGridLinkCollector<T> {

Links getLinksFor(Object object, Links existing);
Links getLinksFor(T object, Links existing);

Links getLinksForNested(Object object, Links existing);
default Links getLinksForNested(T object, Links existing) {
return existing;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Import(ContentGridSpringDataLinksConfiguration.class)
public class ContentGridSpringContentRestLinksConfiguration {
@Bean
ContentGridLinkCollector contentGridSpringContentLinkCollector(
ContentGridLinkCollector<?> contentGridSpringContentLinkCollector(
PersistentEntities entities, Stores stores, MappingContext mappingContext,
RestConfiguration restConfiguration, ContentPropertyToRequestMappingContext requestMappingContext,
ContentPropertyToLinkrelMappingContext linkrelMappingContext, MessageResolver resolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ContentGridSpringDataLinksConfiguration {

@Bean
RepositoryRestConfigurer contentGridLinkCollectorConfigurer(
ObjectProvider<ContentGridLinkCollector> collectors
ObjectProvider<ContentGridLinkCollector<?>> collectors
) {
return new RepositoryRestConfigurer() {
@Override
Expand All @@ -40,7 +40,8 @@ public LinkCollector customizeLinkCollector(LinkCollector collector) {
}

@Bean
ContentGridLinkCollector contentGridRelationLinkCollector(PersistentEntities entities, Associations associations, SelfLinkProvider selfLinkProvider, MessageResolver resolver) {
ContentGridLinkCollector<?> contentGridRelationLinkCollector(PersistentEntities entities, Associations associations,
SelfLinkProvider selfLinkProvider, MessageResolver resolver) {
return new SpringDataAssociationLinkCollector(entities, associations, selfLinkProvider, resolver);
}

Expand Down
Loading