Skip to content

Commit

Permalink
Remove corpusQuery param in the statistics web-service (close #758).
Browse files Browse the repository at this point in the history
Change-Id: Id0948be3f2f358d1cf747ecde4cebadb6d9b57b3
  • Loading branch information
margaretha committed Jun 12, 2024
1 parent c55b861 commit f6f6c3c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 184 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# version 0.73.3-SNAPSHOT

- Remove corpusQuery param in the statistics web-service (close #758).

# version 0.73.2

- Added tests for the DNB scenario with custom max match
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.ids-mannheim.korap.kustvakt</groupId>
<artifactId>Kustvakt</artifactId>
<version>0.73.2</version>
<version>0.73.3-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.response.Notifications;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
import de.ids_mannheim.korap.web.SearchKrill;
Expand All @@ -24,8 +22,7 @@ public class StatisticService extends BasicService {
@Autowired
private KustvaktConfiguration config;

public String retrieveStatisticsForCorpusQuery (List<String> cqList,
boolean isDeprecated) throws KustvaktException {
public String retrieveStatisticsForCorpusQuery (List<String> cqList) throws KustvaktException {

KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
String cq = combineMultipleCorpusQuery(cqList);
Expand All @@ -40,16 +37,6 @@ public String retrieveStatisticsForCorpusQuery (List<String> cqList,
}
String stats = searchKrill.getStatistics(json);

if (isDeprecated) {
Notifications n = new Notifications();
n.addWarning(StatusCodes.DEPRECATED,
"Parameter corpusQuery is deprecated in favor of cq.");
ObjectNode warning = (ObjectNode) n.toJsonNode();
ObjectNode node = (ObjectNode) JsonUtils.readTree(stats);
node.setAll(warning);
stats = node.toString();
}

if (stats.contains("-1")) {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,11 @@ public class StatisticController {
*/
@GET
public Response getStatistics (@Context SecurityContext context,
@Context Locale locale, @QueryParam("cq") List<String> cq,
@QueryParam("corpusQuery") List<String> corpusQuery) {
@Context Locale locale, @QueryParam("cq") List<String> cq) {

String stats;
boolean isDeprecated = false;
try {
if (cq.isEmpty() && corpusQuery != null && !corpusQuery.isEmpty()) {
isDeprecated = true;
cq = corpusQuery;
}
stats = service.retrieveStatisticsForCorpusQuery(cq, isDeprecated);
stats = service.retrieveStatisticsForCorpusQuery(cq);
if (DEBUG) {
jlog.debug("Stats: " + stats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,4 @@ public void testStatisticsWithMultipleCq ()
assertEquals(258, node.at("/paragraphs").asInt());
assertTrue(node.at("/warnings").isMissingNode());
}

@Test
public void testStatisticsWithMultipleCorpusQuery ()
throws ProcessingException, KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "textType=Autobiographie")
.queryParam("corpusQuery", "corpusSigle=GOE").request()
.method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(9, node.at("/documents").asInt());
assertEquals(527662, node.at("/tokens").asInt());
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
assertEquals(node.at("/warnings/0/1").asText(),
"Parameter corpusQuery is deprecated in favor of cq.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void testGetStatisticsNoResource ()
throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=WPD15";
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", corpusQuery).request().get();
.queryParam("cq", corpusQuery).request().get();
assert Status.OK.getStatusCode() == response.getStatus();
assertEquals(response.getHeaders().getFirst("X-Index-Revision"),
"Wes8Bd4h1OypPqbWF5njeQ==");
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(), 0);
assertEquals(node.get("tokens").asInt(), 0);
assertEquals(0,node.get("documents").asInt());
assertEquals(0,node.get("tokens").asInt());
}

@Test
Expand All @@ -54,83 +54,62 @@ public void testStatisticsWithCq () throws KustvaktException {
assertTrue(node.at("/warnings").isMissingNode());
}

@Test
public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.queryParam("corpusQuery",
"textType=Autobiographie & corpusSigle=GOE")
.request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
assertEquals(5687, node.at("/sentences").asInt());
assertEquals(258, node.at("/paragraphs").asInt());
assertTrue(node.at("/warnings").isMissingNode());
}

@Test
public void testGetStatisticsWithcorpusQuery1 ()
throws IOException, KustvaktException {
String corpusQuery = "corpusSigle=GOE";
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", corpusQuery).request().get();
.queryParam("cq", corpusQuery).request().get();
assert Status.OK.getStatusCode() == response.getStatus();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.get("documents").asInt(), 11);
assertEquals(node.get("tokens").asInt(), 665842);
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
assertEquals(node.at("/warnings/0/1").asText(),
"Parameter corpusQuery is deprecated in favor of cq.");
assertEquals(11,node.get("documents").asInt());
assertEquals(665842,node.get("tokens").asInt());
}

@Test
public void testGetStatisticsWithcorpusQuery2 ()
throws IOException, KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "creationDate since 1810").request()
.queryParam("cq", "creationDate since 1810").request()
.get();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assert Status.OK.getStatusCode() == response.getStatus();
assertEquals(node.get("documents").asInt(), 7);
assertEquals(node.get("tokens").asInt(), 279402);
assertEquals(node.get("sentences").asInt(), 11047);
assertEquals(node.get("paragraphs").asInt(), 489);
assertEquals(7,node.get("documents").asInt());
assertEquals(279402,node.get("tokens").asInt());
assertEquals(11047,node.get("sentences").asInt());
assertEquals(489,node.get("paragraphs").asInt());
}

@Test
public void testGetStatisticsWithWrongcorpusQuery ()
throws IOException, KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "creationDate geq 1810").request()
.get();
.queryParam("cq", "creationDate geq 1810").request().get();
assert Status.BAD_REQUEST.getStatusCode() == response.getStatus();
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 302);
assertEquals(node.at("/errors/0/1").asText(),
"Could not parse query >>> (creationDate geq 1810) <<<.");
assertEquals(node.at("/errors/0/2").asText(),
"(creationDate geq 1810)");
assertEquals(302, node.at("/errors/0/0").asInt());
assertEquals("Could not parse query >>> (creationDate geq 1810) <<<.",
node.at("/errors/0/1").asText());
assertEquals("(creationDate geq 1810)",
node.at("/errors/0/2").asText());
}

@Test
public void testGetStatisticsWithWrongcorpusQuery2 ()
throws IOException, KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "creationDate >= 1810").request()
.get();
.queryParam("cq", "creationDate >= 1810").request().get();
String ent = response.readEntity(String.class);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 305);
assertEquals(node.at("/errors/0/1").asText(),
"Operator >= is not acceptable.");
assertEquals(node.at("/errors/0/2").asText(), ">=");
assertEquals(305, node.at("/errors/0/0").asInt());
assertEquals("Operator >= is not acceptable.",
node.at("/errors/0/1").asText());
assertEquals(">=", node.at("/errors/0/2").asText());
}

@Test
Expand Down Expand Up @@ -178,10 +157,10 @@ public void testGetStatisticsWithEmptyCollection ()
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
String ent = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(),
de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION);
assertEquals(node.at("/errors/0/1").asText(),
"Collection is not found");
assertEquals(de.ids_mannheim.korap.util.StatusCodes.MISSING_COLLECTION,
node.at("/errors/0/0").asInt());
assertEquals("Collection is not found",
node.at("/errors/0/1").asText());
}

@Test
Expand All @@ -196,8 +175,8 @@ public void testGetStatisticsWithIncorrectJson ()
JsonNode node = JsonUtils.readTree(ent);
assertEquals(StatusCodes.DESERIALIZATION_FAILED,
node.at("/errors/0/0").asInt());
assertEquals(node.at("/errors/0/1").asText(),
"Failed deserializing json object: { \"collection\" : }");
assertEquals("Failed deserializing json object: { \"collection\" : }",
node.at("/errors/0/1").asText());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import com.fasterxml.jackson.databind.JsonNode;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import com.fasterxml.jackson.databind.JsonNode;

import de.ids_mannheim.korap.config.LiteJerseyTest;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.utils.JsonUtils;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;

public class LiteMultipleCorpusQueryTest extends LiteJerseyTest {

Expand All @@ -28,15 +27,15 @@ public void testSearchGet () throws KustvaktException {
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
node = node.at("/collection");
assertEquals(node.at("/@type").asText(), "koral:docGroup");
assertEquals(node.at("/operation").asText(), "operation:and");
assertEquals("koral:docGroup",node.at("/@type").asText());
assertEquals("operation:and",node.at("/operation").asText());
assertEquals(2, node.at("/operands").size());
assertEquals(node.at("/operands/0/@type").asText(), "koral:doc");
assertEquals(node.at("/operands/0/match").asText(), "match:eq");
assertEquals(node.at("/operands/0/key").asText(), "pubPlace");
assertEquals(node.at("/operands/0/value").asText(), "München");
assertEquals(node.at("/operands/1/key").asText(), "textSigle");
assertEquals(node.at("/operands/1/value").asText(), "GOE/AGA/01784");
assertEquals("koral:doc",node.at("/operands/0/@type").asText());
assertEquals("match:eq",node.at("/operands/0/match").asText());
assertEquals("pubPlace",node.at("/operands/0/key").asText());
assertEquals("München",node.at("/operands/0/value").asText());
assertEquals("textSigle",node.at("/operands/1/key").asText());
assertEquals("GOE/AGA/01784",node.at("/operands/1/value").asText());
}

@Test
Expand All @@ -55,22 +54,4 @@ public void testStatisticsWithMultipleCq ()
assertTrue(node.at("/warnings").isMissingNode());
}

@Test
public void testStatisticsWithMultipleCorpusQuery ()
throws ProcessingException, KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "textType=Autobiographie")
.queryParam("corpusQuery", "corpusSigle=GOE").request()
.method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String entity = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(9, node.at("/documents").asInt());
assertEquals(527662, node.at("/tokens").asInt());
assertEquals(19387, node.at("/sentences").asInt());
assertEquals(514, node.at("/paragraphs").asInt());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
assertEquals(node.at("/warnings/0/1").asText(),
"Parameter corpusQuery is deprecated in favor of cq.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,9 @@ public void testStatisticsWithCq () throws KustvaktException {
}

@Test
public void testStatisticsWithCqAndCorpusQuery () throws KustvaktException {
public void testStatisticsEmptyCq () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("cq", "textType=Abhandlung & corpusSigle=GOE")
.queryParam("corpusQuery",
"textType=Autobiographie & corpusSigle=GOE")
.request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
assertEquals(2, node.at("/documents").asInt());
assertEquals(138180, node.at("/tokens").asInt());
assertEquals(5687, node.at("/sentences").asInt());
assertEquals(258, node.at("/paragraphs").asInt());
assertTrue(node.at("/warnings").isMissingNode());
}

@Test
public void testStatisticsWithCorpusQuery () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery",
"textType=Autobiographie & corpusSigle=GOE")
.request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(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());
assertEquals(StatusCodes.DEPRECATED, node.at("/warnings/0/0").asInt());
assertEquals(node.at("/warnings/0/1").asText(),
"Parameter corpusQuery is deprecated in favor of cq.");
}

@Test
public void testEmptyStatistics () throws KustvaktException {
Response response = target().path(API_VERSION).path("statistics")
.queryParam("corpusQuery", "").request().method("GET");
.queryParam("cq", "").request().method("GET");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
String query = response.readEntity(String.class);
JsonNode node = JsonUtils.readTree(query);
Expand Down
Loading

0 comments on commit f6f6c3c

Please sign in to comment.