Updated light services and fixed the tests.
Change-Id: Ia2744ae1d7f76d2af27d030546f4eeb5119b3d5e
diff --git a/lite/pom.xml b/lite/pom.xml
index 02fe1af..fc394fb 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -7,7 +7,7 @@
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <spring-framework.version>4.3.7.RELEASE</spring-framework.version>
+ <spring-framework.version>4.3.11.RELEASE</spring-framework.version>
<jersey.version>1.19.4</jersey.version>
</properties>
diff --git a/lite/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java b/lite/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
index 476b6bf..e86279d 100644
--- a/lite/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
+++ b/lite/src/main/java/de/ids_mannheim/korap/web/service/light/LightService.java
@@ -4,12 +4,14 @@
import java.util.List;
import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -33,7 +35,6 @@
import de.ids_mannheim.korap.utils.KustvaktLogger;
import de.ids_mannheim.korap.web.ClientsHandler;
import de.ids_mannheim.korap.web.SearchKrill;
-import de.ids_mannheim.korap.web.TRACE;
import de.ids_mannheim.korap.web.utils.KustvaktResponseHandler;
/**
@@ -41,7 +42,14 @@
* @date 29/01/2014
*
* @author margaretha
- * @date 21/09/2017
+ * @update 10/10/2017
+ *
+ * <pre>
+ * Recent changes:
+ * - removed version from service paths
+ * - altered service with path /search and method trace to path
+ * /query and method get
+ * </pre>
*/
@Controller
@Path("/")
@@ -90,15 +98,16 @@
}
- @TRACE
- @Path("search")
+ @GET
+ @Path("query")
public Response buildQuery (@QueryParam("q") String q,
@QueryParam("ql") String ql, @QueryParam("v") String v,
@QueryParam("context") String context,
@QueryParam("cutoff") Boolean cutoff,
@QueryParam("count") Integer pageLength,
@QueryParam("offset") Integer pageIndex,
- @QueryParam("page") Integer startPage, @QueryParam("cq") String cq) {
+ @QueryParam("page") Integer startPage,
+ @QueryParam("cq") String cq) {
QuerySerializer ss = new QuerySerializer().setQuery(q, ql, v);
MetaQueryBuilder meta = new MetaQueryBuilder();
@@ -109,8 +118,7 @@
meta.setSpanContext(context);
meta.addEntry("cutOff", cutoff);
ss.setMeta(meta.raw());
- if (cq != null)
- ss.setCollection(cq);
+ if (cq != null) ss.setCollection(cq);
String query;
try {
@@ -125,7 +133,8 @@
@POST
@Path("search")
- public Response queryRaw (@QueryParam("engine") String engine, String jsonld) {
+ public Response queryRaw (@QueryParam("engine") String engine,
+ String jsonld) {
try {
jsonld = processor.processQuery(jsonld, null);
}
@@ -136,10 +145,10 @@
jlog.info("Serialized search: {}", jsonld);
try {
String result = searchKrill.search(jsonld);
- KustvaktLogger.QUERY_LOGGER.trace("The result set: {}", result);
+ jlog.debug("The result set: {}", result);
return Response.ok(result).build();
- } catch(Exception e) {
- System.out.println("_____________________________________" );
+ }
+ catch (Exception e) {
e.printStackTrace();
}
return Response.ok().build();
@@ -167,8 +176,7 @@
if (fields != null && !fields.isEmpty())
meta.addEntry("fields", fields);
serializer.setMeta(meta.raw());
- if (cq != null)
- serializer.setCollection(cq);
+ if (cq != null) serializer.setCollection(cq);
String query;
try {
@@ -225,8 +233,9 @@
* @return
*/
//fixme: search in collection /collection/collection-id/search
+ @Deprecated
@GET
- @Path("/{type}/{id}/search")
+ // @Path("/{type}/{id}/search")
public Response searchbyName (@PathParam("id") String id,
@PathParam("type") String type, @QueryParam("q") String query,
@QueryParam("ql") String ql, @QueryParam("v") String v,
@@ -257,10 +266,9 @@
String result;
try {
if (eng.equals(KustvaktConfiguration.BACKENDS.NEO4J)) {
- if (raw)
- throw KustvaktResponseHandler.throwit(
- StatusCodes.ILLEGAL_ARGUMENT, "raw not supported!",
- null);
+ if (raw) throw KustvaktResponseHandler.throwit(
+ StatusCodes.ILLEGAL_ARGUMENT, "raw not supported!",
+ null);
MultivaluedMap map = new MultivaluedMapImpl();
map.add("q", query);
map.add("count", String.valueOf(pageLength));
@@ -284,55 +292,44 @@
}
-// //todo: switch to new serialization
-// @POST
-// @Path("stats")
-// public Response getStats (String json) {
-// KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
-// builder.with(json);
-//
-// // todo: policy override in extension!
-// String stats = searchKrill.getStatistics(builder.toJSON());
-// if (stats.contains("-1"))
-// throw KustvaktResponseHandler.throwit(StatusCodes.NO_VALUE_FOUND);
-//
-// return Response.ok(stats).build();
-// }
-
@GET
@Path("statistics")
- public Response getStatistics (@QueryParam("collectionQuery")
- String collectionQuery) {
-
+ public Response getStatistics (
+ @QueryParam("collectionQuery") String 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);
+ jlog.debug("Stats: " + stats);
return Response.ok(stats).build();
}
- /*
- * TODO: The problem here is, that the matchinfo path makes no
- * distinction between docs and texts - unlike DeReKo, the backend
- * and the frontend. Luckily there is a convenient method
- * "getMatchID()" for a workaround, but this should be fixed.
- */
+ /*
+ * TODO: The problem here is, that the matchinfo path makes no
+ * distinction between docs and texts - unlike DeReKo, the backend
+ * and the frontend. Luckily there is a convenient method
+ * "getMatchID()" for a workaround, but this should be fixed.
+ */
@GET
@Path("/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
public Response getMatchInfo (@PathParam("corpusId") String corpusId,
@PathParam("docId") String docId,
- @PathParam("textId") String textId,
+ @PathParam("textId") String textId,
@PathParam("matchId") String matchId,
@QueryParam("foundry") Set<String> foundries,
@QueryParam("layer") Set<String> layers,
- @QueryParam("spans") Boolean spans) throws KustvaktException {
- String matchid = searchKrill.getMatchId(corpusId, docId, textId, matchId);
+ @QueryParam("spans") Boolean spans,
+ @Context HttpServletRequest request) throws KustvaktException {
+
+ String matchid =
+ searchKrill.getMatchId(corpusId, docId, textId, matchId);
+
List<String> f_list = null;
List<String> l_list = null;
if (layers != null && !layers.isEmpty())
@@ -343,14 +340,14 @@
f_list = new ArrayList<>(foundries);
spans = spans != null ? spans : false;
-
+
boolean match_only = foundries == null || foundries.isEmpty();
String results;
if (match_only)
- results = searchKrill.getMatch(matchid,null);
+ results = searchKrill.getMatch(matchid, null);
else
results = searchKrill.getMatch(matchid, f_list, l_list, spans,
- false, true,null);
+ false, true, null);
return Response.ok(results).build();
}
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java
index 8d87265..81ae635 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/FastJerseyLightTest.java
@@ -23,7 +23,7 @@
}
@Before
- public static void startServerBeforeFirstTestRun () {
+ public void startServerBeforeFirstTestRun () {
if (testContainer == null) {
initServer(PORT, classPackages);
startServer();
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
index 17c7df6..e0ecf31 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LightServiceTest.java
@@ -5,8 +5,6 @@
import static org.junit.Assert.assertNotNull;
import org.apache.lucene.LucenePackage;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.databind.JsonNode;
@@ -17,28 +15,48 @@
import de.ids_mannheim.korap.utils.JsonUtils;
/**
- * EM: FIX ME: Database restructure
- *
* Created by hanl on 29.04.16.
+ *
+ * @author margaretha
+ * @date 10/10/2017
+ *
+ * Recent changes:
+ * - updated the service paths and methods of query serialization tests
+ * - added statistic service test
*/
-@Ignore
public class LightServiceTest extends FastJerseyLightTest {
@Override
public void initMethod () throws KustvaktException {}
-
@Test
- public void testQueryTrace () {
- ClientResponse response = resource().path(getAPIVersion())
- .path("search").queryParam("q", "[orth=das]")
- .queryParam("ql", "poliqarp").queryParam("context", "sentence")
- .queryParam("count", "13")
- .method("TRACE", ClientResponse.class);
+ public void testStatistics () {
+ ClientResponse response = resource()
+ .path("statistics")
+ .queryParam("collectionQuery", "textType=Autobiographie & corpusSigle=GOE")
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String query = response.getEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
+ assertEquals(9, node.at("/documents").asInt());
+ assertEquals(527662, node.at("/tokens").asInt());
+ assertEquals(19387, node.at("/sentences").asInt());
+ assertEquals(514, node.at("/paragraphs").asInt());
+ }
+
+ @Test
+ public void testGetJSONQuery () {
+ ClientResponse response = resource()
+ .path("query").queryParam("q", "[orth=das]")
+ .queryParam("ql", "poliqarp").queryParam("context", "sentence")
+ .queryParam("count", "13")
+ .method("GET", ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String query = response.getEntity(String.class);
+ System.out.println(query);
+ JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
assertEquals("orth", node.at("/query/wrap/layer").asText());
assertEquals("opennlp", node.at("/query/wrap/foundry").asText());
@@ -49,11 +67,11 @@
@Test
public void testbuildAndPostQuery () {
- ClientResponse response = resource().path(getAPIVersion())
- .path("search").queryParam("q", "[orth=das]")
+ ClientResponse response = resource()
+ .path("query").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp")
.queryParam("cq", "corpusSigle=WPD | corpusSigle=GOE")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -61,7 +79,7 @@
JsonNode node = JsonUtils.readTree(query);
assertNotNull(node);
- response = resource().path(getAPIVersion()).path("search")
+ response = resource().path("search")
.post(ClientResponse.class, query);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
@@ -74,7 +92,7 @@
@Test
public void testQueryGet () {
- ClientResponse response = resource().path(getAPIVersion())
+ ClientResponse response = resource()
.path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp").queryParam("context", "sentence")
.queryParam("count", "13").get(ClientResponse.class);
@@ -92,7 +110,7 @@
@Test
public void testFoundryRewrite () {
- ClientResponse response = resource().path(getAPIVersion())
+ ClientResponse response = resource()
.path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp").queryParam("context", "sentence")
.queryParam("count", "13").get(ClientResponse.class);
@@ -111,7 +129,7 @@
QuerySerializer s = new QuerySerializer();
s.setQuery("[orth=das]", "poliqarp");
- ClientResponse response = resource().path(getAPIVersion())
+ ClientResponse response = resource()
.path("search").post(ClientResponse.class, s.toJSON());
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
@@ -125,7 +143,7 @@
@Test
public void testParameterField () {
- ClientResponse response = resource().path(getAPIVersion())
+ ClientResponse response = resource()
.path("search").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp")
.queryParam("fields", "author, docSigle")
@@ -145,7 +163,7 @@
@Test
public void testMatchInfoGetWithoutSpans () {
ClientResponse response = resource()
- .path(getAPIVersion())
+
.path("corpus/GOE/AGA/01784/p36-46/matchInfo")
.queryParam("foundry", "*")
.queryParam("spans", "false")
@@ -162,7 +180,7 @@
@Test
public void testMatchInfoGet2 () {
ClientResponse response = resource()
- .path(getAPIVersion())
+
.path("corpus/GOE/AGA/01784/p36-46/matchInfo")
.queryParam("foundry", "*")
.get(ClientResponse.class);
@@ -176,14 +194,14 @@
};
@Test
- public void testCQParameter () {
- ClientResponse response = resource().path(getAPIVersion())
- .path("search").queryParam("q", "[orth=das]")
+ public void testCollectionQueryParameter () {
+ ClientResponse response = resource()
+ .path("query").queryParam("q", "[orth=das]")
.queryParam("ql", "poliqarp")
.queryParam("fields", "author, docSigle")
.queryParam("context", "sentence").queryParam("count", "13")
.queryParam("cq", "textClass=Politik & corpus=WPD")
- .method("TRACE", ClientResponse.class);
+ .method("GET", ClientResponse.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
String query = response.getEntity(String.class);
@@ -194,15 +212,15 @@
.asText());
assertEquals("WPD", node.at("/collection/operands/1/value").asText());
- response = resource().path(getAPIVersion()).path("search")
+ response = resource().path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.queryParam("fields", "author, docSigle")
.queryParam("context", "sentence").queryParam("count", "13")
.queryParam("cq", "textClass=Politik & corpus=WPD")
.get(ClientResponse.class);
String version = LucenePackage.get().getImplementationVersion();;
- System.out.println("VERSION "+ version);
- System.out.println("RESPONSE "+ response);
+// System.out.println("VERSION "+ version);
+// System.out.println("RESPONSE "+ response);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
query = response.getEntity(String.class);