Skip to content

Commit e6d59b0

Browse files
committed
Added deprecation warning for the old matchInfo service (#757)
Change-Id: I07309f7dba50916bfff10ad6a75f9f73592ae7c3
1 parent d709be5 commit e6d59b0

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

src/main/java/de/ids_mannheim/korap/core/service/SearchService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public String retrieveMatchInfo (String corpusId, String docId,
503503
String textId, String matchId, boolean info, Set<String> foundries,
504504
String username, HttpHeaders headers, Set<String> layers,
505505
boolean spans, boolean snippet, boolean tokens,
506-
boolean sentenceExpansion, boolean highlights)
506+
boolean sentenceExpansion, boolean highlights, boolean isDeprecated)
507507
throws KustvaktException {
508508
String matchid = searchKrill.getMatchId(corpusId, docId, textId,
509509
matchId);
@@ -540,7 +540,7 @@ public String retrieveMatchInfo (String corpusId, String docId,
540540
};
541541

542542
results = searchKrill.getMatch(matchid, info, foundryList, layerList,
543-
spans, snippet, tokens, highlights, sentenceExpansion, p);
543+
spans, snippet, tokens, highlights, sentenceExpansion, p, isDeprecated);
544544
// }
545545
// catch (Exception e) {
546546
// jlog.error("Exception in the MatchInfo service encountered!", e);

src/main/java/de/ids_mannheim/korap/core/web/controller/SearchController.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,50 @@ public Response getMatchInfo (@Context SecurityContext ctx,
261261
@QueryParam("foundry") Set<String> foundries,
262262
@QueryParam("layer") Set<String> layers,
263263
@QueryParam("spans") Boolean spans,
264+
@DefaultValue("true") @QueryParam("show-snippet") String snippetStr,
265+
@DefaultValue("false") @QueryParam("show-tokens") String tokensStr,
266+
@QueryParam("expand") String expansion,
264267
// Highlights may also be a list of valid highlight classes
265268
@QueryParam("hls") Boolean highlights) throws KustvaktException {
266269

267-
return retrieveMatchInfo(ctx, headers, locale, corpusId, docId, textId,
268-
matchId, foundries, layers, spans, "true", "false", "sentence",
269-
highlights);
270+
TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
271+
try {
272+
scopeService.verifyScope(tokenContext, OAuth2Scope.MATCH_INFO);
273+
}
274+
catch (KustvaktException e) {
275+
throw kustvaktResponseHandler.throwit(e);
276+
}
277+
278+
Boolean expandToSentence = true;
279+
if (expansion != null
280+
&& (expansion.equals("false") || expansion.equals("null"))) {
281+
expandToSentence = false;
282+
}
283+
spans = spans != null ? spans : false;
284+
Boolean snippet = true;
285+
Boolean tokens = false;
286+
if (snippetStr != null
287+
&& (snippetStr.equals("false") || snippetStr.equals("null")))
288+
snippet = false;
289+
290+
if (tokensStr != null && (tokensStr.equals("true")
291+
|| tokensStr.equals("1") || tokensStr.equals("yes")))
292+
tokens = true;
293+
294+
highlights = highlights != null ? highlights : false;
295+
if (layers == null || layers.isEmpty())
296+
layers = new HashSet<>();
297+
298+
try {
299+
String results = searchService.retrieveMatchInfo(corpusId, docId,
300+
textId, matchId, true, foundries,
301+
tokenContext.getUsername(), headers, layers, spans, snippet,
302+
tokens, expandToSentence, highlights, true);
303+
return Response.ok(results).build();
304+
}
305+
catch (KustvaktException e) {
306+
throw kustvaktResponseHandler.throwit(e);
307+
}
270308
}
271309

272310
@GET
@@ -320,7 +358,7 @@ public Response retrieveMatchInfo (@Context SecurityContext ctx,
320358
String results = searchService.retrieveMatchInfo(corpusId, docId,
321359
textId, matchId, true, foundries,
322360
tokenContext.getUsername(), headers, layers, spans, snippet,
323-
tokens, expandToSentence, highlights);
361+
tokens, expandToSentence, highlights, false);
324362
return Response.ok(results).build();
325363
}
326364
catch (KustvaktException e) {

src/main/java/de/ids_mannheim/korap/web/SearchKrill.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ else if (fields != null) {
203203
public String getMatch (String id, boolean info, List<String> foundries,
204204
List<String> layers, boolean includeSpans, boolean includeSnippet,
205205
boolean includeTokens, boolean includeHighlights,
206-
boolean sentenceExpansion, Pattern licensePattern)
206+
boolean sentenceExpansion, Pattern licensePattern,
207+
boolean isDeprecated)
207208
throws KustvaktException {
208209
Match km;
209210
if (index != null) {
@@ -223,6 +224,13 @@ public String getMatch (String id, boolean info, List<String> foundries,
223224
km = new Match();
224225
km.addError(601, "Unable to find index");
225226
}
227+
228+
if (isDeprecated) {
229+
km.addWarning(StatusCodes.DEPRECATED,
230+
"This service is deprecated. Please use the following service"
231+
+ " URL instead: {version}/corpus/{corpusId}/{docId}/"
232+
+ "{textId}/{matchId}");
233+
}
226234
return km.toJsonString();
227235
};
228236

src/test/java/de/ids_mannheim/korap/web/controller/MatchInfoControllerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ public void testGetMatchInfoNotAllowed () throws KustvaktException {
5353
node.at("/errors/0/1").asText());
5454
assertTrue(node.at("/snippet").isMissingNode());
5555
}
56+
57+
@Test
58+
public void testUsingDeprecatedMatchInfoService () throws KustvaktException {
59+
Response response = target().path(API_VERSION).path("corpus")
60+
.path("GOE").path("AGA").path("01784").path("p36-100")
61+
.path("matchInfo")
62+
.queryParam("foundry", "*").request().get();
63+
assertEquals(Status.OK.getStatusCode(), response.getStatus());
64+
String entity = response.readEntity(String.class);
65+
JsonNode node = JsonUtils.readTree(entity);
66+
assertEquals(StatusCodes.DEPRECATED,
67+
node.at("/warnings/0/0").asInt());
68+
assertEquals("This service is deprecated. Please use the following "
69+
+ "service URL instead: {version}/corpus/{corpusId}/{docId}/"
70+
+ "{textId}/{matchId}",
71+
node.at("/warnings/0/1").asText());
72+
}
5673

5774
@Test
5875
public void testGetMatchInfoWithAuthentication () throws KustvaktException {
@@ -103,6 +120,7 @@ public void testAvailabilityAllUnauthorized () throws KustvaktException {
103120
"kustvakt2015"))
104121
.header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32").get();
105122
JsonNode node = JsonUtils.readTree(response.readEntity(String.class));
123+
106124
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
107125
node.at("/errors/0/0").asInt());
108126
assertEquals(

0 commit comments

Comments
 (0)