Fixed rewrite bugs (updated rewriteQuery & KoralNode)

Change-Id: Ic010e0f6210d34a8fe8dfe15a68f1112423f60eb
diff --git a/full/Changes b/full/Changes
index 49d53bd..d2d6755 100644
--- a/full/Changes
+++ b/full/Changes
@@ -17,6 +17,7 @@
    - Implemented revoking all tokens of a user client via a super client
    (margaretha)   
    - Removed document controllers and KustvaktResource (margaretha)
+   - Fixed rewrite bugs (updated rewriteQuery & KoralNode) (margaretha)
 
    
 # version 0.61.3
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionConstraint.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionConstraint.java
index 3228f76..19040e9 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionConstraint.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionConstraint.java
@@ -15,7 +15,7 @@
 public class CollectionConstraint implements RewriteTask.IterableRewritePath {
 
     @Override
-    public JsonNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
+    public KoralNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
             User user) {
         if (node.get("@type").equals("koral:doc")) {
             if (node.get("key").equals(Attributes.CORPUS_SIGLE)) {
@@ -27,7 +27,7 @@
                             Attributes.CORPUS_SIGLE, id));
             }
         }
-        return node.rawNode();
+        return node;
     }
 
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
index 153c3db..806069b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/CollectionRewrite.java
@@ -11,8 +11,8 @@
 import com.google.common.collect.Lists;
 
 import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.config.FullConfiguration;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
 import de.ids_mannheim.korap.query.object.KoralMatchOperator;
 import de.ids_mannheim.korap.query.object.KoralOperation;
@@ -127,7 +127,7 @@
     }
 
     @Override
-    public JsonNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
+    public KoralNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
             User user) throws KustvaktException {
         JsonNode jsonNode = node.rawNode();
 
@@ -188,7 +188,7 @@
         node = node.at("/collection");
         jlog.debug("REWRITES: " + node.toString());
         
-        return node.rawNode();
+        return node;
     }
 
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
index 320dcdb..55110d0 100644
--- a/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
+++ b/full/src/main/java/de/ids_mannheim/korap/rewrite/VirtualCorpusRewrite.java
@@ -24,13 +24,13 @@
     private VirtualCorpusService vcService;
 
     @Override
-    public JsonNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
+    public KoralNode rewriteQuery (KoralNode node, KustvaktConfiguration config,
             User user) throws KustvaktException {
         if (node.has("collection")) {
             node = node.at("/collection");
             findVCRef(user.getUsername(), node);
         }
-        return node.rawNode();
+        return node;
     }
 
     private void findVCRef (String username, KoralNode koralNode)
diff --git a/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
index f153baa..28bab56 100644
--- a/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/CollectionRewriteTest.java
@@ -241,6 +241,7 @@
                 node.at("/collection/operands/1/operands/0/key").asText());
         assertEquals("textClass",
                 node.at("/collection/operands/1/operands/1/key").asText());
+        System.out.println(node);
         assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type")
                 .asText());
         assertEquals("availability(FREE)", node.at("/collection/rewrites/0/scope")
diff --git a/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/VirtualCorpusRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/VirtualCorpusRewriteTest.java
index e91dde2..7702beb 100644
--- a/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/VirtualCorpusRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/resource/rewrite/VirtualCorpusRewriteTest.java
@@ -36,32 +36,31 @@
     private VirtualCorpusDao dao;
 
     @Test
-    public void testNoRewriteWithCachedVCRef ()
+    public void testCachedVCRef ()
             throws KustvaktException, IOException, QueryException {
         KrillCollection.cache = CacheManager.newInstance().getCache("named_vc");
         vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
 
-        // ClientResponse response =
-        // resource().path(API_VERSION).path("search")
-        // .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
-        // .queryParam("cq", "referTo named-vc1")
-        // .get(ClientResponse.class);
-        //
-        // String ent = response.getEntity(String.class);
-        // JsonNode node = JsonUtils.readTree(ent);
-        // node = node.at("/collection");
-        //
-        // assertEquals("koral:docGroup", node.at("/@type").asText());
-        // assertTrue(node.at("/operands/1/rewrites").isMissingNode());
+        ClientResponse response = resource().path(API_VERSION).path("search")
+                .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
+                .queryParam("cq", "referTo named-vc1")
+                .get(ClientResponse.class);
 
-        testNoRewriteWithUsername();
+        String ent = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(ent);
+        node = node.at("/collection");
+
+        assertEquals("koral:docGroup", node.at("/@type").asText());
+        assertTrue(node.at("/operands/1/rewrites").isMissingNode());
+
+        testCachedVCRefWithUsername();
 
         KrillCollection.cache.removeAll();
         VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system");
         dao.deleteVirtualCorpus(vc);
     }
 
-    private void testNoRewriteWithUsername ()
+    private void testCachedVCRefWithUsername ()
             throws KustvaktException, IOException, QueryException {
 
         ClientResponse response = resource().path(API_VERSION).path("search")
@@ -144,7 +143,6 @@
         String ent = response.getEntity(String.class);
         JsonNode node = JsonUtils.readTree(ent);
         node = node.at("/collection");
-        // System.out.println(node);
         assertEquals("koral:docGroup", node.at("/@type").asText());
         node = node.at("/operands/1/rewrites");
         assertEquals(3, node.size());