>>();
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/CopyOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/CopyOperation.java
index f57f78063..416571bd1 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/CopyOperation.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/CopyOperation.java
@@ -15,9 +15,8 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.RequiredArgsConstructor;
-
import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
+import org.springframework.util.Assert;
/**
*
@@ -62,11 +61,17 @@ class CopyOperation extends PatchOperation {
return new CopyOperationBuilder(from);
}
- @RequiredArgsConstructor
static class CopyOperationBuilder {
private final String from;
+ public CopyOperationBuilder(String from) {
+
+ Assert.hasText(from, "From must not be null!");
+
+ this.from = from;
+ }
+
CopyOperation to(String to) {
return new CopyOperation(SpelPath.untyped(to), SpelPath.untyped(from));
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonLateObjectEvaluator.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonLateObjectEvaluator.java
index 6474b44d6..5a0dce93e 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonLateObjectEvaluator.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonLateObjectEvaluator.java
@@ -15,8 +15,7 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
+import org.springframework.util.Assert;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -29,11 +28,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* @author Oliver Gierke
* @author Simon Allegraud
*/
-@RequiredArgsConstructor
class JsonLateObjectEvaluator implements LateObjectEvaluator {
- private final @NonNull ObjectMapper mapper;
- private final @NonNull JsonNode valueNode;
+ private final ObjectMapper mapper;
+ private final JsonNode node;
+
+ public JsonLateObjectEvaluator(ObjectMapper mapper, JsonNode node) {
+
+ Assert.notNull(mapper, "ObjectMapper must not be null!");
+ Assert.notNull(node, "JsonNode must not be null!");
+
+ this.mapper = mapper;
+ this.node = node;
+ }
/*
* (non-Javadoc)
@@ -43,9 +50,9 @@ class JsonLateObjectEvaluator implements LateObjectEvaluator {
public Object evaluate(Class> type) {
try {
- return mapper.readValue(valueNode.traverse(mapper.getFactory().getCodec()), type);
+ return mapper.readValue(node.traverse(mapper.getFactory().getCodec()), type);
} catch (Exception o_O) {
- throw new PatchException(String.format("Could not read %s into %s!", valueNode, type), o_O);
+ throw new PatchException(String.format("Could not read %s into %s!", node, type), o_O);
}
}
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchPatchConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchPatchConverter.java
index 7464dac4a..71201002c 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchPatchConverter.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/JsonPatchPatchConverter.java
@@ -15,13 +15,12 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.springframework.util.Assert;
+
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -34,10 +33,16 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
* @author Mathias Düsterhöft
* @author Oliver Trosien
*/
-@RequiredArgsConstructor
public class JsonPatchPatchConverter implements PatchConverter {
- private final @NonNull ObjectMapper mapper;
+ private final ObjectMapper mapper;
+
+ public JsonPatchPatchConverter(ObjectMapper mapper) {
+
+ Assert.notNull(mapper, "ObjectMapper must not be null!");
+
+ this.mapper = mapper;
+ }
/**
* Constructs a {@link Patch} object given a JsonNode.
@@ -99,7 +104,7 @@ public class JsonPatchPatchConverter implements PatchConverter {
return valueNode.asInt();
} else if (valueNode.isLong()) {
return valueNode.asLong();
- } else if (valueNode.isObject() || (valueNode.isArray())) {
+ } else if (valueNode.isObject() || valueNode.isArray()) {
return new JsonLateObjectEvaluator(mapper, valueNode);
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/MoveOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/MoveOperation.java
index d757ccdc3..929f1ab3c 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/MoveOperation.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/MoveOperation.java
@@ -15,10 +15,8 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-
import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
+import org.springframework.util.Assert;
/**
*
@@ -56,11 +54,17 @@ class MoveOperation extends PatchOperation {
return new MoveOperationBuilder(from);
}
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
static class MoveOperationBuilder {
private final String from;
+ private MoveOperationBuilder(String from) {
+
+ Assert.hasText(from, "From must not be null or empty!");
+
+ this.from = from;
+ }
+
public MoveOperation to(String to) {
return new MoveOperation(SpelPath.untyped(to), SpelPath.untyped(from));
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java
index ddea57348..46e38bb19 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/PatchOperation.java
@@ -15,10 +15,8 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-
import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
+import org.springframework.util.Assert;
/**
* Abstract base class representing and providing support methods for patch operations.
@@ -27,11 +25,10 @@ import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
* @author Mathias Düsterhöft
* @author Oliver Gierke
*/
-@RequiredArgsConstructor
public abstract class PatchOperation {
- protected final @NonNull String op;
- protected final @NonNull UntypedSpelPath path;
+ protected final String op;
+ protected final UntypedSpelPath path;
protected final Object value;
/**
@@ -44,6 +41,16 @@ public abstract class PatchOperation {
this(op, path, null);
}
+ protected PatchOperation(String op, UntypedSpelPath path, Object value) {
+
+ Assert.hasText(op, "Operation must not be null or empty!");
+ Assert.notNull(path, "UntypedSpelPath must not be null!");
+
+ this.op = op;
+ this.path = path;
+ this.value = value;
+ }
+
/**
* Performs late-value evaluation on the operation value if the value is a {@link LateObjectEvaluator}.
*
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperation.java
index 9813405de..665e6baac 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperation.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/ReplaceOperation.java
@@ -1,3 +1,4 @@
+// Generated by delombok at Tue Aug 11 12:51:25 CEST 2020
/*
* Copyright 2014-2020 the original author or authors.
*
@@ -15,9 +16,6 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-
import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
/**
@@ -27,7 +25,6 @@ import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
* @author Oliver Gierke
*/
class ReplaceOperation extends PatchOperation {
-
/**
* Constructs the replace operation
*
@@ -42,14 +39,18 @@ class ReplaceOperation extends PatchOperation {
return new ReplaceOperationBuilder(path);
}
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
- static class ReplaceOperationBuilder {
+ static class ReplaceOperationBuilder {
private final String path;
public ReplaceOperation with(Object value) {
return new ReplaceOperation(SpelPath.untyped(path), value);
}
+
+ @java.lang.SuppressWarnings("all")
+ private ReplaceOperationBuilder(final String path) {
+ this.path = path;
+ }
}
/*
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java
index 964dabce6..25becfaa1 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/SpelPath.java
@@ -15,16 +15,11 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.AccessLevel;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.Value;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
@@ -52,14 +47,24 @@ import org.springframework.util.StringUtils;
*
* @author Oliver Gierke
*/
-@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class SpelPath {
private static final SpelExpressionParser SPEL_EXPRESSION_PARSER = new SpelExpressionParser();
private static final String APPEND_CHARACTER = "-";
private static final Map UNTYPED_PATHS = new ConcurrentReferenceHashMap<>(32);
- protected final @Getter String path;
+ protected final String path;
+
+ private SpelPath(String path) {
+
+ Assert.notNull(path, "Path must not be null!");
+
+ this.path = path;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
/**
* Returns a {@link UntypedSpelPath} for the given source.
@@ -153,7 +158,6 @@ class SpelPath {
*
* @author Oliver Gierke
*/
- @EqualsAndHashCode(callSuper = true)
static class TypedSpelPath extends SpelPath {
private static final String INVALID_PATH_REFERENCE = "Invalid path reference %s on type %s!";
@@ -164,10 +168,62 @@ class SpelPath {
private final Expression expression;
private final Class> type;
- @Value(staticConstructor = "of")
- private static class CacheKey {
- Class> type;
- UntypedSpelPath path;
+ private static final class CacheKey {
+
+ private final Class> type;
+ private final UntypedSpelPath path;
+
+ private CacheKey(Class> type, UntypedSpelPath path) {
+
+ Assert.notNull(type, "Type must not be null!");
+ Assert.notNull(path, "UntypedSpelPath must not be null!");
+
+ this.type = type;
+ this.path = path;
+ }
+
+ public static CacheKey of(final Class> type, final UntypedSpelPath path) {
+ return new CacheKey(type, path);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof CacheKey)) {
+ return false;
+ }
+
+ CacheKey that = (CacheKey) o;
+
+ return Objects.equals(type, that.type) //
+ && Objects.equals(path, that.path);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, path);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public java.lang.String toString() {
+ return "SpelPath.TypedSpelPath.CacheKey(type=" + type + ", path=" + path + ")";
+ }
}
private TypedSpelPath(UntypedSpelPath path, Class> type) {
@@ -441,17 +497,31 @@ class SpelPath {
}
}
- @Value
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE, staticName = "of")
- private static class SkippedPropertyPath {
+ private static final class SkippedPropertyPath {
- PropertyPath path;
- boolean skipped;
+ private final PropertyPath path;
+ private final boolean skipped;
+
+ private SkippedPropertyPath(PropertyPath path, boolean skipped) {
+
+ Assert.notNull(path, "PropertyPath must not be null!");
+
+ this.path = path;
+ this.skipped = skipped;
+ }
public static SkippedPropertyPath of(String segment, Class> type) {
return of(PropertyPath.from(segment, type), false);
}
+ private static SkippedPropertyPath of(PropertyPath path, boolean skipped) {
+ return new SkippedPropertyPath(path, skipped);
+ }
+
+ public PropertyPath getPath() {
+ return this.path;
+ }
+
public SkippedPropertyPath nested(String segment) {
if (skipped) {
@@ -464,6 +534,44 @@ class SpelPath {
? SkippedPropertyPath.of(path, true) //
: SkippedPropertyPath.of(path.nested(segment), false);
}
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof SkippedPropertyPath)) {
+ return false;
+ }
+ SkippedPropertyPath other = (SkippedPropertyPath) o;
+
+ return Objects.equals(path, other.path) //
+ && skipped == other.skipped;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(path, skipped);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public java.lang.String toString() {
+ return "SpelPath.TypedSpelPath.SkippedPropertyPath(path=" + path + ", skipped=" + skipped + ")";
+ }
}
private static Expression toSpel(String path, Class> type) {
@@ -494,8 +602,7 @@ class SpelPath {
.orElseGet(() -> SkippedPropertyPath.of(next, type));
}
- @Value
- private static class SpelExpressionBuilder {
+ private static final class SpelExpressionBuilder {
private static final TypeInformation STRING_TYPE = ClassTypeInformation.from(String.class);
@@ -504,6 +611,35 @@ class SpelPath {
private final String spelSegment;
private final boolean skipped;
+ public SpelExpressionBuilder(@Nullable PropertyPath basePath, Class> type, String spelSegment,
+ boolean skipped) {
+
+ Assert.notNull(type, "Type must not be null!");
+ Assert.notNull(spelSegment, "SpEL segment must not be null!");
+
+ this.basePath = basePath;
+ this.type = type;
+ this.spelSegment = spelSegment;
+ this.skipped = skipped;
+ }
+
+ @Nullable
+ public PropertyPath getBasePath() {
+ return this.basePath;
+ }
+
+ public Class> getType() {
+ return this.type;
+ }
+
+ public String getSpelSegment() {
+ return this.spelSegment;
+ }
+
+ public boolean isSkipped() {
+ return this.skipped;
+ }
+
public String getExpression() {
return StringUtils.hasText(spelSegment) ? spelSegment : null;
}
@@ -570,6 +706,77 @@ class SpelPath {
return nested(segment);
}
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof SpelExpressionBuilder)) {
+ return false;
+ }
+
+ SpelExpressionBuilder that = (SpelExpressionBuilder) o;
+
+ return Objects.equals(basePath, that.basePath) //
+ && Objects.equals(type, that.type) //
+ && Objects.equals(spelSegment, that.spelSegment) //
+ && skipped == that.skipped;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(basePath, type, spelSegment, skipped);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public java.lang.String toString() {
+ return "SpelPath.TypedSpelPath.SpelExpressionBuilder(basePath=" + this.getBasePath() + ", type="
+ + this.getType() + ", spelSegment=" + this.getSpelSegment() + ", skipped=" + this.isSkipped() + ")";
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.rest.webmvc.json.patch.SpelPath#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final java.lang.Object o) {
+
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof TypedSpelPath) || !super.equals(o)) {
+ return false;
+ }
+
+ TypedSpelPath that = (TypedSpelPath) o;
+
+ return Objects.equals(expression, that.expression) //
+ && Objects.equals(type, that.type);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.rest.webmvc.json.patch.SpelPath#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return Objects.hash(expression, type);
}
}
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/TestOperation.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/TestOperation.java
index 4df260c06..65ad7040f 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/TestOperation.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/patch/TestOperation.java
@@ -15,13 +15,11 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-
import java.math.BigDecimal;
import java.math.BigInteger;
import org.springframework.data.rest.webmvc.json.patch.SpelPath.UntypedSpelPath;
+import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
@@ -52,11 +50,17 @@ class TestOperation extends PatchOperation {
return new TestOperationBuilder(path);
}
- @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
static class TestOperationBuilder {
private final String path;
+ private TestOperationBuilder(String path) {
+
+ Assert.hasText(path, "Path must not be null or empty!");
+
+ this.path = path;
+ }
+
public TestOperation hasValue(Object value) {
return new TestOperation(SpelPath.untyped(path), value);
}
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/Associations.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/Associations.java
index f0aa9cf03..473124b77 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/Associations.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/Associations.java
@@ -17,10 +17,6 @@ package org.springframework.data.rest.webmvc.mapping;
import static org.springframework.hateoas.TemplateVariable.VariableType.*;
-import lombok.Getter;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-
import java.util.Collections;
import java.util.List;
@@ -47,11 +43,23 @@ import org.springframework.util.Assert;
* @author Haroun Pacquee
* @since 2.1
*/
-@RequiredArgsConstructor
public class Associations {
- private final @NonNull @Getter ResourceMappings mappings;
- private final @NonNull RepositoryRestConfiguration config;
+ private final ResourceMappings mappings;
+ private final RepositoryRestConfiguration config;
+
+ public Associations(ResourceMappings mappings, RepositoryRestConfiguration config) {
+
+ Assert.notNull(mappings, "ResourceMappings must not be null!");
+ Assert.notNull(config, "RepositoryRestConfiguration must not be null!");
+
+ this.mappings = mappings;
+ this.config = config;
+ }
+
+ public ResourceMappings getMappings() {
+ return this.mappings;
+ }
/**
* Returns the links to render for the given {@link Association}.
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollectingAssociationHandler.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollectingAssociationHandler.java
index addd4287a..e9c6e3a86 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollectingAssociationHandler.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollectingAssociationHandler.java
@@ -33,7 +33,10 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @since 2.1
+ * @deprecated no replacement, internal usage only. For removal in 3.5.
+ * @see LinkCollector
*/
+@Deprecated
public class LinkCollectingAssociationHandler implements SimpleAssociationHandler {
private static final String AMBIGUOUS_ASSOCIATIONS = "Detected multiple association links with same relation type! Disambiguate association %s using @RestResource!";
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollector.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollector.java
index f60068ab4..d370d8866 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollector.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/mapping/LinkCollector.java
@@ -15,10 +15,6 @@
*/
package org.springframework.data.rest.webmvc.mapping;
-import lombok.Getter;
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -99,7 +95,7 @@ public class LinkCollector {
Path path = new Path(selfLink.expand().getHref());
- LinkCollectingAssociationHandler handler = new LinkCollectingAssociationHandler(entities, path, associationLinks);
+ LinkCollectingAssociationHandler handler = new LinkCollectingAssociationHandler(path, associationLinks);
entities.getRequiredPersistentEntity(object.getClass()).doWithAssociations(handler);
return addSelfLinkIfNecessary(object, existingLinks.and(handler.getLinks()));
@@ -117,11 +113,8 @@ public class LinkCollector {
}
private Links addSelfLinkIfNecessary(Object object, Links existing) {
-
- return existing.hasLink(IanaLinkRelations.SELF) //
- ? existing //
- : Links.of(createSelfLink(object, existing)) //
- .and(existing);
+ return existing.andIf(!existing.hasLink(IanaLinkRelations.SELF),
+ () -> links.createSelfLinkFor(object).withSelfRel());
}
private Link createSelfLink(Object object, Links existing) {
@@ -136,15 +129,22 @@ public class LinkCollector {
* @author Oliver Gierke
* @since 2.1
*/
- @RequiredArgsConstructor
private static class LinkCollectingAssociationHandler implements SimpleAssociationHandler {
private static final String AMBIGUOUS_ASSOCIATIONS = "Detected multiple association links with same relation type! Disambiguate association %s using @RestResource!";
- private final @NonNull PersistentEntities entities;
- private final @NonNull Path basePath;
- private final @NonNull Associations associationLinks;
- private final @NonNull List links = new ArrayList();
+ private final Path basePath;
+ private final Associations associationLinks;
+ private final List links = new ArrayList();
+
+ public LinkCollectingAssociationHandler(Path basePath, Associations associationLinks) {
+
+ Assert.notNull(basePath, "Base Path must not be null!");
+ Assert.notNull(associationLinks, "Associations must not be null!");
+
+ this.basePath = basePath;
+ this.associationLinks = associationLinks;
+ }
/**
* Returns the links collected after the {@link Association} has been traversed.
@@ -178,13 +178,28 @@ public class LinkCollector {
}
}
- @RequiredArgsConstructor
private static class NestedLinkCollectingAssociationHandler implements SimpleAssociationHandler {
private final SelfLinkProvider selfLinks;
private final PersistentPropertyAccessor> accessor;
private final Associations associations;
- private final @Getter List links = new ArrayList();
+ private final List links = new ArrayList();
+
+ public NestedLinkCollectingAssociationHandler(SelfLinkProvider selfLinks,
+ PersistentPropertyAccessor> accessor, Associations associations) {
+
+ Assert.notNull(selfLinks, "SelfLinkProvider must not be null!");
+ Assert.notNull(accessor, "PersistentPropertyAccessor must not be null!");
+ Assert.notNull(associations, "Associations must not be null!");
+
+ this.selfLinks = selfLinks;
+ this.accessor = accessor;
+ this.associations = associations;
+ }
+
+ public List getLinks() {
+ return this.links;
+ }
/*
* (non-Javadoc)
@@ -198,7 +213,6 @@ public class LinkCollector {
}
PersistentProperty> property = association.getInverse();
-
Object value = accessor.getProperty(property);
if (value == null) {
@@ -236,11 +250,9 @@ public class LinkCollector {
@SuppressWarnings("unchecked")
private static Collection