Class SlicedResourcesAssembler<T>

java.lang.Object
org.springframework.data.web.SlicedResourcesAssembler<T>
All Implemented Interfaces:
org.springframework.hateoas.server.RepresentationModelAssembler<Slice<T>,org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>>>

public class SlicedResourcesAssembler<T> extends Object implements org.springframework.hateoas.server.RepresentationModelAssembler<Slice<T>,org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>>>
RepresentationModelAssembler to easily convert Slice instances into SlicedModel.
Since:
3.1
Author:
Michael Schout, Oliver Drotbohm
  • Constructor Summary

    Constructors
    Constructor
    Description
    SlicedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, org.springframework.web.util.UriComponents baseUri)
    Creates a new SlicedResourcesAssembler using the given PageableHandlerMethodArgumentResolver and base URI.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <R extends org.springframework.hateoas.RepresentationModel<?>, S>
    org.springframework.hateoas.SlicedModel<R>
    createSlicedModel(List<R> resources, org.springframework.hateoas.SlicedModel.SliceMetadata metadata, Slice<S> slice)
    Creates the SlicedModel to be equipped with pagination links downstream.
    void
    setForceFirstRel(boolean forceFirstRel)
    Configures whether to always add first links to the SlicedModel * created.
    org.springframework.hateoas.SlicedModel<?>
    toEmptyModel(Slice<?> slice, Class<?> type)
    Creates a SlicedModel with an empty collection EmbeddedWrapper for the given domain type.
    org.springframework.hateoas.SlicedModel<?>
    toEmptyModel(Slice<?> slice, Class<?> type, Optional<org.springframework.hateoas.Link> link)
     
    org.springframework.hateoas.SlicedModel<?>
    toEmptyModel(Slice<?> slice, Class<?> type, org.springframework.hateoas.Link link)
    Creates a SlicedModel with an empty collection EmbeddedWrapper for the given domain type.
    org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>>
    toModel(Slice<T> entity)
     
    org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>>
    toModel(Slice<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 * SlicedModel instances.
    <R extends org.springframework.hateoas.RepresentationModel<?>>
    org.springframework.hateoas.SlicedModel<R>
    toModel(Slice<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 SlicedModel to turn elements of the Slice into resources.
    <R extends org.springframework.hateoas.RepresentationModel<?>>
    org.springframework.hateoas.SlicedModel<R>
    toModel(Slice<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 SlicedModel to turn elements of the Slice into resources.
    withParameter(org.springframework.core.MethodParameter parameter)
    Creates a new SlicedResourcesAssembler with the given reference MethodParameter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.hateoas.server.RepresentationModelAssembler

    toCollectionModel
  • Constructor Details

  • Method Details

    • setForceFirstRel

      public void setForceFirstRel(boolean forceFirstRel)
      Configures whether to always add first links to the SlicedModel * created. Defaults to false which means that first links onlys appear in conjunction with prev and next links.
      Parameters:
      forceFirstRel - whether to always add first links to the SlicedModel created.
    • withParameter

      public SlicedResourcesAssembler<T> withParameter(@Nullable org.springframework.core.MethodParameter parameter)
      Creates a new SlicedResourcesAssembler with the given reference MethodParameter.
      Parameters:
      parameter - can be null.
      Returns:
      will never be null.
      Since:
      3.1
    • toModel

      public org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>> toModel(Slice<T> entity)
      Specified by:
      toModel in interface org.springframework.hateoas.server.RepresentationModelAssembler<Slice<T>,org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>>>
    • toModel

      public org.springframework.hateoas.SlicedModel<org.springframework.hateoas.EntityModel<T>> toModel(Slice<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 * SlicedModel instances. Will add pagination links based on the given self link.
      Parameters:
      slice - must not be null.
      selfLink - must not be null.
      Returns:
    • toModel

      public <R extends org.springframework.hateoas.RepresentationModel<?>> org.springframework.hateoas.SlicedModel<R> toModel(Slice<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 SlicedModel to turn elements of the Slice into resources.
      Parameters:
      slice - must not be null.
      assembler - must not be null.
      Returns:
    • toModel

      public <R extends org.springframework.hateoas.RepresentationModel<?>> org.springframework.hateoas.SlicedModel<R> toModel(Slice<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 SlicedModel to turn elements of the Slice into resources. Will add pagination links based on the given the self link.
      Parameters:
      slice - must not be null.
      assembler - must not be null.
      link - must not be null.
      Returns:
    • toEmptyModel

      public org.springframework.hateoas.SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type)
      Creates a SlicedModel with an empty collection EmbeddedWrapper for the given domain type.
      Parameters:
      slice - must not be null, content must be empty.
      type - must not be null.
      Returns:
    • toEmptyModel

      public org.springframework.hateoas.SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, org.springframework.hateoas.Link link)
      Creates a SlicedModel with an empty collection EmbeddedWrapper for the given domain type.
      Parameters:
      slice - must not be null, content must be empty.
      type - must not be null.
      link - must not be null.
      Returns:
    • toEmptyModel

      public org.springframework.hateoas.SlicedModel<?> toEmptyModel(Slice<?> slice, Class<?> type, Optional<org.springframework.hateoas.Link> link)
    • createSlicedModel

      protected <R extends org.springframework.hateoas.RepresentationModel<?>, S> org.springframework.hateoas.SlicedModel<R> createSlicedModel(List<R> resources, org.springframework.hateoas.SlicedModel.SliceMetadata metadata, Slice<S> slice)
      Creates the SlicedModel to be equipped with pagination links downstream.
      Parameters:
      resources - the original slices's elements mapped into RepresentationModel instances.
      metadata - the calculated SlicedModel.SliceMetadata, must not be null.
      slice - the original page handed to the assembler, must not be null.
      Returns:
      must not be null.