DATAREST-1403 - CollectionResourceMapping.getExcerptProjection() now returns Optional.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
|
||||
/**
|
||||
@@ -40,9 +42,10 @@ public interface CollectionResourceMapping extends ResourceMapping {
|
||||
|
||||
/**
|
||||
* Returns the projection type to be used when embedding item resources into collections and related resources. If
|
||||
* {@literal null} is returned this will mean full rendering for collections and no rendering for related resources.
|
||||
* {@link Optional#empty()} is returned this will mean full rendering for collections and no rendering for related
|
||||
* resources.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?> getExcerptProjection();
|
||||
Optional<Class<?>> getExcerptProjection();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
@@ -184,7 +186,7 @@ class RepositoryAwareResourceMetadata implements ResourceMetadata {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getExcerptProjection()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getExcerptProjection() {
|
||||
public Optional<Class<?>> getExcerptProjection() {
|
||||
return mapping.getExcerptProjection();
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping {
|
||||
|
||||
Class<?> domainType = metadata.getDomainType();
|
||||
|
||||
CollectionResourceMapping domainTypeMapping = EVO_INFLECTOR_IS_PRESENT
|
||||
? new EvoInflectorTypeBasedCollectionResourceMapping(domainType, relProvider)
|
||||
: new TypeBasedCollectionResourceMapping(domainType, relProvider);
|
||||
|
||||
@@ -212,8 +213,8 @@ class RepositoryCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getExcerptProjection()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getExcerptProjection() {
|
||||
return excerptProjection.getOptional().orElse(null);
|
||||
public Optional<Class<?>> getExcerptProjection() {
|
||||
return excerptProjection.getOptional();
|
||||
}
|
||||
|
||||
private static Optional<LinkRelation> toLinkRelation(Optional<String> source) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.rest.core.mapping;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.rest.core.Path;
|
||||
@@ -164,8 +165,8 @@ class TypeBasedCollectionResourceMapping implements CollectionResourceMapping {
|
||||
* @see org.springframework.data.rest.core.mapping.CollectionResourceMapping#getExcerptProjection()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getExcerptProjection() {
|
||||
return null;
|
||||
public Optional<Class<?>> getExcerptProjection() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -121,8 +121,8 @@ public class RepositoryCollectionResourceMappingUnitTests {
|
||||
@Test // DATAREST-1401
|
||||
public void exposesProjectionTypeIfConfigured() {
|
||||
|
||||
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).isEqualTo(Object.class);
|
||||
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isNull();
|
||||
assertThat(getResourceMappingFor(WithProjection.class).getExcerptProjection()).hasValue(Object.class);
|
||||
assertThat(getResourceMappingFor(WithoutProjection.class).getExcerptProjection()).isEmpty();
|
||||
}
|
||||
|
||||
private static CollectionResourceMapping getResourceMappingFor(Class<?> repositoryInterface) {
|
||||
|
||||
Reference in New Issue
Block a user