-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for fully-qualified links
- also make the linkrel configurable Fixes #148
- Loading branch information
Paul Warren
committed
Mar 11, 2020
1 parent
53c1e4f
commit ca7edff
Showing
24 changed files
with
1,194 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,4 @@ class CustomContentRestMvcConfiguration { | |
} | ||
---- | ||
==== | ||
|
104 changes: 104 additions & 0 deletions
104
spring-content-rest/src/main/asciidoc/rest-fullyqualifiedlinks.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
== Fully Qualified Links | ||
By default, and where possible, Spring Content REST exports Spring Resources to shortened link URIs. These will often | ||
match the Spring Data Rest Entity URI. | ||
|
||
Given the following example: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
@Entity | ||
public class Dvd { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
@ContentId | ||
private UUID contentId; | ||
@ContentLength | ||
private Long contentLength; | ||
@MimeType | ||
private String mimeType; | ||
// getters and setters | ||
} | ||
public interface DvdRepository extends CrudRepository<Dvd, Long> {} | ||
public interface DvdStore extends ContentStore<Dvd, UUID> {} | ||
---- | ||
==== | ||
|
||
As there is only a single associated Spring Resource, Spring Content REST will generate the following URI: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
"_links" : { | ||
"self" : { | ||
... | ||
}, | ||
"dvd" : { | ||
... | ||
}, | ||
"dvds" : { | ||
"href" : "http://localhost:8080/dvds/1" | ||
} | ||
} | ||
---- | ||
==== | ||
|
||
To generate fully qualified link URIs set the following property: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
spring.content.rest.fullyQualifiedLinks=true | ||
---- | ||
==== | ||
|
||
Or if you are not using Spring Boot, you can do the following: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
@Configuration | ||
class CustomContentRestMvcConfiguration { | ||
@Bean | ||
public ContentRestConfigurer contentRestConfigurer() { | ||
return new ContentRestConfigurer() { | ||
@Override | ||
public void configure(RestConfiguration config) { | ||
config.setFullyQualifiedLinks(true); | ||
} | ||
}; | ||
} | ||
} | ||
---- | ||
==== | ||
|
||
Spring Content REST will now generate links as follows: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
"_links" : { | ||
"self" : { | ||
... | ||
}, | ||
"dvd" : { | ||
... | ||
}, | ||
"content" : { | ||
"href" : "http://localhost:8080/dvds/1/content" | ||
} | ||
} | ||
---- | ||
==== | ||
|
||
where `content` is the extracted property name taken from the field `contentId`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
== Changing the link relation | ||
|
||
For each exported Spring Resource, Spring Content REST will generate a suitable linkrel. | ||
|
||
However, it can sometimes be useful to control this yourself. | ||
|
||
Given the following example: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
@Entity | ||
public class Dvd { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
@ContentId | ||
private UUID contentId; | ||
@ContentLength | ||
private Long contentLength; | ||
@MimeType | ||
private String mimeType; | ||
// getters and setters | ||
} | ||
public interface DvdRepository extends CrudRepository<Dvd, Long> {} | ||
public interface DvdStore extends ContentStore<Dvd, UUID> {} | ||
---- | ||
==== | ||
|
||
Spring Content REST will export the Spring Resource to the following linkrel: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
"_links" : { | ||
"self" : { | ||
... | ||
}, | ||
"dvd" : { | ||
... | ||
}, | ||
"dvds" : { | ||
"href" : "http://localhost:8080/dvds/1" | ||
} | ||
} | ||
---- | ||
==== | ||
|
||
Specifying a `linkRel` on the StoreRestResource, as follows: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
@StoreRestResource(linkRel="content") | ||
public interface DvdStore extends ContentStore<Dvd, UUID> {} | ||
---- | ||
==== | ||
|
||
will result in the following linkrel instead: | ||
|
||
==== | ||
[source, java] | ||
---- | ||
"_links" : { | ||
"self" : { | ||
... | ||
}, | ||
"dvd" : { | ||
... | ||
}, | ||
"content" : { | ||
"href" : "http://localhost:8080/dvds/1" | ||
} | ||
} | ||
---- | ||
==== | ||
|
Oops, something went wrong.