DATAREST-427 - Refactorings in UriToEntityConverter.
Instead of using a DomainClassConverter directly we now use a raw ConversionService in UriToEntityConverter. This allos us to get rid off the bean definitions for UriToEntityConverter and DomainClassConverter. The population of the ConversionService is now taken care of by calling SpringDataWebConfiguration's addFormatter(…) in defaultConversionService(). Added unit tests for UriToEntityConverter.
This commit is contained in:
@@ -43,15 +43,10 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.GeoModule;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.data.geo.format.DistanceFormatter;
|
||||
import org.springframework.data.geo.format.PointFormatter;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.repository.support.DefaultRepositoryInvokerFactory;
|
||||
import org.springframework.data.repository.support.DomainClassConverter;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.UriToEntityConverter;
|
||||
@@ -191,16 +186,6 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
return conversionService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainClassConverter<?> domainClassConverter() {
|
||||
return new DomainClassConverter<DefaultFormattingConversionService>(defaultConversionService());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UriToEntityConverter uriToEntityConverter() {
|
||||
return new UriToEntityConverter(persistentEntities(), domainClassConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link org.springframework.context.ApplicationListener} implementation for invoking
|
||||
* {@link org.springframework.validation.Validator} instances assigned to specific domain types.
|
||||
@@ -534,8 +519,11 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
* @return
|
||||
*/
|
||||
private Module persistentEntityJackson2Module() {
|
||||
return new PersistentEntityJackson2Module(resourceMappings(), persistentEntities(), config(),
|
||||
uriToEntityConverter());
|
||||
|
||||
PersistentEntities entities = persistentEntities();
|
||||
|
||||
return new PersistentEntityJackson2Module(resourceMappings(), entities, config(), new UriToEntityConverter(
|
||||
entities, defaultConversionService()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.json;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,6 +35,7 @@ import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||
import org.springframework.data.rest.webmvc.mongodb.MongoDbRepositoryConfig;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
@@ -69,27 +69,22 @@ public class RepositoryTestsConfig {
|
||||
|
||||
config.setResourceMappingForDomainType(Person.class).setRel("person");
|
||||
|
||||
// config.setResourceMappingForRepository(ConfiguredPersonRepository.class)
|
||||
// .setRel("people")
|
||||
// .setPath("people")
|
||||
// .setExported(false);
|
||||
|
||||
config.setResourceMappingForRepository(PersonRepository.class).setRel("people").setPath("people")
|
||||
.addResourceMappingFor("findByFirstName").setRel("firstname").setPath("firstname");
|
||||
|
||||
config.setBaseUri(URI.create("http://localhost:8080"));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultFormattingConversionService defaultConversionService() {
|
||||
return new DefaultFormattingConversionService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DomainClassConverter<?> domainClassConverter() {
|
||||
return new DomainClassConverter<DefaultFormattingConversionService>(defaultConversionService());
|
||||
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
|
||||
|
||||
DomainClassConverter<FormattingConversionService> converter = new DomainClassConverter<FormattingConversionService>(
|
||||
conversionService);
|
||||
converter.setApplicationContext(appCtx);
|
||||
|
||||
return conversionService;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -97,15 +92,10 @@ public class RepositoryTestsConfig {
|
||||
return new PersistentEntities(mappingContexts);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UriToEntityConverter uriToEntityConverter() {
|
||||
return new UriToEntityConverter(persistentEntities(), domainClassConverter());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Module persistentEntityModule() {
|
||||
return new PersistentEntityJackson2Module(new RepositoryResourceMappings(config(), repositories()),
|
||||
persistentEntities(), config(), uriToEntityConverter());
|
||||
persistentEntities(), config(), new UriToEntityConverter(persistentEntities(), defaultConversionService()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user