DATAREST-1341 - Adapt to package refactorings in Spring HATEOAS.
This commit is contained in:
@@ -32,8 +32,8 @@ import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy;
|
||||
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
|
||||
import org.springframework.data.rest.core.support.EntityLookup;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class CrudMethodsSupportedHttpMethods implements SupportedHttpMethods {
|
||||
@Override
|
||||
public HttpMethods getMethodsFor(ResourceType resourceType) {
|
||||
|
||||
Assert.notNull(resourceType, "Resource type must not be null!");
|
||||
Assert.notNull(resourceType, "EntityRepresentationModel type must not be null!");
|
||||
|
||||
Set<HttpMethod> methods = new HashSet<HttpMethod>();
|
||||
methods.add(OPTIONS);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import org.atteo.evo.inflector.English;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
|
||||
/**
|
||||
* {@link TypeBasedCollectionResourceMapping} extension to use Evo Inflector to pluralize the simple class name by as
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.core.AnnotationAttribute;
|
||||
import org.springframework.hateoas.core.MethodParameters;
|
||||
import org.springframework.hateoas.server.core.AnnotationAttribute;
|
||||
import org.springframework.hateoas.server.core.MethodParameters;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.data.rest.core.annotation.Description;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.rest.core.support;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DefaultSelfLinkProvider implements SelfLinkProvider {
|
||||
|
||||
Assert.notNull(instance, "Domain object must not be null!");
|
||||
|
||||
return entityLinks.linkToSingleResource(instance.getClass(), getResourceId(instance));
|
||||
return entityLinks.linkToItemResource(instance.getClass(), getResourceId(instance));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +81,7 @@ public class DefaultSelfLinkProvider implements SelfLinkProvider {
|
||||
|
||||
return lookups.getPluginFor(instanceType)//
|
||||
.map(it -> it.getClass().cast(it))//
|
||||
.map(it -> (Object) it.getResourceIdentifier(instance))//
|
||||
.map(it -> it.getResourceIdentifier(instance))//
|
||||
.orElseGet(() -> identifierOrNull(instance));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ public class RepositoryRelProvider implements RelProvider {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
@@ -55,7 +55,7 @@ public class RepositoryRelProvider implements RelProvider {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.rest.core.support;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ public class SimpleRelProvider implements RelProvider {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.RelProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
@@ -46,7 +46,7 @@ public class SimpleRelProvider implements RelProvider {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.RelProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
|
||||
@@ -27,8 +27,8 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
import org.springframework.data.rest.core.domain.Person;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMapping;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
|
||||
/**
|
||||
* Ensure the {@link ResourceMapping} components convey the correct information.
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
|
||||
import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.domain.Profile;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class DefaultSelfLinkProviderUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
when(entityLinks.linkToSingleResource((Class<?>) any(), any())).then(invocation -> {
|
||||
when(entityLinks.linkToItemResource((Class<?>) any(), any())).then(invocation -> {
|
||||
|
||||
Class<?> type = invocation.getArgument(0);
|
||||
Serializable id = invocation.getArgument(1);
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@@ -49,12 +49,12 @@ import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVari
|
||||
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -121,7 +121,7 @@ public class RepositoryTestsConfig {
|
||||
|
||||
return new PersistentEntityJackson2Module(associations, persistentEntities(), uriToEntityConverter, collector,
|
||||
invokerFactory, mock(LookupObjectSerializer.class),
|
||||
new ResourceProcessorInvoker(Collections.<ResourceProcessor<?>> emptyList()),
|
||||
new RepresentationModelProcessorInvoker(Collections.<RepresentationModelProcessor<?>> emptyList()),
|
||||
new EmbeddedResourcesAssembler(persistentEntities(), associations, mock(ExcerptProjector.class)));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ import static org.junit.Assert.assertThat;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.springframework.web.util.UriTemplate;
|
||||
*/
|
||||
public class ResourceTester {
|
||||
|
||||
private final ResourceSupport resource;
|
||||
private final RepresentationModel resource;
|
||||
|
||||
public static ResourceTester of(Object object) {
|
||||
assertThat(object, is(instanceOf(ResourceSupport.class)));
|
||||
return new ResourceTester((ResourceSupport) object);
|
||||
assertThat(object, is(instanceOf(RepresentationModel.class)));
|
||||
return new ResourceTester((RepresentationModel) object);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,8 +48,8 @@ public class ResourceTester {
|
||||
*
|
||||
* @param resource must not be {@literal null}.
|
||||
*/
|
||||
private ResourceTester(ResourceSupport resource) {
|
||||
Assert.notNull(resource, "Resource must not be null!");
|
||||
private ResourceTester(RepresentationModel resource) {
|
||||
Assert.notNull(resource, "EntityRepresentationModel must not be null!");
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@@ -96,27 +96,27 @@ public class ResourceTester {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> PagedResources<T> assertIsPage() {
|
||||
public <T> PagedModel<T> assertIsPage() {
|
||||
|
||||
assertThat(resource, is(instanceOf(PagedResources.class)));
|
||||
return (PagedResources<T>) resource;
|
||||
assertThat(resource, is(instanceOf(PagedModel.class)));
|
||||
return (PagedModel<T>) resource;
|
||||
}
|
||||
|
||||
public ResourceTester getContentResource() {
|
||||
|
||||
assertThat(resource, is(instanceOf(Resources.class)));
|
||||
Object next = ((Resources<?>) resource).getContent().iterator().next();
|
||||
assertThat(resource, is(instanceOf(CollectionModel.class)));
|
||||
Object next = ((CollectionModel<?>) resource).getContent().iterator().next();
|
||||
|
||||
assertThat(next, is(instanceOf(ResourceSupport.class)));
|
||||
return new ResourceTester((ResourceSupport) next);
|
||||
assertThat(next, is(instanceOf(RepresentationModel.class)));
|
||||
return new ResourceTester((RepresentationModel) next);
|
||||
}
|
||||
|
||||
public void withContentResource(ContentResourceHandler handler) {
|
||||
|
||||
assertThat(resource, is(instanceOf(Resources.class)));
|
||||
assertThat(resource, is(instanceOf(CollectionModel.class)));
|
||||
|
||||
for (Object element : ((Resources<?>) resource).getContent()) {
|
||||
assertThat(element, is(instanceOf(ResourceSupport.class)));
|
||||
for (Object element : ((CollectionModel<?>) resource).getContent()) {
|
||||
assertThat(element, is(instanceOf(RepresentationModel.class)));
|
||||
handler.doWith(of(element));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -365,7 +365,7 @@ public class TestMvcClient {
|
||||
* Using the servlet response's content type, find the corresponding link discoverer.
|
||||
*
|
||||
* @param response
|
||||
* @return {@link org.springframework.hateoas.LinkDiscoverer}
|
||||
* @return {@link org.springframework.hateoas.client.LinkDiscoverer}
|
||||
*/
|
||||
public LinkDiscoverer getDiscoverer(MockHttpServletResponse response) {
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.springframework.data.rest.webmvc.jpa.Order;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
||||
import org.springframework.data.rest.webmvc.support.ETag;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -243,7 +243,7 @@ public class RepositoryEntityControllerIntegrationTests extends AbstractControll
|
||||
|
||||
Mockito.when(assembler.toFullResource(Mockito.any(Object.class))).thenReturn(resource);
|
||||
|
||||
ResponseEntity<Resource<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
|
||||
ResponseEntity<EntityModel<?>> entity = controller.getItemResource(getResourceInformation(Address.class), address.id,
|
||||
assembler, new HttpHeaders());
|
||||
|
||||
assertThat(entity.getHeaders().getETag()).isNotNull();
|
||||
|
||||
@@ -35,9 +35,9 @@ import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.data.rest.webmvc.jpa.Person;
|
||||
import org.springframework.data.rest.webmvc.jpa.TestDataPopulator;
|
||||
import org.springframework.data.rest.webmvc.support.DefaultedPageable;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -72,7 +72,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
public void rendersCorrectSearchLinksForPersons() throws Exception {
|
||||
|
||||
RootResourceInformation request = getResourceInformation(Person.class);
|
||||
ResourceSupport resource = controller.listSearches(request);
|
||||
RepresentationModel resource = controller.listSearches(request);
|
||||
|
||||
ResourceTester tester = ResourceTester.of(resource);
|
||||
tester.assertNumberOfLinks(7); // Self link included
|
||||
@@ -107,7 +107,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
Sort.unsorted(), assembler, new HttpHeaders());
|
||||
|
||||
ResourceTester tester = ResourceTester.of(response.getBody());
|
||||
PagedResources<Object> pagedResources = tester.assertIsPage();
|
||||
PagedModel<Object> pagedResources = tester.assertIsPage();
|
||||
assertThat(pagedResources.getContent()).hasSize(1);
|
||||
|
||||
ResourceMetadata metadata = getMetadata(Person.class);
|
||||
@@ -169,7 +169,7 @@ public class RepositorySearchControllerIntegrationTests extends AbstractControll
|
||||
ResponseEntity<?> result = controller.executeSearch(resourceInformation, parameters, "findByAuthorsContains",
|
||||
PAGEABLE, Sort.unsorted(), assembler, new HttpHeaders());
|
||||
|
||||
assertThat(result.getBody()).isInstanceOf(Resources.class);
|
||||
assertThat(result.getBody()).isInstanceOf(CollectionModel.class);
|
||||
}
|
||||
|
||||
@Test // DATAREST-515
|
||||
|
||||
@@ -38,9 +38,9 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.data.rest.webmvc.jpa.Item;
|
||||
import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -122,7 +122,7 @@ public class DataRest262Tests {
|
||||
|
||||
JpaPersistentEntity<?> persistentEntity = mappingContext.getRequiredPersistentEntity(AircraftMovement.class);
|
||||
|
||||
Resource<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
|
||||
EntityModel<Object> resource = PersistentEntityResource.build(movement, persistentEntity).//
|
||||
withLink(new Link("/api/airports/" + movement.id)).//
|
||||
build();
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.rest.tests.TestMvcClient;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.core.JsonPathLinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.JsonPathLinkDiscoverer;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.data.rest.webmvc.ProfileResourceProcessor;
|
||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@@ -41,14 +41,14 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.rest.webmvc.jpa.*;
|
||||
import org.springframework.data.rest.webmvc.util.TestUtils;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.hal.HalLinkDiscoverer;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -204,7 +204,7 @@ public class PersistentEntitySerializationTests {
|
||||
withLink(new Link("/orders/1")).//
|
||||
build();
|
||||
|
||||
PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
|
||||
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
|
||||
Arrays.asList(orderResource), new PageMetadata(1, 0, 10));
|
||||
|
||||
String result = mapper.writeValueAsString(persistentEntityResource);
|
||||
@@ -260,7 +260,7 @@ public class PersistentEntitySerializationTests {
|
||||
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
|
||||
PersonSummary projection = factory.createProjection(PersonSummary.class, person);
|
||||
|
||||
String result = mapper.writeValueAsString(new Resource<PersonSummary>(projection));
|
||||
String result = mapper.writeValueAsString(new EntityModel<PersonSummary>(projection));
|
||||
|
||||
assertThat(JsonPath.<Object> read(result, "$._links.self")).isNotNull();
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVari
|
||||
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
@@ -129,7 +129,7 @@ public class RepositoryTestsConfig {
|
||||
|
||||
return new PersistentEntityJackson2Module(associations, persistentEntities(), uriToEntityConverter, collector,
|
||||
invokerFactory, mock(LookupObjectSerializer.class),
|
||||
new ResourceProcessorInvoker(Collections.<ResourceProcessor<?>> emptyList()),
|
||||
new RepresentationModelProcessorInvoker(Collections.<RepresentationModelProcessor<?>> emptyList()),
|
||||
new EmbeddedResourcesAssembler(persistentEntities(), associations, mock(ExcerptProjector.class)));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test
|
||||
public void returnsLinkToSingleResource() {
|
||||
|
||||
Link link = entityLinks.linkToSingleResource(Person.class, 1);
|
||||
Link link = entityLinks.linkToItemResource(Person.class, 1);
|
||||
|
||||
assertThat(link.getHref(), endsWith("/people/1{?projection}"));
|
||||
assertThat(link.getRel()).isEqualTo(LinkRelation.of("person"));
|
||||
@@ -70,7 +70,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-221
|
||||
public void returnsLinkWithProjectionTemplateVariableIfProjectionIsDefined() {
|
||||
|
||||
Link link = entityLinks.linkToSingleResource(Order.class, 1);
|
||||
Link link = entityLinks.linkToItemResource(Order.class, 1);
|
||||
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getVariableNames()).contains(configuration.getProjectionConfiguration().getParameterName());
|
||||
@@ -79,7 +79,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt
|
||||
@Test // DATAREST-155
|
||||
public void usesCustomGeneratedBackendId() {
|
||||
|
||||
Link link = entityLinks.linkToSingleResource(Book.class, 7L);
|
||||
Link link = entityLinks.linkToItemResource(Book.class, 7L);
|
||||
assertThat(link.expand().getHref(), endsWith("/7-7-7-7-7-7-7"));
|
||||
}
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ public class MongoWebTests extends CommonWebTests {
|
||||
Link link = client.discoverUnique("users", "search", "findByColleaguesContains");
|
||||
|
||||
User thomas = userRepository.findAll(QUser.user.firstname.eq("Thomas")).iterator().next();
|
||||
Link thomasUri = entityLinks.linkToSingleResource(User.class, thomas.id).expand();
|
||||
Link thomasUri = entityLinks.linkToItemResource(User.class, thomas.id).expand();
|
||||
|
||||
String href = link.expand(thomasUri.getHref()).getHref();
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.data.rest.tests.mongodb.MongoDbRepositoryConfig;
|
||||
import org.springframework.data.rest.tests.mongodb.User;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -63,7 +63,7 @@ public class PersistentEntityResourceAssemblerIntegrationTests extends AbstractC
|
||||
User user = new User();
|
||||
user.id = BigInteger.valueOf(4711);
|
||||
|
||||
PersistentEntityResource resource = assembler.toResource(user);
|
||||
PersistentEntityResource resource = assembler.toModel(user);
|
||||
|
||||
Links links = resource.getLinks();
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ import org.springframework.data.rest.tests.mongodb.User.Nested;
|
||||
import org.springframework.data.rest.tests.mongodb.UserRepository;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.PagedResources.PageMetadata;
|
||||
import org.springframework.hateoas.hal.HalLinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.PagedModel.PageMetadata;
|
||||
import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -109,7 +109,7 @@ public class PersistentEntitySerializationTests {
|
||||
withLink(new Link("/users/1")).//
|
||||
build();
|
||||
|
||||
PagedResources<PersistentEntityResource> persistentEntityResource = new PagedResources<PersistentEntityResource>(
|
||||
PagedModel<PersistentEntityResource> persistentEntityResource = new PagedModel<PersistentEntityResource>(
|
||||
Arrays.asList(userResource), new PageMetadata(1, 0, 10));
|
||||
|
||||
String result = mapper.writeValueAsString(persistentEntityResource);
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.springframework.data.rest.tests.shop.Customer.Gender;
|
||||
import org.springframework.data.rest.tests.shop.Product.ProductNameOnlyProjection;
|
||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
@@ -44,15 +44,15 @@ public class ShopConfiguration {
|
||||
@Autowired LineItemTypeRepository lineItemTypes;
|
||||
|
||||
@Bean
|
||||
public ResourceProcessor<Resource<LineItem>> lineItemResourceProcessor() {
|
||||
return new ResourceProcessor<Resource<LineItem>>() {
|
||||
public RepresentationModelProcessor<EntityModel<LineItem>> lineItemResourceProcessor() {
|
||||
return new RepresentationModelProcessor<EntityModel<LineItem>>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceProcessor#process(org.springframework.hateoas.ResourceSupport)
|
||||
* @see org.springframework.hateoas.server.RepresentationModelProcessor#process(org.springframework.hateoas.RepresentationModel)
|
||||
*/
|
||||
@Override
|
||||
public Resource<LineItem> process(Resource<LineItem> resource) {
|
||||
public EntityModel<LineItem> process(EntityModel<LineItem> resource) {
|
||||
resource.add(new Link("foo", "bar"));
|
||||
return resource;
|
||||
}
|
||||
@@ -60,16 +60,16 @@ public class ShopConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceProcessor<Resource<ProductNameOnlyProjection>> productNameOnlyProjectionResourceProcessor() {
|
||||
public RepresentationModelProcessor<EntityModel<ProductNameOnlyProjection>> productNameOnlyProjectionResourceProcessor() {
|
||||
|
||||
return new ResourceProcessor<Resource<ProductNameOnlyProjection>>() {
|
||||
return new RepresentationModelProcessor<EntityModel<ProductNameOnlyProjection>>() {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceProcessor#process(org.springframework.hateoas.ResourceSupport)
|
||||
* @see org.springframework.hateoas.server.RepresentationModelProcessor#process(org.springframework.hateoas.RepresentationModel)
|
||||
*/
|
||||
@Override
|
||||
public Resource<ProductNameOnlyProjection> process(Resource<Product.ProductNameOnlyProjection> resource) {
|
||||
public EntityModel<ProductNameOnlyProjection> process(EntityModel<Product.ProductNameOnlyProjection> resource) {
|
||||
resource.add(new Link("alpha", "beta"));
|
||||
return resource;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ShopIntegrationTests extends AbstractWebIntegrationTests {
|
||||
ResultActions actions = client.follow(selfLink)
|
||||
// Lookup type is rendered as String
|
||||
.andExpect(jsonPath("items[0].type", is("good")))//
|
||||
// Invokes ResourceProcessor for nested Resource
|
||||
// Invokes RepresentationModelProcessor for nested Resource
|
||||
.andExpect(jsonPath("items[0]._links.bar").exists());//
|
||||
|
||||
// Adds excerpt projection for related product
|
||||
|
||||
@@ -26,13 +26,13 @@ import org.springframework.data.auditing.AuditableBeanWrapperFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
@@ -61,7 +61,7 @@ class AbstractRepositoryRestController {
|
||||
this.pagedResourcesAssembler = pagedResourcesAssembler;
|
||||
}
|
||||
|
||||
protected Link resourceLink(RootResourceInformation resourceLink, Resource resource) {
|
||||
protected Link resourceLink(RootResourceInformation resourceLink, EntityModel resource) {
|
||||
|
||||
ResourceMetadata repoMapping = resourceLink.getResourceMetadata();
|
||||
|
||||
@@ -72,7 +72,7 @@ class AbstractRepositoryRestController {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected Resources<?> toResources(Iterable<?> source, PersistentEntityResourceAssembler assembler,
|
||||
protected CollectionModel<?> toCollectionModel(Iterable<?> source, PersistentEntityResourceAssembler assembler,
|
||||
Class<?> domainType, Optional<Link> baseLink) {
|
||||
|
||||
if (source instanceof Page) {
|
||||
@@ -81,38 +81,38 @@ class AbstractRepositoryRestController {
|
||||
} else if (source instanceof Iterable) {
|
||||
return entitiesToResources((Iterable<Object>) source, assembler, domainType);
|
||||
} else {
|
||||
return new Resources(EMPTY_RESOURCE_LIST);
|
||||
return new CollectionModel(EMPTY_RESOURCE_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
protected Resources<?> entitiesToResources(Page<Object> page, PersistentEntityResourceAssembler assembler,
|
||||
protected CollectionModel<?> entitiesToResources(Page<Object> page, PersistentEntityResourceAssembler assembler,
|
||||
Class<?> domainType, Optional<Link> baseLink) {
|
||||
|
||||
if (page.getContent().isEmpty()) {
|
||||
return baseLink.<PagedResources<?>> map(it -> pagedResourcesAssembler.toEmptyResource(page, domainType, it))//
|
||||
.orElseGet(() -> pagedResourcesAssembler.toEmptyResource(page, domainType));
|
||||
return baseLink.<PagedModel<?>> map(it -> pagedResourcesAssembler.toEmptyModel(page, domainType, it))//
|
||||
.orElseGet(() -> pagedResourcesAssembler.toEmptyModel(page, domainType));
|
||||
}
|
||||
|
||||
return baseLink.map(it -> pagedResourcesAssembler.toResource(page, assembler, it))//
|
||||
.orElseGet(() -> pagedResourcesAssembler.toResource(page, assembler));
|
||||
return baseLink.map(it -> pagedResourcesAssembler.toModel(page, assembler, it))//
|
||||
.orElseGet(() -> pagedResourcesAssembler.toModel(page, assembler));
|
||||
}
|
||||
|
||||
protected Resources<?> entitiesToResources(Iterable<Object> entities, PersistentEntityResourceAssembler assembler,
|
||||
Class<?> domainType) {
|
||||
protected CollectionModel<?> entitiesToResources(Iterable<Object> entities,
|
||||
PersistentEntityResourceAssembler assembler, Class<?> domainType) {
|
||||
|
||||
if (!entities.iterator().hasNext()) {
|
||||
|
||||
List<Object> content = Arrays.<Object> asList(WRAPPERS.emptyCollectionOf(domainType));
|
||||
return new Resources<Object>(content, getDefaultSelfLink());
|
||||
return new CollectionModel<Object>(content, getDefaultSelfLink());
|
||||
}
|
||||
|
||||
List<Resource<Object>> resources = new ArrayList<Resource<Object>>();
|
||||
List<EntityModel<Object>> resources = new ArrayList<EntityModel<Object>>();
|
||||
|
||||
for (Object obj : entities) {
|
||||
resources.add(obj == null ? null : assembler.toResource(obj));
|
||||
resources.add(obj == null ? null : assembler.toModel(obj));
|
||||
}
|
||||
|
||||
return new Resources<Resource<Object>>(resources, getDefaultSelfLink());
|
||||
return new CollectionModel<EntityModel<Object>>(resources, getDefaultSelfLink());
|
||||
}
|
||||
|
||||
protected Link getDefaultSelfLink() {
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.data.rest.webmvc;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -31,10 +31,10 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ControllerUtils {
|
||||
|
||||
public static final Iterable<Resource<?>> EMPTY_RESOURCE_LIST = Collections.emptyList();
|
||||
public static final Iterable<EntityModel<?>> EMPTY_RESOURCE_LIST = Collections.emptyList();
|
||||
|
||||
public static <R extends ResourceSupport> ResponseEntity<ResourceSupport> toResponseEntity(HttpStatus status,
|
||||
HttpHeaders headers, Optional<R> resource) {
|
||||
public static <R extends RepresentationModel<?>> ResponseEntity<RepresentationModel<?>> toResponseEntity(
|
||||
HttpStatus status, HttpHeaders headers, Optional<R> resource) {
|
||||
|
||||
HttpHeaders hdrs = new HttpHeaders();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ControllerUtils {
|
||||
hdrs.putAll(headers);
|
||||
}
|
||||
|
||||
return new ResponseEntity<ResourceSupport>(resource.orElse(null), hdrs, status);
|
||||
return new ResponseEntity<RepresentationModel<?>>(resource.orElse(null), hdrs, status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,8 +54,8 @@ public class ControllerUtils {
|
||||
* @param <R>
|
||||
* @return
|
||||
*/
|
||||
public static <R extends ResourceSupport> ResponseEntity<ResourceSupport> toResponseEntity(HttpStatus status,
|
||||
HttpHeaders headers, R resource) {
|
||||
public static <R extends RepresentationModel<?>> ResponseEntity<RepresentationModel<?>> toResponseEntity(
|
||||
HttpStatus status, HttpHeaders headers, R resource) {
|
||||
|
||||
Assert.notNull(status, "Http status must not be null!");
|
||||
Assert.notNull(headers, "Http headers must not be null!");
|
||||
@@ -70,7 +70,7 @@ public class ControllerUtils {
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public static ResponseEntity<ResourceSupport> toEmptyResponse(HttpStatus status) {
|
||||
public static ResponseEntity<RepresentationModel<?>> toEmptyResponse(HttpStatus status) {
|
||||
return toEmptyResponse(status, new HttpHeaders());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ControllerUtils {
|
||||
* @param headers
|
||||
* @return
|
||||
*/
|
||||
public static ResponseEntity<ResourceSupport> toEmptyResponse(HttpStatus status, HttpHeaders headers) {
|
||||
public static ResponseEntity<RepresentationModel<?>> toEmptyResponse(HttpStatus status, HttpHeaders headers) {
|
||||
return toResponseEntity(status, headers, Optional.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.data.rest.webmvc.support.ExcerptProjector;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.springframework.data.mapping.PersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentPropertyAccessor;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -39,7 +39,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class PersistentEntityResource extends Resource<Object> {
|
||||
public class PersistentEntityResource extends EntityModel<Object> {
|
||||
|
||||
private static final Iterable<EmbeddedWrapper> NO_EMBEDDEDS = new NoLinksResources<EmbeddedWrapper>(
|
||||
Collections.<EmbeddedWrapper> emptyList());
|
||||
@@ -203,7 +203,7 @@ public class PersistentEntityResource extends Resource<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
private static class NoLinksResources<T> extends Resources<T> {
|
||||
private static class NoLinksResources<T> extends CollectionModel<T> {
|
||||
|
||||
public NoLinksResources(Iterable<T> content) {
|
||||
super(content);
|
||||
@@ -211,7 +211,7 @@ public class PersistentEntityResource extends Resource<Object> {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceSupport#getLinks()
|
||||
* @see org.springframework.hateoas.RepresentationModel#getLinks()
|
||||
*/
|
||||
@Override
|
||||
@JsonIgnore
|
||||
|
||||
@@ -25,9 +25,9 @@ import org.springframework.data.rest.webmvc.PersistentEntityResource.Builder;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.data.rest.webmvc.support.Projector;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceAssembler;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.server.RepresentationModelAssembler;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.Assert;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class PersistentEntityResourceAssembler implements ResourceAssembler<Object, PersistentEntityResource> {
|
||||
public class PersistentEntityResourceAssembler implements RepresentationModelAssembler<Object, PersistentEntityResource> {
|
||||
|
||||
private final @NonNull PersistentEntities entities;
|
||||
private final @NonNull Projector projector;
|
||||
@@ -46,10 +46,10 @@ public class PersistentEntityResourceAssembler implements ResourceAssembler<Obje
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.ResourceAssembler#toResource(java.lang.Object)
|
||||
* @see org.springframework.hateoas.server.RepresentationModelAssembler#toModel(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public PersistentEntityResource toResource(Object instance) {
|
||||
public PersistentEntityResource toModel(Object instance) {
|
||||
|
||||
Assert.notNull(instance, "Entity instance must not be null!");
|
||||
return wrap(projector.projectExcerpt(instance), instance).build();
|
||||
|
||||
@@ -26,11 +26,10 @@ import org.springframework.data.rest.core.mapping.RepositoryResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMapping;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -84,7 +83,7 @@ public class ProfileController {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAllow(Collections.singleton(HttpMethod.GET));
|
||||
|
||||
return new ResponseEntity<Object>(headers, HttpStatus.OK);
|
||||
return ResponseEntity.ok().headers(headers).build();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,9 +92,9 @@ public class ProfileController {
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = PROFILE_ROOT_MAPPING, method = GET)
|
||||
HttpEntity<ResourceSupport> listAllFormsOfMetadata() {
|
||||
HttpEntity<RepresentationModel<?>> listAllFormsOfMetadata() {
|
||||
|
||||
ResourceSupport profile = new ResourceSupport();
|
||||
RepresentationModel<?> profile = new RepresentationModel<>();
|
||||
|
||||
profile.add(new Link(getRootPath(this.configuration)).withSelfRel());
|
||||
|
||||
@@ -108,7 +107,7 @@ public class ProfileController {
|
||||
}
|
||||
}
|
||||
|
||||
return new ResponseEntity<ResourceSupport>(profile, HttpStatus.OK);
|
||||
return ResponseEntity.ok(profile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.data.rest.webmvc;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
|
||||
* @author Greg Turnquist
|
||||
* @since 2.4
|
||||
*/
|
||||
public class ProfileResourceProcessor implements ResourceProcessor<RepositoryLinksResource> {
|
||||
public class ProfileResourceProcessor implements RepresentationModelProcessor<RepositoryLinksResource> {
|
||||
|
||||
public static final String PROFILE_REL = "profile";
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
@@ -50,12 +50,12 @@ import org.springframework.data.rest.webmvc.support.ETag;
|
||||
import org.springframework.data.rest.webmvc.support.ETagDoesntMatchException;
|
||||
import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.PagedModel;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -186,7 +186,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET)
|
||||
public Resources<?> getCollectionResource(@QuerydslPredicate RootResourceInformation resourceInformation,
|
||||
public CollectionModel<?> getCollectionResource(@QuerydslPredicate RootResourceInformation resourceInformation,
|
||||
DefaultedPageable pageable, Sort sort, PersistentEntityResourceAssembler assembler)
|
||||
throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {
|
||||
|
||||
@@ -205,7 +205,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
Optional<Link> baseLink = Optional.of(entityLinks.linkToPagedResource(resourceInformation.getDomainType(),
|
||||
pageable.isDefault() ? null : pageable.getPageable()));
|
||||
|
||||
Resources<?> result = toResources(results, assembler, metadata.getDomainType(), baseLink);
|
||||
CollectionModel<?> result = toCollectionModel(results, assembler, metadata.getDomainType(), baseLink);
|
||||
result.add(getCollectionResourceLinks(resourceInformation, pageable));
|
||||
return result;
|
||||
}
|
||||
@@ -228,22 +228,22 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET,
|
||||
produces = { "application/x-spring-data-compact+json", "text/uri-list" })
|
||||
public Resources<?> getCollectionResourceCompact(@QuerydslPredicate RootResourceInformation resourceinformation,
|
||||
public CollectionModel<?> getCollectionResourceCompact(@QuerydslPredicate RootResourceInformation resourceinformation,
|
||||
DefaultedPageable pageable, Sort sort, PersistentEntityResourceAssembler assembler)
|
||||
throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {
|
||||
|
||||
Resources<?> resources = getCollectionResource(resourceinformation, pageable, sort, assembler);
|
||||
CollectionModel<?> resources = getCollectionResource(resourceinformation, pageable, sort, assembler);
|
||||
Links links = resources.getLinks();
|
||||
|
||||
for (Resource<?> resource : ((Resources<Resource<?>>) resources).getContent()) {
|
||||
for (EntityModel<?> resource : ((CollectionModel<EntityModel<?>>) resources).getContent()) {
|
||||
PersistentEntityResource persistentEntityResource = (PersistentEntityResource) resource;
|
||||
links = links.and(resourceLink(resourceinformation, persistentEntityResource));
|
||||
}
|
||||
|
||||
if (resources instanceof PagedResources) {
|
||||
return new PagedResources<Object>(Collections.emptyList(), ((PagedResources<?>) resources).getMetadata(), links);
|
||||
if (resources instanceof PagedModel) {
|
||||
return new PagedModel<Object>(Collections.emptyList(), ((PagedModel<?>) resources).getMetadata(), links);
|
||||
} else {
|
||||
return new Resources<Object>(Collections.emptyList(), links);
|
||||
return new CollectionModel<Object>(Collections.emptyList(), links);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.POST)
|
||||
public ResponseEntity<ResourceSupport> postCollectionResource(RootResourceInformation resourceInformation,
|
||||
public ResponseEntity<RepresentationModel<?>> postCollectionResource(RootResourceInformation resourceInformation,
|
||||
PersistentEntityResource payload, PersistentEntityResourceAssembler assembler,
|
||||
@RequestHeader(value = ACCEPT_HEADER, required = false) String acceptHeader)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
@@ -304,7 +304,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
|
||||
return getItemResource(resourceInformation, id).map(it -> {
|
||||
|
||||
Links links = assembler.toResource(it).getLinks();
|
||||
Links links = assembler.toModel(it).getLinks();
|
||||
|
||||
HttpHeaders headers = headersPreparer.prepareHeaders(resourceInformation.getPersistentEntity(), it);
|
||||
headers.add(LINK_HEADER, links.toString());
|
||||
@@ -323,7 +323,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
* @throws HttpRequestMethodNotSupportedException
|
||||
*/
|
||||
@RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.GET)
|
||||
public ResponseEntity<Resource<?>> getItemResource(RootResourceInformation resourceInformation,
|
||||
public ResponseEntity<EntityModel<?>> getItemResource(RootResourceInformation resourceInformation,
|
||||
@BackendId Serializable id, final PersistentEntityResourceAssembler assembler, @RequestHeader HttpHeaders headers)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
|
||||
@@ -334,7 +334,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
return resourceStatus.getStatusAndHeaders(headers, it, entity).toResponseEntity(//
|
||||
() -> assembler.toFullResource(it));
|
||||
|
||||
}).orElseGet(() -> new ResponseEntity<Resource<?>>(HttpStatus.NOT_FOUND));
|
||||
}).orElseGet(() -> new ResponseEntity<EntityModel<?>>(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -350,7 +350,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
* @throws HttpRequestMethodNotSupportedException
|
||||
*/
|
||||
@RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.PUT)
|
||||
public ResponseEntity<? extends ResourceSupport> putItemResource(RootResourceInformation resourceInformation,
|
||||
public ResponseEntity<? extends RepresentationModel<?>> putItemResource(RootResourceInformation resourceInformation,
|
||||
PersistentEntityResource payload, @BackendId Serializable id, PersistentEntityResourceAssembler assembler,
|
||||
ETag eTag, @RequestHeader(value = ACCEPT_HEADER, required = false) String acceptHeader)
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
@@ -384,7 +384,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
* @throws ETagDoesntMatchException
|
||||
*/
|
||||
@RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.PATCH)
|
||||
public ResponseEntity<ResourceSupport> patchItemResource(RootResourceInformation resourceInformation,
|
||||
public ResponseEntity<RepresentationModel<?>> patchItemResource(RootResourceInformation resourceInformation,
|
||||
PersistentEntityResource payload, @BackendId Serializable id, PersistentEntityResourceAssembler assembler,
|
||||
ETag eTag, @RequestHeader(value = ACCEPT_HEADER, required = false) String acceptHeader)
|
||||
throws HttpRequestMethodNotSupportedException, ResourceNotFoundException {
|
||||
@@ -442,7 +442,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
* @param httpMethod
|
||||
* @return
|
||||
*/
|
||||
private ResponseEntity<ResourceSupport> saveAndReturn(Object domainObject, RepositoryInvoker invoker,
|
||||
private ResponseEntity<RepresentationModel<?>> saveAndReturn(Object domainObject, RepositoryInvoker invoker,
|
||||
HttpMethod httpMethod, PersistentEntityResourceAssembler assembler, boolean returnBody) {
|
||||
|
||||
publisher.publishEvent(new BeforeSaveEvent(domainObject));
|
||||
@@ -470,7 +470,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
* @param invoker
|
||||
* @return
|
||||
*/
|
||||
private ResponseEntity<ResourceSupport> createAndReturn(Object domainObject, RepositoryInvoker invoker,
|
||||
private ResponseEntity<RepresentationModel<?>> createAndReturn(Object domainObject, RepositoryInvoker invoker,
|
||||
PersistentEntityResourceAssembler assembler, boolean returnBody) {
|
||||
|
||||
publisher.publishEvent(new BeforeCreateEvent(domainObject));
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
/**
|
||||
* Dedicated resource type to represent the links pointing to collection resources exposed for repositories.
|
||||
@@ -23,4 +23,4 @@ import org.springframework.hateoas.ResourceSupport;
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryLinksResource extends ResourceSupport {}
|
||||
public class RepositoryLinksResource extends RepresentationModel<RepositoryLinksResource> {}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc;
|
||||
|
||||
import static org.springframework.data.rest.webmvc.ControllerUtils.*;
|
||||
import static org.springframework.data.rest.webmvc.RestMediaTypes.*;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.*;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
@@ -56,12 +56,13 @@ import org.springframework.data.rest.core.mapping.ResourceMapping;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.webmvc.support.BackendId;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -110,32 +111,32 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
}
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING, method = GET)
|
||||
public ResponseEntity<ResourceSupport> followPropertyReference(final RootResourceInformation repoRequest,
|
||||
public ResponseEntity<RepresentationModel<?>> followPropertyReference(final RootResourceInformation repoRequest,
|
||||
@BackendId Serializable id, final @PathVariable String property,
|
||||
final PersistentEntityResourceAssembler assembler) throws Exception {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> {
|
||||
Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> prop.mapValue(it -> {
|
||||
|
||||
if (prop.property.isCollectionLike()) {
|
||||
|
||||
return toResources((Iterable<?>) it, assembler, prop.propertyType, Optional.empty());
|
||||
return toCollectionModel((Iterable<?>) it, assembler, prop.propertyType, Optional.empty());
|
||||
|
||||
} else if (prop.property.isMap()) {
|
||||
|
||||
Map<Object, Resource<?>> resources = new HashMap<Object, Resource<?>>();
|
||||
Map<Object, EntityModel<?>> resources = new HashMap<Object, EntityModel<?>>();
|
||||
|
||||
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) it).entrySet()) {
|
||||
resources.put(entry.getKey(), assembler.toResource(entry.getValue()));
|
||||
resources.put(entry.getKey(), assembler.toModel(entry.getValue()));
|
||||
}
|
||||
|
||||
return new Resource<Object>(resources);
|
||||
return new EntityModel<Object>(resources);
|
||||
|
||||
} else {
|
||||
|
||||
PersistentEntityResource resource = assembler.toResource(it);
|
||||
headers.set("Content-Location", resource.getRequiredLink(Link.REL_SELF).getHref());
|
||||
PersistentEntityResource resource = assembler.toModel(it);
|
||||
headers.set("Content-Location", resource.getRequiredLink(IanaLinkRelations.SELF).getHref());
|
||||
return resource;
|
||||
}
|
||||
|
||||
@@ -146,10 +147,10 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
}
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING, method = DELETE)
|
||||
public ResponseEntity<? extends ResourceSupport> deletePropertyReference(RootResourceInformation repoRequest,
|
||||
public ResponseEntity<? extends RepresentationModel<?>> deletePropertyReference(RootResourceInformation repoRequest,
|
||||
@BackendId Serializable id, @PathVariable String property) throws Exception {
|
||||
|
||||
Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> {
|
||||
Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> prop.mapValue(it -> {
|
||||
|
||||
if (prop.property.isCollectionLike() || prop.property.isMap()) {
|
||||
throw HttpRequestMethodNotSupportedException.forRejectedMethod(HttpMethod.DELETE)
|
||||
@@ -162,7 +163,7 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
Object result = repoRequest.getInvoker().invokeSave(prop.accessor.getBean());
|
||||
publisher.publishEvent(new AfterLinkDeleteEvent(result, prop.propertyValue));
|
||||
|
||||
return (ResourceSupport) null;
|
||||
return (RepresentationModel<?>) null;
|
||||
|
||||
}).orElse(null);
|
||||
|
||||
@@ -172,13 +173,13 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
}
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING + "/{propertyId}", method = GET)
|
||||
public ResponseEntity<ResourceSupport> followPropertyReference(RootResourceInformation repoRequest,
|
||||
public ResponseEntity<RepresentationModel<?>> followPropertyReference(RootResourceInformation repoRequest,
|
||||
@BackendId Serializable id, @PathVariable String property, @PathVariable String propertyId,
|
||||
PersistentEntityResourceAssembler assembler) throws Exception {
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> {
|
||||
Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> prop.mapValue(it -> {
|
||||
|
||||
if (prop.property.isCollectionLike()) {
|
||||
|
||||
@@ -187,8 +188,8 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
IdentifierAccessor accessor1 = prop.entity.getIdentifierAccessor(obj);
|
||||
if (propertyId.equals(accessor1.getIdentifier().toString())) {
|
||||
|
||||
PersistentEntityResource resource1 = assembler.toResource(obj);
|
||||
headers.set("Content-Location", resource1.getRequiredLink(Link.REL_SELF).getHref());
|
||||
PersistentEntityResource resource1 = assembler.toModel(obj);
|
||||
headers.set("Content-Location", resource1.getRequiredLink(IanaLinkRelations.SELF).getHref());
|
||||
return resource1;
|
||||
}
|
||||
}
|
||||
@@ -200,14 +201,14 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
IdentifierAccessor accessor2 = prop.entity.getIdentifierAccessor(entry.getValue());
|
||||
if (propertyId.equals(accessor2.getIdentifier().toString())) {
|
||||
|
||||
PersistentEntityResource resource2 = assembler.toResource(entry.getValue());
|
||||
headers.set("Content-Location", resource2.getRequiredLink(Link.REL_SELF).getHref());
|
||||
PersistentEntityResource resource2 = assembler.toModel(entry.getValue());
|
||||
headers.set("Content-Location", resource2.getRequiredLink(IanaLinkRelations.SELF).getHref());
|
||||
return resource2;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return new Resource<>(prop.propertyValue);
|
||||
return new EntityModel<>(prop.propertyValue);
|
||||
}
|
||||
|
||||
throw new ResourceNotFoundException();
|
||||
@@ -220,11 +221,11 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING, method = GET,
|
||||
produces = { SPRING_DATA_COMPACT_JSON_VALUE, TEXT_URI_LIST_VALUE })
|
||||
public ResponseEntity<ResourceSupport> followPropertyReferenceCompact(RootResourceInformation repoRequest,
|
||||
public ResponseEntity<RepresentationModel<?>> followPropertyReferenceCompact(RootResourceInformation repoRequest,
|
||||
@BackendId Serializable id, @PathVariable String property, PersistentEntityResourceAssembler assembler)
|
||||
throws Exception {
|
||||
|
||||
ResponseEntity<ResourceSupport> response = followPropertyReference(repoRequest, id, property, assembler);
|
||||
ResponseEntity<RepresentationModel<?>> response = followPropertyReference(repoRequest, id, property, assembler);
|
||||
|
||||
if (response.getStatusCode() != HttpStatus.OK) {
|
||||
return response;
|
||||
@@ -234,28 +235,29 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
PersistentProperty<?> persistentProp = repoRequest.getPersistentEntity().getRequiredPersistentProperty(property);
|
||||
ResourceMapping propertyMapping = repoMapping.getMappingFor(persistentProp);
|
||||
|
||||
ResourceSupport resource = response.getBody();
|
||||
RepresentationModel<?> resource = response.getBody();
|
||||
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
|
||||
ControllerLinkBuilder linkBuilder = linkTo(methodOn(RepositoryPropertyReferenceController.class)
|
||||
WebMvcLinkBuilder linkBuilder = linkTo(methodOn(RepositoryPropertyReferenceController.class)
|
||||
.followPropertyReference(repoRequest, id, property, assembler));
|
||||
|
||||
if (resource instanceof Resource) {
|
||||
if (resource instanceof EntityModel) {
|
||||
|
||||
Object content = ((Resource<?>) resource).getContent();
|
||||
Object content = ((EntityModel<?>) resource).getContent();
|
||||
if (content instanceof Iterable) {
|
||||
|
||||
for (Resource<?> res : (Iterable<Resource<?>>) content) {
|
||||
for (EntityModel<?> res : (Iterable<EntityModel<?>>) content) {
|
||||
links.add(linkBuilder.withRel(propertyMapping.getRel()));
|
||||
}
|
||||
|
||||
} else if (content instanceof Map) {
|
||||
|
||||
Map<Object, Resource<?>> map = (Map<Object, Resource<?>>) content;
|
||||
Map<Object, EntityModel<?>> map = (Map<Object, EntityModel<?>>) content;
|
||||
|
||||
for (Entry<Object, Resource<?>> entry : map.entrySet()) {
|
||||
Link l = new Link(entry.getValue().getRequiredLink(Link.REL_SELF).getHref(), entry.getKey().toString());
|
||||
for (Entry<Object, EntityModel<?>> entry : map.entrySet()) {
|
||||
Link l = new Link(entry.getValue().getRequiredLink(IanaLinkRelations.SELF).getHref(),
|
||||
entry.getKey().toString());
|
||||
links.add(l);
|
||||
}
|
||||
}
|
||||
@@ -264,19 +266,20 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
links.add(linkBuilder.withRel(propertyMapping.getRel()));
|
||||
}
|
||||
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, new Resource<Object>(EMPTY_RESOURCE_LIST, links));
|
||||
return ControllerUtils.toResponseEntity(HttpStatus.OK, null, new EntityModel<Object>(EMPTY_RESOURCE_LIST, links));
|
||||
}
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING, method = { PATCH, PUT, POST }, //
|
||||
consumes = { MediaType.APPLICATION_JSON_VALUE, SPRING_DATA_COMPACT_JSON_VALUE, TEXT_URI_LIST_VALUE })
|
||||
public ResponseEntity<? extends ResourceSupport> createPropertyReference(RootResourceInformation resourceInformation,
|
||||
HttpMethod requestMethod, @RequestBody(required = false) Resources<Object> incoming, @BackendId Serializable id,
|
||||
public ResponseEntity<? extends RepresentationModel<?>> createPropertyReference(
|
||||
RootResourceInformation resourceInformation, HttpMethod requestMethod,
|
||||
@RequestBody(required = false) CollectionModel<Object> incoming, @BackendId Serializable id,
|
||||
@PathVariable String property) throws Exception {
|
||||
|
||||
Resources<Object> source = incoming == null ? new Resources<Object>(Collections.emptyList()) : incoming;
|
||||
CollectionModel<Object> source = incoming == null ? new CollectionModel<Object>(Collections.emptyList()) : incoming;
|
||||
RepositoryInvoker invoker = resourceInformation.getInvoker();
|
||||
|
||||
Function<ReferencedProperty, ResourceSupport> handler = prop -> {
|
||||
Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> {
|
||||
|
||||
Class<?> propertyType = prop.property.getType();
|
||||
|
||||
@@ -337,11 +340,11 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
}
|
||||
|
||||
@RequestMapping(value = BASE_MAPPING + "/{propertyId}", method = DELETE)
|
||||
public ResponseEntity<ResourceSupport> deletePropertyReferenceId(RootResourceInformation repoRequest,
|
||||
public ResponseEntity<RepresentationModel<?>> deletePropertyReferenceId(RootResourceInformation repoRequest,
|
||||
@BackendId Serializable backendId, @PathVariable String property, @PathVariable String propertyId)
|
||||
throws Exception {
|
||||
|
||||
Function<ReferencedProperty, ResourceSupport> handler = prop -> prop.mapValue(it -> {
|
||||
Function<ReferencedProperty, RepresentationModel<?>> handler = prop -> prop.mapValue(it -> {
|
||||
|
||||
if (prop.property.isCollectionLike()) {
|
||||
|
||||
@@ -381,7 +384,7 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
Object result = repoRequest.getInvoker().invokeSave(prop.accessor.getBean());
|
||||
publisher.publishEvent(new AfterLinkDeleteEvent(result, it));
|
||||
|
||||
return (ResourceSupport) null;
|
||||
return (RepresentationModel<?>) null;
|
||||
|
||||
}).orElse(null);
|
||||
|
||||
@@ -400,9 +403,9 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
return invoker.invokeFindById(id).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<ResourceSupport> doWithReferencedProperty(RootResourceInformation resourceInformation,
|
||||
Serializable id, String propertyPath, Function<ReferencedProperty, ResourceSupport> handler, HttpMethod method)
|
||||
throws Exception {
|
||||
private Optional<RepresentationModel<?>> doWithReferencedProperty(RootResourceInformation resourceInformation,
|
||||
Serializable id, String propertyPath, Function<ReferencedProperty, RepresentationModel<?>> handler,
|
||||
HttpMethod method) throws Exception {
|
||||
|
||||
ResourceMetadata metadata = resourceInformation.getResourceMetadata();
|
||||
PropertyAwareResourceMapping mapping = metadata.getProperty(propertyPath);
|
||||
@@ -421,7 +424,7 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
|
||||
return domainObj.map(it -> {
|
||||
|
||||
PersistentPropertyAccessor accessor = property.getOwner().getPropertyAccessor(it);
|
||||
PersistentPropertyAccessor<?> accessor = property.getOwner().getPropertyAccessor(it);
|
||||
return handler.apply(new ReferencedProperty(property, accessor.getProperty(property), accessor));
|
||||
});
|
||||
}
|
||||
@@ -432,14 +435,14 @@ class RepositoryPropertyReferenceController extends AbstractRepositoryRestContro
|
||||
final PersistentProperty<?> property;
|
||||
final Class<?> propertyType;
|
||||
final Object propertyValue;
|
||||
final PersistentPropertyAccessor accessor;
|
||||
final PersistentPropertyAccessor<?> accessor;
|
||||
|
||||
private ReferencedProperty(PersistentProperty<?> property, Object propertyValue,
|
||||
PersistentPropertyAccessor wrapper) {
|
||||
PersistentPropertyAccessor<?> accessor) {
|
||||
|
||||
this.property = property;
|
||||
this.propertyValue = propertyValue;
|
||||
this.accessor = wrapper;
|
||||
this.accessor = accessor;
|
||||
this.propertyType = property.getActualType();
|
||||
this.entity = repositories.getPersistentEntity(propertyType);
|
||||
}
|
||||
|
||||
@@ -33,19 +33,19 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositoryRestHandlerAdapter
|
||||
extends org.springframework.hateoas.mvc.ResourceProcessorInvokingHandlerAdapter {
|
||||
extends org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvokingHandlerAdapter {
|
||||
|
||||
private final List<HandlerMethodArgumentResolver> argumentResolvers;
|
||||
|
||||
/**
|
||||
* Creates a new {@link RepositoryRestHandlerAdapter} using the given {@link HandlerMethodArgumentResolver} and
|
||||
* {@link org.springframework.hateoas.mvc.ResourceProcessorInvoker}.
|
||||
* {@link org.springframework.hateoas.server.mvc.ResourceProcessorInvoker}.
|
||||
*
|
||||
* @param argumentResolvers must not be {@literal null}.
|
||||
* @param invoker must not be {@literal null}.
|
||||
*/
|
||||
public RepositoryRestHandlerAdapter(List<HandlerMethodArgumentResolver> argumentResolvers,
|
||||
org.springframework.hateoas.mvc.ResourceProcessorInvoker invoker) {
|
||||
org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker invoker) {
|
||||
|
||||
super(invoker);
|
||||
this.argumentResolvers = argumentResolvers;
|
||||
@@ -53,7 +53,7 @@ public class RepositoryRestHandlerAdapter
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter#afterPropertiesSet()
|
||||
* @see org.springframework.data.rest.webmvc.RepresentationModelProcessorInvokingHandlerAdapter#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,14 +40,14 @@ import org.springframework.data.rest.webmvc.support.RepositoryEntityLinks;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.AnnotationAttribute;
|
||||
import org.springframework.hateoas.core.MethodParameters;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.core.AnnotationAttribute;
|
||||
import org.springframework.hateoas.server.core.MethodParameters;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -154,11 +153,9 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
RepositorySearchesResource result = new RepositorySearchesResource(resourceInformation.getDomainType());
|
||||
result.add(queryMethodLinks);
|
||||
result.add(getDefaultSelfLink());
|
||||
|
||||
return result;
|
||||
return new RepositorySearchesResource(resourceInformation.getDomainType()) //
|
||||
.add(queryMethodLinks) //
|
||||
.add(getDefaultSelfLink());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +184,7 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
MethodResourceMapping methodMapping = searchMappings.getExportedMethodMappingForPath(search);
|
||||
Class<?> domainType = methodMapping.getReturnedDomainType();
|
||||
|
||||
return toResource(result, assembler, domainType, Optional.empty(), headers, resourceInformation);
|
||||
return toModel(result, assembler, domainType, Optional.empty(), headers, resourceInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,13 +197,13 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
* @param baseLink can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected ResponseEntity<?> toResource(Optional<Object> source, final PersistentEntityResourceAssembler assembler,
|
||||
protected ResponseEntity<?> toModel(Optional<Object> source, final PersistentEntityResourceAssembler assembler,
|
||||
Class<?> domainType, Optional<Link> baseLink, HttpHeaders headers, RootResourceInformation information) {
|
||||
|
||||
return source.map(it -> {
|
||||
|
||||
if (it instanceof Iterable) {
|
||||
return ResponseEntity.ok(toResources((Iterable<?>) it, assembler, domainType, baseLink));
|
||||
return ResponseEntity.ok(toCollectionModel((Iterable<?>) it, assembler, domainType, baseLink));
|
||||
} else if (ClassUtils.isPrimitiveOrWrapper(it.getClass())) {
|
||||
return ResponseEntity.ok(it);
|
||||
}
|
||||
@@ -239,7 +236,7 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
@ResponseBody
|
||||
@RequestMapping(value = BASE_MAPPING + "/{search}", method = RequestMethod.GET, //
|
||||
produces = { "application/x-spring-data-compact+json" })
|
||||
public ResourceSupport executeSearchCompact(RootResourceInformation resourceInformation,
|
||||
public RepresentationModel<?> executeSearchCompact(RootResourceInformation resourceInformation,
|
||||
@RequestHeader HttpHeaders headers, @RequestParam MultiValueMap<String, Object> parameters,
|
||||
@PathVariable String repository, @PathVariable String search, DefaultedPageable pageable, Sort sort,
|
||||
PersistentEntityResourceAssembler assembler) {
|
||||
@@ -248,28 +245,28 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
Optional<Object> result = executeQueryMethod(resourceInformation.getInvoker(), parameters, method, pageable, sort,
|
||||
assembler);
|
||||
ResourceMetadata metadata = resourceInformation.getResourceMetadata();
|
||||
ResponseEntity<?> entity = toResource(result, assembler, metadata.getDomainType(), Optional.empty(), headers,
|
||||
ResponseEntity<?> entity = toModel(result, assembler, metadata.getDomainType(), Optional.empty(), headers,
|
||||
resourceInformation);
|
||||
Object resource = entity.getBody();
|
||||
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
|
||||
if (resource instanceof Resources && ((Resources<?>) resource).getContent() != null) {
|
||||
if (resource instanceof CollectionModel && ((CollectionModel<?>) resource).getContent() != null) {
|
||||
|
||||
for (Object obj : ((Resources<?>) resource).getContent()) {
|
||||
if (null != obj && obj instanceof Resource) {
|
||||
Resource<?> res = (Resource<?>) obj;
|
||||
for (Object obj : ((CollectionModel<?>) resource).getContent()) {
|
||||
if (null != obj && obj instanceof EntityModel) {
|
||||
EntityModel<?> res = (EntityModel<?>) obj;
|
||||
links.add(resourceLink(resourceInformation, res));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (resource instanceof Resource) {
|
||||
} else if (resource instanceof EntityModel) {
|
||||
|
||||
Resource<?> res = (Resource<?>) resource;
|
||||
EntityModel<?> res = (EntityModel<?>) resource;
|
||||
links.add(resourceLink(resourceInformation, res));
|
||||
}
|
||||
|
||||
return new Resources<Resource<?>>(EMPTY_RESOURCE_LIST, links);
|
||||
return new CollectionModel<EntityModel<?>>(EMPTY_RESOURCE_LIST, links);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,18 +343,17 @@ class RepositorySearchController extends AbstractRepositoryRestController {
|
||||
|
||||
parameters.entrySet().forEach(entry ->
|
||||
|
||||
methodParameters.getParameter(entry.getKey()).ifPresent(parameter -> {
|
||||
methodParameters.getParameter(entry.getKey()).ifPresent(parameter -> {
|
||||
|
||||
int parameterIndex = parameterList.indexOf(parameter);
|
||||
TypeInformation<?> domainType = parameterTypeInformations.get(parameterIndex).getActualType();
|
||||
int parameterIndex = parameterList.indexOf(parameter);
|
||||
TypeInformation<?> domainType = parameterTypeInformations.get(parameterIndex).getActualType();
|
||||
|
||||
ResourceMetadata metadata = mappings.getMetadataFor(domainType.getType());
|
||||
ResourceMetadata metadata = mappings.getMetadataFor(domainType.getType());
|
||||
|
||||
if (metadata != null && metadata.isExported()) {
|
||||
result.put(parameter.getParameterName(), prepareUris(entry.getValue()));
|
||||
}
|
||||
if (metadata != null && metadata.isExported()) {
|
||||
result.put(parameter.getParameterName(), prepareUris(entry.getValue()));
|
||||
}
|
||||
));
|
||||
}));
|
||||
|
||||
return invoker.invokeQueryMethod(method, result, pageable.getPageable(), sort);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -27,7 +26,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class RepositorySearchesResource extends ResourceSupport {
|
||||
public class RepositorySearchesResource extends RepresentationModel<RepositorySearchesResource> {
|
||||
|
||||
private final Class<?> domainType;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class ResourceNotFoundException extends RuntimeException {
|
||||
private static final long serialVersionUID = 7992904489502842099L;
|
||||
|
||||
public ResourceNotFoundException() {
|
||||
this("Resource not found!");
|
||||
this("EntityRepresentationModel not found!");
|
||||
}
|
||||
|
||||
public ResourceNotFoundException(String message) {
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.mvc.HeaderLinksResponseEntity;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* {@link HandlerMethodReturnValueHandler} to post-process the objects returned from controller methods using the
|
||||
* configured {@link ResourceProcessor}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @deprecated use the same type from Spring HATEOAS, will be removed in 2.7.
|
||||
*/
|
||||
@Deprecated
|
||||
@RequiredArgsConstructor
|
||||
public class ResourceProcessorHandlerMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
static final ResolvableType RESOURCE_TYPE = ResolvableType.forClass(Resource.class);
|
||||
static final ResolvableType RESOURCES_TYPE = ResolvableType.forClass(Resources.class);
|
||||
private static final ResolvableType HTTP_ENTITY_TYPE = ResolvableType.forClass(HttpEntity.class);
|
||||
|
||||
static final Field CONTENT_FIELD = ReflectionUtils.findField(Resources.class, "content");
|
||||
|
||||
static {
|
||||
ReflectionUtils.makeAccessible(CONTENT_FIELD);
|
||||
}
|
||||
|
||||
private final @NonNull HandlerMethodReturnValueHandler delegate;
|
||||
private final @NonNull ResourceProcessorInvoker invoker;
|
||||
|
||||
private boolean rootLinksAsHeaders = false;
|
||||
|
||||
/**
|
||||
* @param rootLinksAsHeaders the rootLinksAsHeaders to set
|
||||
*/
|
||||
public void setRootLinksAsHeaders(boolean rootLinksAsHeaders) {
|
||||
this.rootLinksAsHeaders = rootLinksAsHeaders;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.method.support.HandlerMethodReturnValueHandler#supportsReturnType(org.springframework.core.MethodParameter)
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return delegate.supportsReturnType(returnType);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.method.support.HandlerMethodReturnValueHandler#handleReturnValue(java.lang.Object, org.springframework.core.MethodParameter, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.context.request.NativeWebRequest)
|
||||
*/
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
Object value = returnValue;
|
||||
|
||||
if (returnValue instanceof HttpEntity) {
|
||||
value = ((HttpEntity<?>) returnValue).getBody();
|
||||
}
|
||||
|
||||
// No post-processable type found - proceed with delegate
|
||||
if (!ResourceSupport.class.isInstance(value)) {
|
||||
delegate.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
// We have a Resource or Resources - find suitable processors
|
||||
ResolvableType targetType = ResolvableType.forMethodReturnType(returnType.getMethod());
|
||||
|
||||
// Unbox HttpEntity
|
||||
if (HTTP_ENTITY_TYPE.isAssignableFrom(targetType)) {
|
||||
targetType = targetType.getGeneric(0);
|
||||
}
|
||||
|
||||
ResolvableType returnValueType = ResolvableType.forClass(value.getClass());
|
||||
|
||||
// Returned value is actually of a more specific type, use this type information
|
||||
if (!getRawType(targetType).equals(getRawType(returnValueType))) {
|
||||
targetType = returnValueType;
|
||||
}
|
||||
|
||||
ResourceSupport result = invoker.invokeProcessorsFor((ResourceSupport) value, targetType);
|
||||
delegate.handleReturnValue(rewrapResult(result, returnValue), returnType, mavContainer, webRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-wraps the result of the post-processing work into an {@link HttpEntity} or {@link ResponseEntity} if the
|
||||
* original value was one of those two types. Copies headers and status code from the original value but uses the new
|
||||
* body.
|
||||
*
|
||||
* @param newBody the post-processed value.
|
||||
* @param originalValue the original input value.
|
||||
* @return
|
||||
*/
|
||||
Object rewrapResult(ResourceSupport newBody, Object originalValue) {
|
||||
|
||||
if (!(originalValue instanceof HttpEntity)) {
|
||||
return newBody;
|
||||
}
|
||||
|
||||
HttpEntity<ResourceSupport> entity = null;
|
||||
|
||||
if (originalValue instanceof ResponseEntity) {
|
||||
ResponseEntity<?> source = (ResponseEntity<?>) originalValue;
|
||||
entity = new ResponseEntity<ResourceSupport>(newBody, source.getHeaders(), source.getStatusCode());
|
||||
} else {
|
||||
HttpEntity<?> source = (HttpEntity<?>) originalValue;
|
||||
entity = new HttpEntity<ResourceSupport>(newBody, source.getHeaders());
|
||||
}
|
||||
|
||||
return addLinksToHeaderWrapper(entity);
|
||||
}
|
||||
|
||||
private HttpEntity<?> addLinksToHeaderWrapper(HttpEntity<ResourceSupport> entity) {
|
||||
return rootLinksAsHeaders ? HeaderLinksResponseEntity.wrap(entity) : entity;
|
||||
}
|
||||
|
||||
private static Class<?> getRawType(ResolvableType type) {
|
||||
|
||||
Class<?> rawType = type.getRawClass();
|
||||
return rawType == null ? Object.class : rawType;
|
||||
}
|
||||
}
|
||||
@@ -1,413 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Component to easily invoke all {@link ResourceProcessor} instances registered for values of type
|
||||
* {@link ResourceSupport}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @since 2.5
|
||||
* @deprecated use the same type from Spring HATEOAS, will be removed in 2.7.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ResourceProcessorInvoker {
|
||||
|
||||
private final List<ProcessorWrapper> processors;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ResourceProcessorInvoker} to consider the given {@link ResourceProcessor} to post-process the
|
||||
* controller methods return value to before invoking the delegate.
|
||||
*
|
||||
* @param processors the {@link ResourceProcessor}s to be considered, must not be {@literal null}.
|
||||
*/
|
||||
public ResourceProcessorInvoker(Collection<ResourceProcessor<?>> processors) {
|
||||
|
||||
Assert.notNull(processors, "ResourceProcessors must not be null!");
|
||||
|
||||
this.processors = new ArrayList<ProcessorWrapper>();
|
||||
|
||||
for (ResourceProcessor<?> processor : processors) {
|
||||
|
||||
ResolvableType processorType = ResolvableType.forClass(ResourceProcessor.class, processor.getClass());
|
||||
Class<?> rawType = processorType.getGeneric(0).resolve();
|
||||
|
||||
if (Resource.class.isAssignableFrom(rawType)) {
|
||||
this.processors.add(new ResourceProcessorWrapper(processor));
|
||||
} else if (Resources.class.isAssignableFrom(rawType)) {
|
||||
this.processors.add(new ResourcesProcessorWrapper(processor));
|
||||
} else {
|
||||
this.processors.add(new DefaultProcessorWrapper(processor));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(this.processors, AnnotationAwareOrderComparator.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all {@link ResourceProcessor} instances registered for the type of the given value.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public <T extends ResourceSupport> T invokeProcessorsFor(T value) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
|
||||
return invokeProcessorsFor(value, ResolvableType.forClass(value.getClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all {@link ResourceProcessor} instances registered for the type of the given value and reference type.
|
||||
*
|
||||
* @param value must not be {@literal null}.
|
||||
* @param referenceType must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ResourceSupport> T invokeProcessorsFor(T value, ResolvableType referenceType) {
|
||||
|
||||
Assert.notNull(value, "Value must not be null!");
|
||||
Assert.notNull(referenceType, "Reference type must not be null!");
|
||||
|
||||
// For Resources implementations, process elements first
|
||||
if (ResourceProcessorHandlerMethodReturnValueHandler.RESOURCES_TYPE.isAssignableFrom(referenceType)) {
|
||||
|
||||
Resources<?> resources = (Resources<?>) value;
|
||||
ResolvableType elementTargetType = ResolvableType.forClass(Resources.class, referenceType.getRawClass())
|
||||
.getGeneric(0);
|
||||
List<Object> result = new ArrayList<Object>(resources.getContent().size());
|
||||
|
||||
for (Object element : resources) {
|
||||
|
||||
ResolvableType elementType = ResolvableType.forClass(element.getClass());
|
||||
|
||||
if (!getRawType(elementTargetType).equals(elementType.getRawClass())) {
|
||||
elementTargetType = elementType;
|
||||
}
|
||||
|
||||
result.add(invokeProcessorsFor(element, elementTargetType));
|
||||
}
|
||||
|
||||
ReflectionUtils.setField(ResourceProcessorHandlerMethodReturnValueHandler.CONTENT_FIELD, resources, result);
|
||||
}
|
||||
|
||||
return (T) invokeProcessorsFor((Object) value, referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes all registered {@link ResourceProcessor}s registered for the given {@link ResolvableType}.
|
||||
*
|
||||
* @param value the object to process
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private Object invokeProcessorsFor(Object value, ResolvableType type) {
|
||||
|
||||
Object currentValue = value;
|
||||
|
||||
// Process actual value
|
||||
for (ResourceProcessorInvoker.ProcessorWrapper wrapper : this.processors) {
|
||||
if (wrapper.supports(type, currentValue)) {
|
||||
currentValue = wrapper.invokeProcessor(currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
private static boolean isRawTypeAssignable(ResolvableType left, Class<?> right) {
|
||||
return getRawType(left).isAssignableFrom(right);
|
||||
}
|
||||
|
||||
private static Class<?> getRawType(ResolvableType type) {
|
||||
|
||||
Class<?> rawType = type.getRawClass();
|
||||
return rawType == null ? Object.class : rawType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to unify interaction with {@link ResourceProcessor}s. The {@link Ordered} rank should be determined by
|
||||
* the underlying processor.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private interface ProcessorWrapper extends Ordered {
|
||||
|
||||
/**
|
||||
* Returns whether the underlying processor supports the given {@link ResolvableType}. It might also additionally
|
||||
* inspect the object that would eventually be handed to the processor.
|
||||
*
|
||||
* @param type the type of object to be post processed, will never be {@literal null}.
|
||||
* @param value the object that would be passed into the processor eventually, can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
boolean supports(ResolvableType type, Object value);
|
||||
|
||||
/**
|
||||
* Performs the actual invocation of the processor. Implementations can be sure
|
||||
* {@link #supports(ResolvableType, Object)} has been called before and returned {@literal true}.
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
Object invokeProcessor(Object object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of {@link ProcessorWrapper} to generically deal with {@link ResourceSupport} types.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static class DefaultProcessorWrapper implements ResourceProcessorInvoker.ProcessorWrapper {
|
||||
|
||||
private final ResourceProcessor<?> processor;
|
||||
private final ResolvableType targetType;
|
||||
|
||||
/**
|
||||
* Creates a new {@link DefaultProcessorWrapper} with the given {@link ResourceProcessor}.
|
||||
*
|
||||
* @param processor must not be {@literal null}.
|
||||
*/
|
||||
public DefaultProcessorWrapper(ResourceProcessor<?> processor) {
|
||||
|
||||
Assert.notNull(processor, "ResourceProcessor must not be null!");
|
||||
|
||||
this.processor = processor;
|
||||
this.targetType = ResolvableType.forClass(ResourceProcessor.class, processor.getClass()).getGeneric(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.ProcessorWrapper#supports(org.springframework.core.ResolvableType, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(ResolvableType type, Object value) {
|
||||
return isRawTypeAssignable(targetType, getRawType(type));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.PostProcessorWrapper#invokeProcessor(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object invokeProcessor(Object object) {
|
||||
return ((ResourceProcessor<ResourceSupport>) processor).process((ResourceSupport) object);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.core.Ordered#getOrder()
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return CustomOrderAwareComparator.INSTANCE.getOrder(processor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target type the underlying {@link ResourceProcessor} wants to get invoked for.
|
||||
*
|
||||
* @return the targetType
|
||||
*/
|
||||
public ResolvableType getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ProcessorWrapper} to deal with {@link ResourceProcessor}s for {@link Resource}s. Will fall back to peeking
|
||||
* into the {@link Resource}'s content for type resolution.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static class ResourceProcessorWrapper extends ResourceProcessorInvoker.DefaultProcessorWrapper {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ResourceProcessorWrapper} for the given {@link ResourceProcessor}.
|
||||
*
|
||||
* @param processor must not be {@literal null}.
|
||||
*/
|
||||
public ResourceProcessorWrapper(ResourceProcessor<?> processor) {
|
||||
super(processor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.DefaultProcessorWrapper#supports(org.springframework.core.ResolvableType, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(ResolvableType type, Object value) {
|
||||
|
||||
if (!ResourceProcessorHandlerMethodReturnValueHandler.RESOURCE_TYPE.isAssignableFrom(type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.supports(type, value) && isValueTypeMatch((Resource<?>) value, getTargetType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given {@link Resource} matches the given target {@link ResolvableType}. We inspect the
|
||||
* {@link Resource}'s value to determine the match.
|
||||
*
|
||||
* @param resource
|
||||
* @param target must not be {@literal null}.
|
||||
* @return whether the given {@link Resource} can be assigned to the given target {@link ResolvableType}
|
||||
*/
|
||||
private static boolean isValueTypeMatch(Resource<?> resource, ResolvableType target) {
|
||||
|
||||
if (resource == null || !isRawTypeAssignable(target, resource.getClass())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object content = resource.getContent();
|
||||
|
||||
if (content == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResolvableType type = findGenericType(target, Resource.class);
|
||||
return type != null && type.getGeneric(0).isAssignableFrom(ResolvableType.forClass(content.getClass()));
|
||||
}
|
||||
|
||||
private static ResolvableType findGenericType(ResolvableType source, Class<?> type) {
|
||||
|
||||
Class<?> rawType = getRawType(source);
|
||||
|
||||
if (Object.class.equals(rawType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (rawType.equals(type)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
return findGenericType(source.getSuperType(), type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ProcessorWrapper} for {@link ResourceProcessor}s targeting {@link Resources}. Will peek into the content of
|
||||
* the {@link Resources} for type matching decisions if needed.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
static class ResourcesProcessorWrapper extends ResourceProcessorInvoker.DefaultProcessorWrapper {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ResourcesProcessorWrapper} for the given {@link ResourceProcessor}.
|
||||
*
|
||||
* @param processor must not be {@literal null}.
|
||||
*/
|
||||
public ResourcesProcessorWrapper(ResourceProcessor<?> processor) {
|
||||
super(processor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.DefaultProcessorWrapper#supports(org.springframework.core.ResolvableType, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(ResolvableType type, Object value) {
|
||||
|
||||
if (!ResourceProcessorHandlerMethodReturnValueHandler.RESOURCES_TYPE.isAssignableFrom(type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return super.supports(type, value) && isValueTypeMatch((Resources<?>) value, getTargetType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given {@link Resources} instance matches the given {@link ResolvableType}. We predict this by
|
||||
* inspecting the first element of the content of the {@link Resources}.
|
||||
*
|
||||
* @param resources the {@link Resources} to inspect.
|
||||
* @param target that target {@link ResolvableType}.
|
||||
* @return
|
||||
*/
|
||||
static boolean isValueTypeMatch(Resources<?> resources, ResolvableType target) {
|
||||
|
||||
if (resources == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<?> content = resources.getContent();
|
||||
|
||||
if (content.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResolvableType superType = null;
|
||||
|
||||
for (Class<?> resourcesType : Arrays.<Class<?>> asList(resources.getClass(), Resources.class)) {
|
||||
|
||||
superType = ResolvableType.forClass(resourcesType, getRawType(target));
|
||||
|
||||
if (superType != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (superType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Object element = content.iterator().next();
|
||||
ResolvableType resourceType = superType.getGeneric(0);
|
||||
|
||||
if (element instanceof Resource) {
|
||||
return ResourceProcessorWrapper.isValueTypeMatch((Resource<?>) element, resourceType);
|
||||
} else if (element instanceof EmbeddedWrapper) {
|
||||
return isRawTypeAssignable(resourceType, ((EmbeddedWrapper) element).getRelTargetType());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper extension of {@link AnnotationAwareOrderComparator} to make {@link #getOrder(Object)} public to allow it
|
||||
* being used in a standalone fashion.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static class CustomOrderAwareComparator extends AnnotationAwareOrderComparator {
|
||||
|
||||
public static ResourceProcessorInvoker.CustomOrderAwareComparator INSTANCE = new CustomOrderAwareComparator();
|
||||
|
||||
@Override
|
||||
protected int getOrder(Object obj) {
|
||||
return super.getOrder(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
/**
|
||||
* Special {@link RequestMappingHandlerAdapter} that tweaks the {@link HandlerMethodReturnValueHandlerComposite} to be
|
||||
* proxied by a {@link ResourceProcessorHandlerMethodReturnValueHandler} which will invoke the {@link ResourceProcessor}
|
||||
* s found in the application context and eventually delegate to the originally configured
|
||||
* {@link HandlerMethodReturnValueHandler}.
|
||||
* <p/>
|
||||
* This is a separate component as it might make sense to deploy it in a standalone SpringMVC application to enable post
|
||||
* processing. It would actually make most sense in Spring HATEOAS project.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Phil Webb
|
||||
* @author Mark Paluch
|
||||
* @deprecated use the same type from Spring HATEOAS, will be removed in 2.7.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ResourceProcessorInvokingHandlerAdapter extends RequestMappingHandlerAdapter {
|
||||
|
||||
private static final Method RETURN_VALUE_HANDLER_METHOD = ReflectionUtils
|
||||
.findMethod(ResourceProcessorInvokingHandlerAdapter.class, "getReturnValueHandlers");
|
||||
|
||||
private final ResourceProcessorInvoker invoker;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ResourceProcessorInvokingHandlerAdapter} with the given {@link ResourceProcessorInvoker}.
|
||||
*
|
||||
* @param invoker must not be {@literal null}.
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
public ResourceProcessorInvokingHandlerAdapter(ResourceProcessorInvoker invoker) {
|
||||
|
||||
Assert.notNull(invoker, "ResourceProcessorInvoker must not be null!");
|
||||
this.invoker = invoker;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
super.afterPropertiesSet();
|
||||
|
||||
// Retrieve actual handlers to use as delegate
|
||||
HandlerMethodReturnValueHandlerComposite oldHandlers = getReturnValueHandlersComposite();
|
||||
|
||||
// Set up ResourceProcessingHandlerMethodResolver to delegate to originally configured ones
|
||||
List<HandlerMethodReturnValueHandler> newHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
|
||||
newHandlers.add(new ResourceProcessorHandlerMethodReturnValueHandler(oldHandlers, invoker));
|
||||
|
||||
// Configure the new handler to be used
|
||||
this.setReturnValueHandlers(newHandlers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link HandlerMethodReturnValueHandlerComposite} for return handlers, dealing with API changes introduced in
|
||||
* Spring 4.0.
|
||||
*
|
||||
* @return a HandlerMethodReturnValueHandlerComposite
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private HandlerMethodReturnValueHandlerComposite getReturnValueHandlersComposite() {
|
||||
|
||||
Object handlers = ReflectionUtils.invokeMethod(RETURN_VALUE_HANDLER_METHOD, this);
|
||||
|
||||
if (handlers instanceof HandlerMethodReturnValueHandlerComposite) {
|
||||
return (HandlerMethodReturnValueHandlerComposite) handlers;
|
||||
}
|
||||
|
||||
return new HandlerMethodReturnValueHandlerComposite()
|
||||
.addHandlers((List<? extends HandlerMethodReturnValueHandler>) handlers);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.rest.webmvc.support.ETag;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -98,9 +98,9 @@ class ResourceStatus {
|
||||
* {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public ResponseEntity<Resource<?>> toResponseEntity(Supplier<PersistentEntityResource> supplier) {
|
||||
return modified ? new ResponseEntity<Resource<?>>(supplier.get(), headers, HttpStatus.OK)
|
||||
: new ResponseEntity<Resource<?>>(headers, HttpStatus.NOT_MODIFIED);
|
||||
public ResponseEntity<EntityModel<?>> toResponseEntity(Supplier<PersistentEntityResource> supplier) {
|
||||
return modified ? new ResponseEntity<EntityModel<?>>(supplier.get(), headers, HttpStatus.OK)
|
||||
: new ResponseEntity<EntityModel<?>>(headers, HttpStatus.NOT_MODIFIED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class RootResourceInformation {
|
||||
throws HttpRequestMethodNotSupportedException, ResourceNotFoundException {
|
||||
|
||||
Assert.notNull(httpMethod, "HTTP method must not be null!");
|
||||
Assert.notNull(resourceType, "Resource type must not be null!");
|
||||
Assert.notNull(resourceType, "EntityRepresentationModel type must not be null!");
|
||||
|
||||
if (!resourceMetadata.isExported()) {
|
||||
throw new ResourceNotFoundException();
|
||||
@@ -121,7 +121,7 @@ public class RootResourceInformation {
|
||||
throws HttpRequestMethodNotSupportedException {
|
||||
|
||||
Assert.notNull(httpMethod, "HTTP method must not be null!");
|
||||
Assert.notNull(property, "Resource type must not be null!");
|
||||
Assert.notNull(property, "EntityRepresentationModel type must not be null!");
|
||||
|
||||
if (!resourceMetadata.isExported()) {
|
||||
throw new ResourceNotFoundException();
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.rest.webmvc.RestMediaTypes;
|
||||
import org.springframework.data.rest.webmvc.RootResourceInformation;
|
||||
import org.springframework.hateoas.alps.Alps;
|
||||
import org.springframework.hateoas.mediatype.alps.Alps;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.alps;
|
||||
|
||||
import static org.springframework.hateoas.alps.Alps.*;
|
||||
import static org.springframework.hateoas.mediatype.alps.Alps.*;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -55,16 +55,16 @@ import org.springframework.data.rest.webmvc.RootResourceInformation;
|
||||
import org.springframework.data.rest.webmvc.json.EnumTranslator;
|
||||
import org.springframework.data.rest.webmvc.json.JacksonMetadata;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.TemplateVariable;
|
||||
import org.springframework.hateoas.alps.Alps;
|
||||
import org.springframework.hateoas.alps.Descriptor;
|
||||
import org.springframework.hateoas.alps.Descriptor.DescriptorBuilder;
|
||||
import org.springframework.hateoas.alps.Doc;
|
||||
import org.springframework.hateoas.alps.Format;
|
||||
import org.springframework.hateoas.alps.Type;
|
||||
import org.springframework.hateoas.mediatype.alps.Alps;
|
||||
import org.springframework.hateoas.mediatype.alps.Descriptor;
|
||||
import org.springframework.hateoas.mediatype.alps.Descriptor.DescriptorBuilder;
|
||||
import org.springframework.hateoas.mediatype.alps.Doc;
|
||||
import org.springframework.hateoas.mediatype.alps.Format;
|
||||
import org.springframework.hateoas.mediatype.alps.Type;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class ArgumentResolverPagingAndSortingTemplateVariables implements PagingAndSort
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
|
||||
* @see org.springframework.hateoas.server.mvc.UriComponentsContributor#enhance(org.springframework.web.util.UriComponentsBuilder, org.springframework.core.MethodParameter, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void enhance(UriComponentsBuilder builder, MethodParameter parameter, Object value) {
|
||||
@@ -98,7 +98,7 @@ class ArgumentResolverPagingAndSortingTemplateVariables implements PagingAndSort
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.mvc.UriComponentsContributor#supportsParameter(org.springframework.core.MethodParameter)
|
||||
* @see org.springframework.hateoas.server.mvc.UriComponentsContributor#supportsParameter(org.springframework.core.MethodParameter)
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
|
||||
@@ -97,18 +97,18 @@ import org.springframework.data.web.config.HateoasAwareSpringDataWebConfiguratio
|
||||
import org.springframework.data.web.config.SpringDataJacksonConfiguration;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.RelProvider;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.server.RelProvider;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport;
|
||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.hal.CurieProvider;
|
||||
import org.springframework.hateoas.hal.HalConfiguration;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule.HalHandlerInstantiator;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.CurieProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.HalConfiguration;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalHandlerInstantiator;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
|
||||
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
@@ -365,7 +365,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
}
|
||||
|
||||
/**
|
||||
* A special {@link org.springframework.hateoas.EntityLinks} implementation that takes repository and current
|
||||
* A special {@link org.springframework.hateoas.server.EntityLinks} implementation that takes repository and current
|
||||
* configuration into account when generating links.
|
||||
*
|
||||
* @return
|
||||
@@ -525,17 +525,17 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("rawtypes")
|
||||
public ResourceProcessorInvoker resourceProcessorInvoker() {
|
||||
public RepresentationModelProcessorInvoker resourceProcessorInvoker() {
|
||||
|
||||
Collection<ResourceProcessor> beans = applicationContext.getBeansOfType(ResourceProcessor.class, false, false)
|
||||
Collection<RepresentationModelProcessor> beans = applicationContext.getBeansOfType(RepresentationModelProcessor.class, false, false)
|
||||
.values();
|
||||
List<ResourceProcessor<?>> processors = new ArrayList<ResourceProcessor<?>>(beans.size());
|
||||
List<RepresentationModelProcessor<?>> processors = new ArrayList<RepresentationModelProcessor<?>>(beans.size());
|
||||
|
||||
for (ResourceProcessor<?> bean : beans) {
|
||||
for (RepresentationModelProcessor<?> bean : beans) {
|
||||
processors.add(bean);
|
||||
}
|
||||
|
||||
return new ResourceProcessorInvoker(processors);
|
||||
return new RepresentationModelProcessorInvoker(processors);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -903,7 +903,7 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
|
||||
* @param order the order for the {@link HttpMessageConverter}.
|
||||
*/
|
||||
public ResourceSupportHttpMessageConverter(int order) {
|
||||
super(ResourceSupport.class);
|
||||
super(RepresentationModel.class);
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.util.Scanner;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -43,7 +43,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class UriListHttpMessageConverter implements HttpMessageConverter<ResourceSupport> {
|
||||
public class UriListHttpMessageConverter implements HttpMessageConverter<RepresentationModel> {
|
||||
|
||||
private static final List<MediaType> MEDIA_TYPES = new ArrayList<MediaType>();
|
||||
|
||||
@@ -60,7 +60,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter<Resourc
|
||||
if (null == mediaType) {
|
||||
return false;
|
||||
}
|
||||
return ResourceSupport.class.isAssignableFrom(clazz) && mediaType.getSubtype().contains("uri-list");
|
||||
return RepresentationModel.class.isAssignableFrom(clazz) && mediaType.getSubtype().contains("uri-list");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -86,7 +86,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter<Resourc
|
||||
* @see org.springframework.http.converter.HttpMessageConverter#read(java.lang.Class, org.springframework.http.HttpInputMessage)
|
||||
*/
|
||||
@Override
|
||||
public ResourceSupport read(Class<? extends ResourceSupport> clazz, HttpInputMessage inputMessage)
|
||||
public RepresentationModel read(Class<? extends RepresentationModel> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
List<Link> links = new ArrayList<Link>();
|
||||
@@ -107,7 +107,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter<Resourc
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
return new Resources<Object>(Collections.emptyList(), links);
|
||||
return new CollectionModel<Object>(Collections.emptyList(), links);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -115,7 +115,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter<Resourc
|
||||
* @see org.springframework.http.converter.HttpMessageConverter#write(java.lang.Object, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
|
||||
*/
|
||||
@Override
|
||||
public void write(ResourceSupport resource, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
public void write(RepresentationModel resource, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputMessage.getBody()));
|
||||
|
||||
@@ -52,9 +52,9 @@ import org.springframework.data.rest.webmvc.mapping.LinkCollector;
|
||||
import org.springframework.data.util.CastUtils;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -120,7 +120,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
*/
|
||||
public PersistentEntityJackson2Module(Associations associations, PersistentEntities entities,
|
||||
UriToEntityConverter converter, LinkCollector collector, RepositoryInvokerFactory factory,
|
||||
LookupObjectSerializer lookupObjectSerializer, ResourceProcessorInvoker invoker,
|
||||
LookupObjectSerializer lookupObjectSerializer, RepresentationModelProcessorInvoker invoker,
|
||||
EmbeddedResourcesAssembler assembler) {
|
||||
|
||||
super("persistent-entity-resource", new Version(2, 0, 0, null, "org.springframework.data.rest", "jackson-module"));
|
||||
@@ -191,7 +191,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
return;
|
||||
}
|
||||
|
||||
Resource<Object> resourceToRender = new Resource<Object>(resource.getContent(), links) {
|
||||
EntityModel<Object> resourceToRender = new EntityModel<Object>(resource.getContent(), links) {
|
||||
|
||||
@JsonUnwrapped
|
||||
public Iterable<?> getEmbedded() {
|
||||
@@ -326,10 +326,10 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
private final PersistentEntities entities;
|
||||
private final EmbeddedResourcesAssembler assembler;
|
||||
private final ResourceProcessorInvoker invoker;
|
||||
private final RepresentationModelProcessorInvoker invoker;
|
||||
|
||||
public NestedEntitySerializer(PersistentEntities entities, EmbeddedResourcesAssembler assembler,
|
||||
ResourceProcessorInvoker invoker) {
|
||||
RepresentationModelProcessorInvoker invoker) {
|
||||
|
||||
super(Object.class);
|
||||
this.entities = entities;
|
||||
@@ -350,7 +350,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
List<Object> resources = new ArrayList<Object>();
|
||||
|
||||
for (Object element : source) {
|
||||
resources.add(toResource(element));
|
||||
resources.add(toModel(element));
|
||||
}
|
||||
|
||||
provider.defaultSerializeValue(resources, gen);
|
||||
@@ -361,13 +361,13 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
Map<Object, Object> resources = CollectionFactory.createApproximateMap(value.getClass(), source.size());
|
||||
|
||||
for (Entry<?, ?> entry : source.entrySet()) {
|
||||
resources.put(entry.getKey(), toResource(entry.getValue()));
|
||||
resources.put(entry.getKey(), toModel(entry.getValue()));
|
||||
}
|
||||
|
||||
provider.defaultSerializeValue(resources, gen);
|
||||
|
||||
} else {
|
||||
provider.defaultSerializeValue(toResource(value), gen);
|
||||
provider.defaultSerializeValue(toModel(value), gen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
serialize(value, gen, provider);
|
||||
}
|
||||
|
||||
private Resource<Object> toResource(Object value) {
|
||||
private EntityModel<Object> toModel(Object value) {
|
||||
|
||||
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(value.getClass());
|
||||
|
||||
@@ -540,7 +540,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
|
||||
private final LinkCollector collector;
|
||||
private final Associations associations;
|
||||
private final ResourceProcessorInvoker invoker;
|
||||
private final RepresentationModelProcessorInvoker invoker;
|
||||
private final boolean unwrapping;
|
||||
|
||||
/**
|
||||
@@ -552,7 +552,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
* @param invoker must not be {@literal null}.
|
||||
* @param unwrapping
|
||||
*/
|
||||
private ProjectionSerializer(LinkCollector collector, Associations mappings, ResourceProcessorInvoker invoker,
|
||||
private ProjectionSerializer(LinkCollector collector, Associations mappings, RepresentationModelProcessorInvoker invoker,
|
||||
boolean unwrapping) {
|
||||
|
||||
super(TargetAware.class);
|
||||
@@ -578,7 +578,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
provider.//
|
||||
findValueSerializer(ProjectionResource.class, null).//
|
||||
unwrappingSerializer(null).//
|
||||
serialize(toResource(value), jgen, provider);
|
||||
serialize(toModel(value), jgen, provider);
|
||||
|
||||
if (!unwrapping) {
|
||||
jgen.writeEndObject();
|
||||
@@ -609,19 +609,19 @@ public class PersistentEntityJackson2Module extends SimpleModule {
|
||||
* @param value must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
private ProjectionResource toResource(TargetAware value) {
|
||||
private ProjectionResource toModel(TargetAware value) {
|
||||
|
||||
Object target = value.getTarget();
|
||||
ResourceMetadata metadata = associations.getMetadataFor(value.getTargetClass());
|
||||
Links links = metadata.isExported() ? collector.getLinksFor(target) : Links.NONE;
|
||||
|
||||
Resource<TargetAware> resource = invoker.invokeProcessorsFor(new Resource<TargetAware>(value, links));
|
||||
EntityModel<TargetAware> resource = invoker.invokeProcessorsFor(new EntityModel<TargetAware>(value, links));
|
||||
|
||||
return new ProjectionResource(resource.getContent(), resource.getLinks());
|
||||
}
|
||||
}
|
||||
|
||||
static class ProjectionResource extends Resource<ProjectionResourceContent> {
|
||||
static class ProjectionResource extends EntityModel<ProjectionResourceContent> {
|
||||
|
||||
ProjectionResource(TargetAware projection, Iterable<Link> links) {
|
||||
super(new ProjectionResourceContent(projection, projection.getClass().getInterfaces()[0]), links);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.data.mapping.context.PersistentEntities;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMapping;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMappings;
|
||||
import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ public class NestedLinkCollectingAssociationHandler implements SimpleAssociation
|
||||
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(element.getClass());
|
||||
IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(element);
|
||||
|
||||
links.add(entityLinks.linkForSingleResource(element.getClass(), identifierAccessor.getIdentifier())
|
||||
links.add(entityLinks.linkForItemResource(element.getClass(), identifierAccessor.getIdentifier())
|
||||
.withRel(propertyMapping.getRel()));
|
||||
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class NestedLinkCollectingAssociationHandler implements SimpleAssociation
|
||||
PersistentEntity<?, ?> entity = entities.getRequiredPersistentEntity(propertyValue.getClass());
|
||||
IdentifierAccessor identifierAccessor = entity.getIdentifierAccessor(propertyValue);
|
||||
|
||||
links.add(entityLinks.linkForSingleResource(propertyValue.getClass(), identifierAccessor.getIdentifier())
|
||||
links.add(entityLinks.linkForItemResource(propertyValue.getClass(), identifierAccessor.getIdentifier())
|
||||
.withRel(propertyMapping.getRel()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.data.rest.webmvc.support;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.hateoas.TemplateVariables;
|
||||
import org.springframework.hateoas.mvc.UriComponentsContributor;
|
||||
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,21 +10,21 @@ import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.webmvc.PersistentEntityResource;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.hateoas.Resource;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.EntityModel;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class PersistentEntityResourceProcessor implements ResourceProcessor<PersistentEntityResource> {
|
||||
public class PersistentEntityResourceProcessor implements RepresentationModelProcessor<PersistentEntityResource> {
|
||||
|
||||
private final List<DomainTypeResourceProcessor> resourceProcessors = new ArrayList<DomainTypeResourceProcessor>();
|
||||
|
||||
@Autowired
|
||||
public PersistentEntityResourceProcessor(Repositories repositories,
|
||||
List<ResourceProcessor<Resource<?>>> resourceProcessors) {
|
||||
List<RepresentationModelProcessor<EntityModel<?>>> resourceProcessors) {
|
||||
if (null != resourceProcessors) {
|
||||
for (ResourceProcessor<Resource<?>> rp : resourceProcessors) {
|
||||
for (RepresentationModelProcessor<EntityModel<?>> rp : resourceProcessors) {
|
||||
TypeInformation<?> typeInfo = ClassTypeInformation.from(rp.getClass());
|
||||
TypeInformation<?> domainType = typeInfo.getTypeArguments().get(0);
|
||||
if (null != repositories.getPersistentEntity(domainType.getType())) {
|
||||
@@ -55,9 +55,9 @@ public class PersistentEntityResourceProcessor implements ResourceProcessor<Pers
|
||||
|
||||
private static class DomainTypeResourceProcessor {
|
||||
final Class<?> domainType;
|
||||
final ResourceProcessor<Resource<?>> resourceProcessor;
|
||||
final RepresentationModelProcessor<EntityModel<?>> resourceProcessor;
|
||||
|
||||
private DomainTypeResourceProcessor(Class<?> domainType, ResourceProcessor<Resource<?>> resourceProcessor) {
|
||||
private DomainTypeResourceProcessor(Class<?> domainType, RepresentationModelProcessor<EntityModel<?>> resourceProcessor) {
|
||||
this.domainType = domainType;
|
||||
this.resourceProcessor = resourceProcessor;
|
||||
}
|
||||
|
||||
@@ -38,16 +38,16 @@ import org.springframework.data.rest.core.mapping.SearchResourceMappings;
|
||||
import org.springframework.data.rest.webmvc.BaseUri;
|
||||
import org.springframework.data.rest.webmvc.spi.BackendIdConverter;
|
||||
import org.springframework.data.rest.webmvc.spi.BackendIdConverter.DefaultIdConverter;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkBuilder;
|
||||
import org.springframework.hateoas.server.LinkBuilder;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Links;
|
||||
import org.springframework.hateoas.TemplateVariable;
|
||||
import org.springframework.hateoas.TemplateVariable.VariableType;
|
||||
import org.springframework.hateoas.TemplateVariables;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
import org.springframework.hateoas.core.AbstractEntityLinks;
|
||||
import org.springframework.hateoas.server.core.AbstractEntityLinks;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
@@ -80,7 +80,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.EntityLinks#linkFor(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.EntityLinks#linkFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkBuilder linkFor(Class<?> type) {
|
||||
@@ -91,7 +91,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.EntityLinks#linkFor(java.lang.Class, java.lang.Object[])
|
||||
* @see org.springframework.hateoas.server.EntityLinks#linkFor(java.lang.Class, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public LinkBuilder linkFor(Class<?> type, Object... parameters) {
|
||||
@@ -119,7 +119,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.EntityLinks#linkToCollectionResource(java.lang.Class)
|
||||
* @see org.springframework.hateoas.server.EntityLinks#linkToCollectionResource(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public Link linkToCollectionResource(Class<?> type) {
|
||||
@@ -128,10 +128,10 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.EntityLinks#linkToSingleResource(java.lang.Class, java.lang.Object)
|
||||
* @see org.springframework.hateoas.server.EntityLinks#linkToItemResource(java.lang.Class, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Link linkToSingleResource(Class<?> type, Object id) {
|
||||
public Link linkToItemResource(Class<?> type, Object id) {
|
||||
|
||||
Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!");
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.data.rest.core.mapping.ResourceMetadata;
|
||||
import org.springframework.data.rest.webmvc.BaseUri;
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkBuilder;
|
||||
import org.springframework.hateoas.core.LinkBuilderSupport;
|
||||
import org.springframework.hateoas.server.LinkBuilder;
|
||||
import org.springframework.hateoas.server.core.LinkBuilderSupport;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class RepositoryLinkBuilder extends LinkBuilderSupport<RepositoryLinkBuil
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.LinkBuilderSupport#slash(java.lang.Object)
|
||||
* @see org.springframework.hateoas.server.core.LinkBuilderSupport#slash(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public RepositoryLinkBuilder slash(Object object) {
|
||||
@@ -86,7 +86,7 @@ public class RepositoryLinkBuilder extends LinkBuilderSupport<RepositoryLinkBuil
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.LinkBuilderSupport#createNewInstance(org.springframework.web.util.UriComponentsBuilder, java.util.List)
|
||||
* @see org.springframework.hateoas.server.core.LinkBuilderSupport#createNewInstance(org.springframework.web.util.UriComponentsBuilder, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryLinkBuilder createNewInstance(UriComponentsBuilder builder, List<Affordance> affordances) {
|
||||
@@ -95,7 +95,7 @@ public class RepositoryLinkBuilder extends LinkBuilderSupport<RepositoryLinkBuil
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.LinkBuilderSupport#getThis()
|
||||
* @see org.springframework.hateoas.server.core.LinkBuilderSupport#getThis()
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryLinkBuilder getThis() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
|
||||
import org.springframework.hateoas.server.core.AnnotationMappingDiscoverer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@@ -27,9 +27,9 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.core.EmbeddedWrappers;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrapper;
|
||||
import org.springframework.hateoas.server.core.EmbeddedWrappers;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PersistentEntityResource}.
|
||||
@@ -42,7 +42,7 @@ public class PersistentEntityResourceUnitTests {
|
||||
@Mock Object payload;
|
||||
@Mock PersistentEntity<?, ?> entity;
|
||||
|
||||
Resources<EmbeddedWrapper> resources;
|
||||
CollectionModel<EmbeddedWrapper> resources;
|
||||
Link link = new Link("http://localhost", "foo");
|
||||
|
||||
@Before
|
||||
@@ -50,7 +50,7 @@ public class PersistentEntityResourceUnitTests {
|
||||
|
||||
EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
|
||||
EmbeddedWrapper wrapper = wrappers.wrap("Embedded", LinkRelation.of("foo"));
|
||||
this.resources = new Resources<EmbeddedWrapper>(Collections.singleton(wrapper));
|
||||
this.resources = new CollectionModel<EmbeddedWrapper>(Collections.singleton(wrapper));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAREST-317
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.springframework.data.rest.core.mapping.ResourceType;
|
||||
import org.springframework.data.rest.core.mapping.SupportedHttpMethods;
|
||||
import org.springframework.data.web.PagedResourcesAssembler;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,7 @@ public class RepositoryPropertyReferenceControllerUnitTests {
|
||||
doReturn(new Sample()).when(invoker).invokeSave(any(Object.class));
|
||||
|
||||
RootResourceInformation information = new RootResourceInformation(metadata, entity, invoker);
|
||||
Resources<Object> request = new Resources<Object>(Collections.emptySet(), new Link("/reference/some-id"));
|
||||
CollectionModel<Object> request = new CollectionModel<Object>(Collections.emptySet(), new Link("/reference/some-id"));
|
||||
|
||||
controller.createPropertyReference(information, HttpMethod.POST, request, 4711, "references");
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.rest.webmvc.support.PagingAndSortingTemplateVariables;
|
||||
import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver;
|
||||
import org.springframework.data.web.HateoasSortHandlerMethodArgumentResolver;
|
||||
import org.springframework.hateoas.mvc.UriComponentsContributor;
|
||||
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,10 +49,10 @@ import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module;
|
||||
import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver;
|
||||
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
|
||||
import org.springframework.format.datetime.DateFormatter;
|
||||
import org.springframework.hateoas.LinkDiscoverers;
|
||||
import org.springframework.hateoas.client.LinkDiscoverers;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.core.DefaultRelProvider;
|
||||
import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||
import org.springframework.hateoas.server.core.DefaultRelProvider;
|
||||
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@@ -49,10 +49,10 @@ import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.
|
||||
import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.NestedEntitySerializer;
|
||||
import org.springframework.data.rest.webmvc.mapping.Associations;
|
||||
import org.springframework.data.rest.webmvc.support.ExcerptProjector;
|
||||
import org.springframework.hateoas.EntityLinks;
|
||||
import org.springframework.hateoas.ResourceProcessor;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.hateoas.UriTemplate;
|
||||
import org.springframework.hateoas.mvc.ResourceProcessorInvoker;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorInvoker;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
@@ -92,7 +92,7 @@ public class PersistentEntityJackson2ModuleUnitTests {
|
||||
|
||||
this.persistentEntities = new PersistentEntities(Arrays.asList(mappingContext));
|
||||
|
||||
ResourceProcessorInvoker invoker = new ResourceProcessorInvoker(Collections.<ResourceProcessor<?>> emptyList());
|
||||
RepresentationModelProcessorInvoker invoker = new RepresentationModelProcessorInvoker(Collections.<RepresentationModelProcessor<?>> emptyList());
|
||||
|
||||
NestedEntitySerializer nestedEntitySerializer = new NestedEntitySerializer(persistentEntities,
|
||||
new EmbeddedResourcesAssembler(persistentEntities, associations, mock(ExcerptProjector.class)), invoker);
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.hateoas.Resources;
|
||||
import org.springframework.hateoas.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule.HalHandlerInstantiator;
|
||||
import org.springframework.hateoas.CollectionModel;
|
||||
import org.springframework.hateoas.server.core.EvoInflectorRelProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalHandlerInstantiator;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -78,7 +78,7 @@ public class ProjectionJacksonIntegrationTests {
|
||||
customer.address = new Address();
|
||||
|
||||
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
|
||||
Resources<CustomerProjection> resources = new Resources<CustomerProjection>(Arrays.asList(projection));
|
||||
CollectionModel<CustomerProjection> resources = new CollectionModel<CustomerProjection>(Arrays.asList(projection));
|
||||
|
||||
String result = mapper.writeValueAsString(resources);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user