DATAREST-724 - Added configuration API for entity lookup customizations.
RepositoryRestConfiguration now exposes a withCustomEntityLookup() returning an EntityLookupRegistrar that allows to define customizations as follows on Java 8: config.withCustomEntityLookup() .forRepository(UserRepository.class) .withIdMapping(User::getUsername) .withLookup(UserRepository::findByUsername); or even abbreviated to: config.withCustomEntityLookup() .forRepository(UserRepository.class, User::getUsername, UserRepository::findByUsername); The API basically takes two lambdas or method references to define the id mapping (User::getUsername in this case) as well as the lookup call based on the repository type with which the customization builder was set up in the first place (UserRepository::findByUsername in this case).
This commit is contained in:
@@ -630,7 +630,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
public RepositoryInvokerFactory repositoryInvokerFactory() {
|
||||
|
||||
return new UnwrappingRepositoryInvokerFactory(
|
||||
new DefaultRepositoryInvokerFactory(repositories(), defaultConversionService()), lookups);
|
||||
new DefaultRepositoryInvokerFactory(repositories(), defaultConversionService()), getEntityLookups());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -715,7 +715,16 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
|
||||
@Bean
|
||||
public SelfLinkProvider selfLinkProvider() {
|
||||
return new DefaultSelfLinkProvider(persistentEntities(), entityLinks(), lookups);
|
||||
return new DefaultSelfLinkProvider(persistentEntities(), entityLinks(), getEntityLookups());
|
||||
}
|
||||
|
||||
protected List<EntityLookup<?>> getEntityLookups() {
|
||||
|
||||
List<EntityLookup<?>> lookups = new ArrayList<EntityLookup<?>>();
|
||||
lookups.addAll(config().getEntityLookups(repositories()));
|
||||
lookups.addAll(this.lookups);
|
||||
|
||||
return lookups;
|
||||
}
|
||||
|
||||
protected List<HandlerMethodArgumentResolver> defaultMethodArgumentResolvers() {
|
||||
|
||||
Reference in New Issue
Block a user