error handling for missing query string
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder2.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder2.java
index 7f68b64..5f37988 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder2.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryBuilder2.java
@@ -16,13 +16,20 @@
private List<Map> rq;
private Map groups;
private CollectionTypes types;
+ private boolean verbose;
public CollectionQueryBuilder2() {
+ this.verbose = false;
this.rq = new ArrayList<>();
this.groups = new HashMap();
this.types = new CollectionTypes();
}
+ public CollectionQueryBuilder2(boolean verbose) {
+ this();
+ this.verbose = verbose;
+ }
+
public CollectionQueryBuilder2 addResource(String collections) {
try {
@@ -43,8 +50,7 @@
public CollectionQueryBuilder2 setQuery(String query) throws QueryException {
CollectionQueryTree tree = new CollectionQueryTree();
tree.process(query);
- this.groups = (Map) tree.getRequestMap().get("query");
- System.out.println("RAW QUERY: " + this.groups);
+ this.groups = tree.getRequestMap();
return this;
}
@@ -54,18 +60,22 @@
return list;
}
+ private Object raw2() {
+ return this.groups;
+ }
+
public String toCollections() {
Map value = new HashMap();
- value.put("collections", raw());
+ value.put("collections", raw2());
return JsonUtils.toJSON(value);
}
public JsonNode toNode() {
- return JsonUtils.valueToTree(raw());
+ return JsonUtils.valueToTree(raw2());
}
public String toJSON() {
- return JsonUtils.toJSON(raw());
+ return JsonUtils.toJSON(raw2());
}
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 75f9803..6e86dc4 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
@@ -4,6 +4,8 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import de.ids_mannheim.korap.util.QueryException;
import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.utils.KorAPLogger;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -14,6 +16,7 @@
*/
public class QuerySerializer {
+ private Logger qllogger = KorAPLogger.initiate("ql");
public static String queryLanguageVersion;
private AbstractSyntaxTree ast;
@@ -95,6 +98,11 @@
public QuerySerializer setQuery(String query, String ql, String version)
throws QueryException {
+
+ if (query.isEmpty())
+ throw new QueryException(406, "No Content!");
+
+
try {
if (ql.equalsIgnoreCase("poliqarp")) {
ast = new PoliqarpPlusTree(query);
@@ -103,8 +111,10 @@
} else if (ql.equalsIgnoreCase("poliqarpplus")) {
ast = new PoliqarpPlusTree(query);
} else if (ql.equalsIgnoreCase("cql")) {
-// queryLanguageVersion = "1.2"; // set me
- ast = new CQLTree(query, version);
+ if (version == null)
+ ast = new CQLTree(query);
+ else
+ ast = new CQLTree(query, version);
} else if (ql.equalsIgnoreCase("annis")) {
ast = new AqlTree(query);
} else {
@@ -113,6 +123,7 @@
} catch (QueryException e) {
throw e;
} catch (Exception e) {
+ e.printStackTrace();
throw new QueryException("UNKNOWN: Query could not be parsed (" + query + ")");
}
return this;
@@ -123,7 +134,9 @@
}
public final String toJSON() {
- return JsonUtils.toJSON(raw());
+ String ser = JsonUtils.toJSON(raw());
+ qllogger.info("Serialized query: " + ser);
+ return ser;
}
public final Map build() {
diff --git a/src/test/java/CollectionQueryTreeTest.java b/src/test/java/CollectionQueryTreeTest.java
index aef9d49..24aadfd 100644
--- a/src/test/java/CollectionQueryTreeTest.java
+++ b/src/test/java/CollectionQueryTreeTest.java
@@ -1,13 +1,9 @@
-import static org.junit.Assert.*;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryBuilder;
-import de.ids_mannheim.korap.query.serialize.CollectionQueryBuilder2;
import de.ids_mannheim.korap.query.serialize.CollectionQueryTree;
-import de.ids_mannheim.korap.resource.Relation;
import de.ids_mannheim.korap.util.QueryException;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.utils.TimeUtils;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class CollectionQueryTreeTest {
CollectionQueryTree cqt;
@@ -166,8 +162,8 @@
cqt.process(query);
map = cqt.getRequestMap().toString();
assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
-
- query = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & year=2010)";
+
+ query = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & year=2010)";
expected =
"{@type=korap:filter, filter=" +
"{@type=korap:docGroup, relation=relation:or, operands=[" +