Skip to content

Commit d72ee18

Browse files
committed
DATES-666 - Rebase 4.0.x onto master and merge.
1 parent d3295a6 commit d72ee18

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

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

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
import org.springframework.data.elasticsearch.ElasticsearchException;
66
import org.springframework.data.elasticsearch.annotations.Mapping;
77
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
8-
import org.springframework.util.Assert;
8+
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
99
import org.springframework.util.StringUtils;
1010

1111
/**
1212
* AbstractElasticsearchTemplate
13-
*
13+
*
1414
* @author Sascha Woo
1515
*/
1616
public abstract class AbstractElasticsearchTemplate {
@@ -19,12 +19,6 @@ public abstract class AbstractElasticsearchTemplate {
1919

2020
protected ElasticsearchConverter elasticsearchConverter;
2121

22-
public AbstractElasticsearchTemplate(ElasticsearchConverter elasticsearchConverter) {
23-
24-
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
25-
this.elasticsearchConverter = elasticsearchConverter;
26-
}
27-
2822
protected String buildMapping(Class<?> clazz) {
2923

3024
// load mapping specified in Mapping annotation if present

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
102102
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
103103
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
104-
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
105104
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
106105
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
107106
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@@ -162,8 +161,8 @@ public ElasticsearchRestTemplate(RestHighLevelClient client) {
162161
new DefaultResultMapper(mappingElasticsearchConverter.getMappingContext()));
163162
}
164163

165-
public ElasticsearchRestTemplate(RestHighLevelClient client,
166-
ElasticsearchConverter elasticsearchConverter, EntityMapper entityMapper) {
164+
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
165+
EntityMapper entityMapper) {
167166
initialize(client, elasticsearchConverter,
168167
new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper));
169168
}
@@ -172,14 +171,12 @@ public ElasticsearchRestTemplate(RestHighLevelClient client, ResultsMapper resul
172171
initialize(client, createElasticsearchConverter(), resultsMapper);
173172
}
174173

175-
public ElasticsearchRestTemplate(RestHighLevelClient client,
176-
ElasticsearchConverter elasticsearchConverter) {
177-
initialize(client, elasticsearchConverter,
178-
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
174+
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter) {
175+
initialize(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
179176
}
180177

181-
public ElasticsearchRestTemplate(RestHighLevelClient client,
182-
ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
178+
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
179+
ResultsMapper resultsMapper) {
183180
initialize(client, elasticsearchConverter, resultsMapper);
184181
}
185182

@@ -190,9 +187,8 @@ private MappingElasticsearchConverter createElasticsearchConverter() {
190187
private void initialize(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
191188
ResultsMapper resultsMapper) {
192189

193-
super(elasticsearchConverter);
194-
195190
Assert.notNull(client, "Client must not be null!");
191+
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
196192
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
197193

198194
this.client = client;

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
8989
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
9090
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
91-
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
9291
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
9392
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
9493
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@@ -128,7 +127,8 @@
128127
* @deprecated as of 4.0
129128
*/
130129
@Deprecated
131-
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
130+
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
131+
implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
132132

133133
private static final Logger QUERY_LOGGER = LoggerFactory
134134
.getLogger("org.springframework.data.elasticsearch.core.QUERY");
@@ -155,8 +155,7 @@ public ElasticsearchTemplate(Client client, ResultsMapper resultsMapper) {
155155
}
156156

157157
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) {
158-
this(client, elasticsearchConverter,
159-
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
158+
this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
160159
}
161160

162161
private MappingElasticsearchConverter createElasticsearchConverter() {
@@ -166,17 +165,16 @@ private MappingElasticsearchConverter createElasticsearchConverter() {
166165
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter,
167166
ResultsMapper resultsMapper) {
168167

169-
super(elasticsearchConverter);
170-
171168
initialize(client, elasticsearchConverter, resultsMapper);
172169
}
173170

174-
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter,
175-
ResultsMapper resultsMapper) {
171+
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
176172
Assert.notNull(client, "Client must not be null!");
173+
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
177174
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
178175

179176
this.client = client;
177+
this.elasticsearchConverter = elasticsearchConverter;
180178
this.resultsMapper = resultsMapper;
181179
}
182180

src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import lombok.NoArgsConstructor;
2929

3030
import java.io.IOException;
31+
import java.lang.Double;
32+
import java.lang.Integer;
33+
import java.lang.Long;
34+
import java.lang.Object;
3135
import java.util.ArrayList;
3236
import java.util.Arrays;
3337
import java.util.Collection;
@@ -80,6 +84,7 @@
8084
import org.springframework.data.elasticsearch.annotations.ScriptedField;
8185
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
8286
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
87+
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
8388
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
8489
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
8590
import org.springframework.data.elasticsearch.core.query.*;
@@ -1667,12 +1672,14 @@ public void shouldReturnHighlightedFieldsInScroll() {
16671672
SearchResultMapper searchResultMapper = new SearchResultMapper() {
16681673
@Override
16691674
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
1670-
DefaultEntityMapper defaultEntityMapper = new DefaultEntityMapper(new SimpleElasticsearchMappingContext());
1675+
MappingElasticsearchConverter mappingElasticsearchConverter = new MappingElasticsearchConverter(
1676+
new SimpleElasticsearchMappingContext());
16711677
ArrayList<T> result = new ArrayList<>();
16721678

16731679
for (SearchHit searchHit : response.getHits()) {
16741680
try {
1675-
result.add((T) defaultEntityMapper.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
1681+
result
1682+
.add((T) mappingElasticsearchConverter.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
16761683
} catch (IOException e) {
16771684
e.printStackTrace();
16781685
}
@@ -1688,8 +1695,8 @@ public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz,
16881695
assertThat(highlightFieldMessage.fragments()[0].toString()).isEqualTo(highlightedMessage);
16891696
}
16901697

1691-
return new AggregatedPageImpl<>(result, pageable, response.getHits().getTotalHits(), response.getAggregations(),
1692-
response.getScrollId(), response.getHits().getMaxScore());
1698+
return new AggregatedPageImpl<T>(result, pageable, response.getHits().getTotalHits().value,
1699+
response.getAggregations(), response.getScrollId(), response.getHits().getMaxScore());
16931700
}
16941701

16951702
@Override

0 commit comments

Comments
 (0)