From 26eba0311638f2f983918a1e8105dfb2714aaed1 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 20 Jun 2018 20:30:40 +0200 Subject: [PATCH] DATAES-283 - Get rid of Commons Lang dependency. Replace all StringUtils and ArrayUtils usages with Springframework's StringUtils and ObjectUtils. Left the commons-lang as test-scope dependency as I believe it brings some values in the tests. Original pull request: #211. --- pom.xml | 1 + .../client/NodeClientFactoryBean.java | 8 ++- .../client/TransportClientFactoryBean.java | 23 ++++--- .../core/AbstractResultMapper.java | 5 +- .../core/DefaultResultMapper.java | 4 +- .../core/ElasticsearchTemplate.java | 62 ++++++++++++------- .../elasticsearch/core/MappingBuilder.java | 22 ++++--- .../facet/request/HistogramFacetRequest.java | 4 +- .../core/facet/request/RangeFacetRequest.java | 6 +- .../request/StatisticalFacetRequest.java | 4 +- .../core/facet/request/TermFacetRequest.java | 12 ++-- .../elasticsearch/core/query/Criteria.java | 22 ++++--- 12 files changed, 102 insertions(+), 71 deletions(-) diff --git a/pom.xml b/pom.xml index 5d1ddfc18..4de789aaf 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,7 @@ commons-lang commons-lang ${commonslang} + test diff --git a/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java b/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java index 717e2895a..5a3517287 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java @@ -15,10 +15,12 @@ */ package org.springframework.data.elasticsearch.client; +import static java.util.Arrays.*; + import java.io.IOException; import java.io.InputStream; import java.util.Collection; -import org.apache.commons.lang.StringUtils; + import org.elasticsearch.client.Client; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; @@ -31,7 +33,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import static java.util.Arrays.*; +import org.springframework.util.StringUtils; /** * NodeClientFactoryBean @@ -96,7 +98,7 @@ public class NodeClientFactoryBean implements FactoryBean, InitializingB } private Settings loadConfig() throws IOException { - if (StringUtils.isNotBlank(pathConfiguration)) { + if (!StringUtils.isEmpty(pathConfiguration)) { InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration); if (stream != null) { return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build(); diff --git a/src/main/java/org/springframework/data/elasticsearch/client/TransportClientFactoryBean.java b/src/main/java/org/springframework/data/elasticsearch/client/TransportClientFactoryBean.java index 515608183..eaf3e5d8f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/client/TransportClientFactoryBean.java +++ b/src/main/java/org/springframework/data/elasticsearch/client/TransportClientFactoryBean.java @@ -15,8 +15,6 @@ */ package org.springframework.data.elasticsearch.client; -import static org.apache.commons.lang.StringUtils.*; - import io.netty.util.ThreadDeathWatcher; import io.netty.util.concurrent.GlobalEventExecutor; @@ -48,6 +46,7 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; /** * TransportClientFactoryBean @@ -108,13 +107,19 @@ public class TransportClientFactoryBean implements FactoryBean, client = new SpringDataTransportClient(settings()); Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing."); - for (String clusterNode : split(clusterNodes, COMMA)) { - String hostName = substringBeforeLast(clusterNode, COLON); - String port = substringAfterLast(clusterNode, COLON); - Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'"); - Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'"); - logger.info("adding transport node : " + clusterNode); - client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port))); + String[] clusterNodesArray = StringUtils.split(clusterNodes, COMMA); + if (clusterNodesArray != null) { + for (String clusterNode : clusterNodesArray) { + if (clusterNode != null) { + int colonPosition = clusterName.lastIndexOf(COLON); + String hostName = colonPosition != -1 ? clusterNode.substring(0, colonPosition) : clusterNode; + String port = colonPosition != -1 ? clusterNode.substring(colonPosition, clusterNode.length()) : ""; + Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'"); + Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'"); + logger.info("adding transport node : " + clusterNode); + client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port))); + } + } } client.connectedNodes(); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractResultMapper.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractResultMapper.java index 0f8a16829..667bdccb5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractResultMapper.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractResultMapper.java @@ -15,11 +15,10 @@ */ package org.springframework.data.elasticsearch.core; -import static org.apache.commons.lang.StringUtils.*; - import java.io.IOException; import org.springframework.data.elasticsearch.ElasticsearchException; +import org.springframework.util.StringUtils; /** * @author Artur Konczak @@ -33,7 +32,7 @@ public abstract class AbstractResultMapper implements ResultsMapper { } public T mapEntity(String source, Class clazz) { - if (isBlank(source)) { + if (StringUtils.isEmpty(source)) { return null; } try { diff --git a/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java b/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java index a1c8b013a..e78e1c7bd 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/DefaultResultMapper.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetResponse; @@ -40,6 +39,7 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; import org.springframework.data.mapping.context.MappingContext; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; @@ -84,7 +84,7 @@ public class DefaultResultMapper extends AbstractResultMapper { for (SearchHit hit : response.getHits()) { if (hit != null) { T result = null; - if (StringUtils.isNotBlank(hit.sourceAsString())) { + if (StringUtils.hasText(hit.sourceAsString())) { result = mapEntity(hit.sourceAsString(), clazz); } else { result = mapEntity(hit.getFields().values(), clazz); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java index 1b1642043..2b3936840 100755 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java @@ -15,6 +15,12 @@ */ package org.springframework.data.elasticsearch.core; +import static org.elasticsearch.client.Requests.*; +import static org.elasticsearch.index.VersionType.*; +import static org.elasticsearch.index.query.QueryBuilders.*; +import static org.springframework.data.elasticsearch.core.MappingBuilder.*; +import static org.springframework.util.CollectionUtils.isEmpty; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -26,6 +32,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; + import org.elasticsearch.action.ListenableActionFuture; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; @@ -86,15 +93,24 @@ import org.springframework.data.elasticsearch.core.facet.FacetRequest; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext; -import org.springframework.data.elasticsearch.core.query.*; +import org.springframework.data.elasticsearch.core.query.AliasQuery; +import org.springframework.data.elasticsearch.core.query.CriteriaQuery; +import org.springframework.data.elasticsearch.core.query.DeleteQuery; +import org.springframework.data.elasticsearch.core.query.FetchSourceFilter; +import org.springframework.data.elasticsearch.core.query.GetQuery; +import org.springframework.data.elasticsearch.core.query.IndexBoost; +import org.springframework.data.elasticsearch.core.query.IndexQuery; +import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.Query; +import org.springframework.data.elasticsearch.core.query.ScriptField; +import org.springframework.data.elasticsearch.core.query.SearchQuery; +import org.springframework.data.elasticsearch.core.query.SourceFilter; +import org.springframework.data.elasticsearch.core.query.StringQuery; +import org.springframework.data.elasticsearch.core.query.UpdateQuery; import org.springframework.data.util.CloseableIterator; import org.springframework.util.Assert; -import static org.apache.commons.lang.StringUtils.*; -import static org.elasticsearch.client.Requests.*; -import static org.elasticsearch.index.VersionType.*; -import static org.elasticsearch.index.query.QueryBuilders.*; -import static org.springframework.data.elasticsearch.core.MappingBuilder.*; -import static org.springframework.util.CollectionUtils.isEmpty; +import org.springframework.util.StringUtils; /** * ElasticsearchTemplate @@ -178,9 +194,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati public boolean putMapping(Class clazz) { if (clazz.isAnnotationPresent(Mapping.class)) { String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath(); - if (isNotBlank(mappingPath)) { + if (StringUtils.hasText(mappingPath)) { String mappings = readFileFromClasspath(mappingPath); - if (isNotBlank(mappings)) { + if (StringUtils.hasText(mappings)) { return putMapping(clazz, mappings); } } else { @@ -564,9 +580,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati } private UpdateRequestBuilder prepareUpdate(UpdateQuery query) { - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() + String indexName = StringUtils.hasText(query.getIndexName()) ? query.getIndexName() : getPersistentEntityFor(query.getClazz()).getIndexName(); - String type = isNotBlank(query.getType()) ? query.getType() + String type = StringUtils.hasText(query.getType()) ? query.getType() : getPersistentEntityFor(query.getClazz()).getIndexType(); Assert.notNull(indexName, "No index defined for Query"); Assert.notNull(type, "No type define for Query"); @@ -666,9 +682,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati @Override public void delete(DeleteQuery deleteQuery, Class clazz) { - String indexName = isNotBlank(deleteQuery.getIndex()) ? deleteQuery.getIndex() + String indexName = StringUtils.hasText(deleteQuery.getIndex()) ? deleteQuery.getIndex() : getPersistentEntityFor(clazz).getIndexName(); - String typeName = isNotBlank(deleteQuery.getType()) ? deleteQuery.getType() + String typeName = StringUtils.hasText(deleteQuery.getType()) ? deleteQuery.getType() : getPersistentEntityFor(clazz).getIndexType(); Integer pageSize = deleteQuery.getPageSize() != null ? deleteQuery.getPageSize() : 1000; Long scrollTimeInMillis = deleteQuery.getScrollTimeInMillis() != null ? deleteQuery.getScrollTimeInMillis() @@ -825,8 +841,8 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati public Page moreLikeThis(MoreLikeThisQuery query, Class clazz) { ElasticsearchPersistentEntity persistentEntity = getPersistentEntityFor(clazz); - String indexName = isNotBlank(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); - String type = isNotBlank(query.getType()) ? query.getType() : persistentEntity.getIndexType(); + String indexName = StringUtils.hasText(query.getIndexName()) ? query.getIndexName() : persistentEntity.getIndexName(); + String type = StringUtils.hasText(query.getType()) ? query.getType() : persistentEntity.getIndexType(); Assert.notNull(indexName, "No 'indexName' defined for MoreLikeThisQuery"); Assert.notNull(type, "No 'type' defined for MoreLikeThisQuery"); @@ -921,9 +937,9 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati private boolean createIndexWithSettings(Class clazz) { if (clazz.isAnnotationPresent(Setting.class)) { String settingPath = clazz.getAnnotation(Setting.class).settingPath(); - if (isNotBlank(settingPath)) { + if (StringUtils.hasText(settingPath)) { String settings = readFileFromClasspath(settingPath); - if (isNotBlank(settings)) { + if (StringUtils.hasText(settings)) { return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings); } } else { @@ -1026,15 +1042,15 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati private IndexRequestBuilder prepareIndex(IndexQuery query) { try { - String indexName = isBlank(query.getIndexName()) + String indexName = StringUtils.isEmpty(query.getIndexName()) ? retrieveIndexNameFromPersistentEntity(query.getObject().getClass())[0] : query.getIndexName(); - String type = isBlank(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] + String type = StringUtils.isEmpty(query.getType()) ? retrieveTypeFromPersistentEntity(query.getObject().getClass())[0] : query.getType(); IndexRequestBuilder indexRequestBuilder = null; if (query.getObject() != null) { - String id = isBlank(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); + String id = StringUtils.isEmpty(query.getId()) ? getPersistentEntityId(query.getObject()) : query.getId(); // If we have a query id and a document id, do not ask ES to generate one. if (id != null) { indexRequestBuilder = client.prepareIndex(indexName, type, id); @@ -1084,11 +1100,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati aliasAction.filter(query.getFilterBuilder()); } else if (query.getFilter() != null) { aliasAction.filter(query.getFilter()); - } else if (isNotBlank(query.getRouting())) { + } else if (StringUtils.hasText(query.getRouting())) { aliasAction.routing(query.getRouting()); - } else if (isNotBlank(query.getSearchRouting())) { + } else if (StringUtils.hasText(query.getSearchRouting())) { aliasAction.searchRouting(query.getSearchRouting()); - } else if (isNotBlank(query.getIndexRouting())) { + } else if (StringUtils.hasText(query.getIndexRouting())) { aliasAction.indexRouting(query.getIndexRouting()); } return client.admin().indices().prepareAliases().addAliasAction(aliasAction).execute().actionGet().isAcknowledged(); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java index 78fd60498..6ad291e8e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/MappingBuilder.java @@ -15,11 +15,15 @@ */ package org.springframework.data.elasticsearch.core; +import static org.elasticsearch.common.xcontent.XContentFactory.*; +import static org.springframework.util.StringUtils.*; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; + import org.elasticsearch.common.xcontent.XContentBuilder; import org.springframework.core.ResolvableType; import org.springframework.core.io.ClassPathResource; @@ -37,9 +41,7 @@ import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.mapping.model.SimpleTypeHolder; import org.springframework.data.util.ClassTypeInformation; import org.springframework.data.util.TypeInformation; -import static org.apache.commons.lang.StringUtils.*; -import static org.elasticsearch.common.xcontent.XContentFactory.*; -import static org.springframework.util.StringUtils.*; +import org.springframework.util.StringUtils; /** * @author Rizwan Idrees @@ -88,7 +90,7 @@ class MappingBuilder { // Properties XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES); - mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null); + mapEntity(xContentBuilder, clazz, true, idFieldName, "", false, FieldType.Auto, null); return xContentBuilder.endObject().endObject().endObject(); } @@ -119,7 +121,7 @@ class MappingBuilder { if (field.isAnnotationPresent(Mapping.class)) { String mappingPath = field.getAnnotation(Mapping.class).mappingPath(); - if (isNotBlank(mappingPath)) { + if (StringUtils.hasText(mappingPath)) { ClassPathResource mappings = new ClassPathResource(mappingPath); if (mappings.exists()) { xContentBuilder.rawField(field.getName(), mappings.getInputStream()); @@ -137,7 +139,7 @@ class MappingBuilder { continue; } boolean nestedOrObject = isNestedOrObjectField(field); - mapEntity(xContentBuilder, getFieldType(field), false, EMPTY, field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class)); + mapEntity(xContentBuilder, getFieldType(field), false, "", field.getName(), nestedOrObject, singleField.type(), field.getAnnotation(Field.class)); if (nestedOrObject) { continue; } @@ -203,10 +205,10 @@ class MappingBuilder { xContentBuilder.field(COMPLETION_MAX_INPUT_LENGTH, annotation.maxInputLength()); xContentBuilder.field(COMPLETION_PRESERVE_POSITION_INCREMENTS, annotation.preservePositionIncrements()); xContentBuilder.field(COMPLETION_PRESERVE_SEPARATORS, annotation.preserveSeparators()); - if (isNotBlank(annotation.searchAnalyzer())) { + if (StringUtils.hasText(annotation.searchAnalyzer())) { xContentBuilder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer()); } - if (isNotBlank(annotation.analyzer())) { + if (StringUtils.hasText(annotation.analyzer())) { xContentBuilder.field(FIELD_INDEX_ANALYZER, annotation.analyzer()); } } @@ -311,10 +313,10 @@ class MappingBuilder { if (!index) { builder.field(FIELD_INDEX, index); } - if (isNotBlank(analyzer)) { + if (StringUtils.hasText(analyzer)) { builder.field(FIELD_INDEX_ANALYZER, analyzer); } - if (isNotBlank(searchAnalyzer)) { + if (StringUtils.hasText(searchAnalyzer)) { builder.field(FIELD_SEARCH_ANALYZER, searchAnalyzer); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/HistogramFacetRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/HistogramFacetRequest.java index 6ba538155..d367bb599 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/HistogramFacetRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/HistogramFacetRequest.java @@ -16,13 +16,13 @@ package org.springframework.data.elasticsearch.core.facet.request; -import org.apache.commons.lang.StringUtils; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** @@ -54,7 +54,7 @@ public class HistogramFacetRequest extends AbstractFacetRequest { public AbstractAggregationBuilder getFacet() { Assert.notNull(getName(), "Facet name can't be a null !!!"); - Assert.isTrue(StringUtils.isNotBlank(field), "Please select field on which to build the facet !!!"); + Assert.isTrue(StringUtils.hasText(field), "Please select field on which to build the facet !!!"); Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!"); DateHistogramAggregationBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(getName()); diff --git a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java index 5f7139a27..24c3e6540 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/RangeFacetRequest.java @@ -19,12 +19,12 @@ package org.springframework.data.elasticsearch.core.facet.request; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.StringUtils; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder; import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** @@ -77,7 +77,7 @@ public class RangeFacetRequest extends AbstractFacetRequest { Assert.notNull(getName(), "Facet name can't be a null !!!"); RangeAggregationBuilder rangeBuilder = AggregationBuilders.range(getName()); - final String field = StringUtils.isNotBlank(keyField) ? keyField : this.field; + final String field = StringUtils.hasText(keyField) ? keyField : this.field; rangeBuilder.field(field); for (Entry entry : entries) { @@ -86,7 +86,7 @@ public class RangeFacetRequest extends AbstractFacetRequest { } rangeBuilder.subAggregation(AggregationBuilders.extendedStats(INTERNAL_STATS).field(field)); - if(StringUtils.isNotBlank(valueField)){ + if(StringUtils.hasText(valueField)){ rangeBuilder.subAggregation(AggregationBuilders.sum(RANGE_INTERNAL_SUM).field(valueField)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/StatisticalFacetRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/StatisticalFacetRequest.java index 85496b349..ce1430b75 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/StatisticalFacetRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/StatisticalFacetRequest.java @@ -16,11 +16,11 @@ package org.springframework.data.elasticsearch.core.facet.request; -import org.apache.commons.lang.StringUtils; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** @@ -47,7 +47,7 @@ public class StatisticalFacetRequest extends AbstractFacetRequest { public AbstractAggregationBuilder getFacet() { Assert.notNull(getName(), "Facet name can't be a null !!!"); - Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!"); + Assert.isTrue(StringUtils.hasText(field) && fields == null, "Please select field or fields on which to build the facets !!!"); return AggregationBuilders.extendedStats(getName()).field(field); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/TermFacetRequest.java b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/TermFacetRequest.java index 1cf99384d..acecdcbf6 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/facet/request/TermFacetRequest.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/facet/request/TermFacetRequest.java @@ -16,8 +16,6 @@ package org.springframework.data.elasticsearch.core.facet.request; -import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; import org.apache.lucene.util.automaton.RegExp; import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -26,6 +24,8 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude; import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest; import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; /** @@ -48,8 +48,8 @@ public class TermFacetRequest extends AbstractFacetRequest { } public void setFields(String... fields) { - Assert.isTrue(ArrayUtils.isNotEmpty(fields), "Term agg need one field only"); - Assert.isTrue(ArrayUtils.getLength(fields) == 1, "Term agg need one field only"); + Assert.isTrue(!ObjectUtils.isEmpty(fields), "Term agg need one field only"); + Assert.isTrue(fields.length == 1, "Term agg need one field only"); this.fields = fields; } @@ -92,7 +92,7 @@ public class TermFacetRequest extends AbstractFacetRequest { default: termsBuilder.order(Terms.Order.count(true)); } - if (ArrayUtils.isNotEmpty(excludeTerms)) { + if (!ObjectUtils.isEmpty(excludeTerms)) { termsBuilder.includeExclude(new IncludeExclude(null,excludeTerms)); } @@ -100,7 +100,7 @@ public class TermFacetRequest extends AbstractFacetRequest { termsBuilder.size(Integer.MAX_VALUE); } - if (StringUtils.isNotBlank(regex)) { + if (StringUtils.hasText(regex)) { termsBuilder.includeExclude(new IncludeExclude(new RegExp(regex),null)); } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java b/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java index 687cf7492..d35588850 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/query/Criteria.java @@ -15,9 +15,14 @@ */ package org.springframework.data.elasticsearch.core.query; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; -import org.apache.commons.lang.StringUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.elasticsearch.core.geo.GeoBox; import org.springframework.data.elasticsearch.core.geo.GeoPoint; @@ -25,6 +30,7 @@ import org.springframework.data.geo.Box; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Point; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Criteria is the central class when constructing queries. It follows more or less a fluent API style, which allows to @@ -42,8 +48,8 @@ public class Criteria { "field=" + field.getName() + ", boost=" + boost + ", negating=" + negating + - ", queryCriteria=" + StringUtils.join(queryCriteria, '|') + - ", filterCriteria=" + StringUtils.join(filterCriteria, '|') + + ", queryCriteria=" + StringUtils.collectionToDelimitedString(queryCriteria, "|") + + ", filterCriteria=" + StringUtils.collectionToDelimitedString(filterCriteria, "|") + '}'; } @@ -437,7 +443,7 @@ public class Criteria { * @return */ public Criteria within(String geoLocation, String distance) { - Assert.isTrue(StringUtils.isNotBlank(geoLocation), "geoLocation value must not be null"); + Assert.isTrue(StringUtils.hasText(geoLocation), "geoLocation value must not be null"); filterCriteria.add(new CriteriaEntry(OperationKey.WITHIN, new Object[]{geoLocation, distance})); return this; } @@ -474,8 +480,8 @@ public class Criteria { * @return Criteria the chaind criteria with the new 'boundedBy' criteria included. */ public Criteria boundedBy(String topLeftGeohash, String bottomRightGeohash) { - Assert.isTrue(StringUtils.isNotBlank(topLeftGeohash), "topLeftGeohash must not be empty"); - Assert.isTrue(StringUtils.isNotBlank(bottomRightGeohash), "bottomRightGeohash must not be empty"); + Assert.isTrue(StringUtils.hasText(topLeftGeohash), "topLeftGeohash must not be empty"); + Assert.isTrue(StringUtils.hasText(bottomRightGeohash), "bottomRightGeohash must not be empty"); filterCriteria.add(new CriteriaEntry(OperationKey.BBOX, new Object[]{topLeftGeohash, bottomRightGeohash})); return this; } @@ -502,7 +508,7 @@ public class Criteria { } private void assertNoBlankInWildcardedQuery(String searchString, boolean leadingWildcard, boolean trailingWildcard) { - if (StringUtils.contains(searchString, CRITERIA_VALUE_SEPERATOR)) { + if (searchString != null && searchString.contains(CRITERIA_VALUE_SEPERATOR)) { throw new InvalidDataAccessApiUsageException("Cannot constructQuery '" + (leadingWildcard ? "*" : "") + "\"" + searchString + "\"" + (trailingWildcard ? "*" : "") + "'. Use expression or multiple clauses instead."); }