From d151c30c5344494299483601d7120c6df0b1d07b Mon Sep 17 00:00:00 2001 From: margaretha Date: Mon, 10 Jun 2024 10:50:42 +0200 Subject: [PATCH] Fixed empty named VC path in configuration (solves #754) Change-Id: I0eb93b056f095c0fb75746842ee636586711a44a --- Changes | 1 + pom.xml | 2 +- .../korap/config/KustvaktConfiguration.java | 22 +------------------ .../controller/StatisticsControllerTest.java | 14 ++++++++++++ ...t.java => VirtualCorpusReferenceTest.java} | 17 ++++++++++++-- .../web/lite/LiteStatisticControllerTest.java | 14 ++++++++++++ 6 files changed, 46 insertions(+), 24 deletions(-) rename src/test/java/de/ids_mannheim/korap/web/controller/{VCReferenceTest.java => VirtualCorpusReferenceTest.java} (92%) diff --git a/Changes b/Changes index 111885d9..691a5d7a 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ - Cleaned up named-vc. - Updated tests using the old match info web-services (#757) - Added deprecation warning for the old matchInfo service (#757) +- Fixed empty named VC path in configuration (solves #754) # version 0.73.1 diff --git a/pom.xml b/pom.xml index 0fce0e9d..9cc6f488 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 11.0.19 10.6.0 2.22.1 - [0.62.4,) + [0.62.5,) [0.42,) diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java index 0e16623d..d69f3c64 100644 --- a/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java +++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java @@ -123,6 +123,7 @@ public KustvaktConfiguration (Properties properties) throws Exception { load(properties); // readPipesFile("pipes"); KrillProperties.setProp(properties); + KrillProperties.updateConfigurations(properties); } public KustvaktConfiguration () {} @@ -145,7 +146,6 @@ public void loadBasicProperties (Properties properties) { */ protected void load (Properties properties) throws Exception { loadBasicProperties(properties); - loadKrillProperties(properties); apiWelcomeMessage = properties.getProperty("api.welcome.message", "Welcome to KorAP API!"); @@ -222,26 +222,6 @@ protected void load (Properties properties) throws Exception { networkEndpointURL = properties.getProperty("network.endpoint.url", ""); } - private void loadKrillProperties (Properties properties) { - try { - String maxTokenMatch = properties.getProperty("krill.match.max.token"); - if (maxTokenMatch != null) { - KrillProperties.maxTokenMatchSize = Integer.parseInt(maxTokenMatch); - } - - String maxTokenContext = properties - .getProperty("krill.context.max.token"); - if (maxTokenContext != null) { - KrillProperties.maxTokenContextSize = Integer - .parseInt(maxTokenContext); - } - } - catch (NumberFormatException e) { - log.error("A Krill property expects numerical values: " - + e.getMessage()); - }; - } - @Deprecated public void readPipesFile (String filename) throws IOException { File file = new File(filename); diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java index ecdad644..ea5008fd 100644 --- a/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java +++ b/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java @@ -213,4 +213,18 @@ public void testGetStatisticsWithoutKoralQuery () assertEquals(25074, node.at("/sentences").asInt()); assertEquals(772, node.at("/paragraphs").asInt()); } + + @Test + public void testStatisticsWithNamedVC () throws KustvaktException { + Response response = target().path(API_VERSION).path("statistics") + .queryParam("cq", "referTo unknownVC") + .request().method("GET"); + String ent = response.readEntity(String.class); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + JsonNode node = JsonUtils.readTree(ent); + assertEquals(0, node.at("/documents").asInt()); + assertEquals(0, node.at("/tokens").asInt()); + assertEquals(0, node.at("/sentences").asInt()); + assertEquals(0, node.at("/paragraphs").asInt()); + } } diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusReferenceTest.java similarity index 92% rename from src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java rename to src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusReferenceTest.java index 2afb2f79..5c53e177 100644 --- a/src/test/java/de/ids_mannheim/korap/web/controller/VCReferenceTest.java +++ b/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusReferenceTest.java @@ -30,7 +30,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; -public class VCReferenceTest extends SpringJerseyTest { +public class VirtualCorpusReferenceTest extends SpringJerseyTest { @Autowired private NamedVCLoader vcLoader; @@ -130,7 +130,7 @@ private JsonNode testSearchWithRef_VC2 () throws KustvaktException { public void testStatisticsWithRef () throws KustvaktException { String corpusQuery = "availability = /CC-BY.*/ & referTo named-vc1"; Response response = target().path(API_VERSION).path("statistics") - .queryParam("corpusQuery", corpusQuery).request().get(); + .queryParam("cq", corpusQuery).request().get(); String ent = response.readEntity(String.class); JsonNode node = JsonUtils.readTree(ent); assertEquals(2, node.at("/documents").asInt()); @@ -138,6 +138,19 @@ public void testStatisticsWithRef () throws KustvaktException { assertFalse(VirtualCorpusCache.contains("named-vc1")); } + @Test + public void testStatisticsWithUnknownVC () throws KustvaktException { + String corpusQuery = "referTo unknown-vc"; + Response response = target().path(API_VERSION).path("statistics") + .queryParam("cq", corpusQuery).request().get(); + String ent = response.readEntity(String.class); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + JsonNode node = JsonUtils.readTree(ent); + assertEquals(0, node.at("/documents").asInt()); + assertEquals(0, node.at("/tokens").asInt()); + assertEquals(0, node.at("/sentences").asInt()); + } + @Test public void testRefVcNotExist () throws KustvaktException { Response response = target().path(API_VERSION).path("search") diff --git a/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java index 4314ef05..5fe5b1af 100644 --- a/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java +++ b/src/test/java/de/ids_mannheim/korap/web/lite/LiteStatisticControllerTest.java @@ -160,4 +160,18 @@ public void testGetStatisticsWithoutKoralQuery () assertEquals(25074, node.at("/sentences").asInt()); assertEquals(772, node.at("/paragraphs").asInt()); } + + @Test + public void testStatisticsWithNamedVC () throws KustvaktException { + Response response = target().path(API_VERSION).path("statistics") + .queryParam("cq", "referTo unknownVC") + .request().method("GET"); + String ent = response.readEntity(String.class); + assertEquals(Status.OK.getStatusCode(), response.getStatus()); + JsonNode node = JsonUtils.readTree(ent); + assertEquals(0, node.at("/documents").asInt()); + assertEquals(0, node.at("/tokens").asInt()); + assertEquals(0, node.at("/sentences").asInt()); + assertEquals(0, node.at("/paragraphs").asInt()); + } }