Commit ed333a67 authored by Stephane Nicoll's avatar Stephane Nicoll

Expose Spring Data Rest RepositoryDetectionStrategy

Closes gh-7113
parent d57f3afd
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.rest; ...@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.rest;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
/** /**
...@@ -61,6 +62,12 @@ public class RepositoryRestProperties { ...@@ -61,6 +62,12 @@ public class RepositoryRestProperties {
*/ */
private String sortParamName; private String sortParamName;
/**
* Strategy to use to determine which repositories get exposed.
*/
private RepositoryDetectionStrategies detectionStrategy =
RepositoryDetectionStrategies.DEFAULT;
/** /**
* Content type to use as a default when none is specified. * Content type to use as a default when none is specified.
*/ */
...@@ -130,6 +137,14 @@ public class RepositoryRestProperties { ...@@ -130,6 +137,14 @@ public class RepositoryRestProperties {
this.sortParamName = sortParamName; this.sortParamName = sortParamName;
} }
public RepositoryDetectionStrategies getDetectionStrategy() {
return this.detectionStrategy;
}
public void setDetectionStrategy(RepositoryDetectionStrategies detectionStrategy) {
this.detectionStrategy = detectionStrategy;
}
public MediaType getDefaultMediaType() { public MediaType getDefaultMediaType() {
return this.defaultMediaType; return this.defaultMediaType;
} }
...@@ -181,6 +196,9 @@ public class RepositoryRestProperties { ...@@ -181,6 +196,9 @@ public class RepositoryRestProperties {
if (this.sortParamName != null) { if (this.sortParamName != null) {
configuration.setSortParamName(this.sortParamName); configuration.setSortParamName(this.sortParamName);
} }
if (this.detectionStrategy != null) {
configuration.setRepositoryDetectionStrategy(this.detectionStrategy);
}
if (this.defaultMediaType != null) { if (this.defaultMediaType != null) {
configuration.setDefaultMediaType(this.defaultMediaType); configuration.setDefaultMediaType(this.defaultMediaType);
} }
......
...@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Bean; ...@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
import org.springframework.data.rest.webmvc.BaseUri; import org.springframework.data.rest.webmvc.BaseUri;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -94,6 +95,7 @@ public class RepositoryRestMvcAutoConfigurationTests { ...@@ -94,6 +95,7 @@ public class RepositoryRestMvcAutoConfigurationTests {
"spring.data.rest.page-param-name:_page", "spring.data.rest.page-param-name:_page",
"spring.data.rest.limit-param-name:_limit", "spring.data.rest.limit-param-name:_limit",
"spring.data.rest.sort-param-name:_sort", "spring.data.rest.sort-param-name:_sort",
"spring.data.rest.detection-strategy=visibility",
"spring.data.rest.default-media-type:application/my-json", "spring.data.rest.default-media-type:application/my-json",
"spring.data.rest.return-body-on-create:false", "spring.data.rest.return-body-on-create:false",
"spring.data.rest.return-body-on-update:false", "spring.data.rest.return-body-on-update:false",
...@@ -107,6 +109,8 @@ public class RepositoryRestMvcAutoConfigurationTests { ...@@ -107,6 +109,8 @@ public class RepositoryRestMvcAutoConfigurationTests {
assertThat(bean.getPageParamName()).isEqualTo("_page"); assertThat(bean.getPageParamName()).isEqualTo("_page");
assertThat(bean.getLimitParamName()).isEqualTo("_limit"); assertThat(bean.getLimitParamName()).isEqualTo("_limit");
assertThat(bean.getSortParamName()).isEqualTo("_sort"); assertThat(bean.getSortParamName()).isEqualTo("_sort");
assertThat(bean.getRepositoryDetectionStrategy())
.isEqualTo(RepositoryDetectionStrategies.VISIBILITY);
assertThat(bean.getDefaultMediaType()) assertThat(bean.getDefaultMediaType())
.isEqualTo(MediaType.parseMediaType("application/my-json")); .isEqualTo(MediaType.parseMediaType("application/my-json"));
assertThat(bean.returnBodyOnCreate(null)).isFalse(); assertThat(bean.returnBodyOnCreate(null)).isFalse();
......
...@@ -576,6 +576,7 @@ content into your application; rather pick only the properties that you need. ...@@ -576,6 +576,7 @@ content into your application; rather pick only the properties that you need.
# DATA REST ({sc-spring-boot-autoconfigure}/data/rest/RepositoryRestProperties.{sc-ext}[RepositoryRestProperties]) # DATA REST ({sc-spring-boot-autoconfigure}/data/rest/RepositoryRestProperties.{sc-ext}[RepositoryRestProperties])
spring.data.rest.base-path= # Base path to be used by Spring Data REST to expose repository resources. spring.data.rest.base-path= # Base path to be used by Spring Data REST to expose repository resources.
spring.data.rest.default-page-size= # Default size of pages. spring.data.rest.default-page-size= # Default size of pages.
spring.data.rest.detection-strategy=default # Strategy to use to determine which repositories get exposed.
spring.data.rest.enable-enum-translation= # Enable enum value translation via the Spring Data REST default resource bundle. spring.data.rest.enable-enum-translation= # Enable enum value translation via the Spring Data REST default resource bundle.
spring.data.rest.limit-param-name= # Name of the URL query string parameter that indicates how many results to return at once. spring.data.rest.limit-param-name= # Name of the URL query string parameter that indicates how many results to return at once.
spring.data.rest.max-page-size= # Maximum size of pages. spring.data.rest.max-page-size= # Maximum size of pages.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment