Added support for unrestricted corpus statistics in full service

Change-Id: Ia8ef60a3943b205924f397562508a37a355620bf
diff --git a/full/Changes b/full/Changes
index 9e6e09e..738c78f 100644
--- a/full/Changes
+++ b/full/Changes
@@ -19,6 +19,7 @@
     - merged OAuth2 client deregistration controllers (margaretha)
     - fixed OAuth2 client unique URL-hashcode (margaretha)
     - migrated logging to log4j 2 and adapted java.util.logging to log4j(margaretha)
+    - Added support for unrestricted corpus statistics (ndiewald)
     
 version 0.60.3
 06/06/2018
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
index f389ea5..14c309a 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
@@ -67,25 +67,24 @@
             @Context Locale locale,
             @QueryParam("corpusQuery") String corpusQuery) {
 
-        if (corpusQuery == null || corpusQuery.isEmpty()) {
-            throw kustvaktResponseHandler
-                    .throwit(new KustvaktException(StatusCodes.MISSING_PARAMETER,
-                            "Parameter corpusQuery is missing.",
-                            "corpusQuery"));
-        }
-
-
         KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
-        builder.with(corpusQuery);
-        String json = null;
-        try {
-            json = builder.toJSON();
-        }
-        catch (KustvaktException e) {
-            throw kustvaktResponseHandler.throwit(e);
-        }
 
-        String stats = searchKrill.getStatistics(json);
+		String stats;
+		if (corpusQuery != null && !corpusQuery.isEmpty()) {
+			builder.with(corpusQuery);
+			String json = null;
+			try {
+				json = builder.toJSON();
+			}
+			catch (KustvaktException e) {
+				throw kustvaktResponseHandler.throwit(e);
+			}
+			stats = searchKrill.getStatistics(json);
+		}
+		else {
+			stats = searchKrill.getStatistics(null);
+		};
+
         if (stats.contains("-1"))
             throw kustvaktResponseHandler.throwit(StatusCodes.NO_RESULT_FOUND);
         jlog.debug("Stats: " + stats);
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index 6fb0dd7..92b6c04 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -14,7 +14,7 @@
 import de.ids_mannheim.korap.config.SpringJerseyTest;
 
 /** 
- * @author margaretha
+ * @author margaretha, diewald
  * @date 27/09/2017
  *
  */
@@ -122,14 +122,14 @@
                 .path("statistics")
                 .get(ClientResponse.class);
 
-        assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
-                response.getStatus());
+        assertEquals(ClientResponse.Status.OK.getStatusCode(),
+					 response.getStatus());
         String ent = response.getEntity(String.class);
-//        System.out.println(ent);
-        JsonNode node = mapper.readTree(ent);
-        assertEquals(node.at("/errors/0/0").asInt(), 105);
-        assertEquals(node.at("/errors/0/1").asText(),
-                "Parameter corpusQuery is missing.");
-        assertEquals(node.at("/errors/0/2").asText(), "corpusQuery");
+
+		JsonNode node = mapper.readTree(ent);
+		assertEquals(11, node.at("/documents").asInt());
+        assertEquals(665842, node.at("/tokens").asInt());
+        assertEquals(25074, node.at("/sentences").asInt());
+        assertEquals(772, node.at("/paragraphs").asInt());
     }
 }