Skip to content

Commit

Permalink
Added deprecation warning for the old matchInfo service (#757)
Browse files Browse the repository at this point in the history
Change-Id: I07309f7dba50916bfff10ad6a75f9f73592ae7c3
  • Loading branch information
margaretha committed Jun 5, 2024
1 parent d709be5 commit e6d59b0
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public String retrieveMatchInfo (String corpusId, String docId,
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);
Expand Down Expand Up @@ -540,7 +540,7 @@ public String retrieveMatchInfo (String corpusId, String docId,
};

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,50 @@ public Response getMatchInfo (@Context SecurityContext ctx,
@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
Expand Down Expand Up @@ -320,7 +358,7 @@ public Response retrieveMatchInfo (@Context SecurityContext ctx,
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) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/de/ids_mannheim/korap/web/SearchKrill.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ else if (fields != null) {
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) {
Expand All @@ -223,6 +224,13 @@ public String getMatch (String id, boolean info, List<String> foundries,
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();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ public void testGetMatchInfoNotAllowed () throws KustvaktException {
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 {
Expand Down Expand Up @@ -103,6 +120,7 @@ public void testAvailabilityAllUnauthorized () throws KustvaktException {
"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(
Expand Down

0 comments on commit e6d59b0

Please sign in to comment.