Introduced APIDeprecationFilter (#759)

Deprecated matchInfo web-service has been removed for API v1.1. It is
still accessible as long as v1.0 is supported on a Kustvakt server.

Change-Id: I382fd3f6200c32420dd0d88cfe5ad05e2de289e2
diff --git a/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java b/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
index 19aea8e..cc02588 100644
--- a/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
+++ b/src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java
@@ -23,6 +23,7 @@
 import de.ids_mannheim.korap.utils.JsonUtils;
 import de.ids_mannheim.korap.utils.ServiceInfo;
 import de.ids_mannheim.korap.web.KustvaktResponseHandler;
+import de.ids_mannheim.korap.web.filter.APIDeprecationFilter;
 import de.ids_mannheim.korap.web.filter.APIVersionFilter;
 import de.ids_mannheim.korap.web.filter.AdminFilter;
 import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
@@ -257,6 +258,8 @@
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
     @Path("{version}/corpus/{corpusId}/{docId}/{textId}/{matchId}/matchInfo")
+    @ResourceFilters({APIDeprecationFilter.class, 
+    	AuthenticationFilter.class, DemoUserFilter.class})
     //@SearchResourceFilters
     public Response getMatchInfo (@Context SecurityContext ctx,
             @Context HttpHeaders headers, @Context Locale locale,
@@ -315,7 +318,7 @@
 
     @GET
     @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-    @Path("{version}/corpus/{corpusId}/{docId}/{textId}/{matchId}")
+    @Path("{version}/corpus/{corpusId}/{docId}/{textId}/{matchId}")    
     //@SearchResourceFilters
     public Response retrieveMatchInfo (@Context SecurityContext ctx,
             @Context HttpHeaders headers, @Context Locale locale,
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/APIDeprecationFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/APIDeprecationFilter.java
new file mode 100644
index 0000000..bd0a7e5
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/APIDeprecationFilter.java
@@ -0,0 +1,33 @@
+package de.ids_mannheim.korap.web.filter;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import jakarta.annotation.Priority;
+import jakarta.ws.rs.NotFoundException;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.core.PathSegment;
+
+@Priority(Integer.MIN_VALUE +1)
+public class APIDeprecationFilter implements ContainerRequestFilter {
+
+    @Autowired
+    private KustvaktConfiguration config;
+
+    public void filter (ContainerRequestContext request) {
+        List<PathSegment> pathSegments = request.getUriInfo().getPathSegments();
+        String version = pathSegments.get(0).getPath();
+
+        double requestedVersion = Double.parseDouble(version.substring(1));
+        if (requestedVersion > 1) {
+            throw new NotFoundException();
+            // throw kustvaktResponseHandler.throwit(
+            // new
+            // KustvaktException(StatusCodes.UNSUPPORTED_API_VERSION,
+            // "API " + version + " is unsupported.", version));
+        }
+	}
+}
diff --git a/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java b/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
index 4334b97..9f0c3cb 100644
--- a/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/config/SpringJerseyTest.java
@@ -23,7 +23,8 @@
 @ContextConfiguration("classpath:test-config.xml")
 public abstract class SpringJerseyTest extends JerseyTest {
 
-    public final static String API_VERSION = "v1.0";
+    public final static String API_VERSION = "v1.1";
+    public final static String API_VERSION_V1_0 = "v1.0";
 
     protected final static String allCorpusAccess = "All corpus access policy "
 			+ "has been added.";
diff --git a/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java b/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
index 2f3f74d..41b27f7 100644
--- a/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java
@@ -55,8 +55,8 @@
     }
     
     @Test
-    public void testUsingDeprecatedMatchInfoService () throws KustvaktException {
-        Response response = target().path(API_VERSION).path("corpus")
+    public void testDeprecatedMatchInfoWithV1_0 () throws KustvaktException {
+        Response response = target().path(API_VERSION_V1_0).path("corpus")
                 .path("GOE").path("AGA").path("01784").path("p36-100")
                 .path("matchInfo")
                 .queryParam("foundry", "*").request().get();
@@ -70,6 +70,15 @@
                 + "{textId}/{matchId}",
                 node.at("/warnings/0/1").asText());
     }
+    
+    @Test
+    public void testDeprecatedMatchInfo () throws KustvaktException {
+        Response response = target().path(API_VERSION).path("corpus")
+                .path("GOE").path("AGA").path("01784").path("p36-100")
+                .path("matchInfo")
+                .queryParam("foundry", "*").request().get();
+        assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
+    }
 
     @Test
     public void testGetMatchInfoWithAuthentication () throws KustvaktException {
diff --git a/src/test/resources/kustvakt-test.conf b/src/test/resources/kustvakt-test.conf
index e4abfec..99e13e5 100644
--- a/src/test/resources/kustvakt-test.conf
+++ b/src/test/resources/kustvakt-test.conf
@@ -20,8 +20,8 @@
 # Kustvakt versions
 #
 # multiple versions comma separated
-current.api.version = v1.0
-supported.api.versions = v0.1, v1.0
+current.api.version = v1.1
+supported.api.versions = v1.0, v1.1
 
 # Server
 #