DATAREST-437 - Moved to projections API of Spring Data Commons.

Related tickets: DATACMNS-630, DATACMNS-618.
This commit is contained in:
Oliver Gierke
2015-01-11 16:45:41 +01:00
parent af745cfb37
commit f09880ff16
15 changed files with 25 additions and 1075 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
package org.springframework.data.rest.webmvc.config;
import org.springframework.core.MethodParameter;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.projection.ProjectionDefinitions;
import org.springframework.data.rest.core.projection.ProjectionFactory;
import org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler;
import org.springframework.data.rest.webmvc.support.PersistentEntityProjector;
import org.springframework.hateoas.EntityLinks;

View File

@@ -46,6 +46,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.geo.GeoModule;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.repository.support.DefaultRepositoryInvokerFactory;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;
@@ -59,7 +60,6 @@ import org.springframework.data.rest.core.event.ValidatingRepositoryEventListene
import org.springframework.data.rest.core.mapping.RepositoryResourceMappings;
import org.springframework.data.rest.core.mapping.ResourceDescription;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.projection.ProxyProjectionFactory;
import org.springframework.data.rest.core.support.DomainObjectMerger;
import org.springframework.data.rest.core.support.RepositoryRelProvider;
import org.springframework.data.rest.webmvc.BasePathAwareController;
@@ -624,9 +624,11 @@ public class RepositoryRestMvcConfiguration extends HateoasAwareSpringDataWebCon
private List<HandlerMethodArgumentResolver> defaultMethodArgumentResolvers() {
SpelAwareProxyProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
projectionFactory.setBeanFactory(applicationContext);
PersistentEntityResourceAssemblerArgumentResolver peraResolver = new PersistentEntityResourceAssemblerArgumentResolver(
repositories(), entityLinks(), config().projectionConfiguration(), new ProxyProjectionFactory(
applicationContext), resourceMappings());
repositories(), entityLinks(), config().projectionConfiguration(), projectionFactory, resourceMappings());
HateoasPageableHandlerMethodArgumentResolver pageableResolver = pageableResolver();
HandlerMethodArgumentResolver defaultedPageableResolver = new DefaultedPageableHandlerMethodArgumentResolver(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,10 +15,10 @@
*/
package org.springframework.data.rest.webmvc.support;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.mapping.ResourceMetadata;
import org.springframework.data.rest.core.projection.ProjectionDefinitions;
import org.springframework.data.rest.core.projection.ProjectionFactory;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -67,7 +67,7 @@ public class PersistentEntityProjector implements Projector {
}
Class<?> projectionType = projectionDefinitions.getProjectionType(source.getClass(), projection);
return projectionType == null ? source : factory.createProjection(source, projectionType);
return projectionType == null ? source : factory.createProjection(projectionType, source);
}
/*
@@ -86,7 +86,7 @@ public class PersistentEntityProjector implements Projector {
return project(source);
}
return projection == null ? source : factory.createProjection(source, projection);
return projection == null ? source : factory.createProjection(projection, source);
}
/*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,9 +36,9 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.data.rest.core.projection.ProxyProjectionFactory;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
import org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.ResourcesProcessorWrapper;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
@@ -233,8 +233,8 @@ public class ResourceProcessorHandlerMethodReturnValueHandlerUnitTests {
ProjectionProcessor projectionProcessor = new ProjectionProcessor();
resourceProcessors.add(projectionProcessor);
ProxyProjectionFactory factory = new ProxyProjectionFactory(new DefaultListableBeanFactory());
SampleProjection projection = factory.createProjection(new Sample(), SampleProjection.class);
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
SampleProjection projection = factory.createProjection(SampleProjection.class, new Sample());
Resource<SampleProjection> resource = new Resource<SampleProjection>(projection);
invokeReturnValueHandler("object", is(resource), resource);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@ import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.rest.core.projection.ProjectionFactory;
import org.springframework.data.rest.core.projection.ProxyProjectionFactory;
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;
@@ -41,7 +41,7 @@ import com.jayway.jsonpath.JsonPath;
public class ProjectionJacksonIntegrationTests {
ObjectMapper mapper;
ProjectionFactory factory = new ProxyProjectionFactory(null);
ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
@Before
public void setUp() {
@@ -62,7 +62,7 @@ public class ProjectionJacksonIntegrationTests {
customer.lastname = "Matthews";
customer.address = new Address();
CustomerProjection projection = factory.createProjection(customer, CustomerProjection.class);
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
String result = mapper.writeValueAsString(projection);
assertThat(JsonPath.read(result, "$firstname"), is((Object) "Dave"));
@@ -83,7 +83,7 @@ public class ProjectionJacksonIntegrationTests {
customer.lastname = "Matthews";
customer.address = new Address();
CustomerProjection projection = factory.createProjection(customer, CustomerProjection.class);
CustomerProjection projection = factory.createProjection(CustomerProjection.class, customer);
Resources<CustomerProjection> resources = new Resources<CustomerProjection>(Arrays.asList(projection));
String result = mapper.writeValueAsString(resources);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.core.projection.ProjectionFactory;
/**
* Unit tests for {@link PersistentEntityProjector}.
@@ -69,7 +69,7 @@ public class PersistentEntityProjectorUnitTests {
Object source = new Object();
projector.project(source);
verify(factory, times(1)).createProjection(source, Sample.class);
verify(factory, times(1)).createProjection(Sample.class, source);
}
interface Sample {