Package org.dspace.app.rest.projection
Class AbstractProjection
- java.lang.Object
-
- org.dspace.app.rest.projection.AbstractProjection
-
- All Implemented Interfaces:
Projection
- Direct Known Subclasses:
CompositeProjection,DefaultProjection,EmbedRelsProjection,FullProjection,SpecificLevelProjection
public abstract class AbstractProjection extends Object implements Projection
Abstract base class for projections. By default, this does no transformation, and allows linking but not embedding of all subresources.
-
-
Field Summary
-
Fields inherited from interface org.dspace.app.rest.projection.Projection
DEFAULT
-
-
Constructor Summary
Constructors Constructor Description AbstractProjection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowEmbedding(HALResource<? extends RestAddressableModel> halResource, LinkRest linkRest, org.springframework.hateoas.Link... oldLinks)Tells whether this projection permits the embedding of a particular embeddable subresource.booleanallowLinking(HALResource halResource, LinkRest linkRest)Tells whether this projection permits the linking of a particular linkable subresource.org.springframework.data.domain.PageRequestgetPagingOptions(String rel, HALResource<? extends RestAddressableModel> resource, org.springframework.hateoas.Link... oldLinks)This method will return thePageRequestobject for a specific given rel<T> TtransformModel(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.dspace.app.rest.projection.Projection
getName
-
-
-
-
Method Detail
-
transformModel
public <T> T transformModel(T modelObject)
Description copied from interface:ProjectionTransforms 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:
transformModelin interfaceProjection- 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
public <T extends RestModel> T transformRest(T restObject)
Description copied from interface:ProjectionTransforms 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:
transformRestin interfaceProjection- 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
public <T extends HALResource> T transformResource(T halResource)
Description copied from interface:ProjectionTransforms 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:
transformResourcein interfaceProjection- 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:ProjectionTells 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 returnstruefor a given subresource, it will be automatically linked regardless of whatProjection.allowLinking(HALResource, LinkRest)returns.- Specified by:
allowEmbeddingin interfaceProjection- 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
public boolean allowLinking(HALResource halResource, LinkRest linkRest)
Description copied from interface:ProjectionTells 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...)returnstruefor a given subresource, it will be automatically linked regardless of what this method returns.- Specified by:
allowLinkingin interfaceProjection- 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.
-
getPagingOptions
public org.springframework.data.domain.PageRequest getPagingOptions(String rel, HALResource<? extends RestAddressableModel> resource, org.springframework.hateoas.Link... oldLinks)
Description copied from interface:ProjectionThis method will return thePageRequestobject for a specific given rel- Specified by:
getPagingOptionsin interfaceProjection- Parameters:
rel- The rel for which thePageRequestobject will be maderesource- the resource from which the embed may or may not be made.oldLinks- The previously traversed links- Returns:
- The
PageRequestobject for the given rel
-
-