Lots of cleanups
diff --git a/src/main/java/de/ids_mannheim/korap/KorapIndex.java b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
index a51eabd..a529a73 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapIndex.java
@@ -1082,7 +1082,7 @@
int i = 0,
startIndex = kr.getStartIndex(),
count = kr.getItemsPerPage(),
- hits = kr.itemsPerPage() + startIndex,
+ hits = kr.getItemsPerPage() + startIndex,
limit = ks.getLimit(),
itemsPerResourceCounter = 0;
boolean cutoff = ks.doCutOff();
@@ -1099,7 +1099,7 @@
};
// Collect matches from atomic readers
- ArrayList<KorapMatch> atomicMatches = new ArrayList<KorapMatch>(kr.itemsPerPage());
+ ArrayList<KorapMatch> atomicMatches = new ArrayList<KorapMatch>(kr.getItemsPerPage());
// Start time out thread
TimeOutThread tthread = new TimeOutThread();
@@ -1261,7 +1261,7 @@
if (itemsPerResource > 0)
kr.setItemsPerResource(itemsPerResource);
- kr.setTotalResults(cutoff ? -1 : i);
+ kr.setTotalResults(cutoff ? (long) -1 : (long) i);
}
catch (IOException e) {
kr.addError(
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index 98811db..74a62bc 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -1339,7 +1339,7 @@
// Identical to KorapResult!
- public String toJSON () {
+ public String toJsonString () {
ObjectNode json = (ObjectNode) mapper.valueToTree(this);
// Match was no match
@@ -1347,7 +1347,7 @@
return "{}";
if (this.context != null)
- json.put("context", this.getContext().toJSON());
+ json.put("context", this.getContext().toJsonNode());
if (this.version != null)
json.put("version", this.getVersion());
diff --git a/src/main/java/de/ids_mannheim/korap/KorapQuery.java b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
index d7962e8..96bd4ac 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapQuery.java
@@ -100,7 +100,7 @@
};
};
- public SpanQueryWrapper fromJSON (String jsonString) throws QueryException {
+ public SpanQueryWrapper fromJson (String jsonString) throws QueryException {
JsonNode json;
try {
json = this.json.readValue(jsonString, JsonNode.class);
@@ -114,7 +114,7 @@
if (!json.has("@type") && json.has("query"))
json = json.get("query");
- return this.fromJSON(json);
+ return this.fromJson(json);
};
// http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/JsonNode.html
@@ -122,7 +122,7 @@
// TODO: Use the shortcuts implemented in this class instead of the wrapper constructors
// TODO: Check for isArray()
// TODO: Rename this span context!
- public SpanQueryWrapper fromJSON (JsonNode json) throws QueryException {
+ public SpanQueryWrapper fromJson (JsonNode json) throws QueryException {
int number = 0;
@@ -161,7 +161,7 @@
case "operation:or":
SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
for (JsonNode operand : operands) {
- ssaq.or(this.fromJSON(operand));
+ ssaq.or(this.fromJson(operand));
};
return ssaq;
@@ -226,8 +226,8 @@
);
return new SpanWithinQueryWrapper(
- this.fromJSON(operands.get(0)),
- this.fromJSON(operands.get(1)),
+ this.fromJson(operands.get(0)),
+ this.fromJson(operands.get(1)),
flag
);
@@ -254,14 +254,14 @@
};
return new SpanMatchModifyQueryWrapper(
- this.fromJSON(operands.get(0)), number
+ this.fromJson(operands.get(0)), number
);
case "operation:sequence":
// Sequence with only one operand
if (operands.size() == 1)
- return this.fromJSON(operands.get(0));
+ return this.fromJson(operands.get(0));
SpanSequenceQueryWrapper sseqqw = this.seq();
@@ -364,7 +364,7 @@
// Add segments to sequence
for (JsonNode operand : operands) {
- sseqqw.append(this.fromJSON(operand));
+ sseqqw.append(this.fromJson(operand));
};
// inOrder was set to false without a distance constraint
@@ -413,7 +413,7 @@
);
};
- SpanQueryWrapper sqw = this.fromJSON(operands.get(0));
+ SpanQueryWrapper sqw = this.fromJson(operands.get(0));
// Problematic
if (sqw.maybeExtension())
@@ -469,7 +469,7 @@
if (min > max)
max = max;
- SpanQueryWrapper sqw = this.fromJSON(operands.get(0));
+ SpanQueryWrapper sqw = this.fromJson(operands.get(0));
if (sqw.maybeExtension())
return sqw.setMin(min).setMax(max);
@@ -530,7 +530,7 @@
log.trace("Wrap class reference {}", number);
return new SpanMatchModifyQueryWrapper(
- this.fromJSON(operands.get(0)), number
+ this.fromJson(operands.get(0)), number
);
case "korap:token":
@@ -539,17 +539,17 @@
if (!json.has("wrap"))
return new SpanRepetitionQueryWrapper();
- return this._segFromJSON(json.get("wrap"));
+ return this._segFromJson(json.get("wrap"));
case "korap:span":
- return this._termFromJSON(json);
+ return this._termFromJson(json);
};
throw new QueryException(713, "Query type is not supported");
};
- private SpanQueryWrapper _segFromJSON (JsonNode json) throws QueryException {
+ private SpanQueryWrapper _segFromJson (JsonNode json) throws QueryException {
if (!json.has("@type"))
throw new QueryException(701, "JSON-LD group has no @type attribute");
@@ -571,11 +571,11 @@
if (DEBUG)
log.trace("Term is negated");
SpanSegmentQueryWrapper ssqw =
- (SpanSegmentQueryWrapper) this._termFromJSON(json);
+ (SpanSegmentQueryWrapper) this._termFromJson(json);
ssqw.makeNegative();
return this.seg().without(ssqw);
case "match:eq":
- return this._termFromJSON(json);
+ return this._termFromJson(json);
};
throw new QueryException(741, "Match relation unknown");
@@ -597,7 +597,7 @@
case "relation:and":
for (JsonNode operand : operands) {
- SpanQueryWrapper part = this._segFromJSON(operand);
+ SpanQueryWrapper part = this._segFromJson(operand);
if (part instanceof SpanAlterQueryWrapper) {
ssegqw.with((SpanAlterQueryWrapper) part);
}
@@ -619,7 +619,7 @@
SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
for (JsonNode operand : operands) {
- ssaq.or(this._segFromJSON(operand));
+ ssaq.or(this._segFromJson(operand));
};
return ssaq;
};
@@ -628,7 +628,7 @@
};
- private SpanQueryWrapper _termFromJSON (JsonNode json) throws QueryException {
+ private SpanQueryWrapper _termFromJson (JsonNode json) throws QueryException {
if (!json.has("key") || json.get("key").asText().length() < 1)
throw new QueryException(740, "Key definition is missing in term or span");
diff --git a/src/main/java/de/ids_mannheim/korap/KorapResult.java b/src/main/java/de/ids_mannheim/korap/KorapResult.java
index 9ac2aef..6b5516e 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapResult.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapResult.java
@@ -30,23 +30,18 @@
@JsonIgnore
public static final short ITEMS_PER_PAGE = 25;
- private int totalResults;
- private long totalTexts;
+ private int startIndex = 0;
+ private long totalTexts, totalResults;
private String query;
private List<KorapMatch> matches;
- private int startIndex = 0;
private SearchContext context;
- private short itemsPerPage = ITEMS_PER_PAGE;
- private short itemsPerResource = 0;
-
- private String benchmarkSearchResults,
- benchmarkHitCounter;
- private String error = null;
+ private short itemsPerPage = ITEMS_PER_PAGE,
+ itemsPerResource = 0;
private JsonNode request;
@@ -95,20 +90,10 @@
return km;
};
- @Deprecated
- public int totalResults() {
- return this.getTotalResults();
- };
-
public short getItemsPerPage() {
return this.itemsPerPage;
};
- @Deprecated
- public short itemsPerPage() {
- return this.itemsPerPage;
- };
-
public void setRequest(JsonNode request) {
this.request = request;
};
@@ -117,24 +102,6 @@
return this.request;
};
- /*
- @JsonIgnore
- public void setBenchmarkHitCounter(long t1, long t2) {
- this.benchmarkHitCounter =
- (t2 - t1) < 100_000_000 ? (((double) (t2 - t1) * 1e-6) + " ms") :
- (((double) (t2 - t1) / 1000000000.0) + " s");
- };
-
- public void setBenchmarkHitCounter(String bm) {
- this.benchmarkHitCounter = bm;
- };
-
- public String getBenchmarkHitCounter() {
- return this.benchmarkHitCounter;
- };
-
- */
-
// Make this working in a KorapResult class
// that is independent from search and collection
public KorapResult setTotalTexts (long i) {
@@ -142,11 +109,17 @@
return this;
};
+ public KorapResult incrTotalTexts (int i) {
+ this.totalTexts += i;
+ return this;
+ };
+
public long getTotalTexts() {
return this.totalTexts;
};
- public KorapResult setTotalResults (int i) {
+
+ public KorapResult setTotalResults (long i) {
this.totalResults = i;
return this;
};
@@ -156,7 +129,7 @@
return this;
};
- public int getTotalResults() {
+ public long getTotalResults() {
return this.totalResults;
};
@@ -189,16 +162,10 @@
return this.matches;
};
- @Deprecated
- public KorapMatch match (int index) {
- return this.matches.get(index);
- };
-
public int getStartIndex () {
return startIndex;
};
-
@JsonIgnore
public KorapResult setContext(SearchContext context) {
this.context = context;
@@ -211,11 +178,12 @@
return this.context;
}
- public JsonNode toJSONnode () {
- ObjectNode json = (ObjectNode) mapper.valueToTree(super.toJSONnode());
+
+ public JsonNode toJsonNode () {
+ ObjectNode json = (ObjectNode) mapper.valueToTree(super.toJsonNode());
if (this.context != null)
- json.put("context", this.getContext().toJSON());
+ json.put("context", this.getContext().toJsonNode());
if (this.itemsPerResource > 0)
json.put("itemsPerResource",
@@ -247,7 +215,7 @@
// For Collocation Analysis API
- public String toTokenListJSON () {
+ public String toTokenListJsonString () {
ObjectNode json = (ObjectNode) mapper.valueToTree(this);
ArrayNode array = json.putArray("matches");
diff --git a/src/main/java/de/ids_mannheim/korap/KorapSearch.java b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
index d145856..bc5d205 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapSearch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapSearch.java
@@ -85,7 +85,7 @@
if (this.request.has("query")) {
try {
KorapQuery kq = new KorapQuery("tokens");
- SpanQueryWrapper qw = kq.fromJSON(this.request.get("query"));
+ SpanQueryWrapper qw = kq.fromJson(this.request.get("query"));
if (qw.isEmpty()) {
@@ -160,7 +160,7 @@
// Defined contexts
if (meta.has("context"))
- this.context.fromJSON(meta.get("context"));
+ this.context.fromJson(meta.get("context"));
// Defined resource count
if (meta.has("timeout"))
diff --git a/src/main/java/de/ids_mannheim/korap/index/SearchContext.java b/src/main/java/de/ids_mannheim/korap/index/SearchContext.java
index 9074512..37fda27 100644
--- a/src/main/java/de/ids_mannheim/korap/index/SearchContext.java
+++ b/src/main/java/de/ids_mannheim/korap/index/SearchContext.java
@@ -106,7 +106,7 @@
return this.setLength((short) value);
};
- public void fromJSON (JsonNode json) {
+ public void fromJson (JsonNode json) {
String type = json.get(0).asText();
if (type.equals("token")) {
this.setToken(true);
@@ -119,20 +119,20 @@
};
- public void fromJSON (JsonNode context) {
+ public void fromJson (JsonNode context) {
if (context.isContainerNode()) {
if (context.has("left"))
- this.left.fromJSON(context.get("left"));
+ this.left.fromJson(context.get("left"));
if (context.has("right"))
- this.right.fromJSON(context.get("right"));
+ this.right.fromJson(context.get("right"));
}
else if (context.isValueNode()) {
this.setSpanContext(context.asText());
};
};
- public JsonNode toJSON () {
+ public JsonNode toJsonNode () {
if (this.isSpanDefined())
return new TextNode(this.spanContext);
diff --git a/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java b/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
index 40a75aa..46d4028 100644
--- a/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
+++ b/src/main/java/de/ids_mannheim/korap/response/KorapResponse.java
@@ -16,7 +16,7 @@
* <blockquote><pre>
* KorapResponse km = new KorapResponse();
* System.out.println(
- * km.toJSON()
+ * km.toJsonString()
* );
* </pre></blockquote>
*
@@ -26,8 +26,6 @@
public class KorapResponse extends Notifications {
ObjectMapper mapper = new ObjectMapper();
- // TODO: Add timeout!!!
-
private String version, name, node, listener;
private String benchmark;
private boolean timeExceeded = false;
@@ -40,17 +38,6 @@
*/
public KorapResponse () {};
- /**
- * Get string representation of the backend's version.
- *
- * @return String representation of the backend's version
- */
- @JsonIgnore
- public String getVersion () {
- if (this.version == null)
- return null;
- return this.version;
- };
/**
* Set the string representation of the backend's version.
@@ -64,19 +51,18 @@
return this;
};
+
/**
- * Get string representation of the backend's name.
- * All nodes in a cluster should have the same backend name.
+ * Get string representation of the backend's version.
*
- * @return String representation of the backend's name
+ * @return String representation of the backend's version
*/
@JsonIgnore
- public String getName () {
- if (this.name == null)
- return null;
- return this.name;
+ public String getVersion () {
+ return this.version;
};
+
/**
* Set the string representation of the backend's name.
* All nodes in a cluster should have the same backend name.
@@ -90,17 +76,19 @@
return this;
};
+
/**
- * Get string representation of the node's name.
- * Each node in a cluster has a unique name.
+ * Get string representation of the backend's name.
+ * All nodes in a cluster should have the same backend name.
*
- * @return String representation of the node's name
+ * @return String representation of the backend's name
*/
@JsonIgnore
- public String getNode () {
- return this.node;
+ public String getName () {
+ return this.name;
};
+
/**
* Set the string representation of the node's name.
* Each node in a cluster has a unique name.
@@ -115,79 +103,154 @@
};
+ /**
+ * Get string representation of the node's name.
+ * Each node in a cluster has a unique name.
+ *
+ * @return String representation of the node's name
+ */
@JsonIgnore
- public void setTimeExceeded (boolean timeout) {
- if (timeout)
- this.addWarning(682, "Search time exceeded");
- this.timeExceeded = timeout;
+ public String getNode () {
+ return this.node;
};
+ /**
+ * Set to <tt>true</tt> if time is exceeded
+ * based on a timeout.
+ *
+ * <p>
+ * Will add a warning (682) to the output.
+ *
+ * @param timeout Either <tt>true</tt> or <tt>false</tt>, in case the response
+ * timed out
+ * @return KorapResponse object for chaining
+ */
+ @JsonIgnore
+ public KorapResponse setTimeExceeded (boolean timeout) {
+ if (timeout)
+ this.addWarning(682, "Response time exceeded");
+ this.timeExceeded = timeout;
+ return this;
+ };
+
+
+ /**
+ * Check if the response time was exceeded.
+ *
+ * @return <tt>true</tt> in case the response had a timeout,
+ * otherwise <tt>false</tt>
+ */
@JsonIgnore
public boolean getTimeExceeded () {
return this.timeExceeded;
};
+ /**
+ * Set the benchmark as timestamp differences.
+ *
+ * @param ts1 Starting time of the benchmark
+ * @param ts2 Ending time of the benchmark
+ * @return KorapResponse object for chaining
+ */
@JsonIgnore
- public KorapResponse setBenchmark (long t1, long t2) {
+ public KorapResponse setBenchmark (long ts1, long ts2) {
this.benchmark =
- (t2 - t1) < 100_000_000 ?
+ (ts2 - ts1) < 100_000_000 ?
// Store as miliseconds
- (((double) (t2 - t1) * 1e-6) + " ms") :
+ (((double) (ts2 - ts1) * 1e-6) + " ms") :
// Store as seconds
- (((double) (t2 - t1) / 1000000000.0) + " s");
+ (((double) (ts2 - ts1) / 1000000000.0) + " s");
return this;
};
+
+ /**
+ * Set the benchmark as a string representation.
+ *
+ * @param bm String representation of a benchmark
+ * (including trailing time unit)
+ * @return KorapResponse for chaining
+ */
@JsonIgnore
public KorapResponse setBenchmark (String bm) {
this.benchmark = bm;
return this;
};
+
+ /**
+ * Get the benchmark time as a string.
+ *
+ * @return String representation of the benchmark
+ * (including trailing time unit)
+ */
@JsonIgnore
public String getBenchmark () {
return this.benchmark;
};
+
+ /**
+ * Set the listener URI as a String. This is probably the localhost
+ * with an arbitrary port, like
+ *
+ * <p>
+ * <blockquote><pre>
+ * http://localhost:8080/
+ * </pre></blockquote>
+ *
+ * @param listener String representation of the listener URI
+ * @return KorapResponse object for chaining
+ */
@JsonIgnore
public KorapResponse setListener (String listener) {
this.listener = listener;
return this;
};
+
+ /**
+ * Get the listener URI as a string.
+ *
+ * @return The listener URI as a string representation
+ */
@JsonIgnore
public String getListener () {
return this.listener;
- }
+ };
+
/**
- * Serialize response to JSON node.
+ * Serialize response as a JsonNode.
+ *
+ * @return JsonNode representation of the response
*/
@Override
- public JsonNode toJSONnode () {
+ public JsonNode toJsonNode () {
// Get notifications json response
- ObjectNode json = (ObjectNode) super.toJSONnode();
+ ObjectNode json = (ObjectNode) super.toJsonNode();
StringBuilder sb = new StringBuilder();
if (this.getName() != null) {
sb.append(this.getName());
if (this.getVersion() != null)
- sb.append("-").append(this.getVersion());
- }
- else if (this.getVersion() != null) {
- sb.append(this.getVersion());
+ sb.append("-");
};
- if (this.timeExceeded)
- json.put("timeExceeded", true);
+ // No name but version is given
+ if (this.getVersion() != null)
+ sb.append(this.getVersion());
if (sb.length() > 0)
json.put("version", sb.toString());
+ if (this.timeExceeded)
+ json.put("timeExceeded", true);
+
if (this.getNode() != null)
json.put("node", this.getNode());
@@ -199,4 +262,43 @@
return (JsonNode) json;
};
+
+ /**
+ * Serialize response as a JSON string.
+ * <p>
+ * <blockquote><pre>
+ * {
+ * "version" : "Lucene-Backend-0.49.1",
+ * "timeExceeded" : true,
+ * "node" : "Tanja",
+ * "listener" : "http://localhost:8080/",
+ * "benchmark" : "12.3s",
+ * "errors": [
+ * [123, "You are not allowed to serialize these messages"],
+ * [124, "Your request was invalid"]
+ * ],
+ * "messages" : [
+ * [125, "Class is deprecated", "Notifications"]
+ * ]
+ * }
+ * </pre></blockquote>
+ *
+ * @return String representation of the response
+ */
+ public String toJsonString () {
+ String msg = "";
+ try {
+ return mapper.writeValueAsString(this.toJsonNode());
+ }
+ catch (Exception e) {
+ // Bad in case the message contains quotes!
+ msg = ", \"" + e.getLocalizedMessage() + "\"";
+ };
+
+ return
+ "{\"errors\":["+
+ "[620, " +
+ "\"Unable to generate JSON\"" + msg + "]" +
+ "]}";
+ };
};
diff --git a/src/main/java/de/ids_mannheim/korap/response/Message.java b/src/main/java/de/ids_mannheim/korap/response/Message.java
index 1fb1709..9a0c91b 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Message.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Message.java
@@ -136,7 +136,7 @@
*
* @return JsonNode representation of the message
*/
- public JsonNode toJSONnode () {
+ public JsonNode toJsonNode () {
ArrayNode message = mapper.createArrayNode();
if (this.code != 0)
@@ -159,10 +159,10 @@
*
* @return String representation of the message
*/
- public String toJSON () {
+ public String toJsonString () {
String msg = "";
try {
- return mapper.writeValueAsString(this.toJSONnode());
+ return mapper.writeValueAsString(this.toJsonNode());
}
catch (Exception e) {
// Bad in case the message contains quotes!
diff --git a/src/main/java/de/ids_mannheim/korap/response/Messages.java b/src/main/java/de/ids_mannheim/korap/response/Messages.java
index 2239842..c78e6aa 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Messages.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Messages.java
@@ -228,10 +228,10 @@
*
* @return JsonNode representation of all messages
*/
- public JsonNode toJSONnode () {
+ public JsonNode toJsonNode () {
ArrayNode messageArray = mapper.createArrayNode();
for (Message msg : this.messages)
- messageArray.add(msg.toJSONnode());
+ messageArray.add(msg.toJsonNode());
return (JsonNode) messageArray;
};
@@ -248,10 +248,10 @@
*
* @return String representation of all messages
*/
- public String toJSON () {
+ public String toJsonString () {
String msg = "";
try {
- return mapper.writeValueAsString(this.toJSONnode());
+ return mapper.writeValueAsString(this.toJsonNode());
}
catch (Exception e) {
// Bad in case the message contains quotes!
diff --git a/src/main/java/de/ids_mannheim/korap/response/Notifications.java b/src/main/java/de/ids_mannheim/korap/response/Notifications.java
index 4b985f7..9074828 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Notifications.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Notifications.java
@@ -28,7 +28,7 @@
* for (Message msg : n.getWarnings())
* System.err.out(msg.getCode() + ": " + msg.getMessage());
* };
- * System.err.println(n.toJSON());
+ * System.err.println(n.toJsonString());
* </pre></blockquote>
*
* @author Nils Diewald
@@ -361,20 +361,36 @@
/**
+ * Clear all notifications.
+ *
+ * @return Notification object for chaining
+ */
+ public Notifications clearNotifications () {
+ if (this.warnings != null)
+ this.warnings.clear();
+ if (this.messages != null)
+ this.messages.clear();
+ if (this.errors != null)
+ this.errors.clear();
+ return this;
+ };
+
+
+ /**
* Serialize Notifications as a JsonNode.
*
* @return JsonNode representation of all warnings, errors, and messages
*/
- public JsonNode toJSONnode () {
+ public JsonNode toJsonNode () {
ObjectNode json = mapper.createObjectNode();
// Add messages
if (this.hasWarnings())
- json.put("warnings", this.getWarnings().toJSONnode());
+ json.put("warnings", this.getWarnings().toJsonNode());
if (this.hasErrors())
- json.put("errors", this.getErrors().toJSONnode());
+ json.put("errors", this.getErrors().toJsonNode());
if (this.hasMessages())
- json.put("messages", this.getMessages().toJSONnode());
+ json.put("messages", this.getMessages().toJsonNode());
return (JsonNode) json;
};
@@ -396,10 +412,10 @@
*
* @return String representation of all warnings, errors, and messages
*/
- public String toJSON () {
+ public String toJsonString () {
String msg = "";
try {
- JsonNode node = this.toJSONnode();
+ JsonNode node = this.toJsonNode();
if (node == null)
return "{}";
return mapper.writeValueAsString(node);
@@ -415,19 +431,4 @@
"\"Unable to generate JSON\"" + msg + "]" +
"]}";
};
-
- /**
- * Clear all notifications.
- *
- * @return Notification object for chaining
- */
- public Notifications clearNotifications () {
- if (this.warnings != null)
- this.warnings.clear();
- if (this.messages != null)
- this.messages.clear();
- if (this.errors != null)
- this.errors.clear();
- return this;
- };
};
diff --git a/src/main/java/de/ids_mannheim/korap/server/Resource.java b/src/main/java/de/ids_mannheim/korap/server/Resource.java
index 6a663ae..f27b14a 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Resource.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Resource.java
@@ -101,7 +101,7 @@
);
*/
kresp.addMessage(680, "Server is up and running!");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@@ -137,7 +137,7 @@
if (index == null) {
kresp.addError(601, "Unable to find index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
kresp.setVersion(index.getVersion());
@@ -152,12 +152,12 @@
// TODO: This may be a field error!
catch (IOException e) {
kresp.addError(602, "Unable to add document to index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
// Set HTTP to 200
kresp.addMessage(681, "Document was added successfully", ID);
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@@ -177,7 +177,7 @@
if (index == null) {
kresp.addError(601, "Unable to find index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
kresp.setVersion(index.getVersion());
@@ -190,11 +190,11 @@
catch (IOException e) {
// Set HTTP to ???
kresp.addError(603, "Unable to commit staged data to index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
// Set HTTP to ???
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@@ -234,12 +234,12 @@
// Only return the first match per text
ks.setItemsPerResource(1);
- return ks.run(index).toJSON();
+ return ks.run(index).toJsonString();
};
KorapResult kr = new KorapResult();
kr.setNode(KorapNode.getName());
kr.addError(610, "Missing request parameters", "No unique IDs were given");
- return kr.toJSON();
+ return kr.toJsonString();
};
KorapResponse kresp = new KorapResponse();
@@ -249,7 +249,7 @@
kresp.addError(601, "Unable to find index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@@ -274,7 +274,7 @@
KorapResponse kresp = new KorapResponse();
kresp.setNode(KorapNode.getName());
kresp.addError(601, "Unable to find index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
// Get the database
@@ -289,7 +289,7 @@
MatchCollector result = index.collect(ks, mc);
result.setNode(KorapNode.getName());
- return result.toJSON();
+ return result.toJsonString();
}
catch (SQLException e) {
log.error(e.getLocalizedMessage());
@@ -301,7 +301,7 @@
kresp.setVersion(index.getVersion());
kresp.addError(604, "Unable to connect to database");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@@ -331,7 +331,7 @@
if (index != null) {
KorapResult kr = new KorapSearch(json).run(index);
kr.setNode(KorapNode.getName());
- return kr.toJSON();
+ return kr.toJsonString();
};
KorapResponse kresp = new KorapResponse();
@@ -340,7 +340,7 @@
kresp.setVersion(index.getVersion());
kresp.addError(601, "Unable to find index");
- return kresp.toJSON();
+ return kresp.toJsonString();
};
@GET
@@ -396,7 +396,7 @@
includeSpans,
includeHighlights,
extendToSentence
- ).toJSON();
+ ).toJsonString();
}
// Nothing found
@@ -404,14 +404,14 @@
// Todo: Make KorapMatch rely on KorapResponse!
KorapMatch km = new KorapMatch();
km.addError(qe.getErrorCode(), qe.getMessage());
- return km.toJSON();
+ return km.toJsonString();
}
};
// Response with error message
KorapMatch km = new KorapMatch();
km.addError(601, "Unable to find index");
- return km.toJSON();
+ return km.toJsonString();
};
/*