|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.core;
|
17 | 17 |
|
18 |
| -import static org.apache.commons.lang.StringUtils.isBlank; |
19 |
| -import static org.apache.commons.lang.StringUtils.isNotBlank; |
20 | 18 | import static org.elasticsearch.client.Requests.refreshRequest;
|
21 | 19 | import static org.elasticsearch.index.VersionType.EXTERNAL;
|
22 | 20 | import static org.elasticsearch.index.query.QueryBuilders.moreLikeThisQuery;
|
23 | 21 | import static org.elasticsearch.index.query.QueryBuilders.wrapperQuery;
|
24 | 22 | import static org.springframework.data.elasticsearch.core.MappingBuilder.buildMapping;
|
25 | 23 | import static org.springframework.util.CollectionUtils.isEmpty;
|
| 24 | +import static org.springframework.util.StringUtils.hasText; |
26 | 25 |
|
27 | 26 | import java.io.BufferedReader;
|
28 | 27 | import java.io.IOException;
|
29 | 28 | import java.io.InputStreamReader;
|
30 | 29 | import java.util.*;
|
31 | 30 | import java.util.stream.Collectors;
|
32 | 31 |
|
33 |
| -import org.apache.commons.lang.StringUtils; |
34 | 32 | import org.apache.http.util.EntityUtils;
|
35 | 33 | import org.elasticsearch.action.ActionFuture;
|
36 | 34 | import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
|
122 | 120 | import com.fasterxml.jackson.core.type.TypeReference;
|
123 | 121 | import com.fasterxml.jackson.databind.JsonNode;
|
124 | 122 | import com.fasterxml.jackson.databind.ObjectMapper;
|
| 123 | +import org.springframework.util.StringUtils; |
125 | 124 |
|
126 | 125 | /**
|
127 | 126 | * ElasticsearchRestTemplate
|
@@ -213,9 +212,9 @@ public boolean createIndex(String indexName) {
|
213 | 212 | public <T> boolean putMapping(Class<T> clazz) {
|
214 | 213 | if (clazz.isAnnotationPresent(Mapping.class)) {
|
215 | 214 | String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath();
|
216 |
| - if (isNotBlank(mappingPath)) { |
| 215 | + if (hasText(mappingPath)) { |
217 | 216 | String mappings = readFileFromClasspath(mappingPath);
|
218 |
| - if (isNotBlank(mappings)) { |
| 217 | + if (hasText(mappings)) { |
219 | 218 | return putMapping(clazz, mappings);
|
220 | 219 | }
|
221 | 220 | } else {
|
@@ -671,9 +670,9 @@ public UpdateResponse update(UpdateQuery query) {
|
671 | 670 | }
|
672 | 671 |
|
673 | 672 | private UpdateRequest prepareUpdate(UpdateQuery query) {
|
674 |
| - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() |
| 673 | + String indexName = hasText(query.getIndexName()) ? query.getIndexName() |
675 | 674 | : getPersistentEntityFor(query.getClazz()).getIndexName();
|
676 |
| - String type = isNotBlank(query.getType()) ? query.getType() |
| 675 | + String type = hasText(query.getType()) ? query.getType() |
677 | 676 | : getPersistentEntityFor(query.getClazz()).getIndexType();
|
678 | 677 | Assert.notNull(indexName, "No index defined for Query");
|
679 | 678 | Assert.notNull(type, "No type define for Query");
|
@@ -803,9 +802,9 @@ public <T> String delete(Class<T> clazz, String id) {
|
803 | 802 | @Override
|
804 | 803 | public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) {
|
805 | 804 |
|
806 |
| - String indexName = isNotBlank(deleteQuery.getIndex()) ? deleteQuery.getIndex() |
| 805 | + String indexName = hasText(deleteQuery.getIndex()) ? deleteQuery.getIndex() |
807 | 806 | : getPersistentEntityFor(clazz).getIndexName();
|
808 |
| - String typeName = isNotBlank(deleteQuery.getType()) ? deleteQuery.getType() |
| 807 | + String typeName = hasText(deleteQuery.getType()) ? deleteQuery.getType() |
809 | 808 | : getPersistentEntityFor(clazz).getIndexType();
|
810 | 809 | Integer pageSize = deleteQuery.getPageSize() != null ? deleteQuery.getPageSize() : 1000;
|
811 | 810 | Long scrollTimeInMillis = deleteQuery.getScrollTimeInMillis() != null ? deleteQuery.getScrollTimeInMillis()
|
@@ -1001,8 +1000,8 @@ public void clearScroll(String scrollId) {
|
1001 | 1000 | public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) {
|
1002 | 1001 |
|
1003 | 1002 | ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
1004 |
| - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); |
1005 |
| - String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType(); |
| 1003 | + String indexName = hasText(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); |
| 1004 | + String type = hasText(query.getType()) ? query.getType() : persistentEntity.getIndexType(); |
1006 | 1005 |
|
1007 | 1006 | Assert.notNull(indexName, "No 'indexName' defined for MoreLikeThisQuery");
|
1008 | 1007 | Assert.notNull(type, "No 'type' defined for MoreLikeThisQuery");
|
@@ -1102,9 +1101,9 @@ private <T> boolean createIndexIfNotCreated(Class<T> clazz) {
|
1102 | 1101 | private <T> boolean createIndexWithSettings(Class<T> clazz) {
|
1103 | 1102 | if (clazz.isAnnotationPresent(Setting.class)) {
|
1104 | 1103 | String settingPath = clazz.getAnnotation(Setting.class).settingPath();
|
1105 |
| - if (isNotBlank(settingPath)) { |
| 1104 | + if (hasText(settingPath)) { |
1106 | 1105 | String settings = readFileFromClasspath(settingPath);
|
1107 |
| - if (isNotBlank(settings)) { |
| 1106 | + if (hasText(settings)) { |
1108 | 1107 | return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings);
|
1109 | 1108 | }
|
1110 | 1109 | } else {
|
@@ -1179,7 +1178,7 @@ private Map<String, String> convertSettingResponse(String settingResponse, Strin
|
1179 | 1178 | Map<String, String> result = new HashMap<String, String>();
|
1180 | 1179 | Set<String> keySet = settings.keySet();
|
1181 | 1180 | for (String key : keySet) {
|
1182 |
| - result.put(StringUtils.substringAfter(key, prefix), settings.get(key)); |
| 1181 | + result.put(key.substring(prefix.length()), settings.get(key)); |
1183 | 1182 | }
|
1184 | 1183 | return result;
|
1185 | 1184 | } catch (IOException e) {
|
@@ -1254,16 +1253,16 @@ private SearchRequest prepareSearch(Query query, Optional<QueryBuilder> builder)
|
1254 | 1253 |
|
1255 | 1254 | private IndexRequest prepareIndex(IndexQuery query) {
|
1256 | 1255 | try {
|
1257 |
| - String indexName = isBlank(query.getIndexName()) |
| 1256 | + String indexName = StringUtils.isEmpty(query.getIndexName()) |
1258 | 1257 | ? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0]
|
1259 | 1258 | : query.getIndexName();
|
1260 |
| - String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] |
| 1259 | + String type = StringUtils.isEmpty(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] |
1261 | 1260 | : query.getType();
|
1262 | 1261 |
|
1263 | 1262 | IndexRequest indexRequest = null;
|
1264 | 1263 |
|
1265 | 1264 | if (query.getObject() != null) {
|
1266 |
| - String id = isBlank(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); |
| 1265 | + String id = StringUtils.isEmpty(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); |
1267 | 1266 | // If we have a query id and a document id, do not ask ES to generate one.
|
1268 | 1267 | if (id != null) {
|
1269 | 1268 | indexRequest = new IndexRequest(indexName, type, id);
|
@@ -1321,11 +1320,11 @@ public Boolean addAlias(AliasQuery query) {
|
1321 | 1320 | aliasAction.filter(query.getFilterBuilder());
|
1322 | 1321 | } else if (query.getFilter() != null) {
|
1323 | 1322 | aliasAction.filter(query.getFilter());
|
1324 |
| - } else if (isNotBlank(query.getRouting())) { |
| 1323 | + } else if (hasText(query.getRouting())) { |
1325 | 1324 | aliasAction.routing(query.getRouting());
|
1326 |
| - } else if (isNotBlank(query.getSearchRouting())) { |
| 1325 | + } else if (hasText(query.getSearchRouting())) { |
1327 | 1326 | aliasAction.searchRouting(query.getSearchRouting());
|
1328 |
| - } else if (isNotBlank(query.getIndexRouting())) { |
| 1327 | + } else if (hasText(query.getIndexRouting())) { |
1329 | 1328 | aliasAction.indexRouting(query.getIndexRouting());
|
1330 | 1329 | }
|
1331 | 1330 |
|
|
0 commit comments