Package org.dspace.app.rest.projection
Class CompositeProjection
java.lang.Object
org.dspace.app.rest.projection.AbstractProjection
org.dspace.app.rest.projection.CompositeProjection
- All Implemented Interfaces:
Projection
A projection that combines the behavior of multiple projections.
Model, rest, and resource transformations will be performed in the order of the projections given in
the constructor. Embedding will be allowed if any of the given projections allow them. Linking will
be allowed if all of the given projections allow them.
-
Field Summary
FieldsFields inherited from interface org.dspace.app.rest.projection.Projection
DEFAULT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
allowEmbedding
(HALResource<? extends RestAddressableModel> halResource, LinkRest linkRest, org.springframework.hateoas.Link... oldLinks) Tells whether this projection permits the embedding of a particular embeddable subresource.boolean
allowLinking
(HALResource halResource, LinkRest linkRest) Tells whether this projection permits the linking of a particular linkable subresource.getName()
Gets the projection name.<T> T
transformModel
(T modelObject) Transforms the original model object (e.g.<T extends HALResource>
TtransformResource
(T halResource) Transforms the resource object after it has been constructed and any constructor or annotation-based links and embeds have been added.<T extends RestModel>
TtransformRest
(T restObject) Transforms the rest object after it was converted from a model object.Methods inherited from class org.dspace.app.rest.projection.AbstractProjection
getPagingOptions
-
Field Details
-
NAME
- See Also:
-
-
Constructor Details
-
CompositeProjection
-
-
Method Details
-
getName
Description copied from interface:Projection
Gets the projection name.- Returns:
- the name, which is a unique alphanumeric string.
-
transformModel
public <T> T transformModel(T modelObject) Description copied from interface:Projection
Transforms the original model object (e.g. JPA entity) before conversion to aRestModel
. This is a good place to omit data for certain properties that should not be included in the object's representation as aHALResource
. Omitting these properties early helps to prevent unnecessary database calls for lazy-loaded properties that are unwanted for the projection.- Specified by:
transformModel
in interfaceProjection
- Overrides:
transformModel
in classAbstractProjection
- Type Parameters:
T
- the return type, which must be the same type as the given model object.- Parameters:
modelObject
- the original model object, which may be of any type.- Returns:
- the transformed model object, or the original, if the projection does not modify it.
-
transformRest
Description copied from interface:Projection
Transforms the rest object after it was converted from a model object. This may add data to, or omit data from the rest representation of the object.- Specified by:
transformRest
in interfaceProjection
- Overrides:
transformRest
in classAbstractProjection
- Type Parameters:
T
- the return type, which must be of the same type as the given rest object.- Parameters:
restObject
- the rest object.- Returns:
- the transformed rest object, or the original, if the projection does not modify it.
-
transformResource
Description copied from interface:Projection
Transforms the resource object after it has been constructed and any constructor or annotation-based links and embeds have been added. This may add data to, or omit data from the HAL resource representation of the object.- Specified by:
transformResource
in interfaceProjection
- Overrides:
transformResource
in classAbstractProjection
- Type Parameters:
T
- the return type, which must be of the same type as the given resource object.- Parameters:
halResource
- the resource object.- Returns:
- the transformed resource object, or the original, if the projection does not modify it.
-
allowEmbedding
public boolean allowEmbedding(HALResource<? extends RestAddressableModel> halResource, LinkRest linkRest, org.springframework.hateoas.Link... oldLinks) Description copied from interface:Projection
Tells whether this projection permits the embedding of a particular embeddable subresource. This gives the projection an opportunity to opt in to to certain embeds, by returningtrue
. Note: If this method returnstrue
for a given subresource, it will be automatically linked regardless of whatProjection.allowLinking(HALResource, LinkRest)
returns.- Specified by:
allowEmbedding
in interfaceProjection
- Overrides:
allowEmbedding
in classAbstractProjection
- Parameters:
halResource
- the resource from which the embed may or may not be made.linkRest
- the LinkRest annotation through which the related resource was discovered on the rest object.oldLinks
- The previously traversed links- Returns:
- true if allowed, false otherwise.
-
allowLinking
Description copied from interface:Projection
Tells whether this projection permits the linking of a particular linkable subresource. This gives the projection an opportunity to opt in to to certain links, by returningtrue
. Note: IfProjection.allowEmbedding(HALResource, LinkRest, Link...)
returnstrue
for a given subresource, it will be automatically linked regardless of what this method returns.- Specified by:
allowLinking
in interfaceProjection
- Overrides:
allowLinking
in classAbstractProjection
- Parameters:
halResource
- the resource from which the link may or may not be made.linkRest
- the LinkRest annotation through which the related resource was discovered on the rest object.- Returns:
- true if allowed, false otherwise.
-