Fix error serialization (flatten arrays instead of nested arrays)
Change-Id: I39b3a4f56fe82d2abd41365da9200604f76571c6
diff --git a/Changes b/Changes
index 17e4db5..b4bc7bd 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
-0.33 2019-01-08
+0.33 2019-02-15
- Added debug flags (margaretha)
- [bugfix] Fixed poliqarp layer bug (#52; margaretha)
- Replaced log4j with log4j2 (margaretha)
- Fixed issue #43 - C2 OPIN (margaretha)
+ - [bugfix] Flatten serialization of query errors (diewald, margaretha)
0.32 2018-12-13
- [bugfix] Support verbatim string queries (#57; diewald).
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
index 53fa5bd..c6a909b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
@@ -181,14 +181,6 @@
errors.add(error);
}
- public void addError (int code, String[] details) {
- List<Object> error = new ArrayList<Object>();
- error.add(code);
- error.add(details);
- errors.add(error);
- }
-
-
/**
* Adds an error to {@link #errors}.
*
@@ -241,4 +233,4 @@
public Map<String, Object> getRequestMap () {
return requestMap;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index 2688675..c2e14e9 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -77,8 +77,11 @@
processNode(tree);
}
else {
- addError(StatusCodes.MALFORMED_QUERY, new String[]{"Could not parse query >>> "
- + query + " <<<.", query});
+ ArrayList<Object> errors = new ArrayList<>(3);
+ errors.add(StatusCodes.MALFORMED_QUERY);
+ errors.add("Could not parse query >>> "+ query + " <<<.");
+ errors.add(query);
+ addError(errors);
}
}
@@ -129,8 +132,13 @@
term.put("match", "match:" + interpretMatchOperator(match));
if (!checkOperatorValueConformance(term)) {
- addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
- new String[]{"Operator "+match+" is not acceptable.", match});
+ ArrayList<Object> errors = new ArrayList<>(3);
+ errors.add(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND);
+ errors.add("Operator "+match+" is not acceptable.");
+ errors.add(match);
+ addError(errors);
+// addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+// new String[]{"Operator "+match+" is not acceptable.", match});
requestMap = new HashMap<String, Object>();
return;
}
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 cba745c..9ae9b77 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
@@ -61,6 +61,16 @@
this.messages = new ArrayList<>();
}
+
+ /**
+ * Remove all messages from the query serialization.
+ */
+ public void resetMsgs () {
+ this.errors.clear();
+ this.warnings.clear();
+ this.messages.clear();
+ }
+
/**
* @param args
*/
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
index 3c37b34..5829482 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/collection/CollectionQueryProcessorTest.java
@@ -279,10 +279,23 @@
assertEquals("match:eq", res.at("/collection/match").asText());
}
+ @Test
+ public void testRegexFailure () throws JsonProcessingException, IOException {
+ collection = "textClass=/po/litik/";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ qs.resetMsgs();
+ assertEquals("302", res.at("/errors/0/0").asText());
+ assertEquals("Could not parse query >>> textClass=/po/litik/ <<<.",
+ res.at("/errors/0/1").asText());
+ assertEquals("", res.at("/errors/1/0").asText());
+ }
@Test
public void testNotDate () throws JsonProcessingException, IOException {
collection = "author=\"firefighter1974\"";
+ qs.resetMsgs();
qs.setQuery(query, ql);
qs.setCollection(collection);
res = mapper.readTree(qs.toJSON());
diff --git a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
index 4958fe2..f8bfa1a 100644
--- a/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/test/poliqarpplus/PoliqarpPlusQueryProcessorTest.java
@@ -155,6 +155,8 @@
assertEquals("NN", res.at("/query/wrap/key").asText());
assertEquals("p", res.at("/query/wrap/layer").asText());
assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("", res.at("/errors/0/0").asText());
+ assertEquals("", res.at("/errors/1/0").asText());
}