Added a legacy support for the old matchinfo service path.
Change-Id: Id8480c18ed0d4e0860d7814f9a042bd63df883ed
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 7441edd..fc8322c 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -39,7 +39,7 @@
// todo: use korap.config to get index location
public SearchKrill (String path) {
- System.out.println("Debug: SearchKrill: path='" + path + "'.");
+// System.out.println("Debug: SearchKrill: path='" + path + "'.");
try {
if (path.equals(":temp:")) {
this.index = new KrillIndex();
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
index a13958e..db2ae48 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/ResourceService.java
@@ -1092,7 +1092,29 @@
return Response.ok().build();
}
-
+ // EM: legacy support
+ // should be deprecated after a while
+ @GET
+ @Path("/corpus/{corpusId}/{docId}/{matchId}/matchInfo")
+ public Response getMatchInfo (@Context SecurityContext ctx,
+ @Context Locale locale, @PathParam("corpusId") String corpusId,
+ @PathParam("docId") String docId,
+ @PathParam("matchId") String matchId,
+ @QueryParam("foundry") Set<String> foundries,
+ @QueryParam("layer") Set<String> layers,
+ @QueryParam("spans") Boolean spans) throws KustvaktException {
+
+ String[] ids = docId.split("\\.");
+ if (ids.length !=2){
+ throw KustvaktResponseHandler.throwit(
+ new KustvaktException(StatusCodes.PARAMETER_VALIDATION_ERROR,
+ docId + " format is wrong. Expected a fullstop between doc id "
+ + "and text id"));
+ }
+ return getMatchInfo(ctx, locale, corpusId, ids[0], ids[1], matchId, foundries, layers, spans);
+
+ }
+
// fixme: only allowed for corpus?!
@GET
@Path("/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
@@ -1124,6 +1146,13 @@
e.string());
throw KustvaktResponseHandler.throwit(e);
}
+
+ try {
+ ResourceFinder.searchPublicFiltered(Corpus.class, corpusId);
+ }
+ catch (KustvaktException e) {
+ throw KustvaktResponseHandler.throwit(e);
+ }
String results;
// fixme: checks for policy matching
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoLegacyServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoLegacyServiceTest.java
new file mode 100644
index 0000000..ce459d9
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoLegacyServiceTest.java
@@ -0,0 +1,94 @@
+package de.ids_mannheim.korap.web.service.full;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.web.service.FastJerseyTest;
+
+public class MatchInfoLegacyServiceTest extends FastJerseyTest {
+
+ @BeforeClass
+ public static void configure () throws Exception {
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+ "de.ids_mannheim.korap.web.filter",
+ "de.ids_mannheim.korap.web.utils");
+ }
+
+
+ @Test
+ public void testGetMatchInfoPublicCorpus () {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("corpus").path("GOE").path("AGI.04846")
+ .path("p36875-36876").path("matchInfo")
+ .queryParam("foundry", "*")
+ .get(ClientResponse.class);
+
+ String entity = response.getEntity(String.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ JsonNode node = JsonUtils.readTree(entity);
+ assertNotNull(node);
+ assertEquals("GOE/AGI/04846", node.at("/textSigle").asText());
+ assertEquals("Zweiter römischer Aufenthalt",
+ node.at("/title").asText());
+ assertEquals("vom Juni 1787 bis April 1788",
+ node.at("/subTitle").asText());
+ assertEquals("Goethe, Johann Wolfgang von",
+ node.at("/author").asText());
+ assertTrue(node.at("/snippet").asText()
+ .startsWith("<span class=\"context-left\"></span>"
+ + "<span class=\"match\"><span title=\"corenlp/p:ADV\">"
+ + "<span title=\"opennlp/p:ADV\">"
+ + "<span title=\"tt/l:fern\">"
+ ));
+ }
+
+ @Test
+ public void testGetMatchOnlyUnauthorizeCorpus () {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("corpus").path("WPD15").path("B07.51608")
+ .path("p46-57").path("matchInfo").get(ClientResponse.class);
+
+ assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
+ response.getStatus());
+ String entity = response.getEntity(String.class);
+ System.out.println(entity);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertNotNull(node);
+ assertEquals(101, node.at("/errors/0/0").asInt());
+ assertEquals("[Cannot found public resources with ids: [WPD15]]",
+ node.at("/errors/0/2").asText());
+ }
+
+// @Test
+// public void testMatchInfoSave () {
+//
+// }
+//
+//
+// @Test
+// public void testMatchInfoDelete () {
+//
+// }
+//
+//
+// @Test
+// public void testGetMatches () {
+//
+// }
+
+
+ @Override
+ public void initMethod () throws KustvaktException {
+ helper().runBootInterfaces();
+ }
+}
\ No newline at end of file