update QueryExceptions in CQL
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
index 0f49ced..332deae 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CQLTree.java
@@ -11,7 +11,7 @@
/**
* @author margaretha
- * @date 23.04.14
+ * @date 09.05.14
*/
public class CQLTree extends AbstractSyntaxTree {
@@ -55,7 +55,7 @@
@Override
public void process(String query) throws QueryException {
if ((query == null) || query.isEmpty())
- throw new QueryException(27, "An empty query is unsupported.");
+ throw new QueryException(400, "SRU diagnostic 27: An empty query is unsupported.");
CQLNode cqlNode = parseQuerytoCQLNode(query);
Map<String,Object> queryMap = parseCQLNode(cqlNode);
@@ -87,7 +87,7 @@
} else if (node instanceof CQLOrNode) {
return parseOrNode((CQLOrNode) node);
} else {
- throw new QueryException(48, "Only basic search including term-only " +
+ throw new QueryException(400, "SRU diagnostic 48: Only basic search including term-only " +
"and boolean operator queries (AND and OR) are currently supported.");
}
}
@@ -96,7 +96,7 @@
checkTermNode(node);
final String term = node.getTerm();
if ((term == null) || term.isEmpty()) {
- throw new QueryException(27, "An empty term is unsupported.");
+ throw new QueryException(400, "SRU diagnostic 27: An empty term is unsupported.");
} else if (term.contains(" ")) {
return writeSequence(term);
} else {
@@ -178,7 +178,7 @@
List<Modifier> modifiers = node.getModifiers();
if ((modifiers != null) && !modifiers.isEmpty()) {
Modifier modifier = modifiers.get(0);
- throw new QueryException(20, "Relation modifier " +
+ throw new QueryException(400, "SRU diagnostic 20: Relation modifier " +
modifier.toCQL() + " is not supported.");
}
}
@@ -187,7 +187,7 @@
// only allow "cql.serverChoice" and "words" index
if (!(INDEX_CQL_SERVERCHOICE.equals(node.getIndex()) ||
INDEX_WORDS.equals(node.getIndex()))) {
- throw new QueryException(16, "Index " + node.getIndex() + " is not supported.");
+ throw new QueryException(400, "SRU diagnostic 16: Index " + node.getIndex() + " is not supported.");
}
// only allow "=" relation without any modifiers
CQLRelation relation = node.getRelation();
@@ -195,13 +195,13 @@
if (!(TERM_RELATION_CQL_1_1.equals(baseRel) ||
TERM_RELATION_CQL_1_2.equals(baseRel) ||
SUPPORTED_RELATION_EXACT.equals(baseRel))) {
- throw new QueryException(19, "Relation " +
+ throw new QueryException(400, "SRU diagnostic 19: Relation " +
relation.getBase() + " is not supported.");
}
List<Modifier> modifiers = relation.getModifiers();
if ((modifiers != null) && !modifiers.isEmpty()) {
Modifier modifier = modifiers.get(0);
- throw new QueryException(20, "Relation modifier " +
+ throw new QueryException(400, "SRU diagnostic 20: Relation modifier " +
modifier.getValue() + " is not supported.");
}
}
diff --git a/src/test/java/CQLTest.java b/src/test/java/CQLTest.java
index 2686b03..b372ce0 100644
--- a/src/test/java/CQLTest.java
+++ b/src/test/java/CQLTest.java
@@ -25,35 +25,40 @@
try {
CQLTree cqlTree = new CQLTree(query, version);
} catch (QueryException e) {
- assertEquals(48,e.getErrorCode());
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
+ assertEquals(48,errorCode);
}
query = "(Kuh) or/rel.combine=sum (Germ) ";
try {
CQLTree cqlTree = new CQLTree(query, version);
}catch (QueryException e) {
- assertEquals(20,e.getErrorCode());
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
+ assertEquals(20,errorCode);
}
query = "dc.title any Germ ";
try {
CQLTree cqlTree = new CQLTree(query, version);
} catch (QueryException e) {
- assertEquals(16,e.getErrorCode());
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
+ assertEquals(16,errorCode);
}
query = "cql.serverChoice any Germ ";
try {
CQLTree cqlTree = new CQLTree(query, version);
} catch (QueryException e) {
- assertEquals(19,e.getErrorCode());
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
+ assertEquals(19,errorCode);
}
query = "";
try {
CQLTree cqlTree = new CQLTree(query, version);
} catch (QueryException e) {
- assertEquals(27,e.getErrorCode());
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
+ assertEquals(27,errorCode);
}
}
@@ -62,7 +67,7 @@
query="(Sonne) and (scheint)";
String jsonLd =
"{@type : korap:group, operation : operation:sequence, distances:[ "+
- "{@type : korap:distance, key : t, min : 0, max : 0 } ],"+
+ "{@type : korap:distance, key : w, min : 0, max : 0 } ],"+
"operands : ["+
"{@type : korap:token, wrap : {@type : korap:term,key : Sonne, layer : orth, match : match:eq}}," +
"{@type : korap:token,wrap : {@type : korap:term,key : scheint,layer : orth,match : match:eq}" +
@@ -83,7 +88,7 @@
query="((Sonne) or (Mond)) and (scheint)";
String jsonLd =
"{@type:korap:group, operation:operation:sequence, distances:[" +
- "{@type:korap:distance, key:t, min:0, max:0}" +
+ "{@type:korap:distance, key:w, min:0, max:0}" +
"], operands:[" +
"{@type:korap:group, operation:operation:or, operands:[" +
"{@type:korap:token, wrap:{@type:korap:term, key:Sonne, layer:orth, match:match:eq}}," +
@@ -99,7 +104,7 @@
query="(scheint) and ((Sonne) or (Mond))";
jsonLd =
"{@type:korap:group, operation:operation:sequence, distances:[" +
- "{@type:korap:distance, key:t, min:0, max:0}" +
+ "{@type:korap:distance, key:w, min:0, max:0}" +
"], operands:[" +
"{@type:korap:token, wrap:{@type:korap:term, key:scheint, layer:orth, match:match:eq}}," +
"{@type:korap:group, operation:operation:or, operands:[" +