From 79efb2511a8b1a8c359226599eb69140b0313396 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Tue, 30 May 2017 22:27:38 +0200
Subject: [PATCH] [fix] PeerDao (hash not always set)

---
 .../src/test/misc/movementByRange.sh          | 36 +++++++++++++++++++
 .../src/test/misc/test_queries_graph.sh       | 18 ++++++++++
 .../elasticsearch/dao/impl/PeerDaoImpl.java   |  2 +-
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100755 duniter4j-es-assembly/src/test/misc/movementByRange.sh
 create mode 100755 duniter4j-es-assembly/src/test/misc/test_queries_graph.sh

diff --git a/duniter4j-es-assembly/src/test/misc/movementByRange.sh b/duniter4j-es-assembly/src/test/misc/movementByRange.sh
new file mode 100755
index 00000000..67901992
--- /dev/null
+++ b/duniter4j-es-assembly/src/test/misc/movementByRange.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+curl -XPOST 'http://localhost:9200/gtest/movement/_search?pretty' -d '
+   {
+     "size": 1000,
+     "query": {
+        "bool": {
+            "filter": [
+                {"term": {"recipient" : "5ocqzyDMMWf1V8bsoNhWb1iNwax1e9M7VTUN6navs8of" }},
+                {"terms": {"code" : ["MEMBER_JOIN","MEMBER_ACTIVE","MEMBER_LEAVE","MEMBER_EXCLUDE","MEMBER_REVOKE"] }}
+            ]
+        }
+     },
+      "aggs": {
+         "tx": {
+           "range": {
+             "field" : "medianTime",
+             "ranges" : [
+                 { "from" : 0, "to" : 1492041600 }
+             ]
+           },
+            "aggs" : {
+                "received" : {
+                    "filter": {"term": {"recipient": "5ocqzyDMMWf1V8bsoNhWb1iNwax1e9M7VTUN6navs8of"}},
+                    "aggs": {
+                      "received_stats": {
+                        "stats": {
+                          "field": "amount"
+                        }
+                      }
+                    }
+                }
+            }
+         }
+       }
+   }'
+
diff --git a/duniter4j-es-assembly/src/test/misc/test_queries_graph.sh b/duniter4j-es-assembly/src/test/misc/test_queries_graph.sh
new file mode 100755
index 00000000..257c5976
--- /dev/null
+++ b/duniter4j-es-assembly/src/test/misc/test_queries_graph.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+curl -XPOST 'http://gtest.data.duniter.fr:80/user/event/_search?pretty' -d '
+   {
+     "size": 1000,
+     "query": {
+        "bool": {
+            "filter": [
+                {"term": {"recipient" : "5ocqzyDMMWf1V8bsoNhWb1iNwax1e9M7VTUN6navs8of" }},
+                {"terms": {"code" : ["MEMBER_JOIN","MEMBER_ACTIVE","MEMBER_LEAVE","MEMBER_EXCLUDE","MEMBER_REVOKE"] }}
+            ]
+        }
+     },
+     "sort" : [
+       { "time" : {"order" : "desc"}}
+     ],
+     _source: ["code", "time"]
+   }'
+
diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java
index a05e8771..61475a4b 100644
--- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java
+++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/dao/impl/PeerDaoImpl.java
@@ -57,7 +57,7 @@ public class PeerDaoImpl extends AbstractDao implements PeerDao {
         Preconditions.checkNotNull(peer);
         Preconditions.checkArgument(StringUtils.isNotBlank(peer.getId()));
         Preconditions.checkArgument(StringUtils.isNotBlank(peer.getCurrency()));
-        Preconditions.checkNotNull(peer.getHash());
+        //Preconditions.checkNotNull(peer.getHash());
         Preconditions.checkNotNull(peer.getHost());
         Preconditions.checkNotNull(peer.getApi());
 
-- 
GitLab