Package it.davidepedone.scp.hateoas
Class SlicedResourcesAssembler<T>
- java.lang.Object
-
- it.davidepedone.scp.hateoas.SlicedResourcesAssembler<T>
-
- All Implemented Interfaces:
org.springframework.hateoas.server.RepresentationModelAssembler<CursorPaginationSlice<T>,SlicedModel<org.springframework.hateoas.EntityModel<T>>>
public class SlicedResourcesAssembler<T> extends Object implements org.springframework.hateoas.server.RepresentationModelAssembler<CursorPaginationSlice<T>,SlicedModel<org.springframework.hateoas.EntityModel<T>>>
- Since:
- 1.0
- Author:
- Davide Pedone
-
-
Constructor Summary
Constructors Constructor Description SlicedResourcesAssembler(HateoasCursorPageableHandlerMethodArgumentResolver resolver, org.springframework.web.util.UriComponents baseUri)Creates a newSlicedResourcesAssemblerusing the givenPageableHandlerMethodArgumentResolverand base URI.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <R extends org.springframework.hateoas.RepresentationModel<?>,S>
SlicedModel<R>createPagedModel(List<R> resources, SlicedModel.SliceMetadata metadata, CursorPaginationSlice<S> page)Creates theSlicedModelto be equipped with pagination links downstream.protected org.springframework.core.MethodParametergetMethodParameter()Return theMethodParameterto be used to potentially qualify the paging and sorting request parameters to.SlicedModel<?>toEmptyModel(CursorPaginationSlice<?> page, Class<?> type)Creates aSlicedModelwith an empty collectionEmbeddedWrapperfor the given domain type.SlicedModel<?>toEmptyModel(CursorPaginationSlice<?> page, Class<?> type, org.springframework.hateoas.Link link)Creates aSlicedModelwith an empt collectionEmbeddedWrapperfor the given domain type.SlicedModel<org.springframework.hateoas.EntityModel<T>>toModel(CursorPaginationSlice<T> slice)SlicedModel<org.springframework.hateoas.EntityModel<T>>toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.Link selfLink)Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and wrapping the contained elements intoEntityModelinstances.<R extends org.springframework.hateoas.RepresentationModel<?>>
SlicedModel<R>toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.server.RepresentationModelAssembler<T,R> assembler)Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and using the givenRepresentationModelAssemblerto turn elements of theSliceinto resources.<R extends org.springframework.hateoas.RepresentationModel<?>>
SlicedModel<R>toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.server.RepresentationModelAssembler<T,R> assembler, org.springframework.hateoas.Link link)Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and using the givenRepresentationModelAssemblerto turn elements of theSliceinto resources.
-
-
-
Constructor Detail
-
SlicedResourcesAssembler
public SlicedResourcesAssembler(@Nullable HateoasCursorPageableHandlerMethodArgumentResolver resolver, @Nullable org.springframework.web.util.UriComponents baseUri)Creates a newSlicedResourcesAssemblerusing the givenPageableHandlerMethodArgumentResolverand base URI. If the former is null, a default one will be created. If the latter is null, calls totoModel(CursorPaginationSlice)will use the current request's URI to build the relevant previous and next links.- Parameters:
resolver- hateoas resolverbaseUri- can be null.
-
-
Method Detail
-
toModel
public SlicedModel<org.springframework.hateoas.EntityModel<T>> toModel(CursorPaginationSlice<T> slice)
- Specified by:
toModelin interfaceorg.springframework.hateoas.server.RepresentationModelAssembler<CursorPaginationSlice<T>,SlicedModel<org.springframework.hateoas.EntityModel<T>>>
-
toModel
public SlicedModel<org.springframework.hateoas.EntityModel<T>> toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.Link selfLink)
Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and wrapping the contained elements intoEntityModelinstances. Will add pagination links based on the given the self link.- Parameters:
slice- must not be null.selfLink- must not be null.- Returns:
- SlicedModel
-
toModel
public <R extends org.springframework.hateoas.RepresentationModel<?>> SlicedModel<R> toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.server.RepresentationModelAssembler<T,R> assembler)
Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and using the givenRepresentationModelAssemblerto turn elements of theSliceinto resources.- Type Parameters:
R- class that extends RepresentationModel- Parameters:
slice- must not be null.assembler- must not be null.- Returns:
- SlicedModel
-
toModel
public <R extends org.springframework.hateoas.RepresentationModel<?>> SlicedModel<R> toModel(CursorPaginationSlice<T> slice, org.springframework.hateoas.server.RepresentationModelAssembler<T,R> assembler, org.springframework.hateoas.Link link)
Creates a newSlicedModelby converting the givenSliceinto aSlicedModel.SliceMetadatainstance and using the givenRepresentationModelAssemblerto turn elements of theSliceinto resources. Will add pagination links based on the given the self link.- Type Parameters:
R- class that extends RepresentationModel- Parameters:
slice- must not be null.assembler- must not be null.link- must not be null.- Returns:
- SlicedModel
-
toEmptyModel
public SlicedModel<?> toEmptyModel(CursorPaginationSlice<?> page, Class<?> type)
Creates aSlicedModelwith an empty collectionEmbeddedWrapperfor the given domain type.- Parameters:
page- must not be null, content must be empty.type- must not be null.- Returns:
- SlicedModel
- Since:
- 1.0
-
toEmptyModel
public SlicedModel<?> toEmptyModel(CursorPaginationSlice<?> page, Class<?> type, org.springframework.hateoas.Link link)
Creates aSlicedModelwith an empt collectionEmbeddedWrapperfor the given domain type.- Parameters:
page- must not be null, content must be empty.type- must not be null.link- must not be null.- Returns:
- SlicedModel
- Since:
- 1.0
-
createPagedModel
protected <R extends org.springframework.hateoas.RepresentationModel<?>,S> SlicedModel<R> createPagedModel(List<R> resources, SlicedModel.SliceMetadata metadata, CursorPaginationSlice<S> page)
Creates theSlicedModelto be equipped with pagination links downstream.- Type Parameters:
R- class that extends RepresentationModelS- class of the entity- Parameters:
resources- the original page's elements mapped intoRepresentationModelinstances.metadata- the calculatedSlicedModel.SliceMetadata, must not be null.page- the original page handed to the assembler, must not be null.- Returns:
- must not be null.
-
getMethodParameter
@Nullable protected org.springframework.core.MethodParameter getMethodParameter()
Return theMethodParameterto be used to potentially qualify the paging and sorting request parameters to. Default implementations returns null, which means the parameters will not be qualified.- Returns:
- null
- Since:
- 1.0
-
-