Class RepositoryRestConfiguration
java.lang.Object
org.springframework.data.rest.core.config.RepositoryRestConfiguration
Spring Data REST configuration options.
- Author:
- Jon Brisbin, Oliver Gierke, Jeremy Rickard, Greg Turnquist, Mark Paluch
-
Constructor Summary
ConstructorsConstructorDescriptionRepositoryRestConfiguration(ProjectionDefinitionConfiguration projectionConfiguration, MetadataConfiguration metadataConfiguration, EnumTranslationConfiguration enumTranslationConfiguration) Creates a newRepositoryRestConfigurationwith the givenProjectionDefinitionConfiguration. -
Method Summary
Modifier and TypeMethodDescriptionvoidDisables the default exposure of repositories entirely.exposeIdsFor(Class<?>... domainTypes) Set the list of domain types for which we will expose the ID value as a normal property.booleanReturns whether to expose repository methods by default.Deprecated.for removal in 3.5The base path to expose repository resources under.Deprecated.usegetBasePath()instead.Get theMediaTypeto use as a default when none is specified.intGet the default size ofPageables.Deprecated.for removal in 3.5List<EntityLookup<?>>getEntityLookups(Repositories repositories) Returns allEntityLookups considering the customizations made to the configuration.Returns theEnumTranslationConfigurationto be used.Get the name of the URL query string parameter that indicates how many results to return at once.Returns theLinkRelationProviderconfigured to calculate the link relation defaults for repositories.intGet the maximum size of pages.Returns theMetadataConfigurationto customize metadata exposure.Get the name of the URL query string parameter that indicates what page to return.Returns theProjectionDefinitionConfigurationto register addition projections.Deprecated.since 3.5, usegetLinkRelationProvider()instead.Returns theRepositoryDetectionStrategyto be used to decide which repositories get exposed.getResourceMappingForDomainType(Class<?> domainType) Deprecated.for removal in 3.5getResourceMappingForRepository(Class<?> repositoryInterface) Deprecated.for removal in 3.5Get the name of the URL query string parameter that indicates what direction to sort results.booleanhasResourceMappingForDomainType(Class<?> domainType) Deprecated.for removal in 3.5booleanhasResourceMappingForRepository(Class<?> repositoryInterface) Deprecated.for removal in 3.5booleanReturns whether enum value translation is enabled.booleanisIdExposedFor(Class<?> domainType) Should we expose the ID property for this domain type?booleanisLookupType(Class<?> type) Deprecated.Deprecated.Deprecated.since 2.4, usegetMetadataConfiguration()instead.Deprecated.since 2.4, usegetProjectionConfiguration()instead.booleanreturnBodyOnCreate(String acceptHeader) Whether to return a response body after creating an entity considering the given accept header.booleanreturnBodyOnDelete(String acceptHeader) Whether to return a response body after deleting an entity considering the given accept header.booleanreturnBodyOnUpdate(String acceptHeader) Whether to return a response body after updating an entity considering the given accept header.setBasePath(String basePath) Configures the base path to be used by Spring Data REST to expose repository resources.setDefaultMediaType(MediaType defaultMediaType) Set theMediaTypeto use as a default when none is specified.setDefaultPageSize(int defaultPageSize) Set the default size ofPageables.setEnableEnumTranslation(boolean enableEnumTranslation) Configures whether to enable enum value translation via the Spring Data REST default resource bundle.voidsetExposeRepositoryMethodsByDefault(boolean exposeRepositoryMethodsByDefault) Sets whether to expose repository methods by default.setLimitParamName(String limitParamName) Set the name of the URL query string parameter that indicates how many results to return at once.setLinkRelationProvider(LinkRelationProvider provider) Configures theLinkRelationProviderto be used to calculate theLinkRelationdefaults for repositories.setMaxPageSize(int maxPageSize) Set the maximum size of pages.setPageParamName(String pageParamName) Set the name of the URL query string parameter that indicates what page to return.voidsetRelProvider(LinkRelationProvider relProvider) Deprecated.since 3.5, usesetLinkRelationProvider(LinkRelationProvider)instead.setRepositoryDetectionStrategy(RepositoryDetectionStrategy repositoryDetectionStrategy) Configures theRepositoryDetectionStrategyto be used to determine which repositories get exposed.setResourceMappingForDomainType(Class<?> domainType) Deprecated.for removal in 3.5setResourceMappingForRepository(Class<?> repositoryInterface) Deprecated.for removal in 3.5setReturnBodyForPutAndPost(Boolean returnBody) Convenience method to activate returning response bodies for allPUTandPOSTrequests, i.e. both creating and updating entities.setReturnBodyOnCreate(Boolean returnBody) Set whether to return a response body after creating an entity.setReturnBodyOnDelete(Boolean returnBodyOnDelete) Set whether to return a response body after deleting an entity.setReturnBodyOnUpdate(Boolean returnBodyOnUpdate) Set whether to return a response body after updating an entity.setSortParamName(String sortParamName) Set the name of the URL query string parameter that indicates what direction to sort results.booleanReturns whether HAL will be served as primary representation in case onapplication/jsonis requested.useHalAsDefaultJsonMediaType(boolean useHalAsDefaultJsonMediaType) Configures whether HAL will be served as primary representation in case onapplication/jsonis requested.Returns theEntityLookupRegistrarto create customEntityLookupinstances registered in the configuration.
-
Constructor Details
-
RepositoryRestConfiguration
public RepositoryRestConfiguration(ProjectionDefinitionConfiguration projectionConfiguration, MetadataConfiguration metadataConfiguration, EnumTranslationConfiguration enumTranslationConfiguration) Creates a newRepositoryRestConfigurationwith the givenProjectionDefinitionConfiguration.- Parameters:
projectionConfiguration- must not be null.metadataConfiguration- must not be null.enumTranslationConfiguration- must not be null.
-
-
Method Details
-
getBaseUri
Deprecated.usegetBasePath()instead.The base URI against which the exporter should calculate its links.- Returns:
- The base URI.
-
getBasePath
The base path to expose repository resources under.- Returns:
- the basePath
-
setBasePath
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 ofPageables. Default is 20.- Returns:
- The default page size.
-
setDefaultPageSize
Set the default size ofPageables.- Parameters:
defaultPageSize- The default page size.- Returns:
- this
-
getMaxPageSize
public int getMaxPageSize()Get the maximum size of pages.- Returns:
- Maximum page size.
-
setMaxPageSize
Set the maximum size of pages.- Parameters:
maxPageSize- Maximum page size.- Returns:
- this
-
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
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
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
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
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
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
Get theMediaTypeto use as a default when none is specified.- Returns:
- Default content type if none has been specified.
-
setDefaultMediaType
Set theMediaTypeto 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 onapplication/jsonis 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 onapplication/jsonis requested. This defaults to true. If configured to false the legacy Spring Data representation will be rendered.- Parameters:
useHalAsDefaultJsonMediaType-- Returns:
-
setReturnBodyForPutAndPost
Convenience method to activate returning response bodies for allPUTandPOSTrequests, i.e. both creating and updating entities.- Parameters:
returnBody- can be null, expressing the decision shall be derived from the presence of anAcceptheader in the request.- Returns:
-
isReturnBodyOnCreate
Deprecated.Whether to return a response body after creating an entity.- Returns:
Boolean.TRUEto enforce returning a body on create,Boolean.FALSEotherwise. If null and anAcceptheader present in the request will cause a body being returned. If theAcceptheader is not present, no body will be rendered.
-
returnBodyOnCreate
Whether to return a response body after creating an entity considering the given accept header.- Parameters:
acceptHeader- can be null or empty.- Returns:
-
setReturnBodyOnCreate
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 anAcceptheader in the request.- Returns:
- this
-
isReturnBodyOnUpdate
Deprecated.Whether to return a response body after updating an entity.- Returns:
Boolean.TRUEto enforce returning a body on create,Boolean.FALSEotherwise. If null and anAcceptheader present in the request will cause a body being returned. If theAcceptheader is not present, no body will be rendered.
-
returnBodyOnUpdate
Whether to return a response body after updating an entity considering the given accept header.- Parameters:
acceptHeader- can be null or empty.- Returns:
-
setReturnBodyOnUpdate
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 anAcceptheader in the request.- Returns:
- this
-
returnBodyOnDelete
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
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 anAcceptheader in the request.- Returns:
- this
- Since:
- 4.1
-
setResourceMappingForDomainType
Deprecated.for removal in 3.5Start configuration aResourceMappingfor a specific domain type.- Parameters:
domainType- TheClassof the domain type to configure a mapping for.- Returns:
- A new
ResourceMappingfor configuring how a domain type is mapped.
-
getResourceMappingForDomainType
Deprecated.for removal in 3.5Get theResourceMappingfor a specific domain type.- Parameters:
domainType- TheClassof the domain type.- Returns:
- A
ResourceMappingfor that domain type or null if none exists.
-
hasResourceMappingForDomainType
Deprecated.for removal in 3.5Whether there is aResourceMappingfor the given domain type.- Parameters:
domainType- The domain type to find aResourceMappingfor.- Returns:
- true if a
ResourceMappingexists for this domain class, false otherwise.
-
getDomainTypesResourceMappingConfiguration
Deprecated.for removal in 3.5Get theResourceMappingConfigurationthat is currently configured.- Returns:
-
setResourceMappingForRepository
Deprecated.for removal in 3.5Start configuration aResourceMappingfor a specific repository interface.- Parameters:
repositoryInterface- TheClassof the repository interface to configure a mapping for.- Returns:
- A new
ResourceMappingfor configuring how a repository interface is mapped.
-
getResourceMappingForRepository
Deprecated.for removal in 3.5Get theResourceMappingfor a specific repository interface.- Parameters:
repositoryInterface- TheClassof the repository interface.- Returns:
- A
ResourceMappingfor that repository interface or null if none exists.
-
hasResourceMappingForRepository
Deprecated.for removal in 3.5Whether there is aResourceMappingconfigured for this Repository class.- Parameters:
repositoryInterface-- Returns:
-
findRepositoryMappingForPath
Deprecated.for removal in 3.5 -
isIdExposedFor
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
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.since 2.4, usegetProjectionConfiguration()instead.Returns theProjectionDefinitionConfigurationto register addition projections.- Returns:
-
getProjectionConfiguration
Returns theProjectionDefinitionConfigurationto register addition projections.- Returns:
-
metadataConfiguration
Deprecated.since 2.4, usegetMetadataConfiguration()instead.Returns theMetadataConfigurationto customize metadata exposure.- Returns:
-
getMetadataConfiguration
Returns theMetadataConfigurationto customize metadata exposure.- Returns:
-
setEnableEnumTranslation
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
Returns theEnumTranslationConfigurationto be used.- Returns:
- must not be null.
- Since:
- 2.4
-
getRepositoryDetectionStrategy
Returns theRepositoryDetectionStrategyto be used to decide which repositories get exposed. Will beRepositoryDetectionStrategy.RepositoryDetectionStrategies.DEFAULTby default.- Returns:
- will never be null.
- Since:
- 2.5
- See Also:
-
setRepositoryDetectionStrategy
public RepositoryRestConfiguration setRepositoryDetectionStrategy(RepositoryDetectionStrategy repositoryDetectionStrategy) Configures theRepositoryDetectionStrategyto be used to determine which repositories get exposed. Defaults toRepositoryDetectionStrategy.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 withRestResourceexplicitly to expose the default set of resources (opt-in). If this is set to true (default), repository methods methods are exposed unless explictly annotated withRestResourceandRestResource.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 withRepositoryRestResourceand methods need to be annotated withRestResourceto trigger exposure of default resources. Basically a shortcut for calling bothsetRepositoryDetectionStrategy(RepositoryDetectionStrategy)toRepositoryDetectionStrategy.RepositoryDetectionStrategies.ANNOTATEDand settingsetExposeRepositoryMethodsByDefault(boolean)to false. -
withEntityLookup
Returns theEntityLookupRegistrarto create customEntityLookupinstances registered in the configuration.- Returns:
- the
EntityLookupRegistrarto build customEntityLookups. - Since:
- 2.5
-
getEntityLookups
Returns allEntityLookups considering the customizations made to the configuration.- Parameters:
repositories- must not be null.- Returns:
-
isLookupType
-
getRelProvider
Deprecated.since 3.5, usegetLinkRelationProvider()instead.TheLinkRelationProviderto be used to calculate the link relation defaults for repositories. -
setRelProvider
Deprecated.since 3.5, usesetLinkRelationProvider(LinkRelationProvider)instead.TheLinkRelationProviderto be used to calculate the link relation defaults for repositories. -
getLinkRelationProvider
Returns theLinkRelationProviderconfigured to calculate the link relation defaults for repositories. Defaults to a delegating wrapper around anAnnotationLinkRelationProviderandEvoInflectorLinkRelationProvider.- Returns:
- Since:
- 3.5
- See Also:
-
setLinkRelationProvider
Configures theLinkRelationProviderto be used to calculate theLinkRelationdefaults for repositories. The provided instance will replace the default setup completely. For details on the defaults and setting up a similar, delegating arrangement, seegetLinkRelationProvider().- Parameters:
provider- must not be null.- Returns:
- the current instance
- Since:
- 3.5
-
getExposureConfiguration
-