From 5d1d46e0c5764ed5d3b2c7fd0a853a733a9b0cb9 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Wed, 1 Dec 2021 11:13:50 +0100 Subject: [PATCH] Fixed Empty query result --- .../geoportal/service/rest/ConcessioniOverMongo.java | 3 ++- .../geoportal/service/ConcessioniOverMongoTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java index 3d85e9c..426f46e 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ConcessioniOverMongo.java @@ -225,7 +225,8 @@ public class ConcessioniOverMongo { StringBuilder builder=new StringBuilder("["); manager.query(Serialization.parseQuery(queryString)) .forEach(d->{builder.append(d.toJson()+",");}); - builder.deleteCharAt(builder.length()-1); + if(builder.length()>1) + builder.deleteCharAt(builder.length()-1); builder.append("]"); return builder.toString(); } diff --git a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java index f58e12f..1830166 100644 --- a/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java +++ b/geoportal-service/src/test/java/org/gcube/application/geoportal/service/ConcessioniOverMongoTest.java @@ -144,10 +144,12 @@ public class ConcessioniOverMongoTest extends BasicServiceTestUnit{ public void query() throws Exception { WebTarget target=target(PATH); - Iterator it = queryFile("lastRegistered.json", target); - assertEquals(1, count(it)); + Iterator it; + assertEquals(1, count( queryFile("lastRegistered.json", target))); + assertEquals(0, count( queryFile("emptyresult.json",target))); + it=queryFile("firstRegistered.json", target); assertEquals(1, count(it));