mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-362 - Polishing.
This commit is contained in:
parent
a42de9b51b
commit
7df6ffb5cd
@ -26,7 +26,6 @@ import org.elasticsearch.cluster.metadata.AliasMetadata;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||||
import org.springframework.core.annotation.AnnotationAttributes;
|
|
||||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
@ -44,7 +43,7 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Base implementation of {@link IndexOperations} common to Transport and Rest based Implementations of IndexOperations.
|
* Base implementation of {@link IndexOperations} common to Transport and Rest based Implementations of IndexOperations.
|
||||||
*
|
*
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
* @author Sascha Woo
|
* @author Sascha Woo
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
@ -107,13 +106,10 @@ abstract class AbstractDefaultIndexOperations implements IndexOperations {
|
|||||||
|
|
||||||
Document settings = null;
|
Document settings = null;
|
||||||
|
|
||||||
if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) {
|
Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class);
|
||||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class);
|
|
||||||
|
|
||||||
if (attributes != null) {
|
if (setting != null) {
|
||||||
String settingPath = attributes.getString("settingPath");
|
settings = loadSettings(setting.settingPath());
|
||||||
settings = loadSettings(settingPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
@ -230,21 +226,18 @@ abstract class AbstractDefaultIndexOperations implements IndexOperations {
|
|||||||
protected Document buildMapping(Class<?> clazz) {
|
protected Document buildMapping(Class<?> clazz) {
|
||||||
|
|
||||||
// load mapping specified in Mapping annotation if present
|
// load mapping specified in Mapping annotation if present
|
||||||
if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) {
|
Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class);
|
||||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class);
|
if (mappingAnnotation != null) {
|
||||||
|
String mappingPath = mappingAnnotation.mappingPath();
|
||||||
|
|
||||||
if (attributes != null) {
|
if (StringUtils.hasText(mappingPath)) {
|
||||||
String mappingPath = attributes.getString("mappingPath");
|
String mappings = ResourceUtil.readFileFromClasspath(mappingPath);
|
||||||
|
|
||||||
if (StringUtils.hasText(mappingPath)) {
|
if (StringUtils.hasText(mappings)) {
|
||||||
String mappings = ResourceUtil.readFileFromClasspath(mappingPath);
|
return Document.parse(mappings);
|
||||||
|
|
||||||
if (StringUtils.hasText(mappings)) {
|
|
||||||
return Document.parse(mappings);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.info("mappingPath in @Mapping has to be defined. Building mappings using @Field");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,14 +159,11 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Document> createMapping(Class<?> clazz) {
|
public Mono<Document> createMapping(Class<?> clazz) {
|
||||||
|
|
||||||
if (AnnotatedElementUtils.hasAnnotation(clazz, Mapping.class)) {
|
Mapping mappingAnnotation = AnnotatedElementUtils.findMergedAnnotation(clazz, Mapping.class);
|
||||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Mapping.class);
|
|
||||||
|
|
||||||
if (attributes != null) {
|
if (mappingAnnotation != null) {
|
||||||
String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath();
|
return loadDocument(mappingAnnotation.mappingPath(), "@Mapping");
|
||||||
return loadDocument(mappingPath, "@Mapping");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String mapping = new MappingBuilder(converter).buildPropertyMapping(clazz);
|
String mapping = new MappingBuilder(converter).buildPropertyMapping(clazz);
|
||||||
return Mono.just(Document.parse(mapping));
|
return Mono.just(Document.parse(mapping));
|
||||||
@ -204,14 +201,11 @@ class DefaultReactiveIndexOperations implements ReactiveIndexOperations {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Document> createSettings(Class<?> clazz) {
|
public Mono<Document> createSettings(Class<?> clazz) {
|
||||||
|
|
||||||
if (AnnotatedElementUtils.hasAnnotation(clazz, Setting.class)) {
|
Setting setting = AnnotatedElementUtils.findMergedAnnotation(clazz, Setting.class);
|
||||||
AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes(clazz, Setting.class);
|
|
||||||
|
|
||||||
if (attributes != null) {
|
if (setting != null) {
|
||||||
String settingPath = attributes.getString("settingPath");
|
return loadDocument(setting.settingPath(), "@Setting");
|
||||||
return loadDocument(settingPath, "@Setting");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Mono.just(getRequiredPersistentEntity(clazz).getDefaultSettings());
|
return Mono.just(getRequiredPersistentEntity(clazz).getDefaultSettings());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user