Skip to content

Commit a89e57e

Browse files
committed
#833 - Changed ResourceSupport class name hierarchy.
1 parent 57f36a5 commit a89e57e

File tree

93 files changed

+1604
-1474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1604
-1474
lines changed

etc/migrate-to-1.0.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ FILES=`find . -name "$FILES_PATTERN"`
3838
EXPRESSION="s/Link\.REL_SELF/IanaLinkRelations.SELF/g;\
3939
s/Link\.REL_PREV/IanaLinkRelations.PREV/g;\
4040
s/Link\.REL_NEXT/IanaLinkRelations.NEXT/g;\
41+
\
4142
s/hateoas\.EntityLinks/hateoas.server.EntityLinks/g;\
4243
s/hateoas\.JsonPathLinkDiscoverer/hateoas.client.JsonPathLinkDiscoverer/g;\
4344
s/hateoas\.LinkBuilder/hateoas.server.LinkBuilder/g;\
@@ -47,7 +48,11 @@ s/hateoas\.MethodLinkBuilderFactory/hateoas.server.MethodLinkBuilderFactory/g;\
4748
s/hateoas\.RelProvider/hateoas.server.RelProvider/g;\
4849
s/hateoas\.ResourceAssembler/hateoas.server.ResourceAssembler/g;\
4950
s/hateoas\.ResourceProcessor/hateoas.server.ResourceProcessor/g;\
51+
s/hateoas\.VndErrors/hateoas.mediatype.vnderror.VndErrors/g;\
52+
s/hateoas\.VndErrors.VndError/hateoas.mediatype.vnderror.VndErrors.VndError/g;\
53+
\
5054
s/hateoas\.alps/hateoas.mediatype.alps/g;\
55+
\
5156
s/hateoas\.core\.AbstractEntityLinks/hateoas.server.core.AbstractEntityLinks/g;\
5257
s/hateoas\.core\.AnnotationAttribute/hateoas.server.core.AnnotationAttribute/g;\
5358
s/hateoas\.core\.AnnotationMappingDiscoverer/hateoas.server.core.AnnotationMappingDiscoverer/g;\
@@ -57,7 +62,9 @@ s/hateoas\.core\.EvoInflectorRelProvider/hateoas.server.core.EvoInflectorRelProv
5762
s/hateoas\.core\.JsonPathLinkDiscoverer/hateoas.client.JsonPathLinkDiscoverer/g;\
5863
s/hateoas\.core\.LinkBuilderSupport/hateoas.server.core.LinkBuilderSupport/g;\
5964
s/hateoas\.core\.MethodParameters/hateoas.server.core.MethodParameters/g;\
65+
\
6066
s/hateoas\.hal/hateoas.mediatype.hal/g;\
67+
\
6168
s/hateoas\.mvc\.ControllerLinkBuilder/hateoas.server.mvc.WebMvcLinkBuilder/g;\
6269
s/hateoas\.mvc\.ControllerLinkBuilderFactory/hateoas.server.mvc.WebMvcLinkBuilderFactory/g;\
6370
s/hateoas\.mvc\.HeaderLinksResponseEntity/hateoas.server.core.HeaderLinksResponseEntity/g;\
@@ -66,12 +73,35 @@ s/hateoas\.mvc\.ResourceProcessorInvokingHandlerAdapter/hateoas.server.mvc.Resou
6673
s/hateoas\.mvc\.TypeConstrainedMappingJackson2HttpMessageConverter/hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter/g;\
6774
s/hateoas\.mvc\.UriComponentsContributor/hateoas.server.mvc.UriComponentsContributor/g;\
6875
s/ControllerLinkBuilderFactory/WebMvcLinkBuilderFactory/g;\
69-
s/ControllerLinkBuilder/WebMvcLinkBuilder/g;"
76+
s/ControllerLinkBuilder/WebMvcLinkBuilder/g;\
77+
\
78+
s/\([^a-z]\)ResourceProcessorInvokingHandlerAdapter\([ ><,#();\.]\)/\1RepresentationModelProcessorInvokingHandlerAdapter\2/g;\
79+
s/\([^a-z]\)ResourceProcessorInvoker\([ ><,#();\.]\)/\1RepresentationModelProcessorInvoker\2/g;\
80+
s/\([^a-z]\)ResourceProcessor\([ ><,#();\.]\)/\1RepresentationModelProcessor\2/g;\
81+
\
82+
s/ ResourceAssembler / RepresentationModelAssembler /g;\
83+
s/\.ResourceAssembler;/.RepresentationModelAssembler;/g;\
84+
s/ResourceAssembler\([<#]\)/RepresentationModelAssembler\1/g;\
85+
s/IdentifiableResourceAssemblerSupport/IdentifiableRepresentationModelAssemblerSupport/g;\
86+
s/toResource(/toModel(/g;\
87+
s/toResources(/toCollectionModel(/g;\
88+
\
89+
s/\([^a-z]\)ResourceSupport\([ ><,#();\.]\)/\1RepresentationModel\2/g;\
90+
s/\([^a-z]\)PagedResources\([ ><,#();\.]\)/\1PagedModel\2/g;\
91+
s/\([^a-z]\)Resources\([ ><,#();\.]\)/\1CollectionModel\2/g;\
92+
s/\([^a-z]\)Resource\([ ><,#();\.]\)/\1EntityModel\2/g;\
93+
\
94+
s/linkForSingleResource/linkForItemResource/g;\
95+
s/linkToSingleResource/linkToItemResource/g;\
96+
"
97+
98+
#EXPRESSION="s/[\s\.]PagedResources\([;<]\)/.PagedRepresentationModel\1/g;"
7099

71100
for FILE in $FILES
72101
do
73102
echo "Adapting $FILE"
74-
sed -i "" $EXPRESSION $FILE
103+
# echo $EXPRESSION
104+
sed -i "" -e "$EXPRESSION" $FILE
75105
done
76106

77107
echo
@@ -81,4 +111,7 @@ echo 'If you have used link relation constants defined in Link (like Link.REL_SE
81111
echo 'codebase, you will have to trigger an organize imports in your IDE to make sure the'
82112
echo 'now referenced IanaLinkRelations gets imported.'
83113
echo
114+
echo "Also, if you were referring to core Spring's Resource type you might see invalid migrations"
115+
echo "as there's no way for us to differentiate that from Spring HATEOAS Resource type."
116+
echo
84117
echo 'After that, review your changes, commit and code on! \ö/'

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@
563563
<groupId>com.jayway.jsonpath</groupId>
564564
<artifactId>json-path</artifactId>
565565
<version>${jsonpath.version}</version>
566-
<optional>true</optional>
567566
</dependency>
568567

569568
<dependency>

src/main/asciidoc/migrate-to-1.0.adoc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ There had been an incredible amount of feedback on it and the major version bump
1010
The biggest changes in package structure were driven by the introduction of a hypermedia type registration API to support additional media types in Spring HATEOAS.
1111
This lead to the clear separation of client and server APIs (packages named respectively) as well as media type implementations in the package `mediatype`.
1212

13-
The easiest way to get your codebase upgraded to the new API is by using the <<migrate-to-1.0.script, migration script>>.
14-
Before we jump to that, here are the changes at a quick glance:
13+
The easiest way to get your code base upgraded to the new API is by using the <<migrate-to-1.0.script, migration script>>.
14+
Before we jump to that, here are the changes at a quick glance.
1515

16-
* `ResourceSupport` now exposes a `Links` instance (over a `List<Link>`) as that exposes additional API to concatenate and merge different `Links` instances using various strategies.
16+
=== Representation models
17+
18+
The `ResourceSupport`/`Resource`/`Resources`/`PagedResources` group of classes never really felt appropriately named.
19+
After all, these types do not actually manifest resources but rather representation models that can be enriched with hypermedia information and affordances.
20+
Here's how new names map to the old ones:
21+
22+
* `ResourceSupport` is now `RepresentationModel`
23+
* `Resource` is now `EntityModel`
24+
* `Resources` is now `CollectionModel`
25+
* `PagedResources` is now `PagedModel`
26+
27+
Consequently, `ResourceAssembler` has been renamed to `RepresentationModelAssembler` and its methods `toResource(…)` and `toResources(…)` have been renamed to `toModel(…)` and `toCollectionModel(…)` respectively.
28+
Also the name changes have been reflected in the classes contained in `TypeReferences`.
29+
30+
* `RepresentationModel.getLinks()` now exposes a `Links` instance (over a `List<Link>`) as that exposes additional API to concatenate and merge different `Links` instances using various strategies.
31+
Also it has been turned into a self-bound generic type to allow the methods that add links to the instance return the instance itself.
1732
* The `LinkDiscoverer` API has been moved to the `client` package.
18-
* The `LinkBuilder` API has been moved to the `server` package.
33+
* The `LinkBuilder` and `EntityLinks` APIs have been moved to the `server` package.
1934
* `ControllerLinkBuilder` has been moved into `server.mvc` and deprecated to be replaced by `WebMvcLinkBuilder`.
35+
* `VndError` has been moved to the `mediatype.vnderror` package.
2036

2137
[migrate-to-1.0.script]
2238
== The migration script

src/main/java/org/springframework/hateoas/Resources.java renamed to src/main/java/org/springframework/hateoas/CollectionModel.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,34 @@
3131
* @author Oliver Gierke
3232
* @author Greg Turnquist
3333
*/
34-
public class Resources<T> extends ResourceSupport implements Iterable<T> {
34+
public class CollectionModel<T> extends RepresentationModel<CollectionModel<T>> implements Iterable<T> {
3535

3636
private final Collection<T> content;
3737

3838
/**
39-
* Creates an empty {@link Resources} instance.
39+
* Creates an empty {@link CollectionModel} instance.
4040
*/
41-
protected Resources() {
41+
protected CollectionModel() {
4242
this(new ArrayList<>());
4343
}
4444

4545
/**
46-
* Creates a {@link Resources} instance with the given content and {@link Link}s (optional).
46+
* Creates a {@link CollectionModel} instance with the given content and {@link Link}s (optional).
4747
*
4848
* @param content must not be {@literal null}.
49-
* @param links the links to be added to the {@link Resources}.
49+
* @param links the links to be added to the {@link CollectionModel}.
5050
*/
51-
public Resources(Iterable<T> content, Link... links) {
51+
public CollectionModel(Iterable<T> content, Link... links) {
5252
this(content, Arrays.asList(links));
5353
}
5454

5555
/**
56-
* Creates a {@link Resources} instance with the given content and {@link Link}s.
56+
* Creates a {@link CollectionModel} instance with the given content and {@link Link}s.
5757
*
5858
* @param content must not be {@literal null}.
59-
* @param links the links to be added to the {@link Resources}.
59+
* @param links the links to be added to the {@link CollectionModel}.
6060
*/
61-
public Resources(Iterable<T> content, Iterable<Link> links) {
61+
public CollectionModel(Iterable<T> content, Iterable<Link> links) {
6262

6363
Assert.notNull(content, "Content must not be null!");
6464

@@ -71,23 +71,24 @@ public Resources(Iterable<T> content, Iterable<Link> links) {
7171
}
7272

7373
/**
74-
* Creates a new {@link Resources} instance by wrapping the given domain class instances into a {@link Resource}.
74+
* Creates a new {@link CollectionModel} instance by wrapping the given domain class instances into a
75+
* {@link EntityModel}.
7576
*
7677
* @param content must not be {@literal null}.
7778
* @return
7879
*/
7980
@SuppressWarnings("unchecked")
80-
public static <T extends Resource<S>, S> Resources<T> wrap(Iterable<S> content) {
81+
public static <T extends EntityModel<S>, S> CollectionModel<T> wrap(Iterable<S> content) {
8182

8283
Assert.notNull(content, "Content must not be null!");
8384

8485
ArrayList<T> resources = new ArrayList<>();
8586

8687
for (S element : content) {
87-
resources.add((T) new Resource<>(element));
88+
resources.add((T) new EntityModel<>(element));
8889
}
8990

90-
return new Resources<>(resources);
91+
return new CollectionModel<>(resources);
9192
}
9293

9394
/**
@@ -133,7 +134,7 @@ public boolean equals(Object obj) {
133134
return false;
134135
}
135136

136-
Resources<?> that = (Resources<?>) obj;
137+
CollectionModel<?> that = (CollectionModel<?>) obj;
137138

138139
boolean contentEqual = this.content == null ? that.content == null : this.content.equals(that.content);
139140
return contentEqual && super.equals(obj);

src/main/java/org/springframework/hateoas/Resource.java renamed to src/main/java/org/springframework/hateoas/EntityModel.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,39 @@
2323
import com.fasterxml.jackson.annotation.JsonUnwrapped;
2424

2525
/**
26-
* A simple {@link Resource} wrapping a domain object and adding links to it.
27-
*
26+
* A simple {@link EntityModel} wrapping a domain object and adding links to it.
27+
*
2828
* @author Oliver Gierke
2929
* @author Greg Turnquist
3030
*/
31-
public class Resource<T> extends ResourceSupport {
31+
public class EntityModel<T> extends RepresentationModel<EntityModel<T>> {
3232

3333
private final T content;
3434

3535
/**
36-
* Creates an empty {@link Resource}.
36+
* Creates an empty {@link EntityModel}.
3737
*/
38-
protected Resource() {
38+
protected EntityModel() {
3939
this.content = null;
4040
}
4141

4242
/**
43-
* Creates a new {@link Resource} with the given content and {@link Link}s (optional).
44-
*
43+
* Creates a new {@link EntityModel} with the given content and {@link Link}s (optional).
44+
*
4545
* @param content must not be {@literal null}.
46-
* @param links the links to add to the {@link Resource}.
46+
* @param links the links to add to the {@link EntityModel}.
4747
*/
48-
public Resource(T content, Link... links) {
48+
public EntityModel(T content, Link... links) {
4949
this(content, Arrays.asList(links));
5050
}
5151

5252
/**
53-
* Creates a new {@link Resource} with the given content and {@link Link}s.
54-
*
53+
* Creates a new {@link EntityModel} with the given content and {@link Link}s.
54+
*
5555
* @param content must not be {@literal null}.
56-
* @param links the links to add to the {@link Resource}.
56+
* @param links the links to add to the {@link EntityModel}.
5757
*/
58-
public Resource(T content, Iterable<Link> links) {
58+
public EntityModel(T content, Iterable<Link> links) {
5959

6060
Assert.notNull(content, "Content must not be null!");
6161
Assert.isTrue(!(content instanceof Collection), "Content must not be a collection! Use Resources instead!");
@@ -65,15 +65,15 @@ public Resource(T content, Iterable<Link> links) {
6565

6666
/**
6767
* Returns the underlying entity.
68-
*
68+
*
6969
* @return the content
7070
*/
7171
@JsonUnwrapped
7272
public T getContent() {
7373
return content;
7474
}
7575

76-
/*
76+
/*
7777
* (non-Javadoc)
7878
* @see org.springframework.hateoas.ResourceSupport#toString()
7979
*/
@@ -82,7 +82,7 @@ public String toString() {
8282
return String.format("Resource { content: %s, %s }", getContent(), super.toString());
8383
}
8484

85-
/*
85+
/*
8686
* (non-Javadoc)
8787
* @see org.springframework.hateoas.ResourceSupport#equals(java.lang.Object)
8888
*/
@@ -97,13 +97,13 @@ public boolean equals(Object obj) {
9797
return false;
9898
}
9999

100-
Resource<?> that = (Resource<?>) obj;
100+
EntityModel<?> that = (EntityModel<?>) obj;
101101

102102
boolean contentEqual = this.content == null ? that.content == null : this.content.equals(that.content);
103103
return contentEqual && super.equals(obj);
104104
}
105105

106-
/*
106+
/*
107107
* (non-Javadoc)
108108
* @see org.springframework.hateoas.ResourceSupport#hashCode()
109109
*/

src/main/java/org/springframework/hateoas/PagedResources.java renamed to src/main/java/org/springframework/hateoas/PagedModel.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,41 @@
3131
* @author Oliver Gierke
3232
* @author Greg Turnquist
3333
*/
34-
public class PagedResources<T> extends Resources<T> {
34+
public class PagedModel<T> extends CollectionModel<T> {
3535

36-
public static PagedResources<?> NO_PAGE = new PagedResources<>();
36+
public static PagedModel<?> NO_PAGE = new PagedModel<>();
3737

3838
private PageMetadata metadata;
3939

4040
/**
4141
* Default constructor to allow instantiation by reflection.
4242
*/
43-
protected PagedResources() {
43+
protected PagedModel() {
4444
this(new ArrayList<>(), null);
4545
}
4646

4747
/**
48-
* Creates a new {@link PagedResources} from the given content, {@link PageMetadata} and {@link Link}s (optional).
48+
* Creates a new {@link PagedModel} from the given content, {@link PageMetadata} and {@link Link}s (optional).
4949
*
5050
* @param content must not be {@literal null}.
5151
* @param metadata
5252
* @param links
5353
*/
54-
public PagedResources(Collection<T> content, PageMetadata metadata, Link... links) {
54+
public PagedModel(Collection<T> content, PageMetadata metadata, Link... links) {
5555
this(content, metadata, Arrays.asList(links));
5656
}
5757

5858
/**
59-
* Creates a new {@link PagedResources} from the given content {@link PageMetadata} and {@link Link}s.
59+
* Creates a new {@link PagedModel} from the given content {@link PageMetadata} and {@link Link}s.
6060
*
6161
* @param content must not be {@literal null}.
6262
* @param metadata
6363
* @param links
6464
*/
65-
public PagedResources(Collection<T> content, PageMetadata metadata, Iterable<Link> links) {
65+
public PagedModel(Collection<T> content, PageMetadata metadata, Iterable<Link> links) {
66+
6667
super(content, links);
68+
6769
this.metadata = metadata;
6870
}
6971

@@ -78,23 +80,23 @@ public PageMetadata getMetadata() {
7880
}
7981

8082
/**
81-
* Factory method to easily create a {@link PagedResources} instance from a set of entities and pagination metadata.
83+
* Factory method to easily create a {@link PagedModel} instance from a set of entities and pagination metadata.
8284
*
8385
* @param content must not be {@literal null}.
8486
* @param metadata
8587
* @return
8688
*/
8789
@SuppressWarnings("unchecked")
88-
public static <T extends Resource<S>, S> PagedResources<T> wrap(Iterable<S> content, PageMetadata metadata) {
90+
public static <T extends EntityModel<S>, S> PagedModel<T> wrap(Iterable<S> content, PageMetadata metadata) {
8991

9092
Assert.notNull(content, "Content must not be null!");
9193
ArrayList<T> resources = new ArrayList<>();
9294

9395
for (S element : content) {
94-
resources.add((T) new Resource<>(element));
96+
resources.add((T) new EntityModel<>(element));
9597
}
9698

97-
return new PagedResources<>(resources, metadata);
99+
return new PagedModel<>(resources, metadata);
98100
}
99101

100102
/**
@@ -141,7 +143,7 @@ public boolean equals(Object obj) {
141143
return false;
142144
}
143145

144-
PagedResources<?> that = (PagedResources<?>) obj;
146+
PagedModel<?> that = (PagedModel<?>) obj;
145147
boolean metadataEquals = this.metadata == null ? that.metadata == null : this.metadata.equals(that.metadata);
146148

147149
return metadataEquals && super.equals(obj);

0 commit comments

Comments
 (0)