Updated StatisticService.
Change-Id: Ie209a55f75f1e4b4e658a5696aa89605b166d11f
diff --git a/README.md b/README.md
index bd00b5c..833e120 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@
Set krill.indexDir in the configuration file to the location of your Krill index (relative path). In Kustvakt root directory, there is a sample index, e.g.
<pre>krill.indexDir = ../../sample-index</pre>
-Set the location of the ldap configuration file for Kustvakt full version. The file should contain an admin password to access an LDAP system.
+Set the location of the ldap configuration file for Kustvakt full version. The file should contain an admin password to access an LDAP system. Without LDAP, user authentication functions and services cannot be used.
<b>Optional custom configuration</b>
@@ -79,7 +79,7 @@
# Running Kustvakt Server
Requires ```kustvakt.conf``` or ```kustvakt-lite.conf``` in the same folder as the jar file. Otherwise assuming sample-index located in the parent directory of the jar file.
-Kustvakt full version requires an LDAP configuration file containing an admin password to access an LDAP system.
+Kustvakt full version requires an LDAP configuration file containing an admin password to access an LDAP system. You can still run Kustvakt full version without an LDAP system, but user authentication functions and services cannot be used. Only services for guest/demo user would work.
<pre>
cd target/
diff --git a/core/pom.xml b/core/pom.xml
index 26765dd..77c03a8 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -89,12 +89,24 @@
</execution>
</executions>
</plugin>
-
+ <!-- Generate source jar -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
-
+
<configuration>
<reuseForks>false</reuseForks>
<forkCount>2</forkCount>
@@ -114,48 +126,6 @@
</includes>
</configuration>
</plugin>
- <plugin>
- <artifactId>maven-shade-plugin</artifactId>
- <version>2.1</version>
- <executions>
- <!-- option 1 -->
- <execution>
- <id>full</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <finalName>Kustvakt-${project.version}}-core</finalName>
- <transformers>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass> de.ids_mannheim.korap.web.KustvaktServer </mainClass>
- </transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.handlers </resource>
- </transformer>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
- <resource>META-INF/spring.schemas </resource>
- </transformer>
- </transformers>
- <!-- Additional configuration. apparently there is a securityException -->
- <filters>
- <filter>
- <artifact>*:*</artifact>
- <excludes>
- <exclude>META-INF/*.SF</exclude>
- <exclude>META-INF/*.DSA </exclude>
- <exclude>META-INF/*.RSA </exclude>
- </excludes>
- </filter>
- </filters>
- </configuration>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
<dependencies>
@@ -359,7 +329,7 @@
</dependency>
<!-- copied from extension -->
- <dependency>
+ <!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-framework.version}</version>
@@ -373,7 +343,7 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>4.0</version>
- </dependency>
+ </dependency> -->
<!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId>
<version>2.6.5</version> </dependency> -->
@@ -418,15 +388,34 @@
<version>3.2.1</version>
</dependency>
- <!-- not part of public release <dependency> <groupId>KorAP-graphDB</groupId>
- <artifactId>KorAP-graphDB</artifactId> <version>1.0-SNAPSHOT</version> <exclusions>
- <exclusion> <groupId>org.antlr</groupId> <artifactId>antlr4-runtime</artifactId>
- </exclusion> <exclusion> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId>
- </exclusion> <exclusion> <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-grizzly2-http</artifactId> </exclusion> <exclusion>
- <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-common</artifactId>
- </exclusion> <exclusion> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId>
- </exclusion> </exclusions> </dependency> -->
+ <!-- not part of public release
+ <dependency>
+ <groupId>KorAP-graphDB</groupId>
+ <artifactId>KorAP-graphDB</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-grizzly2-http</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-server</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency> -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
@@ -437,7 +426,7 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
-
+
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
index e353c70..de39c8b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/DemoUserFilter.java
@@ -23,6 +23,7 @@
/**
* Created by hanl on 7/15/14.
+ * EM: why would we need this?
*/
@Provider
@Component
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/service/BootableBeanInterface.java b/core/src/main/java/de/ids_mannheim/korap/web/service/BootableBeanInterface.java
index c600aaa..56915c3 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/service/BootableBeanInterface.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/service/BootableBeanInterface.java
@@ -7,6 +7,7 @@
* @author hanl
* @date 12/01/2016
*/
+@Deprecated
public interface BootableBeanInterface {
void load (ContextHolder beans) throws KustvaktException;
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/service/BootupInterface.java b/core/src/main/java/de/ids_mannheim/korap/web/service/BootupInterface.java
index f421e92..86b62d9 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/service/BootupInterface.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/service/BootupInterface.java
@@ -6,6 +6,7 @@
* @author hanl
* @date 12/01/2016
*/
+@Deprecated
public interface BootupInterface {
void load () throws KustvaktException;
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java b/core/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
index 8db99be..91f7205 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/service/PolicyLoader.java
@@ -26,6 +26,7 @@
* @author hanl
* @date 15/01/2016
*/
+@Deprecated
public class PolicyLoader implements BootableBeanInterface {
@Override
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java b/core/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
index 3db2f05..cab1e1b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/service/UserLoader.java
@@ -13,6 +13,7 @@
* @author hanl
* @date 12/01/2016
*/
+@Deprecated
public class UserLoader implements BootableBeanInterface {
@Override
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");
+ }
}