001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.data.rest;
018
019import org.springframework.boot.context.properties.ConfigurationProperties;
020import org.springframework.boot.context.properties.PropertyMapper;
021import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
022import org.springframework.data.rest.core.mapping.RepositoryDetectionStrategy.RepositoryDetectionStrategies;
023import org.springframework.http.MediaType;
024
025/**
026 * Configuration properties for Spring Data REST.
027 *
028 * @author Stephane Nicoll
029 * @since 1.3.0
030 */
031@ConfigurationProperties(prefix = "spring.data.rest")
032public class RepositoryRestProperties {
033
034        /**
035         * Base path to be used by Spring Data REST to expose repository resources.
036         */
037        private String basePath;
038
039        /**
040         * Default size of pages.
041         */
042        private Integer defaultPageSize;
043
044        /**
045         * Maximum size of pages.
046         */
047        private Integer maxPageSize;
048
049        /**
050         * Name of the URL query string parameter that indicates what page to return.
051         */
052        private String pageParamName;
053
054        /**
055         * Name of the URL query string parameter that indicates how many results to return at
056         * once.
057         */
058        private String limitParamName;
059
060        /**
061         * Name of the URL query string parameter that indicates what direction to sort
062         * results.
063         */
064        private String sortParamName;
065
066        /**
067         * Strategy to use to determine which repositories get exposed.
068         */
069        private RepositoryDetectionStrategies detectionStrategy = RepositoryDetectionStrategies.DEFAULT;
070
071        /**
072         * Content type to use as a default when none is specified.
073         */
074        private MediaType defaultMediaType;
075
076        /**
077         * Whether to return a response body after creating an entity.
078         */
079        private Boolean returnBodyOnCreate;
080
081        /**
082         * Whether to return a response body after updating an entity.
083         */
084        private Boolean returnBodyOnUpdate;
085
086        /**
087         * Whether to enable enum value translation through the Spring Data REST default
088         * resource bundle.
089         */
090        private Boolean enableEnumTranslation;
091
092        public String getBasePath() {
093                return this.basePath;
094        }
095
096        public void setBasePath(String basePath) {
097                this.basePath = basePath;
098        }
099
100        public Integer getDefaultPageSize() {
101                return this.defaultPageSize;
102        }
103
104        public void setDefaultPageSize(Integer defaultPageSize) {
105                this.defaultPageSize = defaultPageSize;
106        }
107
108        public Integer getMaxPageSize() {
109                return this.maxPageSize;
110        }
111
112        public void setMaxPageSize(Integer maxPageSize) {
113                this.maxPageSize = maxPageSize;
114        }
115
116        public String getPageParamName() {
117                return this.pageParamName;
118        }
119
120        public void setPageParamName(String pageParamName) {
121                this.pageParamName = pageParamName;
122        }
123
124        public String getLimitParamName() {
125                return this.limitParamName;
126        }
127
128        public void setLimitParamName(String limitParamName) {
129                this.limitParamName = limitParamName;
130        }
131
132        public String getSortParamName() {
133                return this.sortParamName;
134        }
135
136        public void setSortParamName(String sortParamName) {
137                this.sortParamName = sortParamName;
138        }
139
140        public RepositoryDetectionStrategies getDetectionStrategy() {
141                return this.detectionStrategy;
142        }
143
144        public void setDetectionStrategy(RepositoryDetectionStrategies detectionStrategy) {
145                this.detectionStrategy = detectionStrategy;
146        }
147
148        public MediaType getDefaultMediaType() {
149                return this.defaultMediaType;
150        }
151
152        public void setDefaultMediaType(MediaType defaultMediaType) {
153                this.defaultMediaType = defaultMediaType;
154        }
155
156        public Boolean getReturnBodyOnCreate() {
157                return this.returnBodyOnCreate;
158        }
159
160        public void setReturnBodyOnCreate(Boolean returnBodyOnCreate) {
161                this.returnBodyOnCreate = returnBodyOnCreate;
162        }
163
164        public Boolean getReturnBodyOnUpdate() {
165                return this.returnBodyOnUpdate;
166        }
167
168        public void setReturnBodyOnUpdate(Boolean returnBodyOnUpdate) {
169                this.returnBodyOnUpdate = returnBodyOnUpdate;
170        }
171
172        public Boolean getEnableEnumTranslation() {
173                return this.enableEnumTranslation;
174        }
175
176        public void setEnableEnumTranslation(Boolean enableEnumTranslation) {
177                this.enableEnumTranslation = enableEnumTranslation;
178        }
179
180        public void applyTo(RepositoryRestConfiguration rest) {
181                PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
182                map.from(this::getBasePath).to(rest::setBasePath);
183                map.from(this::getDefaultPageSize).to(rest::setDefaultPageSize);
184                map.from(this::getMaxPageSize).to(rest::setMaxPageSize);
185                map.from(this::getPageParamName).to(rest::setPageParamName);
186                map.from(this::getLimitParamName).to(rest::setLimitParamName);
187                map.from(this::getSortParamName).to(rest::setSortParamName);
188                map.from(this::getDetectionStrategy).to(rest::setRepositoryDetectionStrategy);
189                map.from(this::getDefaultMediaType).to(rest::setDefaultMediaType);
190                map.from(this::getReturnBodyOnCreate).to(rest::setReturnBodyOnCreate);
191                map.from(this::getReturnBodyOnUpdate).to(rest::setReturnBodyOnUpdate);
192                map.from(this::getEnableEnumTranslation).to(rest::setEnableEnumTranslation);
193        }
194
195}