Updated VC list API and deprecated owner VC list (addressed #580)

Change-Id: Id2b7420e63dc93567410a96213bd242addd58324
diff --git a/full/Changes b/full/Changes
index e9ffeaa..0652f7e 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,6 +1,7 @@
 # version 0.69.4
 
 - Support token array in matchinfo (fixes #570; diewald)
+- Updated VC list API and deprecated owner VC list (addressed #580)
 
 # version 0.69.3
 
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 981cb41..419f374 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
@@ -99,9 +99,8 @@
         }
     }
 
-    public List<QueryDto> listOwnerQuery (String username, String queryCreator,
+    public List<QueryDto> listOwnerQuery (String username,
             QueryType queryType) throws KustvaktException {
-        verifyUsername(username, queryCreator);
         List<QueryDO> list = queryDao.retrieveOwnerQuery(username, queryType);
         return createQueryDtos(list, queryType);
     }
@@ -113,23 +112,8 @@
         return createQueryDtos(list, queryType);
     }
 
-    public List<QueryDto> listAvailableQueryForUser (
-            String authenticatedUsername, String username, QueryType queryType)
-            throws KustvaktException {
-
-        boolean isAdmin = adminDao.isAdmin(authenticatedUsername);
-
-        if (username != null) {
-            if (!username.equals(authenticatedUsername) && !isAdmin) {
-                throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
-                        "Unauthorized operation for user: "
-                                + authenticatedUsername,
-                        authenticatedUsername);
-            }
-        }
-        else {
-            username = authenticatedUsername;
-        }
+    public List<QueryDto> listAvailableQueryForUser (String username,
+            QueryType queryType) throws KustvaktException {
         List<QueryDO> list = queryDao.retrieveQueryByUser(username, queryType);
         return createQueryDtos(list, queryType);
     }
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 3c93e50..d6f1548 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
@@ -196,7 +196,7 @@
         try {
             scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
             List<QueryDto> dtos = service.listAvailableQueryForUser(
-                    context.getUsername(), username, QueryType.QUERY);
+                    context.getUsername(), QueryType.QUERY);
             return dtos;
         }
         catch (KustvaktException e) {
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 20be6dc..01e6bcd 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
@@ -2,6 +2,7 @@
 
 import java.util.List;
 
+import javax.validation.constraints.Email;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -27,6 +28,7 @@
 import de.ids_mannheim.korap.dto.QueryAccessDto;
 import de.ids_mannheim.korap.dto.QueryDto;
 import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
 import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
 import de.ids_mannheim.korap.security.context.TokenContext;
 import de.ids_mannheim.korap.service.QueryService;
@@ -204,7 +206,7 @@
     }
     
     /**
-     * Lists all virtual corpora available to the authenticated user.
+     * Lists all virtual corpora available to the user.
      *
      * System-admins can list available vc for a specific user by
      * specifiying the username parameter.
@@ -221,13 +223,30 @@
     @GET
     public List<QueryDto> listAvailableVC (
             @Context SecurityContext securityContext,
-            @QueryParam("username") String username) {
+            @QueryParam("filter-by") String filter) {
         TokenContext context =
                 (TokenContext) securityContext.getUserPrincipal();
+
         try {
             scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
-            return service.listAvailableQueryForUser(context.getUsername(),
-                    username, QueryType.VIRTUAL_CORPUS);
+            if (filter !=null && !filter.isEmpty() ) {
+                filter = filter.toLowerCase();
+                if (filter.equals("system")) {
+                    return service.listSystemQuery(QueryType.VIRTUAL_CORPUS);
+                }
+                else if (filter.equals("own")) {
+                    return service.listOwnerQuery(context.getUsername(),
+                            QueryType.VIRTUAL_CORPUS);    
+                }
+                else {
+                    throw new KustvaktException(StatusCodes.UNSUPPORTED_VALUE, 
+                            "The given filter is unknown or not supported.");
+                }
+            }
+            else {
+                return service.listAvailableQueryForUser(context.getUsername(),
+                    QueryType.VIRTUAL_CORPUS);
+            }
         }
         catch (KustvaktException e) {
             throw kustvaktResponseHandler.throwit(e);
@@ -253,26 +272,17 @@
      * @return all system VC, if createdBy=system, otherwise a list of
      *         virtual corpora created by the authorized user.
      */
+    @Deprecated
     @GET
     @Path("~{createdBy}")
     public List<QueryDto> listUserOrSystemVC (
             @PathParam("createdBy") String createdBy,
             @Context SecurityContext securityContext) {
-        TokenContext context =
-                (TokenContext) securityContext.getUserPrincipal();
-        try {
-            scopeService.verifyScope(context, OAuth2Scope.VC_INFO);
-            if (createdBy.toLowerCase().equals("system")) {
-                return service.listSystemQuery(QueryType.VIRTUAL_CORPUS);
-            }
-            else {
-                return service.listOwnerQuery(context.getUsername(), createdBy,
-                        QueryType.VIRTUAL_CORPUS);
-            }
-        }
-        catch (KustvaktException e) {
+        
+        KustvaktException e = new KustvaktException(StatusCodes.DEPRECATED,
+                "This service has been deprecated. Please use Virtual Corpus List "
+                + "web-service.");
             throw kustvaktResponseHandler.throwit(e);
-        }
     }
     
    
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
index 21be515..53a2083 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
@@ -10,6 +10,7 @@
 import javax.ws.rs.core.Response.Status;
 
 import org.apache.http.entity.ContentType;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -111,6 +112,8 @@
         testResponseUnauthorized(response);
     }
 
+    @Ignore
+    @Deprecated
     @Test
     public void testListUserVC () throws
             ProcessingException, 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 3730e82..bc84dae 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
@@ -23,6 +23,7 @@
 import org.apache.http.HttpStatus;
 import org.apache.http.entity.ContentType;
 import org.glassfish.jersey.server.ContainerRequest;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -77,7 +78,7 @@
             throws ProcessingException,
             KustvaktException {
         Response response = target().path(API_VERSION).path("vc")
-                .path("~" + username)
+                .queryParam("filter-by", "own")
                 .request()
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue(username, "pass"))
@@ -265,6 +266,8 @@
         assertEquals(4, node.size());
     }
 
+    @Ignore
+    @Deprecated
     @Test
     public void testListAvailableVCByOtherUser ()
             throws ProcessingException,
@@ -308,7 +311,7 @@
     
     private void testListSystemVC () throws KustvaktException {
         Response response = target().path(API_VERSION).path("vc")
-                .path("~system")
+                .queryParam("filter-by", "system")
                 .request()
                 .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
                         .createBasicAuthorizationHeaderValue("pearl", "pass"))