#707 - Refactor Affordances to better support Spring Data REST.

* Move Spring MVC method scanning out of the core Affordances API and into SpringMvcAffordanceBuilder to make it easy to use in Spring Data REST (where method scanning isn't needed).
* Also push attributes from Affordance into AffordanceModel to centralize the details.
* Certain serializers must be registered differently due to Jackson's rules of precedence given Spring Data REST needs to override them.
This commit is contained in:
Greg Turnquist
2018-04-18 14:22:54 -05:00
parent 2e7eabdc1a
commit 820f66179f
29 changed files with 549 additions and 543 deletions

View File

@@ -30,6 +30,8 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.core.ResolvableType;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -189,6 +191,48 @@ public class Link implements Serializable {
return withAffordances(newAffordances);
}
/**
* Convenience method when chaining an existing {@link Link}.
*
* @param name
* @param httpMethod
* @param inputType
* @param queryMethodParameters
* @param outputType
* @return
*/
public Link andAffordance(String name, HttpMethod httpMethod, ResolvableType inputType, List<QueryParameter> queryMethodParameters, ResolvableType outputType) {
return andAffordance(new Affordance(name, this, httpMethod, inputType, queryMethodParameters, outputType));
}
/**
* Convenience method when chaining an existing {@link Link}. Defaults the name of the affordance to verb + classname, e.g.
* {@literal <httpMethod=HttpMethod.PUT, inputType=Employee>} produces {@literal <name=putEmployee>}.
*
* @param httpMethod
* @param inputType
* @param queryMethodParameters
* @param outputType
* @return
*/
public Link andAffordance(HttpMethod httpMethod, ResolvableType inputType, List<QueryParameter> queryMethodParameters, ResolvableType outputType) {
return andAffordance(httpMethod.toString().toLowerCase() + inputType.resolve().getSimpleName(), httpMethod, inputType, queryMethodParameters, outputType);
}
/**
* Convenience method when chaining an existing {@link Link}. Defaults the name of the affordance to verb + classname, e.g.
* {@literal <httpMethod=HttpMethod.PUT, inputType=Employee>} produces {@literal <name=putEmployee>}.
*
* @param httpMethod
* @param inputType
* @param queryMethodParameters
* @param outputType
* @return
*/
public Link andAffordance(HttpMethod httpMethod, Class<?> inputType, List<QueryParameter> queryMethodParameters, Class<?> outputType) {
return andAffordance(httpMethod, ResolvableType.forClass(inputType), queryMethodParameters, ResolvableType.forClass(outputType));
}
/**
* Create new {@link Link} with additional {@link Affordance}s.
*