Added deprecation warning for the old matchInfo service (#757)

Change-Id: I07309f7dba50916bfff10ad6a75f9f73592ae7c3
diff --git a/Changes b/Changes
index 6cd8a9e..111885d 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@
   and context size. (#745)
 - Cleaned up named-vc.  
 - Updated tests using the old match info web-services (#757)
+- Added deprecation warning for the old matchInfo service (#757)
 
 # version 0.73.1
 
diff --git a/src/main/java/de/ids_mannheim/korap/core/service/SearchService.java b/src/main/java/de/ids_mannheim/korap/core/service/SearchService.java
index 03f186d..e616295 100644
--- a/src/main/java/de/ids_mannheim/korap/core/service/SearchService.java
+++ b/src/main/java/de/ids_mannheim/korap/core/service/SearchService.java
@@ -503,7 +503,7 @@
             String textId, String matchId, boolean info, Set<String> foundries,
             String username, HttpHeaders headers, Set<String> layers,
             boolean spans, boolean snippet, boolean tokens,
-            boolean sentenceExpansion, boolean highlights)
+            boolean sentenceExpansion, boolean highlights, boolean isDeprecated)
             throws KustvaktException {
         String matchid = searchKrill.getMatchId(corpusId, docId, textId,
                 matchId);
@@ -540,7 +540,7 @@
         };
 
         results = searchKrill.getMatch(matchid, info, foundryList, layerList,
-                spans, snippet, tokens, highlights, sentenceExpansion, p);
+                spans, snippet, tokens, highlights, sentenceExpansion, p, isDeprecated);
         //        }
         //        catch (Exception e) {
         //            jlog.error("Exception in the MatchInfo service encountered!", e);
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 e78993d..1a8a09a 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
@@ -261,12 +261,50 @@
             @QueryParam("foundry") Set<String> foundries,
             @QueryParam("layer") Set<String> layers,
             @QueryParam("spans") Boolean spans,
+            @DefaultValue("true") @QueryParam("show-snippet") String snippetStr,
+            @DefaultValue("false") @QueryParam("show-tokens") String tokensStr,
+            @QueryParam("expand") String expansion,
             // Highlights may also be a list of valid highlight classes
             @QueryParam("hls") Boolean highlights) throws KustvaktException {
 
-        return retrieveMatchInfo(ctx, headers, locale, corpusId, docId, textId,
-                matchId, foundries, layers, spans, "true", "false", "sentence",
-                highlights);
+        TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
+        try {
+            scopeService.verifyScope(tokenContext, OAuth2Scope.MATCH_INFO);
+        }
+        catch (KustvaktException e) {
+            throw kustvaktResponseHandler.throwit(e);
+        }
+
+        Boolean expandToSentence = true;
+        if (expansion != null
+                && (expansion.equals("false") || expansion.equals("null"))) {
+            expandToSentence = false;
+        }
+        spans = spans != null ? spans : false;
+        Boolean snippet = true;
+        Boolean tokens = false;
+        if (snippetStr != null
+                && (snippetStr.equals("false") || snippetStr.equals("null")))
+            snippet = false;
+
+        if (tokensStr != null && (tokensStr.equals("true")
+                || tokensStr.equals("1") || tokensStr.equals("yes")))
+            tokens = true;
+
+        highlights = highlights != null ? highlights : false;
+        if (layers == null || layers.isEmpty())
+            layers = new HashSet<>();
+
+        try {
+            String results = searchService.retrieveMatchInfo(corpusId, docId,
+                    textId, matchId, true, foundries,
+                    tokenContext.getUsername(), headers, layers, spans, snippet,
+                    tokens, expandToSentence, highlights, true);
+            return Response.ok(results).build();
+        }
+        catch (KustvaktException e) {
+            throw kustvaktResponseHandler.throwit(e);
+        }
     }
 
     @GET
@@ -320,7 +358,7 @@
             String results = searchService.retrieveMatchInfo(corpusId, docId,
                     textId, matchId, true, foundries,
                     tokenContext.getUsername(), headers, layers, spans, snippet,
-                    tokens, expandToSentence, highlights);
+                    tokens, expandToSentence, highlights, false);
             return Response.ok(results).build();
         }
         catch (KustvaktException e) {
diff --git a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
index cf96e3b..e4de9dc 100644
--- a/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
+++ b/src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
@@ -203,7 +203,8 @@
     public String getMatch (String id, boolean info, List<String> foundries,
             List<String> layers, boolean includeSpans, boolean includeSnippet,
             boolean includeTokens, boolean includeHighlights,
-            boolean sentenceExpansion, Pattern licensePattern)
+            boolean sentenceExpansion, Pattern licensePattern, 
+            boolean isDeprecated)
             throws KustvaktException {
         Match km;
         if (index != null) {
@@ -223,6 +224,13 @@
             km = new Match();
             km.addError(601, "Unable to find index");
         }
+        
+        if (isDeprecated) {
+            km.addWarning(StatusCodes.DEPRECATED,
+                    "This service is deprecated. Please use the following service"
+                    + " URL instead: {version}/corpus/{corpusId}/{docId}/"
+                    + "{textId}/{matchId}");
+        }
         return km.toJsonString();
     };
 
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 21f2155..454f9ae 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
@@ -53,6 +53,23 @@
                 node.at("/errors/0/1").asText());
         assertTrue(node.at("/snippet").isMissingNode());
     }
+    
+    @Test
+    public void testUsingDeprecatedMatchInfoService () 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.OK.getStatusCode(), response.getStatus());
+        String entity = response.readEntity(String.class);
+        JsonNode node = JsonUtils.readTree(entity);
+        assertEquals(StatusCodes.DEPRECATED,
+                node.at("/warnings/0/0").asInt());
+        assertEquals("This service is deprecated. Please use the following "
+                + "service URL instead: {version}/corpus/{corpusId}/{docId}/"
+                + "{textId}/{matchId}",
+                node.at("/warnings/0/1").asText());
+    }
 
     @Test
     public void testGetMatchInfoWithAuthentication () throws KustvaktException {
@@ -103,6 +120,7 @@
                                         "kustvakt2015"))
                 .header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
         JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
+        
         assertEquals(StatusCodes.AUTHORIZATION_FAILED,
                 node.at("/errors/0/0").asInt());
         assertEquals(