Skip to content

Commit 7df6ffb

Browse files
committed
DATAES-362 - Polishing.
1 parent a42de9b commit 7df6ffb

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

src/main/java/org/springframework/data/elasticsearch/core/AbstractDefaultIndexOperations.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828
import org.springframework.core.annotation.AnnotatedElementUtils;
29-
import org.springframework.core.annotation.AnnotationAttributes;
3029
import org.springframework.dao.InvalidDataAccessApiUsageException;
3130
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
3231
import org.springframework.data.elasticsearch.annotations.Mapping;
@@ -44,7 +43,7 @@
4443

4544
/**
4645
* Base implementation of {@link IndexOperations} common to Transport and Rest based Implementations of IndexOperations.
47-
*
46+
*
4847
* @author Peter-Josef Meisch
4948
* @author Sascha Woo
5049
* @since 4.0
@@ -107,13 +106,10 @@ public Document createSettings(Class<?> clazz) {
107106

108107
Document settings = null;
109108

110-
if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) {
111-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class);
109+
Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class);
112110

113-
if (attributes != null) {
114-
String settingPath = attributes.getString("settingPath");
115-
settings = loadSettings(settingPath);
116-
}
111+
if (setting != null) {
112+
settings = loadSettings(setting.settingPath());
117113
}
118114

119115
if (settings == null) {
@@ -230,21 +226,18 @@ public Document createMapping(Class<?> clazz) {
230226
protected Document buildMapping(Class<?> clazz) {
231227

232228
// load mapping specified in Mapping annotation if present
233-
if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) {
234-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class);
235-
236-
if (attributes != null) {
237-
String mappingPath = attributes.getString("mappingPath");
229+
Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class);
230+
if (mappingAnnotation != null) {
231+
String mappingPath = mappingAnnotation.mappingPath();
238232

239-
if (StringUtils.hasText(mappingPath)) {
240-
String mappings = ResourceUtil.readFileFromClasspath(mappingPath);
233+
if (StringUtils.hasText(mappingPath)) {
234+
String mappings = ResourceUtil.readFileFromClasspath(mappingPath);
241235

242-
if (StringUtils.hasText(mappings)) {
243-
return Document.parse(mappings);
244-
}
245-
} else {
246-
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
236+
if (StringUtils.hasText(mappings)) {
237+
return Document.parse(mappings);
247238
}
239+
} else {
240+
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
248241
}
249242
}
250243

src/main/java/org/springframework/data/elasticsearch/core/DefaultReactiveIndexOperations.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,11 @@ public Mono<Document> createMapping() {
159159
@Override
160160
public Mono<Document> createMapping(Class<?> clazz) {
161161

162-
if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) {
163-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class);
162+
Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class);
164163

165-
if (attributes != null) {
166-
String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath();
167-
return loadDocument(mappingPath, "@Mapping");
168-
}
169-
}
164+
if (mappingAnnotation != null) {
165+
return loadDocument(mappingAnnotation.mappingPath(), "@Mapping");
166+
}
170167

171168
String mapping = new MappingBuilder(converter).buildPropertyMapping(clazz);
172169
return Mono.just(Document.parse(mapping));
@@ -204,14 +201,11 @@ public Mono<Document> createSettings() {
204201
@Override
205202
public Mono<Document> createSettings(Class<?> clazz) {
206203

207-
if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) {
208-
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class);
204+
Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class);
209205

210-
if (attributes != null) {
211-
String settingPath = attributes.getString("settingPath");
212-
return loadDocument(settingPath, "@Setting");
213-
}
214-
}
206+
if (setting != null) {
207+
return loadDocument(setting.settingPath(), "@Setting");
208+
}
215209

216210
return Mono.just(getRequiredPersistentEntity(clazz).getDefaultSettings());
217211
}

0 commit comments

Comments
 (0)