Added query and query language in virtual corpus table.

Change-Id: I25fbaf27e6e4e74032ffb58c47a2df059c507c6b
diff --git a/full/Changes b/full/Changes
index b94cb3b..9315d2b 100644
--- a/full/Changes
+++ b/full/Changes
@@ -19,6 +19,11 @@
    - Add query reference web-service (diewald,margaretha)   
 10/02/2021
    - Fixed problem with multiple desktop apps (diewald, margaretha)
+12/02/2021
+   - Added listing available queries for users (margaretha)
+17/02/2021
+   - Removed escaping for KoralQuery in VC and query reference responses (margaretha)
+   - Added query and query language in virtual corpus table (margaretha)
 
 # version 0.62.4
 24/01/2020
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
index 06f6ee5..1d5f2e5 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/NamedVCLoader.java
@@ -62,7 +62,7 @@
             cacheVC(json, filename);
             vcService.storeVC(filename, ResourceType.SYSTEM,
                     QueryType.VIRTUAL_CORPUS, json, null, null, null, true,
-                    "system");
+                    "system", null, null);
         }
     }
 
@@ -104,7 +104,7 @@
                 }
                 vcService.storeVC(filename, ResourceType.SYSTEM,
                         QueryType.VIRTUAL_CORPUS, json, null, null, null, true,
-                        "system");
+                        "system", null, null);
             }
         }
     }
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
index fb1dc84..e4f02fa 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/VirtualCorpusDao.java
@@ -56,7 +56,8 @@
     public int createVirtualCorpus (String name, ResourceType type,
             QueryType queryType, CorpusAccess requiredAccess, String koralQuery,
             String definition, String description, String status,
-            boolean isCached, String createdBy) throws KustvaktException {
+            boolean isCached, String createdBy, String query,
+            String queryLanguage) throws KustvaktException {
 
         VirtualCorpus vc = new VirtualCorpus();
         vc.setName(name);
@@ -69,6 +70,8 @@
         vc.setStatus(status);
         vc.setCreatedBy(createdBy);
         vc.setCached(isCached);
+        vc.setQuery(query);
+        vc.setQueryLanguage(queryLanguage);
 
         entityManager.persist(vc);
         return vc.getId();
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 9da3f4b..f6863c4 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
@@ -32,5 +32,7 @@
     private int numberOfSentences;
     private int numberOfTokens;
     
+    private String query;
+    private String queryLanguage;
     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 afaeb7b..974c6b9 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,9 +31,13 @@
         dto.setStatus(vc.getStatus());
         dto.setDescription(vc.getDescription());
         dto.setType(vc.getType().displayName());
+        
+        dto.setQuery(vc.getQuery());
+        dto.setQueryLanguage(vc.getQueryLanguage());
+        
         JsonNode kq = JsonUtils.readTree(vc.getKoralQuery());
         dto.setKoralQuery(kq);
-
+        
         if (statistics != null) {
             JsonNode node = JsonUtils.readTree(statistics);
             dto.setNumberOfDoc(node.at("/documents").asInt());
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
index 1f83756..6cb08ea 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/VirtualCorpus.java
@@ -45,9 +45,6 @@
     private String name;
     @Enumerated(EnumType.STRING)
     private ResourceType type;
-    @Enumerated(EnumType.STRING)
-    @Column(name = "query_type")
-    private QueryType queryType;
     private String status;
     private String description;
     @Enumerated(EnumType.STRING)
@@ -60,6 +57,13 @@
     private String createdBy;
     @Column(name = "is_cached")
     private boolean isCached;
+    
+    @Enumerated(EnumType.STRING)
+    @Column(name = "query_type")
+    private QueryType queryType;
+    private String query;
+    @Column(name = "query_language")
+    private String queryLanguage;
 
     @OneToMany(mappedBy = "virtualCorpus", fetch = FetchType.LAZY,
             cascade = CascadeType.REMOVE)
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java b/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java
index fe76821..c7e0f8b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/QueryReferenceService.java
@@ -31,6 +31,7 @@
  *
  * @author diewald
  */
+@Deprecated
 @Service
 public class QueryReferenceService {
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
index 0dc9f84..67d46d7 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
@@ -339,13 +339,13 @@
 
         storeVC(vcName, vc.getType(), vc.getQueryType(), koralQuery,
                 vc.getDefinition(), vc.getDescription(), vc.getStatus(),
-                vc.isCached(), createdBy);
+                vc.isCached(), createdBy, vc.getQuery(), vc.getQueryLanguage());
     }
 
     public void storeVC (String vcName, ResourceType type, QueryType queryType,
             String koralQuery, String definition, String description,
-            String status, boolean isCached, String username)
-            throws KustvaktException {
+            String status, boolean isCached, String username, String query,
+            String queryLanguage) throws KustvaktException {
         ParameterChecker.checkNameValue(vcName, "vcName");
         ParameterChecker.checkObjectValue(type, "type");
 
@@ -370,7 +370,7 @@
         try {
             vcId = vcDao.createVirtualCorpus(vcName, type, queryType,
                     requiredAccess, koralQuery, definition, description, status,
-                    isCached, username);
+                    isCached, username, query, queryLanguage);
 
         }
         catch (Exception e) {
diff --git a/full/src/main/resources/db/sqlite/V1.7__query_references.sql b/full/src/main/resources/db/sqlite/V1.7__query_references.sql
index 9d33270..5d71fc6 100644
--- a/full/src/main/resources/db/sqlite/V1.7__query_references.sql
+++ b/full/src/main/resources/db/sqlite/V1.7__query_references.sql
@@ -1,16 +1,16 @@
-CREATE TABLE IF NOT EXISTS query_reference (
-  id INTEGER PRIMARY KEY AUTOINCREMENT,
-  name VARCHAR(255) NOT NULL,
-  type VARCHAR(100) NOT NULL,
-  required_access VARCHAR(100) NOT NULL,
-  created_by VARCHAR(100) NOT NULL,
-  description VARCHAR(255) DEFAULT NULL,
-  status VARCHAR(100) DEFAULT NULL,
-  query TEXT NOT NULL,
-  definition VARCHAR(255) DEFAULT NULL
-);
-
-CREATE INDEX query_reference_owner_index ON query_reference(created_by);
-CREATE INDEX query_reference_type_index ON query_reference(type);
-CREATE UNIQUE INDEX query_reference_unique_name 
-	ON query_reference(name,created_by);
\ No newline at end of file
+--CREATE TABLE IF NOT EXISTS query_reference (
+--  id INTEGER PRIMARY KEY AUTOINCREMENT,
+--  name VARCHAR(255) NOT NULL,
+--  type VARCHAR(100) NOT NULL,
+--  required_access VARCHAR(100) NOT NULL,
+--  created_by VARCHAR(100) NOT NULL,
+--  description VARCHAR(255) DEFAULT NULL,
+--  status VARCHAR(100) DEFAULT NULL,
+--  query TEXT NOT NULL,
+--  definition VARCHAR(255) DEFAULT NULL
+--);
+--
+--CREATE INDEX query_reference_owner_index ON query_reference(created_by);
+--CREATE INDEX query_reference_type_index ON query_reference(type);
+--CREATE UNIQUE INDEX query_reference_unique_name 
+--	ON query_reference(name,created_by);
\ No newline at end of file
diff --git a/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql b/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
index 29a4368..384faf5 100644
--- a/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
+++ b/full/src/main/resources/db/sqlite/V1.9__query_alteration.sql
@@ -1,2 +1,15 @@
 ALTER TABLE virtual_corpus 
-ADD COLUMN query_type VARCHAR(100) NOT NULL;
\ No newline at end of file
+ADD COLUMN query_type VARCHAR(100) NOT NULL;
+
+ALTER TABLE virtual_corpus 
+ADD COLUMN query TEXT DEFAULT NULL;
+
+ALTER TABLE virtual_corpus 
+ADD COLUMN query_language VARCHAR(100) DEFAULT NULL;
+
+
+DROP TABLE IF EXISTS query_reference;
+
+DROP INDEX IF EXISTS query_reference_owner_index;
+DROP INDEX IF EXISTS query_reference_type_index;
+DROP INDEX IF EXISTS  query_reference_unique_name;
\ No newline at end of file
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 88697bd..a1ec5fb 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
@@ -1,8 +1,10 @@
 -- query references
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query) 
+INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, 
+    corpus_query, query, query_language) 
 	VALUES ("dory-q", "PRIVATE", "QUERY", "FREE", "dory", "test query", "experimental",
-	'{ "@type": "koral:token" }');
+	'{ "@type": "koral:token" }', "[]", "poliqarp");
 
-INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, corpus_query) 
+INSERT INTO virtual_corpus(name, type, query_type, required_access, created_by, description, status, 
+    corpus_query, query, query_language) 
 	VALUES ("system-q", "SYSTEM", "QUERY", "FREE", "system", '"system" query', "experimental",
-	'{ "@type": "koral:token" }');
+	'{ "@type": "koral:token" }', "[]", "poliqarp");
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
index 4d26b71..3df8c24 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/UserGroupDaoTest.java
@@ -137,7 +137,7 @@
         int id = virtualCorpusDao.createVirtualCorpus(name,
                 ResourceType.PROJECT, QueryType.VIRTUAL_CORPUS,
                 CorpusAccess.PUB, "corpusSigle=WPD15", "", "", "", false,
-                createdBy);
+                createdBy, null, null);
 
         VirtualCorpus virtualCorpus = virtualCorpusDao.retrieveVCById(id);
         userGroupDao.addVCToGroup(virtualCorpus, createdBy,
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
index c6b5c43..3294099 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
@@ -45,7 +45,7 @@
         int id = dao.createVirtualCorpus("system-vc", ResourceType.SYSTEM,
                 QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
                 "corpusSigle=GOE", "definition", "description", "experimental",
-                false, "test class");
+                false, "test class", null, null);
 
         // select vc
         List<VirtualCorpus> vcList =
@@ -69,7 +69,7 @@
         dao.createVirtualCorpus("system-vc", ResourceType.SYSTEM,
                 QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
                 "corpusSigle=GOE", "definition", "description", "experimental",
-                false, "system");
+                false, "system", null, null);
     }
 
     @Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
index e780769..dd7e295 100644
--- a/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/rewrite/QueryRewriteTest.java
@@ -44,7 +44,7 @@
             .get(ClientResponse.class);
 
         String ent = response.getEntity(String.class);
-        System.out.println(ent);
+//        System.out.println(ent);
         JsonNode node = JsonUtils.readTree(ent);
     }
 
diff --git a/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java
index cb3adbf..9590209 100644
--- a/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/service/QueryReferenceServiceTest.java
@@ -1,30 +1,21 @@
 package de.ids_mannheim.korap.service;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 
-import java.util.List;
-
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import com.fasterxml.jackson.databind.JsonNode;
 
-import de.ids_mannheim.korap.constant.UserGroupStatus;
-import de.ids_mannheim.korap.constant.ResourceType;
-import de.ids_mannheim.korap.dto.VirtualCorpusAccessDto;
-import de.ids_mannheim.korap.dto.VirtualCorpusDto;
-import de.ids_mannheim.korap.entity.UserGroup;
-import de.ids_mannheim.korap.entity.VirtualCorpus;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.web.input.QueryJson;
 
+@Ignore
 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration("classpath:test-config.xml")
 public class QueryReferenceServiceTest {
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 f9b297f..a6ea7c7 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
@@ -43,6 +43,8 @@
         assertEquals(ResourceType.PRIVATE.displayName(),
                 node.at("/type").asText());
         assertEquals(testUser, node.at("/createdBy").asText());
+        assertEquals("der", node.at("/query").asText());
+        assertEquals("poliqarp", node.at("/queryLanguage").asText());
     }
 
     @Test
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 f1e8101..d6c786c 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
@@ -120,6 +120,8 @@
         assertEquals(ResourceType.SYSTEM.displayName(),
                 node.at("/type").asText());
         assertEquals("koral:doc", node.at("/koralQuery/collection/@type").asText());
+        assertTrue(node.at("/query").isMissingNode());
+        assertTrue(node.at("/queryLanguage").isMissingNode());
     }
 
     @Test
diff --git a/full/src/test/resources/log4j2-test.properties b/full/src/test/resources/log4j2-test.properties
index c80f94c..f961961 100644
--- a/full/src/test/resources/log4j2-test.properties
+++ b/full/src/test/resources/log4j2-test.properties
@@ -1,8 +1,8 @@
-#appenders = console
-#appender.console.type = Console
-#appender.console.name = STDOUT
-#appender.console.layout.type = PatternLayout
-#appender.console.layout.pattern = %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
+appenders = console
+appender.console.type = Console
+appender.console.name = STDOUT
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
 
 #appender.file.type = File
 #appender.file.name = ERRORLOG
@@ -11,7 +11,7 @@
 #appender.file.layout.pattern= %d{yyyy-MM-dd, HH:mm:ss} %C{6} - %M%n %-5p: %m%n
 
 rootLogger.level = error
-rootLogger.appenderRefs = stdout
+rootLogger.appenderRefs = console
 rootLogger.appenderRef.stdout.ref = STDOUT
 
 #loggers=console