Fixed error passing to responses

Change-Id: I32f4a0cf1523c35ab22880670dfbc57d9068bbac
diff --git a/Changes b/Changes
index e6ecae1..c503c38 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.55.6 2016-08-03
+0.55.6 2016-08-05
         - [bugfix] distance with key "t" uses default foundry (diewald)
 	- [cleanup] Renamed fromJson() to fromKoral() (diewald)
 	- [cleanup] Removed deprecated methods in Krill:
@@ -16,6 +16,7 @@
 	- [bugfix] Escape XML and Brackets in snippets correctly (diewald)
 	- [feature] Differ between matching scope and match highlighting,
 	  in case the match was extended to the sentence scope (diewald)
+	- [bugfix] KoralQuery bugs are now correctly moved to responses (diewald)
 
 0.55.5 2016-05-02
 	- [performance] Changed to a dynamic window for sorting in FocusSpans (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index ccea5df..af529d0 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -172,6 +172,9 @@
 
                 final SpanQueryWrapper qw = kq.fromKoral(json.get("query"));
 
+                // Koral messages are moved to the Krill object
+                this.moveNotificationsFrom(kq);
+
                 // Throw an error, in case the query matches everywhere
                 if (qw.isEmpty())
                     this.addError(780, "This query matches everywhere");
diff --git a/src/main/java/de/ids_mannheim/korap/KrillIndex.java b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
index ca9f70b..d978efc 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillIndex.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillIndex.java
@@ -1268,9 +1268,13 @@
         final KrillMeta meta = ks.getMeta();
 
         // Todo: Make kr subclassing ks - so ks has a method for a new Result!
+        // Or allow passing of Krill object
         final Result kr = new Result(query.toString(), meta.getStartIndex(),
                 meta.getCount(), meta.getContext());
 
+        // Copy notification info
+        kr.moveNotificationsFrom(ks);
+
         // Set version info to result
         if (this.getVersion() != null)
             kr.setVersion(this.getVersion());
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index 538b0ad..3d70505 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -1065,7 +1065,7 @@
 
     private SpanQueryWrapper _termFromJson (JsonNode json)
             throws QueryException {
-        return _termFromJson(json, null);
+        return this._termFromJson(json, null);
     }
 
 
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 753735b..bc4091d 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Notifications.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Notifications.java
@@ -117,9 +117,13 @@
      * @return Notification object for chaining
      */
     public Notifications addWarning (int code, String msg, String ... terms) {
-        if (this.warnings == null)
+
+        if (this.warnings == null) {
             this.warnings = new Messages();
+        };
+
         this.warnings.add(code, msg, terms);
+
         return this;
     };
 
diff --git a/src/main/java/de/ids_mannheim/korap/response/Response.java b/src/main/java/de/ids_mannheim/korap/response/Response.java
index b37619a..5108199 100644
--- a/src/main/java/de/ids_mannheim/korap/response/Response.java
+++ b/src/main/java/de/ids_mannheim/korap/response/Response.java
@@ -492,7 +492,6 @@
      */
     @Override
     public JsonNode toJsonNode () {
-
         // Get notifications json response
         ObjectNode json = (ObjectNode) super.toJsonNode();
 
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSegmentNegationIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSegmentNegationIndex.java
index f30450c..520a3a0 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSegmentNegationIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSegmentNegationIndex.java
@@ -8,9 +8,12 @@
 import org.junit.runners.JUnit4;
 import org.slf4j.Logger;
 
+import de.ids_mannheim.korap.Krill;
 import de.ids_mannheim.korap.KrillIndex;
+import de.ids_mannheim.korap.KrillQuery;
 import de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper;
 import de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper;
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapper;
 import de.ids_mannheim.korap.response.Result;
 
 @RunWith(JUnit4.class)
@@ -30,10 +33,10 @@
         ki.addDoc(createFieldDoc2());
         ki.addDoc(createFieldDoc3());
         ki.commit();
-        SpanSegmentQueryWrapper ssqw = new SpanSegmentQueryWrapper("base",
+        SpanSegmentQueryWrapper ssqw = new SpanSegmentQueryWrapper("tokens",
                 "s:b");
         ssqw.with("s:c");
-        SpanSequenceQueryWrapper sqw = new SpanSequenceQueryWrapper("base",
+        SpanSequenceQueryWrapper sqw = new SpanSequenceQueryWrapper("tokens",
                 ssqw).append("s:d");
 
         kr = ki.search(sqw.toQuery(), (short) 10);
@@ -49,9 +52,9 @@
         assertEquals("StartPos (0)", 0, kr.getMatch(1).startPos);
         assertEquals("EndPos (0)", 2, kr.getMatch(1).endPos);
 
-        ssqw = new SpanSegmentQueryWrapper("base", "s:b");
+        ssqw = new SpanSegmentQueryWrapper("tokens", "s:b");
         ssqw.without("s:c");
-        sqw = new SpanSequenceQueryWrapper("base", ssqw).append("s:a");
+        sqw = new SpanSequenceQueryWrapper("tokens", ssqw).append("s:a");
 
         kr = ki.search(sqw.toQuery(), (short) 10);
 
@@ -73,10 +76,37 @@
     }
 
 
+    @Test
+    public void testcaseWarnings () throws Exception {
+        ki = new KrillIndex();
+        ki.addDoc(createFieldDoc0());
+        ki.addDoc(createFieldDoc1());
+        ki.addDoc(createFieldDoc2());
+        ki.addDoc(createFieldDoc3());
+        ki.commit();
+
+        kr = ki.search(new Krill(
+                "{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:eq\" }}}"));
+        assertEquals("totalResults", kr.getTotalResults(), 6);
+        assertEquals("Warning", kr.hasWarnings(), true);
+        assertEquals("Warning text", kr.getWarning(0).getMessage(),
+                "Flag is unknown");
+
+        // Negation of segment
+        kr = ki.search(new Krill(
+                "{\"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"key\" : \"a\", \"flags\" : [\"flags:caseInsensitive\"], \"layer\" : \"orth\", \"match\" : \"match:ne\" }}}"));
+
+        assertEquals("totalResults", kr.getTotalResults(), 4);
+        assertEquals("Warning", kr.hasWarnings(), true);
+        assertEquals("Warning text", kr.getWarning(0).getMessage(),
+                "Exclusivity of query is ignored");
+    };
+
+
     private FieldDocument createFieldDoc0 () {
         fd = new FieldDocument();
         fd.addString("ID", "doc-0");
-        fd.addTV("base", "bcbabd", "[(0-1)s:b|i:b|_1$<i>0<i>1]"
+        fd.addTV("tokens", "bcbabd", "[(0-1)s:b|i:b|_1$<i>0<i>1]"
                 + "[(1-2)s:c|i:c|s:b|_2$<i>1<i>2]"
                 + "[(2-3)s:b|i:b|_3$<i>2<i>3|<>:e$<b>64<i>2<i>4<i>4<b>0]"
                 + "[(3-4)s:a|i:a|_4$<i>3<i>4|<>:e$<b>64<i>3<i>5<i>5<b>0|"
@@ -90,7 +120,7 @@
     private FieldDocument createFieldDoc1 () {
         fd = new FieldDocument();
         fd.addString("ID", "doc-1");
-        fd.addTV("base", "babaa", "[(0-1)s:b|i:b|s:c|_1$<i>0<i>1]"
+        fd.addTV("tokens", "babaa", "[(0-1)s:b|i:b|s:c|_1$<i>0<i>1]"
                 + "[(1-2)s:a|i:a|s:b|_2$<i>1<i>2|<>:e$<b>64<i>1<i>3<i>3<b>0]"
                 + "[(2-3)s:b|i:b|s:a|_3$<i>2<i>3]"
                 + "[(3-4)s:a|i:a|_4$<i>3<i>4]" + "[(4-5)s:a|i:a|_5$<i>4<i>5]");
@@ -101,7 +131,7 @@
     private FieldDocument createFieldDoc2 () {
         fd = new FieldDocument();
         fd.addString("ID", "doc-2");
-        fd.addTV("base", "bdb", "[(0-1)s:b|i:b|_1$<i>0<i>1]"
+        fd.addTV("tokens", "bdb", "[(0-1)s:b|i:b|_1$<i>0<i>1]"
                 + "[(1-2)s:d|i:d|s:b|_2$<i>1<i>2]"
                 + "[(2-3)s:b|i:b|s:a|_3$<i>2<i>3]");
         return fd;
@@ -111,7 +141,7 @@
     private FieldDocument createFieldDoc3 () {
         fd = new FieldDocument();
         fd.addString("ID", "doc-3");
-        fd.addTV("base", "bdb", "[(0-1)s:b|i:b|s:c|_1$<i>0<i>1]"
+        fd.addTV("tokens", "bdb", "[(0-1)s:b|i:b|s:c|_1$<i>0<i>1]"
                 + "[(1-2)s:d|_2$<i>1<i>2]" + "[(2-3)s:d|i:d|_3$<i>2<i>3]");
         return fd;
     }
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
index 58c0507..72ae83e 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestTemporaryQueryLimitations.java
@@ -59,9 +59,12 @@
         assertEquals(kr.getStartIndex(), 0);
 
         assertEquals("This is a warning coming from the serialization", kr
-                .getWarning(0).getMessage());
+                .getWarning(1).getMessage());
+
         assertEquals("Class reference checks are currently not supported"
-                + " - results may not be correct", kr.getWarning(1)
+                + " - results may not be correct", kr.getWarning(0)
                 .getMessage());
+
+        assertEquals(2, kr.getWarnings().size());
     };
 };