Merge branch 'master' of ssh://korap.ids-mannheim.de:29418/private/Kustvakt-core
diff --git a/pom.xml b/pom.xml
index 1f9be55..3675651 100644
--- a/pom.xml
+++ b/pom.xml
@@ -356,7 +356,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Krill</artifactId>
- <version>0.55.7</version>
+ <version>0.55.8</version>
<exclusions>
<exclusion>
<groupId>org.xerial</groupId>
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 bbca24a..0cbbe13 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
@@ -521,7 +521,7 @@
meta.setSpanContext(ctx);
meta.addEntry("count", pageLength);
// todo: what happened to cutoff?
- meta.addEntry("cutoff", cutoff);
+ meta.addEntry("cutOff", cutoff);
// meta.addMeta(pageIndex, pageInteger, pageLength, ctx, cutoff);
// fixme: should only apply to CQL queries per default!
// meta.addEntry("itemsPerResource", 1);
@@ -1093,7 +1093,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")
@@ -1125,7 +1147,14 @@
e.string());
throw KustvaktResponseHandler.throwit(e);
}
-
+ if (user instanceof DemoUser){
+ try {
+ ResourceFinder.searchPublicFiltered(Corpus.class, corpusId);
+ }
+ catch (KustvaktException e) {
+ throw KustvaktResponseHandler.throwit(e);
+ }
+ }
String results;
// fixme: checks for policy matching
// fixme: currently disabled, due to mishab in foundry/layer spec
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
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
index c3f3724..8ff5794 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/MatchInfoServiceTest.java
@@ -65,10 +65,11 @@
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
- assertEquals(ClientResponse.Status.OK.getStatusCode(),
- response.getStatus());
String entity = response.getEntity(String.class);
// System.out.println(entity);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+
JsonNode node = JsonUtils.readTree(entity);
assertNotNull(node);
assertEquals("WPD15/B07/51608", node.at("/textSigle").asText());
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
index 6e4440f..94cc478 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/SearchServiceTest.java
@@ -3,6 +3,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import java.util.Set;
@@ -65,6 +66,30 @@
assertEquals(6218, node.at("/meta/totalResults").asInt());
}
+
+ @Test
+ public void testSearchQueryWithMeta () {
+ ClientResponse response = resource().path(getAPIVersion())
+ .path("search").queryParam("q", "[orth=der]")
+ .queryParam("ql", "poliqarp").queryParam("cutoff", "true")
+ .queryParam("count", "5")
+ .queryParam("page", "1")
+ .queryParam("context", "40-t,30-t").get(ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String ent = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(ent);
+ assertNotNull(node);
+ assertTrue(node.at("/meta/cutOff").asBoolean());
+ assertEquals(5, node.at("/meta/count").asInt());
+ assertEquals(0, node.at("/meta/startIndex").asInt());
+ assertEquals("token", node.at("/meta/context/left/0").asText());
+ assertEquals(40, node.at("/meta/context/left/1").asInt());
+ assertEquals(30, node.at("/meta/context/right/1").asInt());
+ assertEquals(-1,node.at("/meta/totalResults").asInt());
+ }
+
+
@Test
public void testSearchQueryAuthorized () {
ClientResponse response = resource().path(getAPIVersion())
@@ -107,6 +132,7 @@
assertEquals("koral:token", node.at("/query/@type").asText());
}
+
@Test
public void testSearchForPublicCorpusWithStringId () {
ClientResponse response = resource().path(getAPIVersion())
@@ -124,7 +150,8 @@
assertNotEquals(0, node.path("matches").size());
assertEquals(32, node.at("/meta/totalResults").asInt());
}
-
+
+
@Test
public void testSearchForVirtualCollectionWithStringId () {
ClientResponse response = resource().path(getAPIVersion())
@@ -138,12 +165,12 @@
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("koral:docGroup", node.at("/collection/@type").asText());
- assertEquals("operation:and", node.at("/collection/operation").asText());
+ assertEquals("operation:and",
+ node.at("/collection/operation").asText());
assertNotEquals(0, node.at("/collection/operands").size());
assertEquals("corpusSigle",
node.at("/collection/operands/0/key").asText());
- assertEquals("GOE",
- node.at("/collection/operands/0/value").asText());
+ assertEquals("GOE", node.at("/collection/operands/0/value").asText());
assertEquals("creationDate",
node.at("/collection/operands/1/key").asText());
assertEquals("1810-01-01",
@@ -151,28 +178,28 @@
assertEquals(1, node.at("/meta/totalResults").asInt());
}
-
+
@Test
- public void testSearchForPublicCorpusWithIntegerId () throws KustvaktException {
+ public void testSearchForPublicCorpusWithIntegerId ()
+ throws KustvaktException {
Set<Corpus> publicCorpora = ResourceFinder.searchPublic(Corpus.class);
Iterator<Corpus> i = publicCorpora.iterator();
String id = null;
- while (i.hasNext()){
+ while (i.hasNext()) {
Corpus c = i.next();
- if (c.getName().equals("Goethe")){
- id =c.getId().toString();
+ if (c.getName().equals("Goethe")) {
+ id = c.getId().toString();
}
}
-
+
ClientResponse response = resource().path(getAPIVersion())
- .path("corpus").path(id).path("search")
- .queryParam("q", "blau").queryParam("ql", "poliqarp")
- .get(ClientResponse.class);
-
+ .path("corpus").path(id).path("search").queryParam("q", "blau")
+ .queryParam("ql", "poliqarp").get(ClientResponse.class);
+
String ent = response.getEntity(String.class);
assertEquals(ClientResponse.Status.OK.getStatusCode(),
response.getStatus());
-
+
JsonNode node = JsonUtils.readTree(ent);
assertNotNull(node);
assertEquals("koral:doc", node.at("/collection/@type").asText());
@@ -180,7 +207,8 @@
assertEquals("GOE", node.at("/collection/value").asText());
assertNotEquals(0, node.path("matches").size());
}
-
+
+
@Test
public void testSearchForCorpusWithStringIdUnauthorized () {
ClientResponse response = resource().path(getAPIVersion())
@@ -195,13 +223,13 @@
assertEquals("[Cannot found public resources with ids: [WPD15]]",
error.get(2).asText());
}
-
+
+
@Test
public void testSearchForOwnersCorpusWithStringId () {
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path("WPD15").path("search")
- .queryParam("q", "[orth=das]")
- .queryParam("ql", "poliqarp")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
@@ -215,26 +243,28 @@
assertEquals("WPD15", node.at("/collection/value").asText());
assertNotEquals(0, node.path("matches").size());
}
-
+
+
@Test
- public void testSearchForOwnersCorpusWithIntegerId () throws KustvaktException {
-
- User kustvaktUser = ((EntityHandlerIface) helper().getBean(ContextHolder.KUSTVAKT_USERDB))
- .getAccount("kustvakt");
- Set<Corpus> userCorpora = ResourceFinder.search(kustvaktUser, Corpus.class);
+ public void testSearchForOwnersCorpusWithIntegerId ()
+ throws KustvaktException {
+
+ User kustvaktUser = ((EntityHandlerIface) helper()
+ .getBean(ContextHolder.KUSTVAKT_USERDB)).getAccount("kustvakt");
+ Set<Corpus> userCorpora = ResourceFinder.search(kustvaktUser,
+ Corpus.class);
Iterator<Corpus> i = userCorpora.iterator();
String id = null;
- while (i.hasNext()){
+ while (i.hasNext()) {
Corpus c = i.next();
- if (c.getPersistentID().equals("WPD15")){
- id =c.getId().toString();
-// System.out.println("Corpus "+id);
+ if (c.getPersistentID().equals("WPD15")) {
+ id = c.getId().toString();
+ // System.out.println("Corpus "+id);
}
}
ClientResponse response = resource().path(getAPIVersion())
.path("corpus").path(id).path("search")
- .queryParam("q", "[orth=das]")
- .queryParam("ql", "poliqarp")
+ .queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
.header(Attributes.AUTHORIZATION,
BasicHttpAuth.encode("kustvakt", "kustvakt2015"))
.get(ClientResponse.class);
@@ -249,6 +279,7 @@
assertNotEquals(0, node.path("matches").size());
}
+
@Test
public void testSearchSentenceMeta () {
ClientResponse response = resource().path(getAPIVersion())