Package io.wcm.caravan.rhyme.api.server
Class ResourceConversions
java.lang.Object
io.wcm.caravan.rhyme.api.server.ResourceConversions
Contains utility methods to perform conversions between resources that are semantically identical, but
need some tweaks for the framework to properly handle them
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
asEmbeddedResource
(T linkableResource) Create a proxy of a resource that also implementsEmbeddableResource
.static <T> T
asEmbeddedResourceWithoutLink
(T linkableResource) Create a proxy of a resource that also implementsEmbeddableResource
, withEmbeddableResource.isLinkedWhenEmbedded()
returning false.static <T> T
asLinkableResource
(io.wcm.caravan.hal.resource.Link link, Class<T> halApiInterface) Create a proxy for the given interface that can only be used to create links to that resource.
-
Method Details
-
asEmbeddedResource
public static <T> T asEmbeddedResource(T linkableResource) Create a proxy of a resource that also implementsEmbeddableResource
. This can be useful if you have fetched some resources from an upstream server, and want to embed them in your own output (and include links to the original resources).- Type Parameters:
T
- the interface with theHalApiInterface
annotation- Parameters:
linkableResource
- a resource fetched with theHalApiClient
, or a server-side resource implementation that does not implementEmbeddableResource
- Returns:
- a proxy instance that implements
EmbeddableResource
and all interfaces the given object implements
-
asEmbeddedResourceWithoutLink
public static <T> T asEmbeddedResourceWithoutLink(T linkableResource) Create a proxy of a resource that also implementsEmbeddableResource
, withEmbeddableResource.isLinkedWhenEmbedded()
returning false. This can be useful if you have fetched some resources from an upstream server, and want to embed them in your own output (but not include any links to those embedded resources).- Type Parameters:
T
- the interface with theHalApiInterface
annotation- Parameters:
linkableResource
- a resource fetched with theHalApiClient
, or a server-side resource implementation that does not implementEmbeddableResource
- Returns:
- a proxy instance that implements
EmbeddableResource
and all interfaces the given object implements
-
asLinkableResource
public static <T> T asLinkableResource(io.wcm.caravan.hal.resource.Link link, Class<T> halApiInterface) Create a proxy for the given interface that can only be used to create links to that resource. This can be returned from server-side implementations ofRelated
methods if it's not feasible to create a complete resource implementation, but you do have aLink
pointing to a URI where a resource of the given interface can be retrieved.Note that calling any other method than
LinkableResource.createLink()
on the proxy will fail.- Parameters:
link
- to be returned byLinkableResource.createLink()
halApiInterface
- the interface that should be implemented- Returns:
- a proxy instance implementing
LinkableResource
on which you can only callLinkableResource.createLink()
-