Skip to content

Commit 8aeb8da

Browse files
committed
Add pipe response for the metadata web-service.
Change-Id: I072525f6edfe3850f15da1326d7483eb45f93185
1 parent 61ee66e commit 8aeb8da

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# version 1.1-SNAPSHOT
22
- Change VC and query names to lowercase
33
- Implemented pipe response rewriting for match info API (#814)
4+
- Add pipe response for the metadata web-service.
45

56
# version 1.0.1
67

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ public String retrieveMatchInfo (String corpusId, String docId,
574574
}
575575

576576
public String retrieveDocMetadata (String corpusId, String docId,
577-
String textId, String fields, String username, HttpHeaders headers)
577+
String textId, String fields, String username, HttpHeaders headers,
578+
String responsePipes)
578579
throws KustvaktException {
579580
List<String> fieldList = null;
580581
if (fields != null && !fields.isEmpty()) {
@@ -588,6 +589,8 @@ public String retrieveDocMetadata (String corpusId, String docId,
588589
String textSigle = searchKrill.getTextSigle(corpusId, docId, textId);
589590
String results = searchKrill.getFields(textSigle, fieldList, p);
590591

592+
results = runPipes(results, responsePipes);
593+
591594
return results;
592595
}
593596

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,14 @@ public Response getMetadata (@PathParam("corpusId") String corpusId,
418418
@PathParam("docId") String docId,
419419
@PathParam("textId") String textId,
420420
@QueryParam("fields") String fields,
421+
@QueryParam("response-pipes") String responsePipes,
421422
@Context SecurityContext ctx,
422423
@Context HttpHeaders headers) throws KustvaktException {
423424
TokenContext tokenContext = (TokenContext) ctx.getUserPrincipal();
424425
try {
425426
String results = searchService.retrieveDocMetadata(corpusId, docId,
426-
textId, fields, tokenContext.getUsername(), headers);
427+
textId, fields, tokenContext.getUsername(), headers,
428+
responsePipes);
427429
return Response.ok(results).build();
428430
}
429431
catch (KustvaktException e) {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class SearchPipeTest extends SpringJerseyTest {
4646
private String glemmUri = "http://localhost:" + port + "/glemm";
4747
private String termMapperUri = "http://localhost:" + port
4848
+ "/term-mapper?foundry=corenlp";
49+
private String termMapperUri2 = "http://localhost:" + port
50+
+ "/term-mapper?fields=@all";
4951

5052
public SearchPipeTest () throws URISyntaxException, IOException {
5153
pipeJson = IOUtils.toString(
@@ -139,6 +141,40 @@ public void testRetrieveMatchInfoWithResponsePipe ()
139141
+ "\"corenlp/p:ADJA\">freie</span> <span title="
140142
+ "\"corenlp/p:NN\">Weg</span>"));
141143
}
144+
145+
@Test
146+
public void testRetrieveMetadataWithResponsePipe ()
147+
throws KustvaktException {
148+
149+
mockClient.reset()
150+
.when(request().withMethod("POST")
151+
.withPath("/term-mapper")
152+
.withQueryStringParameter("fields", "@all")
153+
.withHeaders(
154+
new Header("Content-Type",
155+
"application/json; charset=utf-8"),
156+
new Header("Accept", "application/json")))
157+
.respond(response()
158+
.withHeader(new Header("Content-Type",
159+
"application/json; charset=utf-8"))
160+
.withBody(termMapperJson).withStatusCode(200));
161+
162+
Response response = target().path(API_VERSION).path("corpus")
163+
.path("GOE").path("AGA").path("01784")
164+
.queryParam("fields", "@all")
165+
.queryParam("response-pipes", termMapperUri2)
166+
.request().get();
167+
assertEquals(Status.OK.getStatusCode(), response.getStatus());
168+
String entity = response.readEntity(String.class);
169+
JsonNode node = JsonUtils.readTree(entity);
170+
171+
assertTrue(node.at("/snippet").asText().startsWith(
172+
"<span class=\"context-left\"></span><span class=\"match\">"
173+
+ "<span title=\"corenlp/p:ART\">der</span> <span title="
174+
+ "\"corenlp/p:ADJA\">alte</span> <span title="
175+
+ "\"corenlp/p:ADJA\">freie</span> <span title="
176+
+ "\"corenlp/p:NN\">Weg</span>"));
177+
}
142178

143179
@Test
144180
public void testSearchWithPipes ()

0 commit comments

Comments
 (0)