Removed escaping for KoralQuery in VC and query reference responses.

Change-Id: Ic033b2ca4895baf2d96068e7db707182983c83d7
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
index 878dcf4..9da3f4b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
@@ -2,6 +2,7 @@
 
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.JsonNode;
 
 import de.ids_mannheim.korap.entity.VirtualCorpus;
 import lombok.Getter;
@@ -31,4 +32,5 @@
     private int numberOfSentences;
     private int numberOfTokens;
     
-    private String koralQuery;}
+    private JsonNode koralQuery;
+}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
index fb16932..afaeb7b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
@@ -31,7 +31,8 @@
         dto.setStatus(vc.getStatus());
         dto.setDescription(vc.getDescription());
         dto.setType(vc.getType().displayName());
-        dto.setKoralQuery(vc.getKoralQuery());
+        JsonNode kq = JsonUtils.readTree(vc.getKoralQuery());
+        dto.setKoralQuery(kq);
 
         if (statistics != null) {
             JsonNode node = JsonUtils.readTree(statistics);
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
index 955de0e..4f42679 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/QueryReferenceController.java
@@ -171,8 +171,9 @@
                 (TokenContext) securityContext.getUserPrincipal();
         try {
             scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
-            return service.listAvailableVCForUser(context.getUsername(),
-                    username, QueryType.QUERY);
+            List<VirtualCorpusDto> dtos = service.listAvailableVCForUser(
+                    context.getUsername(), username, QueryType.QUERY);
+            return dtos;
         }
         catch (KustvaktException e) {
             throw kustvaktResponseHandler.throwit(e);
diff --git a/full/src/main/resources/db/test/V3.7__insert_query_references.sql b/full/src/main/resources/db/test/V3.7__insert_query_references.sql
index 3adf7bc..88697bd 100644
--- a/full/src/main/resources/db/test/V3.7__insert_query_references.sql
+++ b/full/src/main/resources/db/test/V3.7__insert_query_references.sql
@@ -4,5 +4,5 @@
 	'{ "@type": "koral:token" }');
 
 INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query) 
-	VALUES ("system-q", "SYSTEM", "QUERY", "FREE", "system", "system query", "experimental",
+	VALUES ("system-q", "SYSTEM", "QUERY", "FREE", "system", '"system" query', "experimental",
 	'{ "@type": "koral:token" }');
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
index f4d90ef..f9b297f 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/QueryReferenceControllerTest.java
@@ -46,9 +46,32 @@
     }
 
     @Test
-    public void testListAvailableQuery () throws UniformInterfaceException,
+    public void testAvailableQueryForDory () throws UniformInterfaceException,
             ClientHandlerException, KustvaktException {
-        String username = "dory";
+        JsonNode node = testListAvailableQuery("dory");
+        assertEquals(2, node.size());
+    }
+
+    @Test
+    public void testListAvailableQueryForPearl ()
+            throws UniformInterfaceException, ClientHandlerException,
+            KustvaktException {
+        
+        JsonNode node = testListAvailableQuery("pearl");
+        
+        assertEquals(1, node.size());
+        assertEquals("system-q", node.at("/0/name").asText());
+        assertEquals(ResourceType.SYSTEM.displayName(),
+                node.at("/0/type").asText());
+        assertEquals("\"system\" query", node.at("/0/description").asText());
+        assertEquals("koral:token", node.at("/0/koralQuery/@type").asText());
+
+    }
+
+    private JsonNode testListAvailableQuery (String username)
+            throws UniformInterfaceException, ClientHandlerException,
+            KustvaktException {
+
         ClientResponse response = resource().path(API_VERSION).path("query")
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username, "pass"))
@@ -58,11 +81,11 @@
         assertEquals(Status.OK.getStatusCode(), response.getStatus());
 
         String entity = response.getEntity(String.class);
-//        System.out.println(entity);
+        // System.out.println(entity);
         JsonNode node = JsonUtils.readTree(entity);
-        assertEquals(2, node.size());
+        return node;
     }
-
+    
     private JsonNode testRetrieveQueryByName (String username, String qCreator,
             String qName) throws UniformInterfaceException,
             ClientHandlerException, KustvaktException {
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 66a2b42..f1e8101 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -119,6 +119,7 @@
         assertEquals("system-vc", node.at("/name").asText());
         assertEquals(ResourceType.SYSTEM.displayName(),
                 node.at("/type").asText());
+        assertEquals("koral:doc", node.at("/koralQuery/collection/@type").asText());
     }
 
     @Test
@@ -703,10 +704,7 @@
 
         // check VC
         JsonNode node = testListVC("dory");
-        String koralQuery = node.get(0).get("koralQuery").asText();
-        node = JsonUtils.readTree(koralQuery);
-        assertEquals("WPD17", node.at("/collection/value").asText());
-        assertTrue(koralQuery.contains("WPD17"));
+        assertEquals("WPD17", node.at("/0/koralQuery/collection/value").asText());
     }
 
     @Test