|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.core;
|
17 | 17 |
|
| 18 | +import static org.elasticsearch.client.Requests.*; |
| 19 | +import static org.elasticsearch.index.VersionType.*; |
| 20 | +import static org.elasticsearch.index.query.QueryBuilders.*; |
| 21 | +import static org.springframework.data.elasticsearch.core.MappingBuilder.*; |
| 22 | +import static org.springframework.util.CollectionUtils.isEmpty; |
| 23 | + |
18 | 24 | import java.io.BufferedReader;
|
19 | 25 | import java.io.IOException;
|
20 | 26 | import java.io.InputStreamReader;
|
|
26 | 32 | import java.util.List;
|
27 | 33 | import java.util.Map;
|
28 | 34 | import java.util.NoSuchElementException;
|
| 35 | + |
29 | 36 | import org.elasticsearch.action.ListenableActionFuture;
|
30 | 37 | import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
31 | 38 | import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
|
|
86 | 93 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
87 | 94 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
88 | 95 | import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
89 |
| -import org.springframework.data.elasticsearch.core.query.*; |
| 96 | +import org.springframework.data.elasticsearch.core.query.AliasQuery; |
| 97 | +import org.springframework.data.elasticsearch.core.query.CriteriaQuery; |
| 98 | +import org.springframework.data.elasticsearch.core.query.DeleteQuery; |
| 99 | +import org.springframework.data.elasticsearch.core.query.FetchSourceFilter; |
| 100 | +import org.springframework.data.elasticsearch.core.query.GetQuery; |
| 101 | +import org.springframework.data.elasticsearch.core.query.IndexBoost; |
| 102 | +import org.springframework.data.elasticsearch.core.query.IndexQuery; |
| 103 | +import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; |
| 104 | +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; |
| 105 | +import org.springframework.data.elasticsearch.core.query.Query; |
| 106 | +import org.springframework.data.elasticsearch.core.query.ScriptField; |
| 107 | +import org.springframework.data.elasticsearch.core.query.SearchQuery; |
| 108 | +import org.springframework.data.elasticsearch.core.query.SourceFilter; |
| 109 | +import org.springframework.data.elasticsearch.core.query.StringQuery; |
| 110 | +import org.springframework.data.elasticsearch.core.query.UpdateQuery; |
90 | 111 | import org.springframework.data.util.CloseableIterator;
|
91 | 112 | import org.springframework.util.Assert;
|
92 |
| -import static org.apache.commons.lang.StringUtils.*; |
93 |
| -import static org.elasticsearch.client.Requests.*; |
94 |
| -import static org.elasticsearch.index.VersionType.*; |
95 |
| -import static org.elasticsearch.index.query.QueryBuilders.*; |
96 |
| -import static org.springframework.data.elasticsearch.core.MappingBuilder.*; |
97 |
| -import static org.springframework.util.CollectionUtils.isEmpty; |
| 113 | +import org.springframework.util.StringUtils; |
98 | 114 |
|
99 | 115 | /**
|
100 | 116 | * ElasticsearchTemplate
|
@@ -178,9 +194,9 @@ public boolean createIndex(String indexName) {
|
178 | 194 | public <T> boolean putMapping(Class<T> clazz) {
|
179 | 195 | if (clazz.isAnnotationPresent(Mapping.class)) {
|
180 | 196 | String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath();
|
181 |
| - if (isNotBlank(mappingPath)) { |
| 197 | + if (StringUtils.hasText(mappingPath)) { |
182 | 198 | String mappings = readFileFromClasspath(mappingPath);
|
183 |
| - if (isNotBlank(mappings)) { |
| 199 | + if (StringUtils.hasText(mappings)) { |
184 | 200 | return putMapping(clazz, mappings);
|
185 | 201 | }
|
186 | 202 | } else {
|
@@ -564,9 +580,9 @@ public UpdateResponse update(UpdateQuery query) {
|
564 | 580 | }
|
565 | 581 |
|
566 | 582 | private UpdateRequestBuilder prepareUpdate(UpdateQuery query) {
|
567 |
| - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() |
| 583 | + String indexName = StringUtils.hasText(query.getIndexName()) ? query.getIndexName() |
568 | 584 | : getPersistentEntityFor(query.getClazz()).getIndexName();
|
569 |
| - String type = isNotBlank(query.getType()) ? query.getType() |
| 585 | + String type = StringUtils.hasText(query.getType()) ? query.getType() |
570 | 586 | : getPersistentEntityFor(query.getClazz()).getIndexType();
|
571 | 587 | Assert.notNull(indexName, "No index defined for Query");
|
572 | 588 | Assert.notNull(type, "No type define for Query");
|
@@ -666,9 +682,9 @@ public <T> String delete(Class<T> clazz, String id) {
|
666 | 682 | @Override
|
667 | 683 | public <T> void delete(DeleteQuery deleteQuery, Class<T> clazz) {
|
668 | 684 |
|
669 |
| - String indexName = isNotBlank(deleteQuery.getIndex()) ? deleteQuery.getIndex() |
| 685 | + String indexName = StringUtils.hasText(deleteQuery.getIndex()) ? deleteQuery.getIndex() |
670 | 686 | : getPersistentEntityFor(clazz).getIndexName();
|
671 |
| - String typeName = isNotBlank(deleteQuery.getType()) ? deleteQuery.getType() |
| 687 | + String typeName = StringUtils.hasText(deleteQuery.getType()) ? deleteQuery.getType() |
672 | 688 | : getPersistentEntityFor(clazz).getIndexType();
|
673 | 689 | Integer pageSize = deleteQuery.getPageSize() != null ? deleteQuery.getPageSize() : 1000;
|
674 | 690 | Long scrollTimeInMillis = deleteQuery.getScrollTimeInMillis() != null ? deleteQuery.getScrollTimeInMillis()
|
@@ -825,8 +841,8 @@ public void clearScroll(String scrollId) {
|
825 | 841 | public <T> Page<T> moreLikeThis(MoreLikeThisQuery query, Class<T> clazz) {
|
826 | 842 |
|
827 | 843 | ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz);
|
828 |
| - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); |
829 |
| - String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType(); |
| 844 | + String indexName = StringUtils.hasText(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); |
| 845 | + String type = StringUtils.hasText(query.getType()) ? query.getType() : persistentEntity.getIndexType(); |
830 | 846 |
|
831 | 847 | Assert.notNull(indexName, "No 'indexName' defined for MoreLikeThisQuery");
|
832 | 848 | Assert.notNull(type, "No 'type' defined for MoreLikeThisQuery");
|
@@ -921,9 +937,9 @@ private <T> boolean createIndexIfNotCreated(Class<T> clazz) {
|
921 | 937 | private <T> boolean createIndexWithSettings(Class<T> clazz) {
|
922 | 938 | if (clazz.isAnnotationPresent(Setting.class)) {
|
923 | 939 | String settingPath = clazz.getAnnotation(Setting.class).settingPath();
|
924 |
| - if (isNotBlank(settingPath)) { |
| 940 | + if (StringUtils.hasText(settingPath)) { |
925 | 941 | String settings = readFileFromClasspath(settingPath);
|
926 |
| - if (isNotBlank(settings)) { |
| 942 | + if (StringUtils.hasText(settings)) { |
927 | 943 | return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings);
|
928 | 944 | }
|
929 | 945 | } else {
|
@@ -1026,15 +1042,15 @@ else if (order.getNullHandling() == Sort.NullHandling.NULLS_LAST) {
|
1026 | 1042 |
|
1027 | 1043 | private IndexRequestBuilder prepareIndex(IndexQuery query) {
|
1028 | 1044 | try {
|
1029 |
| - String indexName = isBlank(query.getIndexName()) |
| 1045 | + String indexName = StringUtils.isEmpty(query.getIndexName()) |
1030 | 1046 | ? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0] : query.getIndexName();
|
1031 |
| - String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] |
| 1047 | + String type = StringUtils.isEmpty(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] |
1032 | 1048 | : query.getType();
|
1033 | 1049 |
|
1034 | 1050 | IndexRequestBuilder indexRequestBuilder = null;
|
1035 | 1051 |
|
1036 | 1052 | if (query.getObject() != null) {
|
1037 |
| - String id = isBlank(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); |
| 1053 | + String id = StringUtils.isEmpty(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); |
1038 | 1054 | // If we have a query id and a document id, do not ask ES to generate one.
|
1039 | 1055 | if (id != null) {
|
1040 | 1056 | indexRequestBuilder = client.prepareIndex(indexName, type, id);
|
@@ -1084,11 +1100,11 @@ public Boolean addAlias(AliasQuery query) {
|
1084 | 1100 | aliasAction.filter(query.getFilterBuilder());
|
1085 | 1101 | } else if (query.getFilter() != null) {
|
1086 | 1102 | aliasAction.filter(query.getFilter());
|
1087 |
| - } else if (isNotBlank(query.getRouting())) { |
| 1103 | + } else if (StringUtils.hasText(query.getRouting())) { |
1088 | 1104 | aliasAction.routing(query.getRouting());
|
1089 |
| - } else if (isNotBlank(query.getSearchRouting())) { |
| 1105 | + } else if (StringUtils.hasText(query.getSearchRouting())) { |
1090 | 1106 | aliasAction.searchRouting(query.getSearchRouting());
|
1091 |
| - } else if (isNotBlank(query.getIndexRouting())) { |
| 1107 | + } else if (StringUtils.hasText(query.getIndexRouting())) { |
1092 | 1108 | aliasAction.indexRouting(query.getIndexRouting());
|
1093 | 1109 | }
|
1094 | 1110 | return client.admin().indices().prepareAliases().addAliasAction(aliasAction).execute().actionGet().isAcknowledged();
|
|
0 commit comments