DATAREST-724 - Added support for customizing the property to be used for URI generation.
Spring Data REST now exposes an EntityLookup interface that allows to customize the property of an entity that shall be used to create item resource URIs. By default this mechanism uses the backend identifier and uses the repository's findOne(…) method. The EntityLookup now exposes one method to return the property value to be used for URI generation as well as one method to obtain the entity instance from the very same raw identifier value. The EntityLookups are registered with both the SelfLinkProvider (for link creation) and the RepositoryInvoker (to obtain the entity instance).
This commit is contained in:
@@ -27,10 +27,10 @@ import org.springframework.data.mapping.SimpleAssociationHandler;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource.Builder;
|
||||
import org.springframework.data.rest.webmvc.mapping.AssociationLinks;
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceAssembler;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
@@ -45,29 +45,29 @@ import org.springframework.util.Assert;
|
||||
public class PersistentEntityResourceAssembler implements ResourceAssembler<Object, PersistentEntityResource> {
|
||||
|
||||
private final PersistentEntities entities;
|
||||
private final EntityLinks entityLinks;
|
||||
private final Projector projector;
|
||||
private final ResourceMappings mappings;
|
||||
private final EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
|
||||
private final SelfLinkProvider linkProvider;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PersistentEntityResourceAssembler}.
|
||||
*
|
||||
* @param entities must not be {@literal null}.
|
||||
* @param entityLinks must not be {@literal null}.
|
||||
* @param linkProvider must not be {@literal null}.
|
||||
* @param projector must not be {@literal null}.
|
||||
* @param mappings must not be {@literal null}.
|
||||
*/
|
||||
public PersistentEntityResourceAssembler(PersistentEntities entities, EntityLinks entityLinks, Projector projector,
|
||||
ResourceMappings mappings) {
|
||||
public PersistentEntityResourceAssembler(PersistentEntities entities, SelfLinkProvider linkProvider,
|
||||
Projector projector, ResourceMappings mappings) {
|
||||
|
||||
Assert.notNull(entities, "PersistentEntities must not be null!");
|
||||
Assert.notNull(entityLinks, "EntityLinks must not be null!");
|
||||
Assert.notNull(linkProvider, "SelfLinkProvider must not be null!");
|
||||
Assert.notNull(projector, "PersistentEntityProjector must not be be null!");
|
||||
Assert.notNull(mappings, "ResourceMappings must not be null!");
|
||||
|
||||
this.entities = entities;
|
||||
this.entityLinks = entityLinks;
|
||||
this.linkProvider = linkProvider;
|
||||
this.projector = projector;
|
||||
this.mappings = mappings;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class PersistentEntityResourceAssembler implements ResourceAssembler<Obje
|
||||
return PersistentEntityResource.build(instance, entity).//
|
||||
withEmbedded(getEmbeddedResources(source)).//
|
||||
withLink(getSelfLinkFor(source)).//
|
||||
withLink(getSingleResourceLinkTo(source));
|
||||
withLink(linkProvider.createSelfLinkFor(source));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,23 +184,8 @@ public class PersistentEntityResourceAssembler implements ResourceAssembler<Obje
|
||||
* @return
|
||||
*/
|
||||
public Link getSelfLinkFor(Object instance) {
|
||||
return new Link(getSingleResourceLinkTo(instance).expand().getHref(), Link.REL_SELF);
|
||||
}
|
||||
|
||||
private Link getSingleResourceLinkTo(Object instance) {
|
||||
|
||||
Assert.notNull(instance, "Domain object must not be null!");
|
||||
|
||||
Class<? extends Object> instanceType = instance.getClass();
|
||||
PersistentEntity<?, ?> entity = entities.getPersistentEntity(instanceType);
|
||||
|
||||
if (entity == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Cannot create self link for %s! No persistent entity found!", instanceType));
|
||||
}
|
||||
|
||||
Object id = entity.getIdentifierAccessor(instance).getIdentifier();
|
||||
|
||||
return entityLinks.linkToSingleResource(entity.getType(), id);
|
||||
Link link = linkProvider.createSelfLinkFor(instance);
|
||||
return new Link(link.expand().getHref(), Link.REL_SELF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@ import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.projection.ProjectionDefinitions;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
|
||||
import org.springframework.data.rest.webmvc.support.PersistentEntityProjector;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
@@ -38,30 +39,30 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
public class PersistentEntityResourceAssemblerArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
private final PersistentEntities entities;
|
||||
private final EntityLinks entityLinks;
|
||||
private final SelfLinkProvider linkProvider;
|
||||
private final ProjectionDefinitions projectionDefinitions;
|
||||
private final ProjectionFactory projectionFactory;
|
||||
private final ResourceMappings mappings;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PersistentEntityResourceAssemblerArgumentResolver} for the given {@link Repositories},
|
||||
* {@link EntityLinks}, {@link ProjectionDefinitions} and {@link ProjectionFactory}.
|
||||
* {@link DefaultSelfLinkProvider}, {@link ProjectionDefinitions} and {@link ProjectionFactory}.
|
||||
*
|
||||
* @param entities must not be {@literal null}.
|
||||
* @param entityLinks must not be {@literal null}.
|
||||
* @param linkProvider must not be {@literal null}.
|
||||
* @param projectionDefinitions must not be {@literal null}.
|
||||
* @param projectionFactory must not be {@literal null}.
|
||||
*/
|
||||
public PersistentEntityResourceAssemblerArgumentResolver(PersistentEntities entities, EntityLinks entityLinks,
|
||||
public PersistentEntityResourceAssemblerArgumentResolver(PersistentEntities entities, SelfLinkProvider linkProvider,
|
||||
ProjectionDefinitions projectionDefinitions, ProjectionFactory projectionFactory, ResourceMappings mappings) {
|
||||
|
||||
Assert.notNull(entities, "PersistentEntities must not be null!");
|
||||
Assert.notNull(entityLinks, "EntityLinks must not be null!");
|
||||
Assert.notNull(linkProvider, "EntityLinks must not be null!");
|
||||
Assert.notNull(projectionDefinitions, "ProjectionDefinitions must not be null!");
|
||||
Assert.notNull(projectionFactory, "ProjectionFactory must not be null!");
|
||||
|
||||
this.entities = entities;
|
||||
this.entityLinks = entityLinks;
|
||||
this.linkProvider = linkProvider;
|
||||
this.projectionDefinitions = projectionDefinitions;
|
||||
this.projectionFactory = projectionFactory;
|
||||
this.mappings = mappings;
|
||||
@@ -88,6 +89,6 @@ public class PersistentEntityResourceAssemblerArgumentResolver implements Handle
|
||||
PersistentEntityProjector projector = new PersistentEntityProjector(projectionDefinitions, projectionFactory,
|
||||
projectionParameter, mappings);
|
||||
|
||||
return new PersistentEntityResourceAssembler(entities, entityLinks, projector, mappings);
|
||||
return new PersistentEntityResourceAssembler(entities, linkProvider, projector, mappings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,11 @@ import org.springframework.data.rest.core.event.ValidatingRepositoryEventListene
|
||||
import org.springframework.data.rest.core.mapping.RepositoryResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceDescription;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.DomainObjectMerger;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.data.rest.core.support.RepositoryRelProvider;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.webmvc.BasePathAwareController;
|
||||
import org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping;
|
||||
@@ -162,6 +165,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
|
||||
@Autowired(required = false) List<BackendIdConverter> idConverters = Collections.emptyList();
|
||||
@Autowired(required = false) List<RepositoryRestConfigurer> configurers = Collections.emptyList();
|
||||
@Autowired(required = false) List<EntityLookup<?>> lookups = Collections.emptyList();
|
||||
|
||||
@Autowired(required = false) RelProvider relProvider;
|
||||
@Autowired(required = false) CurieProvider curieProvider;
|
||||
@@ -588,7 +592,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
PersistentEntities entities = persistentEntities();
|
||||
|
||||
return new PersistentEntityJackson2Module(resourceMappings(), entities, config(),
|
||||
uriToEntityConverter(defaultConversionService()), entityLinks());
|
||||
uriToEntityConverter(defaultConversionService()), selfLinkProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -624,8 +628,9 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
|
||||
@Bean
|
||||
public RepositoryInvokerFactory repositoryInvokerFactory() {
|
||||
|
||||
return new UnwrappingRepositoryInvokerFactory(
|
||||
new DefaultRepositoryInvokerFactory(repositories(), defaultConversionService()));
|
||||
new DefaultRepositoryInvokerFactory(repositories(), defaultConversionService()), lookups);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -708,6 +713,11 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
return new MappingAuditableBeanWrapperFactory(persistentEntities());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SelfLinkProvider selfLinkProvider() {
|
||||
return new DefaultSelfLinkProvider(persistentEntities(), entityLinks(), lookups);
|
||||
}
|
||||
|
||||
protected List<HandlerMethodArgumentResolver> defaultMethodArgumentResolvers() {
|
||||
|
||||
SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
|
||||
@@ -715,7 +725,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
projectionFactory.setResourceLoader(applicationContext);
|
||||
|
||||
PersistentEntityResourceAssemblerArgumentResolver peraResolver = new PersistentEntityResourceAssemblerArgumentResolver(
|
||||
persistentEntities(), entityLinks(), config().getProjectionConfiguration(), projectionFactory,
|
||||
persistentEntities(), selfLinkProvider(), config().getProjectionConfiguration(), projectionFactory,
|
||||
resourceMappings());
|
||||
|
||||
HateoasPageableHandlerMethodArgumentResolver pageableResolver = pageableResolver();
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.data.mapping.IdentifierAccessor;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
@@ -36,10 +35,10 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.UriToEntityConverter;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.mapping.AssociationLinks;
|
||||
import org.springframework.data.rest.webmvc.mapping.LinkCollectingAssociationHandler;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.Resource;
|
||||
@@ -91,15 +90,16 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
/**
|
||||
* Creates a new {@link PersistentEntityJackson2Module} using the given {@link ResourceMappings}, {@link Repositories}
|
||||
* , {@link RepositoryRestConfiguration} and {@link UriToEntityConverter}.
|
||||
* , {@link RepositoryRestConfiguration}, {@link UriToEntityConverter} and {@link SelfLinkProvider}.
|
||||
*
|
||||
* @param mappings must not be {@literal null}.
|
||||
* @param entities must not be {@literal null}.
|
||||
* @param config must not be {@literal null}.
|
||||
* @param converter must not be {@literal null}.
|
||||
* @param linkProvider must not be {@literal null}.
|
||||
*/
|
||||
public PersistentEntityJackson2Module(ResourceMappings mappings, PersistentEntities entities,
|
||||
RepositoryRestConfiguration config, UriToEntityConverter converter, EntityLinks entityLinks) {
|
||||
RepositoryRestConfiguration config, UriToEntityConverter converter, SelfLinkProvider linkProvider) {
|
||||
|
||||
super(new Version(2, 0, 0, null, "org.springframework.data.rest", "jackson-module"));
|
||||
|
||||
@@ -107,9 +107,10 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
Assert.notNull(entities, "Repositories must not be null!");
|
||||
Assert.notNull(config, "RepositoryRestConfiguration must not be null!");
|
||||
Assert.notNull(converter, "UriToEntityConverter must not be null!");
|
||||
Assert.notNull(linkProvider, "SelfLinkProvider must not be null!");
|
||||
|
||||
AssociationLinks associationLinks = new AssociationLinks(mappings);
|
||||
LinkCollector collector = new LinkCollector(entities, entityLinks, associationLinks);
|
||||
LinkCollector collector = new LinkCollector(entities, linkProvider, associationLinks);
|
||||
|
||||
addSerializer(new PersistentEntityResourceSerializer(collector));
|
||||
addSerializer(new ProjectionSerializer(collector, mappings));
|
||||
@@ -344,8 +345,8 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
if (persistentProperty.isCollectionLike()) {
|
||||
|
||||
CollectionLikeType collectionType = config.getTypeFactory().constructCollectionLikeType(
|
||||
persistentProperty.getType(), persistentProperty.getActualType());
|
||||
CollectionLikeType collectionType = config.getTypeFactory()
|
||||
.constructCollectionLikeType(persistentProperty.getType(), persistentProperty.getActualType());
|
||||
CollectionValueInstantiator instantiator = new CollectionValueInstantiator(persistentProperty);
|
||||
CollectionDeserializer collectionDeserializer = new CollectionDeserializer(collectionType,
|
||||
uriStringDeserializer, null, instantiator);
|
||||
@@ -454,8 +455,8 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
* @see com.fasterxml.jackson.databind.ser.std.StdSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
|
||||
*/
|
||||
@Override
|
||||
public void serialize(TargetAware value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
|
||||
JsonGenerationException {
|
||||
public void serialize(TargetAware value, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException, JsonGenerationException {
|
||||
|
||||
Object target = value.getTarget();
|
||||
Links links = mappings.getMetadataFor(value.getTargetClass()).isExported() ? collector.getLinksFor(target)
|
||||
@@ -577,22 +578,23 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
private final PersistentEntities entities;
|
||||
private final AssociationLinks associationLinks;
|
||||
private final EntityLinks links;
|
||||
private final SelfLinkProvider links;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PersistentEntities}, {@link EntityLinks} and {@link AssociationLinks}.
|
||||
* Creates a new {@link PersistentEntities}, {@link SelfLinkProvider} and {@link AssociationLinks}.
|
||||
*
|
||||
* @param entities must not be {@literal null}.
|
||||
* @param entityLinks must not be {@literal null}.
|
||||
* @param linkProvider must not be {@literal null}.
|
||||
* @param associationLinks must not be {@literal null}.
|
||||
*/
|
||||
public LinkCollector(PersistentEntities entities, EntityLinks entityLinks, AssociationLinks associationLinks) {
|
||||
public LinkCollector(PersistentEntities entities, SelfLinkProvider linkProvider,
|
||||
AssociationLinks associationLinks) {
|
||||
|
||||
Assert.notNull(entities, "PersistentEntities must not be null!");
|
||||
Assert.notNull(entityLinks, "EntityLinks must not be null!");
|
||||
Assert.notNull(linkProvider, "SelfLinkProvider must not be null!");
|
||||
Assert.notNull(associationLinks, "AssociationLinks must not be null!");
|
||||
|
||||
this.links = entityLinks;
|
||||
this.links = linkProvider;
|
||||
this.entities = entities;
|
||||
this.associationLinks = associationLinks;
|
||||
}
|
||||
@@ -622,7 +624,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
PersistentEntity<?, ?> entity = entities.getPersistentEntity(object.getClass());
|
||||
|
||||
Links links = new Links(existingLinks);
|
||||
Link selfLink = createSelfLink(object, entity, links);
|
||||
Link selfLink = createSelfLink(object, links);
|
||||
|
||||
if (selfLink == null) {
|
||||
return links;
|
||||
@@ -636,10 +638,10 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
List<Link> result = new ArrayList<Link>(existingLinks);
|
||||
result.addAll(handler.getLinks());
|
||||
|
||||
return addSelfLinkIfNecessary(object, entity, result);
|
||||
return addSelfLinkIfNecessary(object, result);
|
||||
}
|
||||
|
||||
private Links addSelfLinkIfNecessary(Object object, PersistentEntity<?, ?> entity, List<Link> existing) {
|
||||
private Links addSelfLinkIfNecessary(Object object, List<Link> existing) {
|
||||
|
||||
Links result = new Links(existing);
|
||||
|
||||
@@ -648,26 +650,19 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
}
|
||||
|
||||
List<Link> list = new ArrayList<Link>();
|
||||
list.add(createSelfLink(object, entity, result));
|
||||
list.add(createSelfLink(object, result));
|
||||
list.addAll(existing);
|
||||
|
||||
return new Links(list);
|
||||
}
|
||||
|
||||
private Link createSelfLink(Object object, PersistentEntity<?, ?> entity, Links existing) {
|
||||
private Link createSelfLink(Object object, Links existing) {
|
||||
|
||||
if (existing.hasLink(Link.REL_SELF)) {
|
||||
return existing.getLink(Link.REL_SELF);
|
||||
}
|
||||
|
||||
IdentifierAccessor accessor = entity.getIdentifierAccessor(object);
|
||||
Object identifier = accessor.getIdentifier();
|
||||
|
||||
if (identifier == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return links.linkToSingleResource(entity.getType(), identifier).withSelfRel();
|
||||
return links.createSelfLinkFor(object).withSelfRel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,8 +707,8 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
Class<?> collectionOrMapType = property.getType();
|
||||
|
||||
return property.isMap() ? CollectionFactory.createMap(collectionOrMapType, 0) : CollectionFactory
|
||||
.createCollection(collectionOrMapType, 0);
|
||||
return property.isMap() ? CollectionFactory.createMap(collectionOrMapType, 0)
|
||||
: CollectionFactory.createCollection(collectionOrMapType, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,6 +28,9 @@ import org.springframework.data.repository.support.RepositoryInvokerFactory;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -53,7 +58,11 @@ public abstract class AbstractControllerIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public PersistentEntityResourceAssembler persistentEntityResourceAssembler() {
|
||||
return new PersistentEntityResourceAssembler(persistentEntities(), entityLinks(), StubProjector.INSTANCE,
|
||||
|
||||
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(persistentEntities(), entityLinks(),
|
||||
Collections.<EntityLookup<?>> emptyList());
|
||||
|
||||
return new PersistentEntityResourceAssembler(persistentEntities(), selfLinkProvider, StubProjector.INSTANCE,
|
||||
resourceMappings());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,15 @@ import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.data.rest.webmvc.AbstractControllerIntegrationTests.TestConfiguration;
|
||||
import org.springframework.data.rest.webmvc.mongodb.MongoDbRepositoryConfig;
|
||||
import org.springframework.data.rest.webmvc.mongodb.User;
|
||||
@@ -57,8 +60,9 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
|
||||
|
||||
when(projector.projectExcerpt(anyObject())).thenAnswer(new ReturnsArgumentAt(0));
|
||||
|
||||
PersistentEntityResourceAssembler assembler = new PersistentEntityResourceAssembler(entities, entityLinks,
|
||||
projector, mappings);
|
||||
PersistentEntityResourceAssembler assembler = new PersistentEntityResourceAssembler(entities,
|
||||
new DefaultSelfLinkProvider(entities, entityLinks, Collections.<EntityLookup<?>> emptyList()), projector,
|
||||
mappings);
|
||||
|
||||
User user = new User();
|
||||
user.id = BigInteger.valueOf(4711);
|
||||
@@ -69,5 +73,4 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
|
||||
assertThat(links.getLink("self").getVariables(), is(Matchers.empty()));
|
||||
assertThat(links.getLink("user").getVariableNames(), is(hasItem("projection")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -269,7 +269,6 @@ public class PersistentEntitySerializationTests {
|
||||
|
||||
PersistentEntityResource resource = PersistentEntityResource.//
|
||||
build(oliver, repositories.getPersistentEntity(Person.class)).//
|
||||
withLink(new Link("/people/1")).//
|
||||
withEmbedded(Arrays.asList(wrapper)).//
|
||||
build();
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ import org.springframework.data.rest.core.config.MetadataConfiguration;
|
||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.data.rest.core.mapping.RepositoryResourceMappings;
|
||||
import org.springframework.data.rest.core.support.DefaultSelfLinkProvider;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.data.rest.core.support.SelfLinkProvider;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.PersonRepository;
|
||||
@@ -113,9 +116,11 @@ public class RepositoryTestsConfig {
|
||||
EntityLinks entityLinks = new RepositoryEntityLinks(repositories(), mappings, config(),
|
||||
mock(PagingAndSortingTemplateVariables.class),
|
||||
OrderAwarePluginRegistry.<Class<?>, BackendIdConverter> create(Arrays.asList(DefaultIdConverter.INSTANCE)));
|
||||
SelfLinkProvider selfLinkProvider = new DefaultSelfLinkProvider(persistentEntities(), entityLinks,
|
||||
Collections.<EntityLookup<?>> emptyList());
|
||||
|
||||
return new PersistentEntityJackson2Module(mappings, persistentEntities(), config(),
|
||||
new UriToEntityConverter(persistentEntities(), defaultConversionService()), entityLinks);
|
||||
new UriToEntityConverter(persistentEntities(), defaultConversionService()), selfLinkProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user