Class 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>>>
    RepresentationModelAssembler to easily convert CursorPaginationSlice instances into SlicedModel.
    Since:
    1.0
    Author:
    Davide Pedone
    • Constructor Detail

      • SlicedResourcesAssembler

        public SlicedResourcesAssembler​(@Nullable
                                        HateoasCursorPageableHandlerMethodArgumentResolver resolver,
                                        @Nullable
                                        org.springframework.web.util.UriComponents baseUri)
        Creates a new SlicedResourcesAssembler using the given PageableHandlerMethodArgumentResolver and base URI. If the former is null, a default one will be created. If the latter is null, calls to toModel(CursorPaginationSlice) will use the current request's URI to build the relevant previous and next links.
        Parameters:
        resolver - hateoas resolver
        baseUri - can be null.
    • Method Detail

      • toModel

        public SlicedModel<org.springframework.hateoas.EntityModel<T>> toModel​(CursorPaginationSlice<T> slice,
                                                                               org.springframework.hateoas.Link selfLink)
        Creates a new SlicedModel by converting the given Slice into a SlicedModel.SliceMetadata instance and wrapping the contained elements into EntityModel instances. 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 new SlicedModel by converting the given Slice into a SlicedModel.SliceMetadata instance and using the given RepresentationModelAssembler to turn elements of the Slice into 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 new SlicedModel by converting the given Slice into a SlicedModel.SliceMetadata instance and using the given RepresentationModelAssembler to turn elements of the Slice into 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 a SlicedModel with an empty collection EmbeddedWrapper for 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 a SlicedModel with an empt collection EmbeddedWrapper for 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 the SlicedModel to be equipped with pagination links downstream.
        Type Parameters:
        R - class that extends RepresentationModel
        S - class of the entity
        Parameters:
        resources - the original page's elements mapped into RepresentationModel instances.
        metadata - the calculated SlicedModel.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 the MethodParameter to 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