Added an API retrieving fields of a virtual corpus.

Change-Id: I577e29bae1b3112ccb16a2d6b2c65d06695198c0
diff --git a/core/Changes b/core/Changes
index 056aed2..0662426 100644
--- a/core/Changes
+++ b/core/Changes
@@ -12,6 +12,8 @@
  - Bumped spring.version from 5.3.13 to 5.3.14
 2022-01-25
  - Added show-tokens option to the search API.
+2022-01-31
+ - Added an API retrieving fields of a virtual corpus.
 
 # version 0.64
 
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index 27665a2..2eb98ab 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -12,6 +12,8 @@
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.store.MMapDirectory;
 
+import com.fasterxml.jackson.databind.JsonNode;
+
 import de.ids_mannheim.korap.Krill;
 import de.ids_mannheim.korap.KrillCollection;
 import de.ids_mannheim.korap.KrillIndex;
@@ -60,11 +62,13 @@
         };
     };
 
+
     public KrillIndex getIndex () {
         return index;
     };
-    
-    public void closeIndexReader() throws KustvaktException{
+
+
+    public void closeIndexReader () throws KustvaktException {
         try {
             index.closeReader();
         }
@@ -73,6 +77,7 @@
         }
     }
 
+
     /**
      * Search in the Lucene index.
      * 
@@ -96,6 +101,7 @@
         return kr.toJsonString();
     };
 
+
     /**
      * Search in the Lucene index and return matches as token lists.
      * 
@@ -115,6 +121,7 @@
         return kr.toJsonString();
     };
 
+
     /**
      * Get info on a match - by means of a richly annotated html
      * snippet.
@@ -124,7 +131,8 @@
      * @param availabilityList
      * @throws KustvaktException
      */
-    public String getMatch (String id, Pattern licensePattern) throws KustvaktException {
+    public String getMatch (String id, Pattern licensePattern)
+            throws KustvaktException {
         Match km;
         if (index != null) {
             try {
@@ -144,6 +152,7 @@
         return km.toJsonString();
     };
 
+
     private void checkAvailability (Pattern licensePattern, String availability,
             String id) throws KustvaktException {
         if (DEBUG) {
@@ -165,12 +174,13 @@
         }
 
     }
-    
+
+
     /*
      * Retrieve the meta fields for a certain document
      */
-    public String getFields (String id, List<String> fields, Pattern licensePattern)
-            throws KustvaktException {
+    public String getFields (String id, List<String> fields,
+            Pattern licensePattern) throws KustvaktException {
         MetaFields meta;
 
         // No index found
@@ -180,7 +190,7 @@
         }
 
         // Index available
-        else if (fields !=null){
+        else if (fields != null) {
             // Get fields
             meta = index.getFields(id, fields);
         }
@@ -188,7 +198,7 @@
             // Get fields
             meta = index.getFields(id);
         }
-        
+
         // EM: this approach forbids the whole metadata
         // this should be refined by filtering out only the restricted
         // metadata fields
@@ -197,7 +207,7 @@
 
         return meta.toJsonString();
     };
-    
+
 
     public String getMatch (String id, List<String> foundries,
             List<String> layers, boolean includeSpans,
@@ -223,6 +233,7 @@
         return km.toJsonString();
     };
 
+
     /**
      * Get info on a match - by means of a richly annotated html
      * snippet.
@@ -270,6 +281,7 @@
         return km.toJsonString();
     };
 
+
     /**
      * Get statistics on (virtual) collections.
      * 
@@ -277,7 +289,7 @@
      * 
      * @param json
      *            JSON-LD string with potential meta filters.
-     * @throws KustvaktException 
+     * @throws KustvaktException
      */
     public String getStatistics (String json) throws KustvaktException {
         if (index == null) {
@@ -317,7 +329,7 @@
         catch (IOException e) {
             e.printStackTrace();
         };
-        
+
         if (kc.hasErrors()) {
             throw new KustvaktException(
                     "{\"errors\":" + kc.getErrors().toJsonString() + "}");
@@ -330,6 +342,7 @@
         return sb.toString();
     };
 
+
     /**
      * Return the match identifier as a string.
      * This is a convenient method to deal with legacy instantiation
@@ -345,6 +358,7 @@
         return sb.toString();
     };
 
+
     /**
      * Return the text sigle as a string.
      */
@@ -356,14 +370,20 @@
         return sb.toString();
     };
 
+
     /**
      * Return the fingerprint of the latest index revision.
      */
-    public String getIndexFingerprint() {
+    public String getIndexFingerprint () {
         if (index != null) {
             return index.getFingerprint();
         };
         return "null";
     }
 
+
+    public JsonNode getFieldValuesForVC (String koralQuery, String fieldName) {
+        return new Krill().retrieveFieldValues(koralQuery, index, fieldName);
+    }
+
 };
diff --git a/full/Changes b/full/Changes
index d84e29a..c32a2f7 100644
--- a/full/Changes
+++ b/full/Changes
@@ -20,6 +20,8 @@
  - Updated tests.
 2022-01-25
  - Added show-tokens option to the search API.
+2022-01-31
+ - Added an API retrieving fields of a virtual corpus.
 
 # version 0.64.1
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
index 3fd5722..c135506 100644
--- a/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
+++ b/full/src/main/java/de/ids_mannheim/korap/authentication/KustvaktAuthenticationManager.java
@@ -315,6 +315,7 @@
 		return false;
 	}
 
+	@Deprecated
 	private User authenticateShib(Map<String, Object> attributes) throws KustvaktException {
 		// todo use persistent id, since eppn is not unique
 		String eppn = (String) attributes.get(Attributes.EPPN);
@@ -648,8 +649,8 @@
 
 		entHandler.createAccount(user);
 
-		s.setUserId(user.getId());
-		d.setUserId(user.getId());
+//		s.setUserId(user.getId());
+//		d.setUserId(user.getId());
 
 		UserDataDbIface dao = BeansFactory.getTypeFactory().getTypeInterfaceBean(userdatadaos, UserDetails.class);
 		assert dao != null;
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java b/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
index 6cfe8ee..7e042f1 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/QueryService.java
@@ -65,8 +65,7 @@
 @Service
 public class QueryService {
 
-    public static Logger jlog =
-            LogManager.getLogger(QueryService.class);
+    public static Logger jlog = LogManager.getLogger(QueryService.class);
 
     public static boolean DEBUG = false;
 
@@ -99,13 +98,13 @@
         }
     }
 
-    public List<QueryDto> listOwnerQuery (String username,
-            String queryCreator, QueryType queryType) throws KustvaktException {
+    public List<QueryDto> listOwnerQuery (String username, String queryCreator,
+            QueryType queryType) throws KustvaktException {
         verifyUsername(username, queryCreator);
         List<QueryDO> list = queryDao.retrieveOwnerQuery(username, queryType);
         return createQueryDtos(list, queryType);
     }
-    
+
     public List<QueryDto> listSystemQuery (QueryType queryType)
             throws KustvaktException {
         List<QueryDO> list = queryDao.retrieveQueryByType(ResourceType.SYSTEM,
@@ -130,14 +129,12 @@
         else {
             username = authenticatedUsername;
         }
-        List<QueryDO> list =
-                queryDao.retrieveQueryByUser(username, queryType);
+        List<QueryDO> list = queryDao.retrieveQueryByUser(username, queryType);
         return createQueryDtos(list, queryType);
     }
 
-    public List<QueryDto> listQueryByType (String username,
-            String createdBy, ResourceType type, QueryType queryType)
-            throws KustvaktException {
+    public List<QueryDto> listQueryByType (String username, String createdBy,
+            ResourceType type, QueryType queryType) throws KustvaktException {
 
         boolean isAdmin = adminDao.isAdmin(username);
 
@@ -153,21 +150,19 @@
         }
     }
 
-    private ArrayList<QueryDto> createQueryDtos (
-            List<QueryDO> queryList, QueryType queryType)
-            throws KustvaktException {
+    private ArrayList<QueryDto> createQueryDtos (List<QueryDO> queryList,
+            QueryType queryType) throws KustvaktException {
         ArrayList<QueryDto> dtos = new ArrayList<>(queryList.size());
         QueryDO query;
         Iterator<QueryDO> i = queryList.iterator();
         while (i.hasNext()) {
             query = i.next();
-//            String json = query.getKoralQuery();
+            // String json = query.getKoralQuery();
             String statistics = null;
-//            if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
-//                statistics = krill.getStatistics(json);
-//            }
-            QueryDto dto =
-                    converter.createQueryDto(query, statistics);
+            // if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
+            // statistics = krill.getStatistics(json);
+            // }
+            QueryDto dto = converter.createQueryDto(query, statistics);
             dtos.add(dto);
         }
         return dtos;
@@ -181,8 +176,7 @@
         if (query == null) {
             String code = createdBy + "/" + queryName;
             throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
-                    "Query " + code + " is not found.",
-                    String.valueOf(code));
+                    "Query " + code + " is not found.", String.valueOf(code));
         }
         else if (query.getCreatedBy().equals(username)
                 || adminDao.isAdmin(username)) {
@@ -196,7 +190,7 @@
             }
             if (type.equals(QueryType.VIRTUAL_CORPUS)
                     && VirtualCorpusCache.contains(queryName)) {
-               VirtualCorpusCache.delete(queryName);
+                VirtualCorpusCache.delete(queryName);
             }
             queryDao.deleteQuery(query);
         }
@@ -211,7 +205,7 @@
 
         verifyUsername(username, queryCreator);
         QueryDO query = queryDao.retrieveQueryByName(queryName, queryCreator);
-        
+
         if (query == null) {
             storeQuery(queryJson, queryName, queryCreator, username);
             return Status.CREATED;
@@ -238,8 +232,8 @@
         String queryLanguage = newQuery.getQueryLanguage();
         if (corpusQuery != null && !corpusQuery.isEmpty()) {
             koralQuery = serializeCorpusQuery(corpusQuery);
-            requiredAccess = determineRequiredAccess(newQuery.isCached(), queryName,
-                    koralQuery);
+            requiredAccess = determineRequiredAccess(newQuery.isCached(),
+                    queryName, koralQuery);
         }
         else if (query != null && !query.isEmpty() && queryLanguage != null
                 && !queryLanguage.isEmpty()) {
@@ -251,8 +245,8 @@
             if (existingQuery.getType().equals(ResourceType.PUBLISHED)) {
                 // withdraw from publication
                 if (!type.equals(ResourceType.PUBLISHED)) {
-                    QueryAccess hiddenAccess =
-                            accessDao.retrieveHiddenAccess(existingQuery.getId());
+                    QueryAccess hiddenAccess = accessDao
+                            .retrieveHiddenAccess(existingQuery.getId());
                     deleteQueryAccess(hiddenAccess.getId(), "system");
                     int groupId = hiddenAccess.getUserGroup().getId();
                     userGroupService.deleteAutoHiddenGroup(groupId, "system");
@@ -269,7 +263,8 @@
 
         queryDao.editQuery(existingQuery, queryName, type, requiredAccess,
                 koralQuery, newQuery.getDefinition(), newQuery.getDescription(),
-                newQuery.getStatus(), newQuery.isCached(), query, queryLanguage);
+                newQuery.getStatus(), newQuery.isCached(), query,
+                queryLanguage);
     }
 
     private void publishQuery (int queryId) throws KustvaktException {
@@ -291,7 +286,7 @@
                     + ". Hidden access exists! Access id: " + access.getId());
         }
     }
-    
+
     public void storeQuery (QueryJson query, String queryName,
             String queryCreator, String username) throws KustvaktException {
         String koralQuery = null;
@@ -323,22 +318,22 @@
         ParameterChecker.checkObjectValue(type, "type");
 
         if (!queryNamePattern.matcher(queryName).matches()) {
-            throw new KustvaktException(StatusCodes.INVALID_ARGUMENT,
-                    queryType.displayName() + " name must only contain "
-                            + "letters, numbers, underscores, hypens and spaces",
+            throw new KustvaktException(StatusCodes.INVALID_ARGUMENT, queryType
+                    .displayName() + " name must only contain "
+                    + "letters, numbers, underscores, hypens and spaces",
                     queryName);
         }
 
-        if (type.equals(ResourceType.SYSTEM)){
+        if (type.equals(ResourceType.SYSTEM)) {
             if (adminDao.isAdmin(username)) {
-                queryCreator="system";
+                queryCreator = "system";
             }
             else if (!username.equals("system")) {
                 throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
-                        "Unauthorized operation for user: " + username, username);    
+                        "Unauthorized operation for user: " + username,
+                        username);
             }
         }
-        
 
         CorpusAccess requiredAccess = CorpusAccess.PUB;
         if (queryType.equals(QueryType.VIRTUAL_CORPUS)) {
@@ -346,10 +341,10 @@
                     determineRequiredAccess(isCached, queryName, koralQuery);
         }
 
-        if (DEBUG){
+        if (DEBUG) {
             jlog.debug("Storing query: " + queryName + "in the database ");
         }
-        
+
         int queryId = 0;
         try {
             queryId = queryDao.createQuery(queryName, type, queryType,
@@ -453,8 +448,7 @@
         if (query == null) {
             String code = createdBy + "/" + queryName;
             throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
-                    "Query " + code + " is not found.",
-                    String.valueOf(code));
+                    "Query " + code + " is not found.", String.valueOf(code));
         }
         if (!username.equals(query.getCreatedBy())
                 && !adminDao.isAdmin(username)) {
@@ -546,10 +540,12 @@
 
         List<QueryAccess> accessList;
         if (adminDao.isAdmin(username)) {
-            accessList = accessDao.retrieveAllAccessByQuery(queryCreator, queryName);
+            accessList =
+                    accessDao.retrieveAllAccessByQuery(queryCreator, queryName);
         }
         else {
-            accessList = accessDao.retrieveActiveAccessByQuery(queryCreator, queryName);
+            accessList = accessDao.retrieveActiveAccessByQuery(queryCreator,
+                    queryName);
             List<QueryAccess> filteredAccessList = new ArrayList<>();
             for (QueryAccess access : accessList) {
                 UserGroup userGroup = access.getUserGroup();
@@ -617,22 +613,38 @@
         }
 
     }
-    
+
     public JsonNode retrieveKoralQuery (String username, String queryName,
             String createdBy, QueryType queryType) throws KustvaktException {
-        QueryDO query = searchQueryByName(username, queryName, createdBy, queryType);
+        QueryDO query =
+                searchQueryByName(username, queryName, createdBy, queryType);
         String koralQuery = query.getKoralQuery();
-        JsonNode kq = JsonUtils.readTree(koralQuery); 
+        JsonNode kq = JsonUtils.readTree(koralQuery);
         return kq;
     }
 
+    public JsonNode retrieveFieldValues (String username, String queryName,
+            String createdBy, QueryType queryType, String fieldName)
+            throws KustvaktException {
+        if (fieldName.equals("tokens") || fieldName.equals("base")) {
+            throw new KustvaktException(StatusCodes.NOT_ALLOWED,
+                    "Retrieving values of field "+fieldName+" is not allowed.");
+        }
+        else {
+            QueryDO query = searchQueryByName(username, queryName, createdBy,
+                    queryType);
+            String koralQuery = query.getKoralQuery();
+            return krill.getFieldValuesForVC(koralQuery, fieldName);
+        }
+    }
+
     public QueryDO searchQueryByName (String username, String queryName,
             String createdBy, QueryType queryType) throws KustvaktException {
         QueryDO query = queryDao.retrieveQueryByName(queryName, createdBy);
         if (query == null) {
             String code = createdBy + "/" + queryName;
             throw new KustvaktException(StatusCodes.NO_RESOURCE_FOUND,
-                    queryType.displayName()+ " " + code + " is not found.",
+                    queryType.displayName() + " " + code + " is not found.",
                     String.valueOf(code));
         }
         checkQueryAccess(query, username);
@@ -641,16 +653,19 @@
 
     public QueryDto retrieveQueryByName (String username, String queryName,
             String createdBy, QueryType queryType) throws KustvaktException {
-        QueryDO query = searchQueryByName(username, queryName, createdBy, queryType);
-//        String json = query.getKoralQuery();
+        QueryDO query =
+                searchQueryByName(username, queryName, createdBy, queryType);
+        // String json = query.getKoralQuery();
         String statistics = null;
-//        long start,end;
-//        start = System.currentTimeMillis();
-//        if (query.getQueryType().equals(QueryType.VIRTUAL_CORPUS)) {
-//            statistics = krill.getStatistics(json);
-//        }
-//        end = System.currentTimeMillis();
-//        jlog.debug("{} statistics duration: {}", queryName, (end - start));
+        // long start,end;
+        // start = System.currentTimeMillis();
+        // if (query.getQueryType().equals(QueryType.VIRTUAL_CORPUS))
+        // {
+        // statistics = krill.getStatistics(json);
+        // }
+        // end = System.currentTimeMillis();
+        // jlog.debug("{} statistics duration: {}", queryName, (end -
+        // start));
         return converter.createQueryDto(query, statistics);
     }
 
@@ -659,8 +674,8 @@
 
         QueryDO query = queryDao.retrieveQueryById(queryId);
         checkQueryAccess(query, username);
-//        String json = query.getKoralQuery();
-//        String statistics = krill.getStatistics(json);
+        // String json = query.getKoralQuery();
+        // String statistics = krill.getStatistics(json);
         return converter.createQueryDto(query, null);
     }
 
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
index 8a9f16f..31a2c19 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
@@ -173,6 +173,25 @@
         }
     }
     
+    @GET
+    @Path("/field/~{createdBy}/{vcName}")
+    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
+    public JsonNode retrieveVCField (
+            @Context SecurityContext securityContext,
+            @PathParam("createdBy") String createdBy,
+            @PathParam("vcName") String vcName,
+            @QueryParam("fieldName") String fieldName) {
+        TokenContext context =
+                (TokenContext) securityContext.getUserPrincipal();
+        try {
+            scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
+            return service.retrieveFieldValues(context.getUsername(), vcName,
+                    createdBy, QueryType.VIRTUAL_CORPUS, fieldName);
+        }
+        catch (KustvaktException e) {
+            throw kustvaktResponseHandler.throwit(e);
+        }
+    }
     
     /**
      * Lists all virtual corpora available to the authenticated user.
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
new file mode 100644
index 0000000..583629b
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusFieldTest.java
@@ -0,0 +1,135 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.http.entity.ContentType;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.net.HttpHeaders;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.ClientResponse.Status;
+import com.sun.jersey.api.client.UniformInterfaceException;
+
+import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
+import de.ids_mannheim.korap.cache.VirtualCorpusCache;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.config.NamedVCLoader;
+import de.ids_mannheim.korap.dao.QueryDao;
+import de.ids_mannheim.korap.entity.QueryDO;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.util.QueryException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+public class VirtualCorpusFieldTest extends VirtualCorpusTestBase {
+
+    @Autowired
+    private NamedVCLoader vcLoader;
+    @Autowired
+    private QueryDao dao;
+
+    private JsonNode testRetrieveField (String username, String vcName,
+            String field) throws UniformInterfaceException,
+            ClientHandlerException, KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path("vc")
+                .path("field").path("~" + username).path(vcName)
+                .queryParam("fieldName", field)
+                .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+                        .createBasicAuthorizationHeaderValue("dory", "pass"))
+                .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+
+        assertEquals(Status.OK.getStatusCode(), response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        return node;
+    }
+
+    private void testRetrieveProhibitedField (String username, String vcName,
+            String field) throws UniformInterfaceException,
+            ClientHandlerException, KustvaktException {
+        ClientResponse response = resource().path(API_VERSION).path("vc")
+                .path("field").path("~" + username).path(vcName)
+                .queryParam("fieldName", field)
+                .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
+                        .createBasicAuthorizationHeaderValue("dory", "pass"))
+                .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+                .get(ClientResponse.class);
+
+        assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+        String entity = response.getEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertEquals(StatusCodes.NOT_ALLOWED, node.at("/errors/0/0").asInt());
+    }
+    
+    private void deleteVcFromDB (String vcName) throws KustvaktException {
+        QueryDO vc = dao.retrieveQueryByName(vcName, "system");
+        dao.deleteQuery(vc);
+        vc = dao.retrieveQueryByName(vcName, "system");
+        assertEquals(null, vc);
+    }
+
+    @Test
+    public void testRetrieveFieldsNamedVC1 ()
+            throws IOException, QueryException, KustvaktException {
+
+        vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
+
+        JsonNode n = testRetrieveField("system", "named-vc1", "textSigle");
+        assertEquals(
+                "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+                n.at("/@context").asText());
+        assertEquals("textSigle", n.at("/corpus/key").asText());
+        assertEquals(2, n.at("/corpus/value").size());
+
+        n = testRetrieveField("system", "named-vc1", "author");
+        assertEquals(2, n.at("/corpus/value").size());
+        assertEquals("Goethe, Johann Wolfgang von",
+                n.at("/corpus/value/0").asText());
+
+        testRetrieveUnknownTokens();
+        testRetrieveProhibitedField("system", "named-vc1", "tokens");
+        testRetrieveProhibitedField("system", "named-vc1", "base");
+
+        VirtualCorpusCache.delete("named-vc1");
+        
+        deleteVcFromDB("named-vc1");
+    }
+
+    private void testRetrieveUnknownTokens () throws UniformInterfaceException,
+            ClientHandlerException, KustvaktException {
+        JsonNode n = testRetrieveField("system", "named-vc1", "unknown");
+        assertEquals("unknown", n.at("/corpus/key").asText());
+        assertEquals(0, n.at("/corpus/value").size());
+    }
+
+    @Test
+    public void testRetrieveTextSigleNamedVC2 ()
+            throws IOException, QueryException, KustvaktException {
+        vcLoader.loadVCToCache("named-vc2", "/vc/named-vc2.jsonld");
+
+        JsonNode n = testRetrieveField("system", "named-vc2", "textSigle");
+        assertEquals(2, n.at("/corpus/value").size());
+        VirtualCorpusCache.delete("named-vc2");
+        deleteVcFromDB("named-vc2");
+    }
+
+    @Test
+    public void testRetrieveTextSigleNamedVC3 ()
+            throws IOException, QueryException, KustvaktException {
+        vcLoader.loadVCToCache("named-vc3", "/vc/named-vc3.jsonld");
+
+        JsonNode n = testRetrieveField("system", "named-vc3", "textSigle");
+        n = n.at("/corpus/value");
+        assertEquals(1, n.size());
+        assertEquals("GOE/AGI/00000", n.get(0).asText());
+
+        VirtualCorpusCache.delete("named-vc3");
+        deleteVcFromDB("named-vc3");
+    }
+}
diff --git a/full/src/test/resources/vc/named-vc3.jsonld b/full/src/test/resources/vc/named-vc3.jsonld
new file mode 100644
index 0000000..a690744
--- /dev/null
+++ b/full/src/test/resources/vc/named-vc3.jsonld
@@ -0,0 +1,9 @@
+{
+    "collection": {
+        "@type": "koral:doc",
+        "key": "title",
+        "match": "match:eq",
+        "type": "type:string",
+        "value": "Italienische Reise"
+    }
+}