Updated StatisticService.
Change-Id: Ie209a55f75f1e4b4e658a5696aa89605b166d11f
diff --git a/full/pom.xml b/full/pom.xml
index a7ca4f4..6feb320 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -160,7 +160,19 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
-
+ <!-- LDAP -->
+ <dependency>
+ <groupId>com.novell.ldap</groupId>
+ <artifactId>jldap</artifactId>
+ <version>4.3</version>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/com.unboundid/unboundid-ldapsdk -->
+ <dependency>
+ <groupId>com.unboundid</groupId>
+ <artifactId>unboundid-ldapsdk</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
@@ -191,6 +203,23 @@
<scope>compile</scope>
</dependency>
-->
-
+<!-- copied from extension -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${spring-framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring-framework.version}</version>
+ </dependency>
+
+ <!-- Flyway -->
+ <dependency>
+ <groupId>org.flywaydb</groupId>
+ <artifactId>flyway-core</artifactId>
+ <version>4.0</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/full/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index 9599b74..5319c51 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -42,6 +42,12 @@
private ResourceConverter resourceConverter;
+ /** Returns descriptions of all free resources stored in
+ * the database.
+ *
+ * @return a json description of all free resources stored in
+ * the database.
+ */
@GET
@Path("info")
public Response getAllResourceInfo () {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/service/full/SearchService.java b/full/src/main/java/de/ids_mannheim/korap/web/service/full/SearchService.java
index 617385e..ab33369 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/service/full/SearchService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/service/full/SearchService.java
@@ -24,7 +24,6 @@
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriBuilder;
-import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -749,34 +748,12 @@
}
}
- // EM: changed method POST to GET
- @GET
- @Path("statistics")
- public Response getStatistics (@Context SecurityContext context,
- @Context Locale locale, @QueryParam("collectionQuery")
- String collectionQuery) {
-
- if (collectionQuery == null || collectionQuery.isEmpty()){
- throw KustvaktResponseHandler.throwit(new KustvaktException(
- StatusCodes.MISSING_ARGUMENT, "Parameter collectionQuery is missing.",
- "collectionQuery"));
- }
-
-
- KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
- builder.with(collectionQuery);
- String json = builder.toJSON();
-
- String stats = searchKrill.getStatistics(json);
- if (stats.contains("-1"))
- throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
- jlog.debug("Stats: "+stats);
- return Response.ok(stats).build();
- }
+
// EM: what is child?
@GET
@Path("{type}/{id}/{child}/statistics")
+ @Deprecated
public Response getStatisticsbyIdChild (@Context SecurityContext context,
@Context Locale locale, @PathParam("type") String type,
@PathParam("id") String id, @PathParam("child") String child) {
@@ -787,6 +764,7 @@
@GET
@Path("{type}/{id}/stats")
+ @Deprecated
public Response getStatisticsbyId (@Context SecurityContext context,
@Context Locale locale, @PathParam("type") String type,
@PathParam("id") String id) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/service/full/StatisticService.java b/full/src/main/java/de/ids_mannheim/korap/web/service/full/StatisticService.java
new file mode 100644
index 0000000..cb76ca8
--- /dev/null
+++ b/full/src/main/java/de/ids_mannheim/korap/web/service/full/StatisticService.java
@@ -0,0 +1,87 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import java.util.Locale;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
+import com.sun.jersey.spi.container.ResourceFilters;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
+import de.ids_mannheim.korap.web.SearchKrill;
+import de.ids_mannheim.korap.web.filter.PiwikFilter;
+import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
+
+/**
+ * Services related to statistics
+ *
+ * @author hanl
+ * @author margaretha
+ *
+ * @date 27/09/2017
+ *
+ */
+@Controller
+@Path("statistics/")
+@ResourceFilters({ PiwikFilter.class })
+@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
+public class StatisticService {
+
+
+ private static Logger jlog =
+ LoggerFactory.getLogger(StatisticService.class);
+
+ @Autowired
+ private SearchKrill searchKrill;
+
+
+ /**
+ * Returns statistics of the virtual corpus defined by the given
+ * collectionQuery parameter.
+ *
+ * @param context
+ * SecurityContext
+ * @param locale
+ * Locale
+ * @param collectionQuery
+ * a collection query specifying a virtual corpus
+ * @return statistics of the virtual corpus defined by the given
+ * collectionQuery parameter.
+ */
+ @GET
+ public Response getStatistics (@Context SecurityContext context,
+ @Context Locale locale,
+ @QueryParam("collectionQuery") String collectionQuery) {
+
+ if (collectionQuery == null || collectionQuery.isEmpty()) {
+ throw KustvaktResponseHandler
+ .throwit(new KustvaktException(StatusCodes.MISSING_ARGUMENT,
+ "Parameter collectionQuery is missing.",
+ "collectionQuery"));
+ }
+
+
+ KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
+ builder.with(collectionQuery);
+ String json = builder.toJSON();
+
+ String stats = searchKrill.getStatistics(json);
+ if (stats.contains("-1"))
+ throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
+ jlog.debug("Stats: " + stats);
+ return Response.ok(stats).build();
+ }
+}
diff --git a/full/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java b/full/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
index 32660bc..f9a1a09 100644
--- a/full/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/config/PolicyLoaderTest.java
@@ -17,6 +17,7 @@
* @date 11/02/2016
*/
@Deprecated
+@Ignore
public class PolicyLoaderTest extends BeanConfigTest {
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
index 9f72b78..d1a7b40 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/StatisticsServiceTest.java
@@ -2,7 +2,6 @@
import java.io.IOException;
-import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -16,7 +15,7 @@
/**
* @author margaretha
- * @date 29/06/2017
+ * @date 27/09/2017
*
*/
public class StatisticsServiceTest extends FastJerseyTest {
@@ -77,7 +76,6 @@
assert ClientResponse.Status.OK.getStatusCode() == response.getStatus();
assertEquals(node.get("documents").asInt(),7);
assertEquals(node.get("tokens").asInt(),279402);
- // EM: why zero?
assertEquals(node.get("sentences").asInt(), 11047);
assertEquals(node.get("paragraphs").asInt(), 489);
}
@@ -121,4 +119,21 @@
assertEquals(node.at("/errors/0/2").asText(), ">=");
}
+
+ @Test
+ public void testGetStatisticsWithoutCollectionQuery ()
+ throws JsonProcessingException, IOException {
+ ClientResponse response = resource()
+ .path("statistics")
+ .get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = mapper.readTree(ent);
+ assertEquals(node.at("/errors/0/0").asInt(), 105);
+ assertEquals(node.at("/errors/0/1").asText(),
+ "Parameter collectionQuery is missing.");
+ assertEquals(node.at("/errors/0/2").asText(), "collectionQuery");
+ }
}