Class RepositoryRestConfiguration

java.lang.Object
org.springframework.data.rest.core.config.RepositoryRestConfiguration

public class RepositoryRestConfiguration extends Object
Spring Data REST configuration options.
Author:
Jon Brisbin, Oliver Gierke, Jeremy Rickard, Greg Turnquist, Mark Paluch
  • Constructor Details

  • Method Details

    • getBaseUri

      @Deprecated public URI getBaseUri()
      Deprecated.
      use getBasePath() instead.
      The base URI against which the exporter should calculate its links.
      Returns:
      The base URI.
    • getBasePath

      public URI getBasePath()
      The base path to expose repository resources under.
      Returns:
      the basePath
    • setBasePath

      public RepositoryRestConfiguration setBasePath(String basePath)
      Configures the base path to be used by Spring Data REST to expose repository resources.
      Parameters:
      basePath - the basePath to set
    • getDefaultPageSize

      public int getDefaultPageSize()
      Get the default size of Pageables. Default is 20.
      Returns:
      The default page size.
    • setDefaultPageSize

      public RepositoryRestConfiguration setDefaultPageSize(int defaultPageSize)
      Set the default size of Pageables.
      Parameters:
      defaultPageSize - The default page size.
      Returns:
      this
    • getMaxPageSize

      public int getMaxPageSize()
      Get the maximum size of pages.
      Returns:
      Maximum page size.
    • setMaxPageSize

      public RepositoryRestConfiguration setMaxPageSize(int maxPageSize)
      Set the maximum size of pages.
      Parameters:
      maxPageSize - Maximum page size.
      Returns:
      this
    • getPageParamName

      public String getPageParamName()
      Get the name of the URL query string parameter that indicates what page to return. Default is 'page'.
      Returns:
      Name of the query parameter used to indicate the page number to return.
    • setPageParamName

      public RepositoryRestConfiguration setPageParamName(String pageParamName)
      Set the name of the URL query string parameter that indicates what page to return.
      Parameters:
      pageParamName - Name of the query parameter used to indicate the page number to return.
      Returns:
      this
    • getLimitParamName

      public String getLimitParamName()
      Get the name of the URL query string parameter that indicates how many results to return at once. Default is 'limit'.
      Returns:
      Name of the query parameter used to indicate the maximum number of entries to return at a time.
    • setLimitParamName

      public RepositoryRestConfiguration setLimitParamName(String limitParamName)
      Set the name of the URL query string parameter that indicates how many results to return at once.
      Parameters:
      limitParamName - Name of the query parameter used to indicate the maximum number of entries to return at a time.
      Returns:
      this
    • getSortParamName

      public String getSortParamName()
      Get the name of the URL query string parameter that indicates what direction to sort results. Default is 'sort'.
      Returns:
      Name of the query string parameter used to indicate what field to sort on.
    • setSortParamName

      public RepositoryRestConfiguration setSortParamName(String sortParamName)
      Set the name of the URL query string parameter that indicates what direction to sort results.
      Parameters:
      sortParamName - Name of the query string parameter used to indicate what field to sort on.
      Returns:
      this
    • getDefaultMediaType

      public MediaType getDefaultMediaType()
      Get the MediaType to use as a default when none is specified.
      Returns:
      Default content type if none has been specified.
    • setDefaultMediaType

      public RepositoryRestConfiguration setDefaultMediaType(MediaType defaultMediaType)
      Set the MediaType to use as a default when none is specified.
      Parameters:
      defaultMediaType - default content type if none has been specified.
      Returns:
      this
    • useHalAsDefaultJsonMediaType

      public boolean useHalAsDefaultJsonMediaType()
      Returns whether HAL will be served as primary representation in case on application/json is requested. This defaults to true. If configured to false the legacy Spring Data representation will be rendered.
      Returns:
    • useHalAsDefaultJsonMediaType

      public RepositoryRestConfiguration useHalAsDefaultJsonMediaType(boolean useHalAsDefaultJsonMediaType)
      Configures whether HAL will be served as primary representation in case on application/json is requested. This defaults to true. If configured to false the legacy Spring Data representation will be rendered.
      Parameters:
      useHalAsDefaultJsonMediaType -
      Returns:
    • setReturnBodyForPutAndPost

      public RepositoryRestConfiguration setReturnBodyForPutAndPost(Boolean returnBody)
      Convenience method to activate returning response bodies for all PUT and POST requests, i.e. both creating and updating entities.
      Parameters:
      returnBody - can be null, expressing the decision shall be derived from the presence of an Accept header in the request.
      Returns:
    • isReturnBodyOnCreate

      @Deprecated public Boolean isReturnBodyOnCreate()
      Whether to return a response body after creating an entity.
      Returns:
      Boolean.TRUE to enforce returning a body on create, Boolean.FALSE otherwise. If null and an Accept header present in the request will cause a body being returned. If the Accept header is not present, no body will be rendered.
    • returnBodyOnCreate

      public boolean returnBodyOnCreate(String acceptHeader)
      Whether to return a response body after creating an entity considering the given accept header.
      Parameters:
      acceptHeader - can be null or empty.
      Returns:
    • setReturnBodyOnCreate

      public RepositoryRestConfiguration setReturnBodyOnCreate(Boolean returnBody)
      Set whether to return a response body after creating an entity.
      Parameters:
      returnBody - can be null, expressing the decision shall be derived from the presence of an Accept header in the request.
      Returns:
      this
    • isReturnBodyOnUpdate

      @Deprecated public Boolean isReturnBodyOnUpdate()
      Whether to return a response body after updating an entity.
      Returns:
      Boolean.TRUE to enforce returning a body on create, Boolean.FALSE otherwise. If null and an Accept header present in the request will cause a body being returned. If the Accept header is not present, no body will be rendered.
    • returnBodyOnUpdate

      public boolean returnBodyOnUpdate(String acceptHeader)
      Whether to return a response body after updating an entity considering the given accept header.
      Parameters:
      acceptHeader - can be null or empty.
      Returns:
    • setReturnBodyOnUpdate

      public RepositoryRestConfiguration setReturnBodyOnUpdate(Boolean returnBodyOnUpdate)
      Set whether to return a response body after updating an entity.
      Parameters:
      returnBodyOnUpdate - can be null, expressing the decision shall be derived from the presence of an Accept header in the request.
      Returns:
      this
    • returnBodyOnDelete

      public boolean returnBodyOnDelete(String acceptHeader)
      Whether to return a response body after deleting an entity considering the given accept header.
      Parameters:
      acceptHeader - can be null or empty.
      Returns:
      Since:
      4.1
    • setReturnBodyOnDelete

      public RepositoryRestConfiguration setReturnBodyOnDelete(Boolean returnBodyOnDelete)
      Set whether to return a response body after deleting an entity.
      Parameters:
      returnBodyOnDelete - can be null, expressing the decision shall be derived from the presence of an Accept header in the request.
      Returns:
      this
      Since:
      4.1
    • setResourceMappingForDomainType

      @Deprecated public ResourceMapping setResourceMappingForDomainType(Class<?> domainType)
      Deprecated.
      for removal in 3.5
      Start configuration a ResourceMapping for a specific domain type.
      Parameters:
      domainType - The Class of the domain type to configure a mapping for.
      Returns:
      A new ResourceMapping for configuring how a domain type is mapped.
    • getResourceMappingForDomainType

      @Deprecated public ResourceMapping getResourceMappingForDomainType(Class<?> domainType)
      Deprecated.
      for removal in 3.5
      Get the ResourceMapping for a specific domain type.
      Parameters:
      domainType - The Class of the domain type.
      Returns:
      A ResourceMapping for that domain type or null if none exists.
    • hasResourceMappingForDomainType

      @Deprecated public boolean hasResourceMappingForDomainType(Class<?> domainType)
      Deprecated.
      for removal in 3.5
      Whether there is a ResourceMapping for the given domain type.
      Parameters:
      domainType - The domain type to find a ResourceMapping for.
      Returns:
      true if a ResourceMapping exists for this domain class, false otherwise.
    • getDomainTypesResourceMappingConfiguration

      @Deprecated public ResourceMappingConfiguration getDomainTypesResourceMappingConfiguration()
      Deprecated.
      for removal in 3.5
      Get the ResourceMappingConfiguration that is currently configured.
      Returns:
    • setResourceMappingForRepository

      @Deprecated public ResourceMapping setResourceMappingForRepository(Class<?> repositoryInterface)
      Deprecated.
      for removal in 3.5
      Start configuration a ResourceMapping for a specific repository interface.
      Parameters:
      repositoryInterface - The Class of the repository interface to configure a mapping for.
      Returns:
      A new ResourceMapping for configuring how a repository interface is mapped.
    • getResourceMappingForRepository

      @Deprecated public ResourceMapping getResourceMappingForRepository(Class<?> repositoryInterface)
      Deprecated.
      for removal in 3.5
      Get the ResourceMapping for a specific repository interface.
      Parameters:
      repositoryInterface - The Class of the repository interface.
      Returns:
      A ResourceMapping for that repository interface or null if none exists.
    • hasResourceMappingForRepository

      @Deprecated public boolean hasResourceMappingForRepository(Class<?> repositoryInterface)
      Deprecated.
      for removal in 3.5
      Whether there is a ResourceMapping configured for this Repository class.
      Parameters:
      repositoryInterface -
      Returns:
    • findRepositoryMappingForPath

      @Deprecated public ResourceMapping findRepositoryMappingForPath(String path)
      Deprecated.
      for removal in 3.5
    • isIdExposedFor

      public boolean isIdExposedFor(Class<?> domainType)
      Should we expose the ID property for this domain type?
      Parameters:
      domainType - The domain type we may need to expose the ID for.
      Returns:
      true is the ID is to be exposed, false otherwise.
    • exposeIdsFor

      public RepositoryRestConfiguration exposeIdsFor(Class<?>... domainTypes)
      Set the list of domain types for which we will expose the ID value as a normal property.
      Parameters:
      domainTypes - Array of types to expose IDs for.
      Returns:
      this
    • projectionConfiguration

      @Deprecated public ProjectionDefinitionConfiguration projectionConfiguration()
      Deprecated.
      since 2.4, use getProjectionConfiguration() instead.
      Returns the ProjectionDefinitionConfiguration to register addition projections.
      Returns:
    • getProjectionConfiguration

      public ProjectionDefinitionConfiguration getProjectionConfiguration()
      Returns the ProjectionDefinitionConfiguration to register addition projections.
      Returns:
    • metadataConfiguration

      @Deprecated public MetadataConfiguration metadataConfiguration()
      Deprecated.
      since 2.4, use getMetadataConfiguration() instead.
      Returns the MetadataConfiguration to customize metadata exposure.
      Returns:
    • getMetadataConfiguration

      public MetadataConfiguration getMetadataConfiguration()
      Returns the MetadataConfiguration to customize metadata exposure.
      Returns:
    • setEnableEnumTranslation

      public RepositoryRestConfiguration setEnableEnumTranslation(boolean enableEnumTranslation)
      Configures whether to enable enum value translation via the Spring Data REST default resource bundle. Defaults to false for backwards compatibility reasons. Will use the fully qualified enum name as key. For further details see {code EnumTranslator}.
      Parameters:
      enableEnumTranslation -
      See Also:
    • isEnableEnumTranslation

      public boolean isEnableEnumTranslation()
      Returns whether enum value translation is enabled.
      Returns:
      Since:
      2.4
    • getEnumTranslationConfiguration

      public EnumTranslationConfiguration getEnumTranslationConfiguration()
      Returns the EnumTranslationConfiguration to be used.
      Returns:
      must not be null.
      Since:
      2.4
    • getRepositoryDetectionStrategy

      public RepositoryDetectionStrategy getRepositoryDetectionStrategy()
      Returns the RepositoryDetectionStrategy to be used to decide which repositories get exposed. Will be RepositoryDetectionStrategy.RepositoryDetectionStrategies.DEFAULT by default.
      Returns:
      will never be null.
      Since:
      2.5
      See Also:
    • setRepositoryDetectionStrategy

      public RepositoryRestConfiguration setRepositoryDetectionStrategy(RepositoryDetectionStrategy repositoryDetectionStrategy)
      Configures the RepositoryDetectionStrategy to be used to determine which repositories get exposed. Defaults to RepositoryDetectionStrategy.RepositoryDetectionStrategies.DEFAULT.
      Parameters:
      repositoryDetectionStrategy - can be null.
      Since:
      2.5
    • exposeRepositoryMethodsByDefault

      public boolean exposeRepositoryMethodsByDefault()
      Returns whether to expose repository methods by default.
      Since:
      3.1
      See Also:
    • setExposeRepositoryMethodsByDefault

      public void setExposeRepositoryMethodsByDefault(boolean exposeRepositoryMethodsByDefault)
      Sets whether to expose repository methods by default. If this is disabled, CRUD methods must be annotated with RestResource explicitly to expose the default set of resources (opt-in). If this is set to true (default), repository methods methods are exposed unless explictly annotated with RestResource and RestResource.exported() set to false.
      Since:
      3.1
      See Also:
    • disableDefaultExposure

      public void disableDefaultExposure()
      Disables the default exposure of repositories entirely. I.e. repositories to be exported must now be explicitly annotated with RepositoryRestResource and methods need to be annotated with RestResource to trigger exposure of default resources. Basically a shortcut for calling both setRepositoryDetectionStrategy(RepositoryDetectionStrategy) to RepositoryDetectionStrategy.RepositoryDetectionStrategies.ANNOTATED and setting setExposeRepositoryMethodsByDefault(boolean) to false.
      Since:
      3.1
      See Also:
    • withEntityLookup

      public EntityLookupRegistrar withEntityLookup()
      Returns the EntityLookupRegistrar to create custom EntityLookup instances registered in the configuration.
      Returns:
      the EntityLookupRegistrar to build custom EntityLookups.
      Since:
      2.5
    • getEntityLookups

      public List<EntityLookup<?>> getEntityLookups(Repositories repositories)
      Returns all EntityLookups considering the customizations made to the configuration.
      Parameters:
      repositories - must not be null.
      Returns:
    • isLookupType

      public boolean isLookupType(Class<?> type)
    • getRelProvider

      @Deprecated public LinkRelationProvider getRelProvider()
      Deprecated.
      since 3.5, use getLinkRelationProvider() instead.
      The LinkRelationProvider to be used to calculate the link relation defaults for repositories.
    • setRelProvider

      @Deprecated public void setRelProvider(LinkRelationProvider relProvider)
      Deprecated.
      The LinkRelationProvider to be used to calculate the link relation defaults for repositories.
    • getLinkRelationProvider

      public LinkRelationProvider getLinkRelationProvider()
      Returns the LinkRelationProvider configured to calculate the link relation defaults for repositories. Defaults to a delegating wrapper around an AnnotationLinkRelationProvider and EvoInflectorLinkRelationProvider.
      Returns:
      Since:
      3.5
      See Also:
    • setLinkRelationProvider

      public RepositoryRestConfiguration setLinkRelationProvider(LinkRelationProvider provider)
      Configures the LinkRelationProvider to be used to calculate the LinkRelation defaults for repositories. The provided instance will replace the default setup completely. For details on the defaults and setting up a similar, delegating arrangement, see getLinkRelationProvider().
      Parameters:
      provider - must not be null.
      Returns:
      the current instance
      Since:
      3.5
    • getExposureConfiguration

      public ExposureConfiguration getExposureConfiguration()