diff --git a/formatter.xml b/formatter.xml
new file mode 100644
index 000000000..b5515c19e
--- /dev/null
+++ b/formatter.xml
@@ -0,0 +1,291 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/DelegatingConversionService.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/DelegatingConversionService.java
index b3ec428cd..15313730f 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/DelegatingConversionService.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/DelegatingConversionService.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2012-2013 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.convert;
import java.util.Stack;
@@ -5,89 +20,91 @@ import java.util.Stack;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.util.Assert;
/**
* This {@link ConversionService} implementation delegates the actual conversion to the {@literal ConversionService} it
* finds in its internal {@link Stack} that claims to be able to convert a given class. It will roll through the
* {@literal ConversionService}s until it finds one that can convert the given type.
- *
+ *
* @author Jon Brisbin
+ * @authot Oliver Gierke
*/
public class DelegatingConversionService implements ConversionService {
- private Stack conversionServices = new Stack();
+ private final Stack conversionServices;
- public DelegatingConversionService() {
- }
+ public DelegatingConversionService(ConversionService... svcs) {
- public DelegatingConversionService(ConversionService... svcs) {
- addConversionServices(svcs);
- }
+ this.conversionServices = new Stack();
- /**
- * Add {@link ConversionService}s to the internal list of those to delegate to.
- *
- * @param svcs
- * The ConversionServices to delegate to (in order).
- *
- * @return @this
- */
- public DelegatingConversionService addConversionServices(ConversionService... svcs) {
- for(ConversionService svc : svcs) {
- conversionServices.add(svc);
- }
- return this;
- }
+ for (ConversionService svc : svcs) {
+ Assert.notNull(svc);
+ conversionServices.add(svc);
+ }
+ }
- /**
- * Add a {@link ConversionService} to the internal list at a specific index for controlling the priority.
- *
- * @param atIndex
- * Where in the stack to add this ConversionService.
- * @param svc
- * The ConversionService to add.
- *
- * @return
- */
- public DelegatingConversionService addConversionService(int atIndex, ConversionService svc) {
- conversionServices.add(atIndex, svc);
- return this;
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.ConversionService#canConvert(java.lang.Class, java.lang.Class)
+ */
+ @Override
+ public boolean canConvert(Class> from, Class> to) {
- @Override public boolean canConvert(Class> from, Class> to) {
- for(ConversionService svc : conversionServices) {
- if(svc.canConvert(from, to)) {
- return true;
- }
- }
- return false;
- }
+ for (ConversionService svc : conversionServices) {
+ if (svc.canConvert(from, to)) {
+ return true;
+ }
+ }
- @Override public boolean canConvert(TypeDescriptor from, TypeDescriptor to) {
- for(ConversionService svc : conversionServices) {
- if(svc.canConvert(from, to)) {
- return true;
- }
- }
- return false;
- }
+ return false;
+ }
- @Override public T convert(Object o, Class type) {
- for(ConversionService svc : conversionServices) {
- if(svc.canConvert(o.getClass(), type)) {
- return svc.convert(o, type);
- }
- }
- throw new ConverterNotFoundException(TypeDescriptor.forObject(o), TypeDescriptor.valueOf(type));
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.ConversionService#canConvert(org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public boolean canConvert(TypeDescriptor from, TypeDescriptor to) {
- @Override public Object convert(Object o, TypeDescriptor from, TypeDescriptor to) {
- for(ConversionService svc : conversionServices) {
- if(svc.canConvert(from, to)) {
- return svc.convert(o, from, to);
- }
- }
- throw new ConverterNotFoundException(from, to);
- }
+ for (ConversionService svc : conversionServices) {
+ if (svc.canConvert(from, to)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.ConversionService#convert(java.lang.Object, java.lang.Class)
+ */
+ @Override
+ public T convert(Object o, Class type) {
+
+ for (ConversionService svc : conversionServices) {
+ if (svc.canConvert(o.getClass(), type)) {
+ return svc.convert(o, type);
+ }
+ }
+
+ throw new ConverterNotFoundException(TypeDescriptor.forObject(o), TypeDescriptor.valueOf(type));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.ConversionService#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public Object convert(Object o, TypeDescriptor from, TypeDescriptor to) {
+
+ for (ConversionService svc : conversionServices) {
+ if (svc.canConvert(from, to)) {
+ return svc.convert(o, from, to);
+ }
+ }
+
+ throw new ConverterNotFoundException(from, to);
+ }
}
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/ISO8601DateConverter.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/ISO8601DateConverter.java
index 98a547003..0e17aa8dc 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/ISO8601DateConverter.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/ISO8601DateConverter.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2012-2013 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.convert;
import java.text.DateFormat;
@@ -15,62 +30,81 @@ import org.springframework.core.convert.converter.Converter;
/**
* @author Jon Brisbin
*/
-public class ISO8601DateConverter implements ConditionalGenericConverter,
- Converter {
+public class ISO8601DateConverter implements ConditionalGenericConverter, Converter {
- public static final ConditionalGenericConverter INSTANCE = new ISO8601DateConverter();
+ public static final ConditionalGenericConverter INSTANCE = new ISO8601DateConverter();
- private static final Set CONVERTIBLE_PAIRS = new HashSet();
+ private static final Set CONVERTIBLE_PAIRS = new HashSet();
- static {
- CONVERTIBLE_PAIRS.add(new ConvertiblePair(String.class, Date.class));
- CONVERTIBLE_PAIRS.add(new ConvertiblePair(Date.class, String.class));
- }
+ static {
+ CONVERTIBLE_PAIRS.add(new ConvertiblePair(String.class, Date.class));
+ CONVERTIBLE_PAIRS.add(new ConvertiblePair(Date.class, String.class));
+ }
- @Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- if(String.class.isAssignableFrom(sourceType.getType())) {
- return Date.class.isAssignableFrom(targetType.getType());
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.ConditionalConverter#matches(org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- return Date.class.isAssignableFrom(sourceType.getType())
- && String.class.isAssignableFrom(targetType.getType());
- }
+ if (String.class.isAssignableFrom(sourceType.getType())) {
+ return Date.class.isAssignableFrom(targetType.getType());
+ }
- @Override public Set getConvertibleTypes() {
- return CONVERTIBLE_PAIRS;
- }
+ return Date.class.isAssignableFrom(sourceType.getType()) && String.class.isAssignableFrom(targetType.getType());
+ }
- @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
- DateFormat dateFmt = iso8601DateFormat();
- if(String.class.isAssignableFrom(sourceType.getType())) {
- return dateFmt.format(source);
- } else {
- try {
- return dateFmt.parse(source.toString());
- } catch(ParseException e) {
- throw new ConversionFailedException(sourceType, targetType, source, e);
- }
- }
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
+ */
+ @Override
+ public Set getConvertibleTypes() {
+ return CONVERTIBLE_PAIRS;
+ }
- @Override public Date convert(String[] source) {
- if(source.length > 0) {
- try {
- return iso8601DateFormat().parse(source[0]);
- } catch(ParseException e) {
- throw new ConversionFailedException(
- TypeDescriptor.valueOf(String[].class),
- TypeDescriptor.valueOf(Date.class),
- source[0],
- new IllegalArgumentException("Source does not conform to ISO8601 date format (YYYY-MM-DDTHH:MM:SS-0000")
- );
- }
- }
- return null;
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
- private DateFormat iso8601DateFormat() {
- return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
- }
+ DateFormat dateFmt = iso8601DateFormat();
+ if (String.class.isAssignableFrom(sourceType.getType())) {
+ return dateFmt.format(source);
+ }
+
+ try {
+ return dateFmt.parse(source.toString());
+ } catch (ParseException e) {
+ throw new ConversionFailedException(sourceType, targetType, source, e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
+ */
+ @Override
+ public Date convert(String[] source) {
+
+ if (source.length == 0) {
+ return null;
+ }
+
+ try {
+ return iso8601DateFormat().parse(source[0]);
+ } catch (ParseException e) {
+ throw new ConversionFailedException(TypeDescriptor.valueOf(String[].class), TypeDescriptor.valueOf(Date.class),
+ source[0], new IllegalArgumentException(
+ "Source does not conform to ISO8601 date format (YYYY-MM-DDTHH:MM:SS-0000"));
+ }
+ }
+
+ private DateFormat iso8601DateFormat() {
+ return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+ }
}
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/UUIDConverter.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/UUIDConverter.java
index 5b2ccf31a..e1cf1a071 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/UUIDConverter.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/UUIDConverter.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2012-2013 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.convert;
import java.util.HashSet;
@@ -9,38 +24,51 @@ import org.springframework.core.convert.converter.ConditionalGenericConverter;
/**
* For converting a {@link UUID} into a {@link String}.
- *
+ *
* @author Jon Brisbin
*/
public class UUIDConverter implements ConditionalGenericConverter {
- public static final UUIDConverter INSTANCE = new UUIDConverter();
- private static final Set CONVERTIBLE_PAIRS = new HashSet();
+ public static final UUIDConverter INSTANCE = new UUIDConverter();
+ private static final Set CONVERTIBLE_PAIRS = new HashSet();
- static {
- CONVERTIBLE_PAIRS.add(new ConvertiblePair(String.class, UUID.class));
- CONVERTIBLE_PAIRS.add(new ConvertiblePair(UUID.class, String.class));
- }
+ static {
+ CONVERTIBLE_PAIRS.add(new ConvertiblePair(String.class, UUID.class));
+ CONVERTIBLE_PAIRS.add(new ConvertiblePair(UUID.class, String.class));
+ }
- @Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- if(String.class.isAssignableFrom(sourceType.getType())) {
- return UUID.class.isAssignableFrom(targetType.getType());
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.ConditionalConverter#matches(org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
+ if (String.class.isAssignableFrom(sourceType.getType())) {
+ return UUID.class.isAssignableFrom(targetType.getType());
+ }
- return UUID.class.isAssignableFrom(sourceType.getType())
- && String.class.isAssignableFrom(targetType.getType());
- }
+ return UUID.class.isAssignableFrom(sourceType.getType()) && String.class.isAssignableFrom(targetType.getType());
+ }
- @Override public Set getConvertibleTypes() {
- return CONVERTIBLE_PAIRS;
- }
-
- @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
- if(String.class.isAssignableFrom(sourceType.getType())) {
- return UUID.fromString(source.toString());
- } else {
- return source.toString();
- }
- }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
+ */
+ @Override
+ public Set getConvertibleTypes() {
+ return CONVERTIBLE_PAIRS;
+ }
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
+ */
+ @Override
+ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
+ if (String.class.isAssignableFrom(sourceType.getType())) {
+ return UUID.fromString(source.toString());
+ } else {
+ return source.toString();
+ }
+ }
}
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/package-info.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/package-info.java
index 2a539f0cc..c79336930 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/package-info.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/convert/package-info.java
@@ -2,3 +2,4 @@
* {@link org.springframework.core.convert.ConversionService} and {@link org.springframework.core.convert.converter.Converter} integration for Spring Data REST.
*/
package org.springframework.data.rest.convert;
+
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/package-info.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/package-info.java
index ba9ee30c4..ab46b12e2 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/package-info.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/package-info.java
@@ -2,3 +2,4 @@
* Core components used across Spring Data REST.
*/
package org.springframework.data.rest.core;
+
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java
index c5c33203a..fc85c546a 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/MapUtils.java
@@ -38,14 +38,14 @@ public abstract class MapUtils {
* @return
*/
public static Map> toMap(MultiValueMap map) {
-
+
Assert.notNull(map, "Given map must not be null!");
Map> result = new LinkedHashMap>(map.size());
for (Entry> entry : map.entrySet()) {
result.put(entry.getKey(), entry.getValue());
}
-
+
return result;
}
}
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java
index 4739be5d7..c7cb057d2 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/util/UriUtils.java
@@ -1,210 +1,25 @@
package org.springframework.data.rest.core.util;
import java.net.URI;
-import java.util.List;
-import java.util.Stack;
-import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponentsBuilder;
/**
* Helper methods for dealing with URIs.
- *
- * @author Jon Brisbin
+ *
+ * @author Jon Brisbin
*/
public abstract class UriUtils {
- private UriUtils() {
- }
-
- /**
- * Is the given {@link URI} based on the "base" {@link URI}?
- *
e.g. given a base URI of {@literal http://localhost:8080/data} and a URI of {@code
- * http://localhost:8080/data/person}, this method would report the baseUri being a valid base of the given URI.
- *
- *
- * @param baseUri
- * {@link URI} to check.
- * @param uri
- * {@link URI} against which to compare the base.
- *
- * @return {@literal true} if the baseUri is valid against the given {@link URI}, {@literal false} otherwise.
- */
- public static boolean validBaseUri(URI baseUri, URI uri) {
- String path = UriUtils.path(baseUri.relativize(uri));
- return !StringUtils.hasText(path) || path.charAt(0) != '/';
- }
-
- /**
- * Execute the given {@link Function} for each segment in the {@link URI}.
- *
e.g. given a URI of {@literal http://localhost:8080/data/person/1} and a base URI of {@code
- * http://localhost:8080/data}, this method will explode the URI into it's components, as compared to the base URI.
- * The result would be: the given handler gets called twice, once passing a relative {@link URI} of "person" and a
- * second time passing a relative {@link URI} of "1".
- *
- *
- * @param baseUri
- * base {@link URI}
- * @param uri
- * {@link URI} to explode and iterate over.
- * @param handler
- * {@link Function} to call for each segment of the URI's path.
- * @param
- * Return type of the handler.
- *
- * @return Handler return value, or possibly {@literal null}.
- */
- public static V foreach(URI baseUri, URI uri, Function handler) {
- List uris = explode(baseUri, uri);
- V v = null;
- for(URI u : uris) {
- v = handler.apply(u);
- }
- return v;
- }
-
- /**
- * Explode the given {@link URI} into its component parts, as compared to the base {@link URI}.
- *
Given a base URI of {@literal http://localhost:8080/data}, exploding the URI {@code
- * http://localhost:8080/data/person/1} strips the first part of the URI, leaving {@literal person/1}. This results
- * in
- * a {@link Stack} of relative {@link URI}s of size 2--one for "person" and one for "1".
- *
- * @param baseUri
- * base {@link URI}
- * @param uri
- * {@link URI} to explode
- *
- * @return {@link Stack} of relative {@link URI}s.
- */
- public static Stack explode(URI baseUri, URI uri) {
- Stack uris = new Stack();
- if(StringUtils.hasText(uri.getPath())) {
- URI relativeUri = baseUri.relativize(uri);
- if(StringUtils.hasText(relativeUri.getPath())) {
- for(String part : relativeUri.getPath().split("/")) {
- uris.add(URI.create(part + (StringUtils.hasText(uri.getQuery()) ? "?" + uri.getQuery() : "")));
- }
- }
- }
- return uris;
- }
-
- /**
- * Merge the components of these {@link URI}s into a single URI. Useful for combining a relative URI with a base URI
- * and coming up with a full absolute URI.
- *
e.g. merging base URI {@literal http://localhost:8080/data} and relative uri {@literal person/1?name=John+Doe}
- * would result in an absolute URI of {@literal http://localhost:8080/data/person/1?name=John+Doe}
- *
- * @param baseUri
- * base {@link URI}
- * @param uris
- * {@link URI}s to merge
- *
- * @return {@link URI} that is the combination of all the given (possibly relative, possibly absolute) URIs.
- */
- public static URI merge(URI baseUri, URI... uris) {
- StringBuilder query = new StringBuilder();
-
- UriComponentsBuilder ub = UriComponentsBuilder.fromUri(baseUri);
- for(URI uri : uris) {
- String s = uri.getScheme();
- if(null != s) {
- ub.scheme(s);
- }
-
- s = uri.getUserInfo();
- if(null != s) {
- ub.userInfo(s);
- }
-
- s = uri.getHost();
- if(null != s) {
- ub.host(s);
- }
-
- int i = uri.getPort();
- if(i > 0) {
- ub.port(i);
- }
-
- s = uri.getPath();
- if(null != s) {
- if(!uri.isAbsolute() && StringUtils.hasText(s)) {
- ub.pathSegment(s);
- } else {
- ub.path(s);
- }
- }
-
- s = uri.getQuery();
- if(null != s) {
- if(query.length() > 0) {
- query.append("&");
- }
- query.append(s);
- }
-
- s = uri.getFragment();
- if(null != s) {
- ub.fragment(s);
- }
- }
-
- if(query.length() > 0) {
- ub.query(query.toString());
- }
-
- return ub.build().toUri();
- }
-
- /**
- * Just the path portion of the {@link URI}, but with any trailing slash "/" removed.
- *
- * @param uri
- * path URI
- *
- * @return the path portion of the URI, but with any trailing slash removed
- */
- public static String path(URI uri) {
- if(null == uri) {
- return null;
- }
- String s = uri.getPath();
- if(s.endsWith("/")) {
- return s.substring(0, s.length() - 1);
- } else {
- return s;
- }
- }
-
- /**
- * The very last segment of the {@link URI}.
- *
- * @param baseUri
- * base {@link URI}
- * @param uri
- * {@link URI} to explode
- *
- * @return Relative {@link URI} that is the last segment of the path for the given URI.
- */
- public static URI tail(URI baseUri, URI uri) {
- Stack uris = explode(baseUri, uri);
- return uris.size() > 0 ? uris.get(Math.max(uris.size() - 1, 0)) : null;
- }
-
- /**
- * Create a new {@link URI} out of the components.
- *
- * @param baseUri
- * The base URI these path segments are relative to.
- * @param pathSegments
- * The path segments to add to the given base URI.
- *
- * @return A new URI built from the given base URI and additional path segments.
- */
- public static URI buildUri(URI baseUri, String... pathSegments) {
- return UriComponentsBuilder.fromUri(baseUri).pathSegment(pathSegments).build().toUri();
- }
+ /**
+ * Create a new {@link URI} out of the components.
+ *
+ * @param baseUri The base URI these path segments are relative to.
+ * @param pathSegments The path segments to add to the given base URI.
+ * @return A new URI built from the given base URI and additional path segments.
+ */
+ public static URI buildUri(URI baseUri, String... pathSegments) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment(pathSegments).build().toUri();
+ }
}
diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/package-info.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/package-info.java
index 91a1bbf41..0acebd7b7 100644
--- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/package-info.java
+++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/package-info.java
@@ -2,3 +2,4 @@
* Spring Data REST
*/
package org.springframework.data.rest;
+
diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/convert/DelegatingConversionServiceUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/convert/DelegatingConversionServiceUnitTests.java
index 480922b2e..4d2b38710 100644
--- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/convert/DelegatingConversionServiceUnitTests.java
+++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/convert/DelegatingConversionServiceUnitTests.java
@@ -1,7 +1,23 @@
+/*
+ * Copyright 2012-2013 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.convert;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
+import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import java.util.UUID;
@@ -16,48 +32,53 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.format.support.DefaultFormattingConversionService;
/**
- * Tests to ensure the {@link DelegatingConversionService} properly delegates conversions to the {@link
- * org.springframework.core.convert.ConversionService} that is appropriate for the given source and return types.
- *
+ * Tests to ensure the {@link DelegatingConversionService} properly delegates conversions to the
+ * {@link org.springframework.core.convert.ConversionService} that is appropriate for the given source and return types.
+ *
* @author Jon Brisbin
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class DelegatingConversionServiceUnitTests {
- private static final UUID RANDOM_UUID = UUID.fromString("9deccfd7-f892-4e26-a4d5-c92893392e78");
+ private static final UUID RANDOM_UUID = UUID.fromString("9deccfd7-f892-4e26-a4d5-c92893392e78");
- @Mock ConversionService conversionService;
- DelegatingConversionService delegatingConversionService;
+ @Mock ConversionService conversionService;
+ DelegatingConversionService delegatingConversionService;
- @Before
- public void setup() {
+ @Before
+ public void setup() {
- DefaultFormattingConversionService cs = new DefaultFormattingConversionService(false);
- cs.addConverter(UUIDConverter.INSTANCE);
+ DefaultFormattingConversionService cs = new DefaultFormattingConversionService(false);
+ cs.addConverter(UUIDConverter.INSTANCE);
- delegatingConversionService = new DelegatingConversionService(conversionService, cs);
-
- when(conversionService.canConvert(String.class, UUID.class)).thenReturn(false);
- when(conversionService.canConvert(UUID.class, String.class)).thenReturn(false);
- }
+ delegatingConversionService = new DelegatingConversionService(conversionService, cs);
- @Test
- public void shouldDelegateToProperConversionService() throws Exception {
- assertThat(delegatingConversionService.canConvert(String.class, UUID.class), is(true));
- assertThat(delegatingConversionService.convert(RANDOM_UUID.toString(), UUID.class), is(RANDOM_UUID));
- verifyConversionService();
- }
+ when(conversionService.canConvert(String.class, UUID.class)).thenReturn(false);
+ when(conversionService.canConvert(UUID.class, String.class)).thenReturn(false);
+ }
- @Test
- public void shouldConvertUUIDToString() throws Exception {
- assertThat(delegatingConversionService.canConvert(UUID.class, String.class), is(true));
- assertThat(delegatingConversionService.convert(RANDOM_UUID, String.class), is(RANDOM_UUID.toString()));
- verifyConversionService();
- }
+ @Test
+ public void shouldDelegateToProperConversionService() {
- private void verifyConversionService() {
- verify(conversionService, times(0)).convert(Matchers.any(String.class), eq(UUID.class));
- verify(conversionService, times(0)).convert(Matchers.any(UUID.class), eq(String.class));
- }
+ assertThat(delegatingConversionService.canConvert(String.class, UUID.class), is(true));
+ assertThat(delegatingConversionService.convert(RANDOM_UUID.toString(), UUID.class), is(RANDOM_UUID));
+
+ verifyConversionService();
+ }
+
+ @Test
+ public void shouldConvertUUIDToString() {
+
+ assertThat(delegatingConversionService.canConvert(UUID.class, String.class), is(true));
+ assertThat(delegatingConversionService.convert(RANDOM_UUID, String.class), is(RANDOM_UUID.toString()));
+
+ verifyConversionService();
+ }
+
+ private void verifyConversionService() {
+
+ verify(conversionService, times(0)).convert(Matchers.any(String.class), eq(UUID.class));
+ verify(conversionService, times(0)).convert(Matchers.any(UUID.class), eq(String.class));
+ }
}
diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java
index 2c9be61fb..77b5686a2 100644
--- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java
+++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/util/UriUtilsUnitTests.java
@@ -1,92 +1,44 @@
+/*
+ * Copyright 2012-2013 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.core.util;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
import org.junit.Test;
/**
* Tests to verify that {@link UriUtils} can manipulate {@link URI}s.
- *
+ *
* @author Jon Brisbin
*/
public class UriUtilsUnitTests {
- private static final String BASE_URI_STR = "http://localhost:8080/data";
- private static final URI BASE_URI = URI.create(BASE_URI_STR);
+ private static final String BASE_URI_STR = "http://localhost:8080/data";
+ private static final URI BASE_URI = URI.create(BASE_URI_STR);
- private static final String PERSON_2LVL_STR = BASE_URI_STR + "/person/1";
- private static final URI PERSON_2LVL_URI = URI.create(PERSON_2LVL_STR);
+ private static final String PERSON_2LVL_STR = BASE_URI_STR + "/person/1";
+ private static final URI PERSON_2LVL_URI = URI.create(PERSON_2LVL_STR);
- @Test
- public void shouldValidateBaseURI() throws Exception {
- URI uri = new URI(BASE_URI + "/person/1");
-
- assertThat(UriUtils.validBaseUri(BASE_URI, uri), is(true));
- }
-
- @Test
- public void shouldIterateOverPathElements() throws Exception {
- final List paths = new ArrayList();
- Function fn = new Function() {
- @Override public Void apply(URI uri) {
- paths.add(uri.getPath());
- return null;
- }
- };
-
- UriUtils.foreach(BASE_URI, PERSON_2LVL_URI, fn);
-
- assertThat(paths, hasSize(2));
- assertThat(paths, contains("person", "1"));
- }
-
- @Test
- public void shouldExplodeRelativeURI() throws Exception {
- Stack uris = UriUtils.explode(BASE_URI, PERSON_2LVL_URI);
-
- assertThat(uris, hasSize(2));
- assertThat(uris, contains(URI.create("person"), URI.create("1")));
- }
-
- @Test
- public void shouldMergeDifferentURIsIntoOne() throws Exception {
- String qrystr = "?queryParam=testValue";
-
- URI uriWithQuery = URI.create(qrystr);
- URI uriWithPath = URI.create("person/1");
-
- URI uri = UriUtils.merge(BASE_URI, uriWithPath, uriWithQuery);
-
- assertThat(uri.toString(), is(PERSON_2LVL_STR + qrystr));
- }
-
- @Test
- public void shouldStripTrailingSlashFromPath() throws Exception {
- URI uri = URI.create("person/");
-
- String path = UriUtils.path(uri);
-
- assertThat(path, is("person"));
- }
-
- @Test
- public void shouldStripTheLastPathSegmentFromAURI() throws Exception {
- URI uri = UriUtils.tail(BASE_URI, PERSON_2LVL_URI);
-
- assertThat(uri, is(URI.create("1")));
- }
-
- @Test
- public void shouldBuildURIFromPathSegments() throws Exception {
- URI uri = UriUtils.buildUri(BASE_URI, "person", "1");
-
- assertThat(uri, is(PERSON_2LVL_URI));
- }
+ @Test
+ public void shouldBuildURIFromPathSegments() throws Exception {
+ URI uri = UriUtils.buildUri(BASE_URI, "person", "1");
+ assertThat(uri, is(PERSON_2LVL_URI));
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/RepositoryRestConfiguration.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/RepositoryRestConfiguration.java
index e1e6305f0..0d85b3f15 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/RepositoryRestConfiguration.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/RepositoryRestConfiguration.java
@@ -30,22 +30,22 @@ import org.springframework.util.Assert;
@SuppressWarnings("deprecation")
public class RepositoryRestConfiguration {
- private URI baseUri = null;
- private int defaultPageSize = 20;
- private int maxPageSize = 1000;
- private String pageParamName = "page";
- private String limitParamName = "limit";
- private String sortParamName = "sort";
- private MediaType defaultMediaType = MediaType.APPLICATION_JSON;
- private boolean returnBodyOnCreate = false;
- private boolean returnBodyOnUpdate = false;
- private List> exposeIdsFor = new ArrayList>();
- private ResourceMappingConfiguration domainMappings = new ResourceMappingConfiguration();
- private ResourceMappingConfiguration repoMappings = new ResourceMappingConfiguration();
+ private URI baseUri = null;
+ private int defaultPageSize = 20;
+ private int maxPageSize = 1000;
+ private String pageParamName = "page";
+ private String limitParamName = "limit";
+ private String sortParamName = "sort";
+ private MediaType defaultMediaType = MediaType.APPLICATION_JSON;
+ private boolean returnBodyOnCreate = false;
+ private boolean returnBodyOnUpdate = false;
+ private List> exposeIdsFor = new ArrayList>();
+ private ResourceMappingConfiguration domainMappings = new ResourceMappingConfiguration();
+ private ResourceMappingConfiguration repoMappings = new ResourceMappingConfiguration();
/**
* The base URI against which the exporter should calculate its links.
- *
+ *
* @return The base URI.
*/
public URI getBaseUri() {
@@ -54,9 +54,8 @@ public class RepositoryRestConfiguration {
/**
* The base URI against which the exporter should calculate its links.
- *
- * @param baseUri
- * The base URI.
+ *
+ * @param baseUri The base URI.
*/
public RepositoryRestConfiguration setBaseUri(URI baseUri) {
Assert.notNull(baseUri, "The baseUri cannot be null.");
@@ -66,7 +65,7 @@ public class RepositoryRestConfiguration {
/**
* Get the default size of {@link org.springframework.data.domain.Pageable}s. Default is 20.
- *
+ *
* @return The default page size.
*/
public int getDefaultPageSize() {
@@ -75,10 +74,8 @@ public class RepositoryRestConfiguration {
/**
* Set the default size of {@link org.springframework.data.domain.Pageable}s.
- *
- * @param defaultPageSize
- * The default page size.
- *
+ *
+ * @param defaultPageSize The default page size.
* @return {@literal this}
*/
public RepositoryRestConfiguration setDefaultPageSize(int defaultPageSize) {
@@ -89,7 +86,7 @@ public class RepositoryRestConfiguration {
/**
* Get the maximum size of pages.
- *
+ *
* @return Maximum page size.
*/
public int getMaxPageSize() {
@@ -98,10 +95,8 @@ public class RepositoryRestConfiguration {
/**
* Set the maximum size of pages.
- *
- * @param maxPageSize
- * Maximum page size.
- *
+ *
+ * @param maxPageSize Maximum page size.
* @return {@literal this}
*/
public RepositoryRestConfiguration setMaxPageSize(int maxPageSize) {
@@ -112,7 +107,7 @@ public class RepositoryRestConfiguration {
/**
* Get the name of the URL query string parameter that indicates what page to return. Default is 'page'.
- *
+ *
* @return Name of the query parameter used to indicate the page number to return.
*/
public String getPageParamName() {
@@ -121,10 +116,8 @@ public class RepositoryRestConfiguration {
/**
* Set the name of the URL query string parameter that indicates what page to return.
- *
- * @param pageParamName
- * Name of the query parameter used to indicate the page number to return.
- *
+ *
+ * @param pageParamName Name of the query parameter used to indicate the page number to return.
* @return {@literal this}
*/
public RepositoryRestConfiguration setPageParamName(String pageParamName) {
@@ -136,7 +129,7 @@ public class RepositoryRestConfiguration {
/**
* Get the name of the URL query string parameter that indicates how many results to return at once. Default is
* 'limit'.
- *
+ *
* @return Name of the query parameter used to indicate the maximum number of entries to return at a time.
*/
public String getLimitParamName() {
@@ -145,10 +138,9 @@ public class RepositoryRestConfiguration {
/**
* Set the name of the URL query string parameter that indicates how many results to return at once.
- *
- * @param limitParamName
- * Name of the query parameter used to indicate the maximum number of entries to return at a time.
- *
+ *
+ * @param limitParamName Name of the query parameter used to indicate the maximum number of entries to return at a
+ * time.
* @return {@literal this}
*/
public RepositoryRestConfiguration setLimitParamName(String limitParamName) {
@@ -159,7 +151,7 @@ public class RepositoryRestConfiguration {
/**
* Get the name of the URL query string parameter that indicates what direction to sort results. Default is 'sort'.
- *
+ *
* @return Name of the query string parameter used to indicate what field to sort on.
*/
public String getSortParamName() {
@@ -168,10 +160,8 @@ public class RepositoryRestConfiguration {
/**
* Set the name of the URL query string parameter that indicates what direction to sort results.
- *
- * @param sortParamName
- * Name of the query string parameter used to indicate what field to sort on.
- *
+ *
+ * @param sortParamName Name of the query string parameter used to indicate what field to sort on.
* @return {@literal this}
*/
public RepositoryRestConfiguration setSortParamName(String sortParamName) {
@@ -182,7 +172,7 @@ public class RepositoryRestConfiguration {
/**
* Get the {@link MediaType} to use as a default when none is specified.
- *
+ *
* @return Default content type if none has been specified.
*/
public MediaType getDefaultMediaType() {
@@ -191,10 +181,8 @@ public class RepositoryRestConfiguration {
/**
* Set the {@link MediaType} to use as a default when none is specified.
- *
- * @param defaultMediaType
- * Default content type if none has been specified.
- *
+ *
+ * @param defaultMediaType Default content type if none has been specified.
* @return {@literal this}
*/
public RepositoryRestConfiguration setDefaultMediaType(MediaType defaultMediaType) {
@@ -204,7 +192,7 @@ public class RepositoryRestConfiguration {
/**
* Whether to return a response body after creating an entity.
- *
+ *
* @return {@literal true} to return a body on create, {@literal false} otherwise.
*/
public boolean isReturnBodyOnCreate() {
@@ -213,10 +201,8 @@ public class RepositoryRestConfiguration {
/**
* Set whether to return a response body after creating an entity.
- *
- * @param returnBodyOnCreate
- * {@literal true} to return a body on create, {@literal false} otherwise.
- *
+ *
+ * @param returnBodyOnCreate {@literal true} to return a body on create, {@literal false} otherwise.
* @return {@literal this}
*/
public RepositoryRestConfiguration setReturnBodyOnCreate(boolean returnBodyOnCreate) {
@@ -226,7 +212,7 @@ public class RepositoryRestConfiguration {
/**
* Whether to return a response body after updating an entity.
- *
+ *
* @return {@literal true} to return a body on update, {@literal false} otherwise.
*/
public boolean isReturnBodyOnUpdate() {
@@ -235,9 +221,8 @@ public class RepositoryRestConfiguration {
/**
* Sets whether to return a response body after updating an entity.
- *
+ *
* @param returnBodyOnUpdate
- *
* @return
*/
public RepositoryRestConfiguration setReturnBodyOnUpdate(boolean returnBodyOnUpdate) {
@@ -247,10 +232,8 @@ public class RepositoryRestConfiguration {
/**
* Start configuration a {@link ResourceMapping} for a specific domain type.
- *
- * @param domainType
- * The {@link Class} of the domain type to configure a mapping for.
- *
+ *
+ * @param domainType The {@link Class} of the domain type to configure a mapping for.
* @return A new {@link ResourceMapping} for configuring how a domain type is mapped.
*/
public ResourceMapping setResourceMappingForDomainType(Class> domainType) {
@@ -259,10 +242,8 @@ public class RepositoryRestConfiguration {
/**
* Get the {@link ResourceMapping} for a specific domain type.
- *
- * @param domainType
- * The {@link Class} of the domain type.
- *
+ *
+ * @param domainType The {@link Class} of the domain type.
* @return A {@link ResourceMapping} for that domain type or {@literal null} if none exists.
*/
public ResourceMapping getResourceMappingForDomainType(Class> domainType) {
@@ -271,10 +252,8 @@ public class RepositoryRestConfiguration {
/**
* Whether there is a {@link ResourceMapping} for the given domain type.
- *
- * @param domainType
- * The domain type to find a {@link ResourceMapping} for.
- *
+ *
+ * @param domainType The domain type to find a {@link ResourceMapping} for.
* @return {@literal true} if a {@link ResourceMapping} exists for this domain class, {@literal false} otherwise.
*/
public boolean hasResourceMappingForDomainType(Class> domainType) {
@@ -283,7 +262,7 @@ public class RepositoryRestConfiguration {
/**
* Get the {@link ResourceMappingConfiguration} that is currently configured.
- *
+ *
* @return
*/
public ResourceMappingConfiguration getDomainTypesResourceMappingConfiguration() {
@@ -292,10 +271,8 @@ public class RepositoryRestConfiguration {
/**
* Start configuration a {@link ResourceMapping} for a specific repository interface.
- *
- * @param repositoryInterface
- * The {@link Class} of the repository interface to configure a mapping for.
- *
+ *
+ * @param repositoryInterface The {@link Class} of the repository interface to configure a mapping for.
* @return A new {@link ResourceMapping} for configuring how a repository interface is mapped.
*/
public ResourceMapping setResourceMappingForRepository(Class> repositoryInterface) {
@@ -304,10 +281,8 @@ public class RepositoryRestConfiguration {
/**
* Get the {@link ResourceMapping} for a specific repository interface.
- *
- * @param repositoryInterface
- * The {@link Class} of the repository interface.
- *
+ *
+ * @param repositoryInterface The {@link Class} of the repository interface.
* @return A {@link ResourceMapping} for that repository interface or {@literal null} if none exists.
*/
public ResourceMapping getResourceMappingForRepository(Class> repositoryInterface) {
@@ -316,9 +291,8 @@ public class RepositoryRestConfiguration {
/**
* Whether there is a {@link ResourceMapping} configured for this {@literal Repository} class.
- *
+ *
* @param repositoryInterface
- *
* @return
*/
public boolean hasResourceMappingForRepository(Class> repositoryInterface) {
@@ -327,7 +301,7 @@ public class RepositoryRestConfiguration {
public ResourceMapping findRepositoryMappingForPath(String path) {
Class> type = repoMappings.findTypeForPath(path);
- if(null == type) {
+ if (null == type) {
return null;
}
return repoMappings.getResourceMappingFor(type);
@@ -335,10 +309,8 @@ public class RepositoryRestConfiguration {
/**
* Should we expose the ID property for this domain type?
- *
- * @param domainType
- * The domain type we may need to expose the ID for.
- *
+ *
+ * @param domainType The domain type we may need to expose the ID for.
* @return {@literal true} is the ID is to be exposed, {@literal false} otherwise.
*/
public boolean isIdExposedFor(Class> domainType) {
@@ -347,10 +319,8 @@ public class RepositoryRestConfiguration {
/**
* Set the list of domain types for which we will expose the ID value as a normal property.
- *
- * @param domainTypes
- * Array of types to expose IDs for.
- *
+ *
+ * @param domainTypes Array of types to expose IDs for.
* @return {@literal this}
*/
public RepositoryRestConfiguration exposeIdsFor(Class>... domainTypes) {
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMapping.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMapping.java
index a799727d3..74c0c83d4 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMapping.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMapping.java
@@ -26,101 +26,97 @@ import java.util.Map;
@Deprecated
public class ResourceMapping {
- private String rel;
- private String path;
- private boolean exported = true;
- private final Map resourceMappings = new HashMap();
+ private String rel;
+ private String path;
+ private boolean exported = true;
+ private final Map resourceMappings = new HashMap();
- public ResourceMapping() {
- }
+ public ResourceMapping() {}
- public ResourceMapping(Class> type) {
- rel = findRel(type);
- path = findPath(type);
- exported = findExported(type);
- }
+ public ResourceMapping(Class> type) {
+ rel = findRel(type);
+ path = findPath(type);
+ exported = findExported(type);
+ }
- public ResourceMapping(String rel, String path) {
- this.rel = rel;
- this.path = path;
- }
+ public ResourceMapping(String rel, String path) {
+ this.rel = rel;
+ this.path = path;
+ }
- public ResourceMapping(String rel, String path, boolean exported) {
- this.rel = rel;
- this.path = path;
- this.exported = exported;
- }
+ public ResourceMapping(String rel, String path, boolean exported) {
+ this.rel = rel;
+ this.path = path;
+ this.exported = exported;
+ }
- public String getRel() {
- return rel;
- }
+ public String getRel() {
+ return rel;
+ }
- public ResourceMapping setRel(String rel) {
- this.rel = rel;
- return this;
- }
+ public ResourceMapping setRel(String rel) {
+ this.rel = rel;
+ return this;
+ }
- public String getPath() {
- return path;
- }
+ public String getPath() {
+ return path;
+ }
- public ResourceMapping setPath(String path) {
- this.path = path;
- return this;
- }
+ public ResourceMapping setPath(String path) {
+ this.path = path;
+ return this;
+ }
- public boolean isExported() {
- return exported;
- }
+ public boolean isExported() {
+ return exported;
+ }
- public ResourceMapping setExported(boolean exported) {
- this.exported = exported;
- return this;
- }
+ public ResourceMapping setExported(boolean exported) {
+ this.exported = exported;
+ return this;
+ }
- public ResourceMapping addResourceMappings(Map mappings) {
- if(null == mappings) {
- return this;
- }
+ public ResourceMapping addResourceMappings(Map mappings) {
+ if (null == mappings) {
+ return this;
+ }
- resourceMappings.putAll(mappings);
- return this;
- }
+ resourceMappings.putAll(mappings);
+ return this;
+ }
- public ResourceMapping addResourceMappingFor(String name) {
- ResourceMapping rm = new ResourceMapping();
- resourceMappings.put(name, rm);
- return rm;
- }
+ public ResourceMapping addResourceMappingFor(String name) {
+ ResourceMapping rm = new ResourceMapping();
+ resourceMappings.put(name, rm);
+ return rm;
+ }
- public ResourceMapping getResourceMappingFor(String name) {
- return resourceMappings.get(name);
- }
+ public ResourceMapping getResourceMappingFor(String name) {
+ return resourceMappings.get(name);
+ }
- public boolean hasResourceMappingFor(String name) {
- return resourceMappings.containsKey(name);
- }
+ public boolean hasResourceMappingFor(String name) {
+ return resourceMappings.containsKey(name);
+ }
- public Map getResourceMappings() {
- return resourceMappings;
- }
+ public Map getResourceMappings() {
+ return resourceMappings;
+ }
- public String getNameForPath(String path) {
- for(Map.Entry mapping : resourceMappings.entrySet()) {
- if(mapping.getValue().getPath().equals(path)) {
- return mapping.getKey();
- }
- }
- return path;
- }
+ public String getNameForPath(String path) {
+ for (Map.Entry mapping : resourceMappings.entrySet()) {
+ if (mapping.getValue().getPath().equals(path)) {
+ return mapping.getKey();
+ }
+ }
+ return path;
+ }
- @Override public String toString() {
- return "ResourceMapping{" +
- "rel='" + rel + '\'' +
- ", path='" + path + '\'' +
- ", exported=" + exported +
- ", resourceMappings=" + resourceMappings +
- '}';
- }
+ @Override
+ public String toString() {
+ return "ResourceMapping{" + "rel='" + rel + '\'' + ", path='" + path + '\'' + ", exported=" + exported
+ + ", resourceMappings=" + resourceMappings + '}';
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMappingConfiguration.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMappingConfiguration.java
index 4d2d7ac9c..9dd745107 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMappingConfiguration.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/config/ResourceMappingConfiguration.java
@@ -21,41 +21,41 @@ import java.util.Map;
/**
* Manages the {@link ResourceMapping} configurations for any resources being exported. This includes domain entities
* and repositories.
- *
+ *
* @author Jon Brisbin
*/
@SuppressWarnings("deprecation")
public class ResourceMappingConfiguration {
- private final Map, ResourceMapping> resourceMappings = new HashMap, ResourceMapping>();
+ private final Map, ResourceMapping> resourceMappings = new HashMap, ResourceMapping>();
- public ResourceMapping setResourceMappingFor(Class> type) {
- ResourceMapping rm = resourceMappings.get(type);
- if(null == rm) {
- rm = new ResourceMapping(type);
- resourceMappings.put(type, rm);
- }
- return rm;
- }
+ public ResourceMapping setResourceMappingFor(Class> type) {
+ ResourceMapping rm = resourceMappings.get(type);
+ if (null == rm) {
+ rm = new ResourceMapping(type);
+ resourceMappings.put(type, rm);
+ }
+ return rm;
+ }
- public ResourceMapping getResourceMappingFor(Class> type) {
- return resourceMappings.get(type);
- }
+ public ResourceMapping getResourceMappingFor(Class> type) {
+ return resourceMappings.get(type);
+ }
- public boolean hasResourceMappingFor(Class> type) {
- return resourceMappings.containsKey(type);
- }
+ public boolean hasResourceMappingFor(Class> type) {
+ return resourceMappings.containsKey(type);
+ }
- public Class> findTypeForPath(String path) {
- if(null == path) {
- return null;
- }
- for(Map.Entry, ResourceMapping> entry : resourceMappings.entrySet()) {
- if(path.equals(entry.getValue().getPath())) {
- return entry.getKey();
- }
- }
- return null;
- }
+ public Class> findTypeForPath(String path) {
+ if (null == path) {
+ return null;
+ }
+ for (Map.Entry, ResourceMapping> entry : resourceMappings.entrySet()) {
+ if (path.equals(entry.getValue().getPath())) {
+ return entry.getKey();
+ }
+ }
+ return null;
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/RepositoryConstraintViolationException.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/RepositoryConstraintViolationException.java
index 86c13e6bb..864920e2f 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/RepositoryConstraintViolationException.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/RepositoryConstraintViolationException.java
@@ -5,22 +5,22 @@ import org.springframework.validation.Errors;
/**
* Exception that is thrown when a Spring {@link org.springframework.validation.Validator} throws an error.
- *
+ *
* @author Jon Brisbin
*/
public class RepositoryConstraintViolationException extends DataIntegrityViolationException {
private static final long serialVersionUID = -4789377071564956366L;
-
+
private final Errors errors;
- public RepositoryConstraintViolationException(Errors errors) {
- super("Validation failed");
- this.errors = errors;
- }
+ public RepositoryConstraintViolationException(Errors errors) {
+ super("Validation failed");
+ this.errors = errors;
+ }
- public Errors getErrors() {
- return errors;
- }
+ public Errors getErrors() {
+ return errors;
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/UriDomainClassConverter.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/UriDomainClassConverter.java
index 41f9f37ba..d2a842110 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/UriDomainClassConverter.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/UriDomainClassConverter.java
@@ -15,58 +15,51 @@ import org.springframework.data.rest.repository.support.RepositoryInformationSup
/**
* A {@link ConditionalGenericConverter} that can convert a {@link URI} domain entity.
- *
+ *
* @author Jon Brisbin
*/
-public class UriDomainClassConverter
- extends RepositoryInformationSupport
- implements ConditionalGenericConverter,
- InitializingBean {
+public class UriDomainClassConverter extends RepositoryInformationSupport implements ConditionalGenericConverter,
+ InitializingBean {
- private static TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
+ private static TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
- @Autowired
- private DomainClassConverter> domainClassConverter;
- private Set convertiblePairs = new HashSet();
+ @Autowired private DomainClassConverter> domainClassConverter;
+ private Set convertiblePairs = new HashSet();
- @Override public void afterPropertiesSet() throws Exception {
- for(Class> domainType : repositories) {
- convertiblePairs.add(new ConvertiblePair(URI.class, domainType));
- }
- }
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ for (Class> domainType : repositories) {
+ convertiblePairs.add(new ConvertiblePair(URI.class, domainType));
+ }
+ }
- @Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- return URI.class.isAssignableFrom(sourceType.getType())
- && (null != repositories.getPersistentEntity(targetType.getType()));
- }
+ @Override
+ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
+ return URI.class.isAssignableFrom(sourceType.getType())
+ && (null != repositories.getPersistentEntity(targetType.getType()));
+ }
- @Override public Set getConvertibleTypes() {
- return convertiblePairs;
- }
+ @Override
+ public Set getConvertibleTypes() {
+ return convertiblePairs;
+ }
- @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
- PersistentEntity, ?> entity = repositories.getPersistentEntity(targetType.getType());
- if(null == entity || !domainClassConverter.matches(STRING_TYPE, targetType)) {
- throw new ConversionFailedException(
- sourceType,
- targetType,
- source,
- new IllegalArgumentException("No PersistentEntity information available for " + targetType.getType())
- );
- }
+ @Override
+ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
+ PersistentEntity, ?> entity = repositories.getPersistentEntity(targetType.getType());
+ if (null == entity || !domainClassConverter.matches(STRING_TYPE, targetType)) {
+ throw new ConversionFailedException(sourceType, targetType, source, new IllegalArgumentException(
+ "No PersistentEntity information available for " + targetType.getType()));
+ }
- URI uri = (URI)source;
- String[] parts = uri.getPath().split("/");
- if(parts.length < 2) {
- throw new ConversionFailedException(
- sourceType,
- targetType,
- source,
- new IllegalArgumentException("Cannot resolve URI " + uri + ". Is it local or remote? Only local URIs are resolvable.")
- );
- }
+ URI uri = (URI) source;
+ String[] parts = uri.getPath().split("/");
+ if (parts.length < 2) {
+ throw new ConversionFailedException(sourceType, targetType, source, new IllegalArgumentException(
+ "Cannot resolve URI " + uri + ". Is it local or remote? Only local URIs are resolvable."));
+ }
- return domainClassConverter.convert(parts[parts.length - 1], STRING_TYPE, targetType);
- }
+ return domainClassConverter.convert(parts[parts.length - 1], STRING_TYPE, targetType);
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/ValidationErrors.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/ValidationErrors.java
index 35eb99f3c..46b311a8e 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/ValidationErrors.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/ValidationErrors.java
@@ -16,71 +16,73 @@ import org.springframework.validation.ObjectError;
/**
* An {@link Errors} implementation for use in the events mechanism of Spring Data REST.
- *
+ *
* @author Jon Brisbin
*/
public class ValidationErrors extends AbstractErrors {
private static final long serialVersionUID = 8141826537389141361L;
-
- private String name;
- private Object entity;
- private PersistentEntity, ?> persistentEntity;
- private List globalErrors = new ArrayList();
- private List fieldErrors = new ArrayList();
- public ValidationErrors(String name, Object entity, PersistentEntity, ?> persistentEntity) {
- this.name = name;
- this.entity = entity;
- this.persistentEntity = persistentEntity;
- }
+ private String name;
+ private Object entity;
+ private PersistentEntity, ?> persistentEntity;
+ private List globalErrors = new ArrayList();
+ private List fieldErrors = new ArrayList();
- @Override public String getObjectName() {
- return name;
- }
+ public ValidationErrors(String name, Object entity, PersistentEntity, ?> persistentEntity) {
+ this.name = name;
+ this.entity = entity;
+ this.persistentEntity = persistentEntity;
+ }
- @Override public void reject(String errorCode, Object[] errorArgs, String defaultMessage) {
- globalErrors.add(new ObjectError(name, new String[]{errorCode}, errorArgs, defaultMessage));
- }
+ @Override
+ public String getObjectName() {
+ return name;
+ }
- @Override public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) {
- fieldErrors.add(new FieldError(name,
- field,
- getFieldValue(field),
- true,
- new String[]{errorCode},
- errorArgs,
- defaultMessage));
- }
+ @Override
+ public void reject(String errorCode, Object[] errorArgs, String defaultMessage) {
+ globalErrors.add(new ObjectError(name, new String[] { errorCode }, errorArgs, defaultMessage));
+ }
- @Override public void addAllErrors(Errors errors) {
- globalErrors.addAll(errors.getAllErrors());
- }
+ @Override
+ public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) {
+ fieldErrors.add(new FieldError(name, field, getFieldValue(field), true, new String[] { errorCode }, errorArgs,
+ defaultMessage));
+ }
- @Override public List getGlobalErrors() {
- return globalErrors;
- }
+ @Override
+ public void addAllErrors(Errors errors) {
+ globalErrors.addAll(errors.getAllErrors());
+ }
- @Override public List getFieldErrors() {
- return fieldErrors;
- }
+ @Override
+ public List getGlobalErrors() {
+ return globalErrors;
+ }
- @Override public Object getFieldValue(String field) {
- PersistentProperty> prop = persistentEntity != null ? persistentEntity.getPersistentProperty(field) : null;
- if(null == prop) {
- return null;
- }
+ @Override
+ public List getFieldErrors() {
+ return fieldErrors;
+ }
- Method getter = prop.getGetter();
- if(null != getter) {
- return invokeMethod(getter, entity);
- }
- Field fld = prop.getField();
- if(null != fld) {
- return getField(fld, entity);
- }
+ @Override
+ public Object getFieldValue(String field) {
+ PersistentProperty> prop = persistentEntity != null ? persistentEntity.getPersistentProperty(field) : null;
+ if (null == prop) {
+ return null;
+ }
- return null;
- }
+ Method getter = prop.getGetter();
+ if (null != getter) {
+ return invokeMethod(getter, entity);
+ }
+ Field fld = prop.getField();
+ if (null != fld) {
+ return getField(fld, entity);
+ }
+
+ return null;
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/ConvertWith.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/ConvertWith.java
index a71a1dfb5..479e3a95c 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/ConvertWith.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/ConvertWith.java
@@ -11,11 +11,11 @@ import org.springframework.core.convert.converter.Converter;
/**
* @author Jon Brisbin
*/
-@Target({ElementType.PARAMETER})
+@Target({ ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ConvertWith {
- Class extends Converter, ?>> value();
+ Class extends Converter, ?>> value();
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/Description.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/Description.java
index d78c6f4f0..0409c1270 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/Description.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/Description.java
@@ -8,12 +8,8 @@ import java.lang.annotation.Target;
/**
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.FIELD,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Description {
- String value();
+ String value();
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterCreate.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterCreate.java
index ec9ec9683..e36d8f5a1 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterCreate.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterCreate.java
@@ -9,10 +9,7 @@ import java.lang.annotation.Target;
/**
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleAfterCreate {
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterDelete.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterDelete.java
index b484f5579..c54d758d9 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterDelete.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterDelete.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal afterDelete} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleAfterDelete {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkDelete.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkDelete.java
index e8f22c458..70de41b3a 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkDelete.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkDelete.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal afterLinkDelete} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleAfterLinkDelete {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkSave.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkSave.java
index dcc73e21c..662ba64a8 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkSave.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterLinkSave.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal afterLinkSave} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleAfterLinkSave {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterSave.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterSave.java
index 467de4827..cdf67c483 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterSave.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleAfterSave.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal afterSave} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleAfterSave {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeCreate.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeCreate.java
index 06cd5850d..7c7c7fa1b 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeCreate.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeCreate.java
@@ -9,10 +9,7 @@ import java.lang.annotation.Target;
/**
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleBeforeCreate {
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeDelete.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeDelete.java
index be175c323..7ea568d94 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeDelete.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeDelete.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal beforeDelete} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleBeforeDelete {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkDelete.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkDelete.java
index eeb8edf2c..c9a5da9c4 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkDelete.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkDelete.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal beforeLinkDelete} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleBeforeLinkDelete {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkSave.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkSave.java
index 705151d63..00929e3ec 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkSave.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeLinkSave.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal beforeLinkSave} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleBeforeLinkSave {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeSave.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeSave.java
index 20a419b27..c53b334e4 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeSave.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/HandleBeforeSave.java
@@ -8,17 +8,14 @@ import java.lang.annotation.Target;
/**
* Denotes a component that should handle the {@literal beforeSave} event.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.TYPE,
- ElementType.METHOD
- })
+@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HandleBeforeSave {
- Class>[] value() default {};
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RepositoryEventHandler.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RepositoryEventHandler.java
index 7b95301ca..4c66e8eaf 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RepositoryEventHandler.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RepositoryEventHandler.java
@@ -8,17 +8,17 @@ import java.lang.annotation.Target;
/**
* Advertises classes annotated with this that they are event handlers.
- *
+ *
* @author Jon Brisbin
*/
-@Target({ElementType.TYPE})
+@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface RepositoryEventHandler {
- /**
- * The list of {@link org.springframework.context.ApplicationEvent} classes this event handler cares about.
- */
- Class>[] value() default {};
+ /**
+ * The list of {@link org.springframework.context.ApplicationEvent} classes this event handler cares about.
+ */
+ Class>[] value() default {};
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RestResource.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RestResource.java
index 303d5cad4..a6585711e 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RestResource.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/annotation/RestResource.java
@@ -9,37 +9,33 @@ import java.lang.annotation.Target;
/**
* Annotate a {@link org.springframework.data.repository.Repository} with this to influence how it is exported and what
* the value of the {@literal rel} attribute will be in links.
- *
+ *
* @author Jon Brisbin
*/
-@Target({
- ElementType.FIELD,
- ElementType.METHOD,
- ElementType.TYPE
- })
+@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface RestResource {
- /**
- * Flag indicating whether this resource is exported at all.
- *
- * @return {@literal true} if the resource is to be exported, {@literal false} otherwise.
- */
- boolean exported() default true;
+ /**
+ * Flag indicating whether this resource is exported at all.
+ *
+ * @return {@literal true} if the resource is to be exported, {@literal false} otherwise.
+ */
+ boolean exported() default true;
- /**
- * The path segment under which this resource is to be exported.
- *
- * @return A valid path segment.
- */
- String path() default "";
+ /**
+ * The path segment under which this resource is to be exported.
+ *
+ * @return A valid path segment.
+ */
+ String path() default "";
- /**
- * The rel value to use when generating links to this resource.
- *
- * @return A valid rel value.
- */
- String rel() default "";
+ /**
+ * The rel value to use when generating links to this resource.
+ *
+ * @return A valid rel value.
+ */
+ String rel() default "";
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AbstractRepositoryEventListener.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AbstractRepositoryEventListener.java
index 31c333eeb..fb646f130 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AbstractRepositoryEventListener.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AbstractRepositoryEventListener.java
@@ -8,147 +8,125 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
/**
- * Abstract class that listens for generic {@link RepositoryEvent}s and dispatches them to a specific
- * method based on the event type.
- *
+ * Abstract class that listens for generic {@link RepositoryEvent}s and dispatches them to a specific method based on
+ * the event type.
+ *
* @author Jon Brisbin
*/
public abstract class AbstractRepositoryEventListener implements ApplicationListener,
- ApplicationContextAware {
+ ApplicationContextAware {
private final Class> INTERESTED_TYPE = resolveTypeArgument(getClass(), AbstractRepositoryEventListener.class);
protected ApplicationContext applicationContext;
- @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
- @SuppressWarnings({"unchecked"})
- @Override public final void onApplicationEvent(RepositoryEvent event) {
+ @SuppressWarnings({ "unchecked" })
+ @Override
+ public final void onApplicationEvent(RepositoryEvent event) {
Class> srcType = event.getSource().getClass();
- if(null != INTERESTED_TYPE && !INTERESTED_TYPE.isAssignableFrom(srcType)) {
+ if (null != INTERESTED_TYPE && !INTERESTED_TYPE.isAssignableFrom(srcType)) {
return;
}
- if(event instanceof BeforeSaveEvent) {
- onBeforeSave((T)event.getSource());
- } else if(event instanceof BeforeCreateEvent) {
- onBeforeCreate((T)event.getSource());
- } else if(event instanceof AfterCreateEvent) {
- onAfterCreate((T)event.getSource());
- } else if(event instanceof AfterSaveEvent) {
- onAfterSave((T)event.getSource());
- } else if(event instanceof BeforeLinkSaveEvent) {
- onBeforeLinkSave((T)event.getSource(), ((BeforeLinkSaveEvent)event).getLinked());
- } else if(event instanceof AfterLinkSaveEvent) {
- onAfterLinkSave((T)event.getSource(), ((AfterLinkSaveEvent)event).getLinked());
- } else if(event instanceof BeforeLinkDeleteEvent) {
- onBeforeLinkDelete((T)event.getSource(), ((BeforeLinkDeleteEvent)event).getLinked());
- } else if(event instanceof AfterLinkDeleteEvent) {
- onAfterLinkDelete((T)event.getSource(), ((AfterLinkDeleteEvent)event).getLinked());
- } else if(event instanceof BeforeDeleteEvent) {
- onBeforeDelete((T)event.getSource());
- } else if(event instanceof AfterDeleteEvent) {
- onAfterDelete((T)event.getSource());
+ if (event instanceof BeforeSaveEvent) {
+ onBeforeSave((T) event.getSource());
+ } else if (event instanceof BeforeCreateEvent) {
+ onBeforeCreate((T) event.getSource());
+ } else if (event instanceof AfterCreateEvent) {
+ onAfterCreate((T) event.getSource());
+ } else if (event instanceof AfterSaveEvent) {
+ onAfterSave((T) event.getSource());
+ } else if (event instanceof BeforeLinkSaveEvent) {
+ onBeforeLinkSave((T) event.getSource(), ((BeforeLinkSaveEvent) event).getLinked());
+ } else if (event instanceof AfterLinkSaveEvent) {
+ onAfterLinkSave((T) event.getSource(), ((AfterLinkSaveEvent) event).getLinked());
+ } else if (event instanceof BeforeLinkDeleteEvent) {
+ onBeforeLinkDelete((T) event.getSource(), ((BeforeLinkDeleteEvent) event).getLinked());
+ } else if (event instanceof AfterLinkDeleteEvent) {
+ onAfterLinkDelete((T) event.getSource(), ((AfterLinkDeleteEvent) event).getLinked());
+ } else if (event instanceof BeforeDeleteEvent) {
+ onBeforeDelete((T) event.getSource());
+ } else if (event instanceof AfterDeleteEvent) {
+ onAfterDelete((T) event.getSource());
}
}
/**
* Override this method if you are interested in {@literal beforeCreate} events.
- *
- * @param entity
- * The entity being created.
+ *
+ * @param entity The entity being created.
*/
- protected void onBeforeCreate(T entity) {
- }
+ protected void onBeforeCreate(T entity) {}
/**
* Override this method if you are interested in {@literal afterCreate} events.
- *
- * @param entity
- * The entity that was created.
+ *
+ * @param entity The entity that was created.
*/
- protected void onAfterCreate(T entity) {
- }
+ protected void onAfterCreate(T entity) {}
/**
* Override this method if you are interested in {@literal beforeSave} events.
- *
- * @param entity
- * The entity being saved.
+ *
+ * @param entity The entity being saved.
*/
- protected void onBeforeSave(T entity) {
- }
+ protected void onBeforeSave(T entity) {}
/**
* Override this method if you are interested in {@literal afterSave} events.
- *
- * @param entity
- * The entity that was just saved.
+ *
+ * @param entity The entity that was just saved.
*/
- protected void onAfterSave(T entity) {
- }
+ protected void onAfterSave(T entity) {}
/**
* Override this method if you are interested in {@literal beforeLinkSave} events.
- *
- * @param parent
- * The parent entity to which the child object is linked.
- * @param linked
- * The linked, child entity.
+ *
+ * @param parent The parent entity to which the child object is linked.
+ * @param linked The linked, child entity.
*/
- protected void onBeforeLinkSave(T parent, Object linked) {
- }
+ protected void onBeforeLinkSave(T parent, Object linked) {}
/**
* Override this method if you are interested in {@literal afterLinkSave} events.
- *
- * @param parent
- * The parent entity to which the child object is linked.
- * @param linked
- * The linked, child entity.
+ *
+ * @param parent The parent entity to which the child object is linked.
+ * @param linked The linked, child entity.
*/
- protected void onAfterLinkSave(T parent, Object linked) {
- }
+ protected void onAfterLinkSave(T parent, Object linked) {}
/**
* Override this method if you are interested in {@literal beforeLinkDelete} events.
- *
- * @param parent
- * The parent entity to which the child object is linked.
- * @param linked
- * The linked, child entity.
+ *
+ * @param parent The parent entity to which the child object is linked.
+ * @param linked The linked, child entity.
*/
- protected void onBeforeLinkDelete(T parent, Object linked) {
- }
+ protected void onBeforeLinkDelete(T parent, Object linked) {}
/**
* Override this method if you are interested in {@literal afterLinkDelete} events.
- *
- * @param parent
- * The parent entity to which the child object is linked.
- * @param linked
- * The linked, child entity.
+ *
+ * @param parent The parent entity to which the child object is linked.
+ * @param linked The linked, child entity.
*/
- protected void onAfterLinkDelete(T parent, Object linked) {
- }
+ protected void onAfterLinkDelete(T parent, Object linked) {}
/**
* Override this method if you are interested in {@literal beforeDelete} events.
- *
- * @param entity
- * The entity that is being deleted.
+ *
+ * @param entity The entity that is being deleted.
*/
- protected void onBeforeDelete(T entity) {
- }
+ protected void onBeforeDelete(T entity) {}
/**
* Override this method if you are interested in {@literal afterDelete} events.
- *
- * @param entity
- * The entity that was just deleted.
+ *
+ * @param entity The entity that was just deleted.
*/
- protected void onAfterDelete(T entity) {
- }
+ protected void onAfterDelete(T entity) {}
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterCreateEvent.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterCreateEvent.java
index de3f61ce8..3490aa020 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterCreateEvent.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterCreateEvent.java
@@ -2,11 +2,11 @@ package org.springframework.data.rest.repository.context;
/**
* Event that is emitted after a new entity is saved.
- *
+ *
* @author Jon Brisbin
*/
public class AfterCreateEvent extends RepositoryEvent {
-
+
private static final long serialVersionUID = -7673953693485678403L;
public AfterCreateEvent(Object source) {
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterDeleteEvent.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterDeleteEvent.java
index 255e5ec36..5f6b44f4c 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterDeleteEvent.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterDeleteEvent.java
@@ -2,14 +2,14 @@ package org.springframework.data.rest.repository.context;
/**
* Emitted after the entity is deleted from the repository.
- *
+ *
* @author Jon Brisbin
*/
public class AfterDeleteEvent extends RepositoryEvent {
-
+
private static final long serialVersionUID = -6090615345948638970L;
public AfterDeleteEvent(Object source) {
- super(source);
- }
+ super(source);
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkDeleteEvent.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkDeleteEvent.java
index 7c9a9c303..fdb264854 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkDeleteEvent.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkDeleteEvent.java
@@ -2,7 +2,7 @@ package org.springframework.data.rest.repository.context;
/**
* Emitted after a link to a related object is deleted from the parent.
- *
+ *
* @author Jon Brisbin
*/
public class AfterLinkDeleteEvent extends LinkSaveEvent {
@@ -10,6 +10,6 @@ public class AfterLinkDeleteEvent extends LinkSaveEvent {
private static final long serialVersionUID = 3887575011761146290L;
public AfterLinkDeleteEvent(Object source, Object linked) {
- super(source, linked);
- }
+ super(source, linked);
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkSaveEvent.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkSaveEvent.java
index 5ce117558..58cbc3c48 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkSaveEvent.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterLinkSaveEvent.java
@@ -2,14 +2,14 @@ package org.springframework.data.rest.repository.context;
/**
* Emitted after saving a linked object to its parent in the repository.
- *
+ *
* @author Jon Brisbin
*/
public class AfterLinkSaveEvent extends LinkSaveEvent {
-
+
private static final long serialVersionUID = 261522353893713633L;
public AfterLinkSaveEvent(Object source, Object child) {
- super(source, child);
- }
+ super(source, child);
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterSaveEvent.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterSaveEvent.java
index 21db5b160..57d606006 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterSaveEvent.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AfterSaveEvent.java
@@ -2,14 +2,14 @@ package org.springframework.data.rest.repository.context;
/**
* Emitted after a save to the repository.
- *
+ *
* @author Jon Brisbin
*/
public class AfterSaveEvent extends RepositoryEvent {
-
+
private static final long serialVersionUID = 8568843338617401903L;
public AfterSaveEvent(Object source) {
- super(source);
- }
+ super(source);
+ }
}
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java
index 14027896e..c7e163f07 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/context/AnnotatedHandlerBeanPostProcessor.java
@@ -31,126 +31,119 @@ import org.springframework.util.ReflectionUtils;
/**
* @author Jon Brisbin
*/
-public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener,
- BeanPostProcessor {
+public class AnnotatedHandlerBeanPostProcessor implements ApplicationListener, BeanPostProcessor {
- private static final Logger LOG = LoggerFactory.getLogger(
- AnnotatedHandlerBeanPostProcessor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AnnotatedHandlerBeanPostProcessor.class);
private final MultiValueMap, EventHandlerMethod> handlerMethods = new LinkedMultiValueMap, AnnotatedHandlerBeanPostProcessor.EventHandlerMethod>();
- @Override public void onApplicationEvent(RepositoryEvent event) {
+ @Override
+ public void onApplicationEvent(RepositoryEvent event) {
Class extends RepositoryEvent> eventType = event.getClass();
- if(!handlerMethods.containsKey(eventType)) {
+ if (!handlerMethods.containsKey(eventType)) {
return;
}
- for(EventHandlerMethod handlerMethod : handlerMethods.get(eventType)) {
+ for (EventHandlerMethod handlerMethod : handlerMethods.get(eventType)) {
try {
Object src = event.getSource();
- if(!ClassUtils.isAssignable(handlerMethod.targetType, src.getClass())) {
+ if (!ClassUtils.isAssignable(handlerMethod.targetType, src.getClass())) {
continue;
}
List