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:
Oliver Gierke
2015-12-09 16:00:32 +01:00
parent 44ab756873
commit 3a66bc75e2
4 changed files with 327 additions and 2 deletions

View File

@@ -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() {