syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skylar...@apache.org
Subject [syncope] branch master updated: [SYNCOPE-1437] Fixed error while searching for users / groups / any objects with Elasticsearch when no data are present
Date Wed, 20 Feb 2019 10:42:18 GMT
This is an automated email from the ASF dual-hosted git repository.

skylark17 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new f3db2f0  [SYNCOPE-1437] Fixed error while searching for users / groups / any objects
with Elasticsearch when no data are present
f3db2f0 is described below

commit f3db2f09a6c3814e2b797856f25664a59bfbed34
Author: skylark17 <matteo.alessandroni@tirasa.net>
AuthorDate: Wed Feb 20 11:39:46 2019 +0100

    [SYNCOPE-1437] Fixed error while searching for users / groups / any objects with Elasticsearch
when no data are present
---
 .../persistence/jpa/dao/ElasticsearchAnySearchDAO.java  | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
b/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
index 58fd9a9..bf8490f 100644
--- a/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
+++ b/ext/elasticsearch/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/ElasticsearchAnySearchDAO.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Triple;
 import org.apache.syncope.common.lib.SyncopeClientException;
@@ -64,6 +65,7 @@ import org.elasticsearch.index.query.DisMaxQueryBuilder;
 import org.elasticsearch.index.query.MatchNoneQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.elasticsearch.search.sort.FieldSortBuilder;
 import org.elasticsearch.search.sort.SortBuilder;
@@ -201,14 +203,17 @@ public class ElasticsearchAnySearchDAO extends AbstractAnySearchDAO
{
                 (page <= 0 ? 0 : page - 1),
                 (itemsPerPage < 0 ? elasticsearchUtils.getIndexMaxResultWindow() : itemsPerPage),
                 sortBuilders(kind, orderBy));
+
+        SearchHit[] esResult = null;
         try {
-            return buildResult(Stream.of(client.search(request, RequestOptions.DEFAULT).getHits().getHits()).
-                    map(hit -> hit.getId()).collect(Collectors.toList()),
-                    kind);
-        } catch (IOException e) {
-            LOG.error("Search error", e);
-            return Collections.emptyList();
+            esResult = client.search(request, RequestOptions.DEFAULT).getHits().getHits();
+        } catch (Exception e) {
+            LOG.error("While searching in Elasticsearch", e);
         }
+
+        return ArrayUtils.isEmpty(esResult)
+                ? Collections.emptyList()
+                : buildResult(Stream.of(esResult).map(hit -> hit.getId()).collect(Collectors.toList()),
kind);
     }
 
     private QueryBuilder getQueryBuilder(final SearchCond cond, final AnyTypeKind kind) {


Mime
View raw message