#788 - Switch to IanaLinkRelations internally.
This commit is contained in:
@@ -71,7 +71,7 @@ public interface EntityLinks extends Plugin<Class<?>> {
|
||||
|
||||
/**
|
||||
* Creates a {@link Link} pointing to the collection resource of the given type. The relation type of the link will be
|
||||
* determined by the implementation class and should be defaulted to {@link Link#REL_SELF}.
|
||||
* determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}.
|
||||
*
|
||||
* @param type the entity type to point to, must not be {@literal null}.
|
||||
* @return the {@link Link} pointing to the collection resource exposed for the given entity. Will never be
|
||||
@@ -82,7 +82,7 @@ public interface EntityLinks extends Plugin<Class<?>> {
|
||||
|
||||
/**
|
||||
* Creates a {@link Link} pointing to single resource backing the given entity type and id. The relation type of the
|
||||
* link will be determined by the implementation class and should be defaulted to {@link Link#REL_SELF}.
|
||||
* link will be determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}.
|
||||
*
|
||||
* @param type the entity type to point to, must not be {@literal null}.
|
||||
* @param id the identifier of the entity of the given type
|
||||
@@ -94,7 +94,7 @@ public interface EntityLinks extends Plugin<Class<?>> {
|
||||
|
||||
/**
|
||||
* Creates a {@link Link} pointing to single resource backing the given entity. The relation type of the link will be
|
||||
* determined by the implementation class and should be defaulted to {@link Link#REL_SELF}.
|
||||
* determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}.
|
||||
*
|
||||
* @param entity the entity type to point to, must not be {@literal null}.
|
||||
* @return the {@link Link} pointing to the resource exposed for the given entity. Will never be {@literal null}.
|
||||
|
||||
@@ -106,11 +106,11 @@ public class Link implements Serializable {
|
||||
/**
|
||||
* Creates a new link to the given URI with the self rel.
|
||||
*
|
||||
* @see #REL_SELF
|
||||
* @see IanaLinkRelation#SELF
|
||||
* @param href must not be {@literal null} or empty.
|
||||
*/
|
||||
public Link(String href) {
|
||||
this(href, REL_SELF);
|
||||
this(href, IanaLinkRelation.SELF.value());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +171,7 @@ public class Link implements Serializable {
|
||||
* @return
|
||||
*/
|
||||
public Link withSelfRel() {
|
||||
return withRel(Link.REL_SELF);
|
||||
return withRel(IanaLinkRelation.SELF.value());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ public interface LinkBuilder {
|
||||
/**
|
||||
* Creates the {@link Link} built by the current builder instance with the default self rel.
|
||||
*
|
||||
* @see Link#REL_SELF
|
||||
* @see IanaLinkRelation#SELF
|
||||
* @return
|
||||
*/
|
||||
Link withSelfRel();
|
||||
|
||||
@@ -104,7 +104,7 @@ public class PagedResources<T> extends Resources<T> {
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Optional<Link> getNextLink() {
|
||||
return getLink(Link.REL_NEXT);
|
||||
return getLink(IanaLinkRelation.NEXT.value());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ public class PagedResources<T> extends Resources<T> {
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Optional<Link> getPreviousLink() {
|
||||
return getLink(Link.REL_PREVIOUS);
|
||||
return getLink(IanaLinkRelation.PREV.value());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -42,11 +42,11 @@ public class ResourceSupport implements Identifiable<Link> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link Link} with a rel of {@link Link#REL_SELF}.
|
||||
* Returns the {@link Link} with a rel of {@link IanaLinkRelation#SELF}.
|
||||
*/
|
||||
@JsonIgnore
|
||||
public Optional<Link> getId() {
|
||||
return getLink(Link.REL_SELF);
|
||||
return getLink(IanaLinkRelation.SELF.value());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.hateoas.IanaLinkRelation;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
@@ -45,7 +46,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
@Override
|
||||
public Link findLinkWithRel(String rel, String representation) {
|
||||
|
||||
if (rel.equals(Link.REL_SELF)) {
|
||||
if (rel.equals(IanaLinkRelation.SELF.value())) {
|
||||
return findSelfLink(representation);
|
||||
} else {
|
||||
return super.findLinkWithRel(rel, representation);
|
||||
@@ -55,7 +56,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
@Override
|
||||
public Link findLinkWithRel(String rel, InputStream representation) {
|
||||
|
||||
if (rel.equals(Link.REL_SELF)) {
|
||||
if (rel.equals(IanaLinkRelation.SELF.value())) {
|
||||
return findSelfLink(representation);
|
||||
} else {
|
||||
return super.findLinkWithRel(rel, representation);
|
||||
@@ -65,7 +66,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
@Override
|
||||
public List<Link> findLinksWithRel(String rel, String representation) {
|
||||
|
||||
if (rel.equals(Link.REL_SELF)) {
|
||||
if (rel.equals(IanaLinkRelation.SELF.value())) {
|
||||
return addSelfLink(super.findLinksWithRel(rel, representation), representation);
|
||||
} else {
|
||||
return super.findLinksWithRel(rel, representation);
|
||||
@@ -75,7 +76,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
@Override
|
||||
public List<Link> findLinksWithRel(String rel, InputStream representation) {
|
||||
|
||||
if (rel.equals(Link.REL_SELF)) {
|
||||
if (rel.equals(IanaLinkRelation.SELF.value())) {
|
||||
return addSelfLink(super.findLinksWithRel(rel, representation), representation);
|
||||
} else {
|
||||
return super.findLinksWithRel(rel, representation);
|
||||
@@ -87,11 +88,11 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer {
|
||||
//
|
||||
|
||||
private Link findSelfLink(String representation) {
|
||||
return this.selfLinkDiscoverer.findLinkWithRel(Link.REL_SELF, representation);
|
||||
return this.selfLinkDiscoverer.findLinkWithRel(IanaLinkRelation.SELF.value(), representation);
|
||||
}
|
||||
|
||||
private Link findSelfLink(InputStream representation) {
|
||||
return this.selfLinkDiscoverer.findLinkWithRel(Link.REL_SELF, representation);
|
||||
return this.selfLinkDiscoverer.findLinkWithRel(IanaLinkRelation.SELF.value(), representation);
|
||||
}
|
||||
|
||||
private List<Link> addSelfLink(List<Link> links, String representation) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.stream.Stream;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.support.MessageSourceAccessor;
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.IanaLinkRelation;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
@@ -111,7 +112,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
|
||||
CollectionJson<?> collectionJson = new CollectionJson()
|
||||
.withVersion("1.0")
|
||||
.withHref(resource.getRequiredLink(Link.REL_SELF).expand().getHref())
|
||||
.withHref(resource.getRequiredLink(IanaLinkRelation.SELF.value()).expand().getHref())
|
||||
.withLinks(withoutSelfLink(value))
|
||||
.withItems(Collections.EMPTY_LIST);
|
||||
|
||||
@@ -168,7 +169,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
@Override
|
||||
public void serialize(ResourceSupport value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
|
||||
String href = value.getRequiredLink(Link.REL_SELF).getHref();
|
||||
String href = value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref();
|
||||
|
||||
CollectionJson<?> collectionJson = new CollectionJson()
|
||||
.withVersion("1.0")
|
||||
@@ -236,7 +237,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
@Override
|
||||
public void serialize(Resource<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
|
||||
String href = value.getRequiredLink(Link.REL_SELF).getHref();
|
||||
String href = value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref();
|
||||
|
||||
CollectionJson<?> collectionJson = new CollectionJson()
|
||||
.withVersion("1.0")
|
||||
@@ -301,7 +302,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
|
||||
CollectionJson<?> collectionJson = new CollectionJson()
|
||||
.withVersion("1.0")
|
||||
.withHref(value.getRequiredLink(Link.REL_SELF).getHref())
|
||||
.withHref(value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref())
|
||||
.withLinks(withoutSelfLink(value.getLinks()))
|
||||
.withItems(resourcesToCollectionJsonItems(value))
|
||||
.withQueries(findQueries(value))
|
||||
@@ -364,7 +365,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
|
||||
CollectionJson<?> collectionJson = new CollectionJson()
|
||||
.withVersion("1.0")
|
||||
.withHref(value.getRequiredLink(Link.REL_SELF).getHref())
|
||||
.withHref(value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref())
|
||||
.withLinks(withoutSelfLink(value.getLinks()))
|
||||
.withItems(resourcesToCollectionJsonItems(value))
|
||||
.withQueries(findQueries(value))
|
||||
@@ -797,7 +798,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
return Collections.singletonList(new Link(href));
|
||||
}
|
||||
|
||||
if (href == null || links.stream().map(Link::getRel).anyMatch(s -> s.equals(Link.REL_SELF))) {
|
||||
if (href == null || links.stream().map(Link::getRel).anyMatch(s -> s.equals(IanaLinkRelation.SELF.value()))) {
|
||||
return links;
|
||||
}
|
||||
|
||||
@@ -813,7 +814,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
private static List<Link> withoutSelfLink(List<Link> links) {
|
||||
|
||||
return links.stream()
|
||||
.filter(link -> !link.getRel().equals(Link.REL_SELF))
|
||||
.filter(link -> !link.getRel().equals(IanaLinkRelation.SELF.value()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -826,7 +827,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
Resource resource = (Resource) content;
|
||||
|
||||
return new CollectionJsonItem<>()
|
||||
.withHref(resource.getRequiredLink(Link.REL_SELF).getHref())
|
||||
.withHref(resource.getRequiredLink(IanaLinkRelation.SELF.value()).getHref())
|
||||
.withLinks(withoutSelfLink(resource.getLinks()))
|
||||
.withRawData(resource.getContent());
|
||||
} else {
|
||||
@@ -846,8 +847,8 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
|
||||
List<CollectionJsonQuery> queries = new ArrayList<>();
|
||||
|
||||
if (resource.hasLink(Link.REL_SELF)) {
|
||||
Link selfLink = resource.getRequiredLink(Link.REL_SELF);
|
||||
if (resource.hasLink(IanaLinkRelation.SELF.value())) {
|
||||
Link selfLink = resource.getRequiredLink(IanaLinkRelation.SELF.value());
|
||||
|
||||
selfLink.getAffordances().forEach(affordance -> {
|
||||
|
||||
@@ -879,8 +880,8 @@ public class Jackson2CollectionJsonModule extends SimpleModule {
|
||||
|
||||
List<CollectionJsonTemplate> templates = new ArrayList<>();
|
||||
|
||||
if (resource.hasLink(Link.REL_SELF)) {
|
||||
resource.getRequiredLink(Link.REL_SELF).getAffordances().forEach(affordance -> {
|
||||
if (resource.hasLink(IanaLinkRelation.SELF.value())) {
|
||||
resource.getRequiredLink(IanaLinkRelation.SELF.value()).getAffordances().forEach(affordance -> {
|
||||
|
||||
CollectionJsonAffordanceModel model = affordance.getAffordanceModel(MediaTypes.COLLECTION_JSON);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.IanaLinkRelation;
|
||||
import org.springframework.hateoas.Identifiable;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkBuilder;
|
||||
@@ -163,7 +164,7 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
|
||||
* @see org.springframework.hateoas.LinkBuilder#withSelfRel()
|
||||
*/
|
||||
public Link withSelfRel() {
|
||||
return withRel(Link.REL_SELF);
|
||||
return withRel(IanaLinkRelation.SELF.value());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.hateoas.Affordance;
|
||||
import org.springframework.hateoas.IanaLinkRelation;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.PagedResources;
|
||||
@@ -192,10 +193,10 @@ class HalFormsSerializers {
|
||||
|
||||
Map<String, HalFormsTemplate> templates = new HashMap<>();
|
||||
|
||||
if (resource.hasLink(Link.REL_SELF)) {
|
||||
if (resource.hasLink(IanaLinkRelation.SELF.value())) {
|
||||
|
||||
|
||||
for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances)
|
||||
for (Affordance affordance : resource.getLink(IanaLinkRelation.SELF.value()).map(Link::getAffordances)
|
||||
.orElse(Collections.emptyList())) {
|
||||
|
||||
HalFormsAffordanceModel model = affordance.getAffordanceModel(MediaTypes.HAL_FORMS_JSON);
|
||||
@@ -228,7 +229,7 @@ class HalFormsSerializers {
|
||||
private static void validate(ResourceSupport resource, Affordance affordance, HalFormsAffordanceModel model) {
|
||||
|
||||
String affordanceUri = model.getURI();
|
||||
String selfLinkUri = resource.getRequiredLink(Link.REL_SELF).expand().getHref();
|
||||
String selfLinkUri = resource.getRequiredLink(IanaLinkRelation.SELF.value()).expand().getHref();
|
||||
|
||||
if (!affordanceUri.equals(selfLinkUri)) {
|
||||
throw new IllegalStateException("Affordance's URI " + affordanceUri + " doesn't match self link "
|
||||
|
||||
Reference in New Issue
Block a user