DATAREST-1104 - Adapt to API changes in mapping subsystem.
This commit is contained in:
committed by
Mark Paluch
parent
069869a69b
commit
2ad963074c
@@ -86,7 +86,7 @@ public class ValidationErrors extends AbstractPropertyBindingResult {
|
||||
String segment = iterator.next();
|
||||
|
||||
Optional<? extends PersistentProperty<?>> property = entities.getPersistentEntity(value.getClass())//
|
||||
.flatMap(it -> it.getPersistentProperty(PropertyAccessorUtils.getPropertyName(segment)));
|
||||
.map(it -> it.getPersistentProperty(PropertyAccessorUtils.getPropertyName(segment)));
|
||||
|
||||
value = getValue(value, property, segment, propertyName);
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ class MappingResourceMetadata extends TypeBasedCollectionResourceMapping impleme
|
||||
this.entity.doWithAssociations(propertyMappings);
|
||||
this.entity.doWithProperties(propertyMappings);
|
||||
|
||||
Optional<RestResource> annotation = entity.findAnnotation(RestResource.class);
|
||||
this.explicitlyExported = annotation.map(it -> it.exported()).orElse(false);
|
||||
this.explicitlyExported = Optional.ofNullable(entity.findAnnotation(RestResource.class))//
|
||||
.map(it -> it.exported())//
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -49,8 +49,9 @@ class PersistentPropertyResourceMapping implements PropertyAwareResourceMapping
|
||||
|
||||
this.property = property;
|
||||
this.mappings = mappings;
|
||||
this.annotation = property.isAssociation() ? property.findAnnotation(RestResource.class) : Optional.empty();
|
||||
this.description = property.findAnnotation(Description.class);
|
||||
this.annotation = Optional
|
||||
.ofNullable(property.isAssociation() ? property.findAnnotation(RestResource.class) : null);
|
||||
this.description = Optional.ofNullable(property.findAnnotation(Description.class));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -111,10 +112,9 @@ class PersistentPropertyResourceMapping implements PropertyAwareResourceMapping
|
||||
CollectionResourceMapping ownerTypeMapping = mappings.getMetadataFor(property.getOwner().getType());
|
||||
ResourceDescription fallback = TypedResourceDescription.defaultFor(ownerTypeMapping.getItemResourceRel(), property);
|
||||
|
||||
return Optionals
|
||||
.<ResourceDescription> firstNonEmpty(//
|
||||
() -> description.map(it -> new AnnotationBasedResourceDescription(it, fallback)), //
|
||||
() -> annotation.map(it -> new AnnotationBasedResourceDescription(it.description(), fallback)))
|
||||
return Optionals.<ResourceDescription> firstNonEmpty(//
|
||||
() -> description.map(it -> new AnnotationBasedResourceDescription(it, fallback)), //
|
||||
() -> annotation.map(it -> new AnnotationBasedResourceDescription(it.description(), fallback)))
|
||||
.orElse(fallback);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ public class DefaultSelfLinkProvider implements SelfLinkProvider {
|
||||
private Object identifierOrNull(Object instance) {
|
||||
|
||||
return entities.getRequiredPersistentEntity(instance.getClass())//
|
||||
.getIdentifierAccessor(instance).getIdentifier()//
|
||||
.orElse(null);
|
||||
.getIdentifierAccessor(instance).getIdentifier();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.data.rest.core.support;
|
||||
|
||||
import static org.springframework.data.rest.core.support.DomainObjectMerger.NullHandlingPolicy.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.mapping.Association;
|
||||
@@ -89,18 +87,18 @@ public class DomainObjectMerger {
|
||||
@Override
|
||||
public void doWithPersistentProperty(PersistentProperty<?> persistentProperty) {
|
||||
|
||||
Optional<Object> sourceValue = sourceWrapper.getProperty(persistentProperty);
|
||||
Optional<Object> targetValue = targetWrapper.getProperty(persistentProperty);
|
||||
Object sourceValue = sourceWrapper.getProperty(persistentProperty);
|
||||
Object targetValue = targetWrapper.getProperty(persistentProperty);
|
||||
|
||||
if (targetEntity.isIdProperty(persistentProperty)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sourceValue.equals(targetValue)) {
|
||||
if (sourceValue != null && sourceValue.equals(targetValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nullPolicy == APPLY_NULLS || sourceValue.isPresent()) {
|
||||
if (nullPolicy == APPLY_NULLS || sourceValue != null) {
|
||||
targetWrapper.setProperty(persistentProperty, sourceValue);
|
||||
}
|
||||
}
|
||||
@@ -116,7 +114,7 @@ public class DomainObjectMerger {
|
||||
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
|
||||
|
||||
PersistentProperty<?> persistentProperty = association.getInverse();
|
||||
Optional<Object> fromVal = sourceWrapper.getProperty(persistentProperty);
|
||||
Object fromVal = sourceWrapper.getProperty(persistentProperty);
|
||||
|
||||
if (!isNullOrEmpty(fromVal) && !fromVal.equals(targetWrapper.getProperty(persistentProperty))) {
|
||||
targetWrapper.setProperty(persistentProperty, fromVal);
|
||||
@@ -132,21 +130,21 @@ public class DomainObjectMerger {
|
||||
* @param source can be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
static boolean isNullOrEmpty(Optional<Object> source) {
|
||||
static boolean isNullOrEmpty(Object source) {
|
||||
|
||||
return source.map(it -> {
|
||||
if (source == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (it instanceof Iterable) {
|
||||
return !((Iterable<?>) it).iterator().hasNext();
|
||||
}
|
||||
if (source instanceof Iterable) {
|
||||
return !((Iterable<?>) source).iterator().hasNext();
|
||||
}
|
||||
|
||||
if (ObjectUtils.isArray(it)) {
|
||||
return ObjectUtils.isEmpty((Object[]) it);
|
||||
}
|
||||
if (ObjectUtils.isArray(source)) {
|
||||
return ObjectUtils.isEmpty((Object[]) source);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}).orElse(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import static org.springframework.data.rest.core.support.DomainObjectMerger.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -34,16 +33,16 @@ public class DomainObjectMergerUnitTests {
|
||||
@Test // DATAREST-327
|
||||
public void considersEmptyObjectsEmpty() {
|
||||
|
||||
assertThat(isNullOrEmpty(Optional.empty())).isTrue();
|
||||
assertThat(isNullOrEmpty(Optional.of(Collections.emptyList()))).isTrue();
|
||||
assertThat(isNullOrEmpty(Optional.of(new Object[0]))).isTrue();
|
||||
assertThat(isNullOrEmpty(Optional.of(new String[0]))).isTrue();
|
||||
assertThat(isNullOrEmpty(Optional.of(new MyIterable()))).isTrue();
|
||||
assertThat(isNullOrEmpty(null)).isTrue();
|
||||
assertThat(isNullOrEmpty(Collections.emptyList())).isTrue();
|
||||
assertThat(isNullOrEmpty(new Object[0])).isTrue();
|
||||
assertThat(isNullOrEmpty(new String[0])).isTrue();
|
||||
assertThat(isNullOrEmpty(new MyIterable())).isTrue();
|
||||
|
||||
assertThat(isNullOrEmpty(Optional.of(new Object()))).isFalse();
|
||||
assertThat(isNullOrEmpty(Optional.of(Collections.singleton(new Object())))).isFalse();
|
||||
assertThat(isNullOrEmpty(Optional.of(new Object[] { "1" }))).isFalse();
|
||||
assertThat(isNullOrEmpty(Optional.of(new String[] { "1" }))).isFalse();
|
||||
assertThat(isNullOrEmpty(new Object())).isFalse();
|
||||
assertThat(isNullOrEmpty(Collections.singleton(new Object()))).isFalse();
|
||||
assertThat(isNullOrEmpty(new Object[] { "1" })).isFalse();
|
||||
assertThat(isNullOrEmpty(new String[] { "1" })).isFalse();
|
||||
}
|
||||
|
||||
class MyIterable implements Iterable<Object> {
|
||||
|
||||
Reference in New Issue
Block a user