Added a method to add warnings in QuerySerializer
Change-Id: Icce3d766461454c985b79cb03be08050a48a4765
diff --git a/Changes b/Changes
index de6a342..d99749f 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,5 @@
-0.35 2019-09-25
+0.35 2019-11-12
+ - Added a method to add warnings in QuerySerializer (margaretha)
0.34 2019-08-27
- [bugfix] Ignore min:max order in distance operators
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 9ae9b77..44221a9 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -350,4 +350,15 @@
map.put("collection", collection);
return mapper.writeValueAsString(map);
}
+
+ public void addWarning (int statusCode, String message,
+ List<String> entities) {
+ ArrayList<Object> warning = new ArrayList<>();
+ warning.add(statusCode);
+ warning.add(message);
+ if (entities != null) {
+ warning.addAll(entities);
+ }
+ this.warnings.add(warning);
+ }
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java b/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
index 43845b4..a1a202f 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/EmptyResultsTest.java
@@ -7,6 +7,9 @@
import org.junit.Assert;
import org.junit.Test;
+import java.util.List;
+import java.util.ArrayList;
+
import static org.junit.Assert.assertEquals;
@@ -49,4 +52,22 @@
assertEquals(node.has("meta"), false);
}
+ @Test
+ public void testWarnings () {
+ QuerySerializer s = new QuerySerializer();
+ s.setQuery("[base=Wort]", "poliqarp");
+ List<String> l = new ArrayList<String>(1);
+ l.add("Hui");
+ s.addWarning(14, "Beispiel", l);
+ s.addWarning(16, "Beispiel 2", null);
+
+ JsonNode node = mapper.valueToTree(s.build());
+ assertEquals(true, node.has("warnings"));
+ assertEquals(14, node.at("/warnings/0/0").asInt());
+ assertEquals("Beispiel", node.at("/warnings/0/1").asText());
+ assertEquals("Hui", node.at("/warnings/0/2").asText());
+ assertEquals(16, node.at("/warnings/1/0").asInt());
+ assertEquals("Beispiel 2", node.at("/warnings/1/1").asText());
+ assertEquals(false, node.has("/warnings/1/2"));
+ }
}