Added dynamic acquisition of resource info using KorAP API.
Change-Id: I884792be0a98b558f6ec67bfc18d7b80ad98ee33
diff --git a/ChangeLog b/ChangeLog
index 4407924..2aaaf03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
+20/12/2019
+ - Added dynamic acquisition of resource info using KorAP API.
+
11/07/2019
- - Updated libraries, resources and endpoint description.
+ - Updated libraries, resources and endpoint description.
07/01/2019
- - Updated Jackson databind library.
- - Updated tests' descriptions.
- - Added change log.
+ - Updated Jackson databind library.
+ - Updated tests' descriptions.
+ - Added change log.
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapClient.java b/src/main/java/de/ids_mannheim/korap/sru/KorapClient.java
index 435e21e..e8d9974 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapClient.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapClient.java
@@ -78,17 +78,17 @@
* @throws URISyntaxException
* @throws IOException
*/
- public JsonNode retrieveResources ()
+ public KorapResource[] retrieveResources ()
throws URISyntaxException, IOException {
- URIBuilder builder = new URIBuilder(serviceUri + "Corpus");
+ URIBuilder builder = new URIBuilder(serviceUri + "/resource");
URI uri = builder.build();
logger.info("Resource URI: " + uri.toString());
HttpGet httpRequest = new HttpGet(uri);
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = null;
- JsonNode resources = null;
+ KorapResource[] resources = null;
try {
response = client.execute(httpRequest);
@@ -102,10 +102,9 @@
response.getStatusLine().getReasonPhrase());
}
- BufferedInputStream jsonStream =
- new BufferedInputStream(response.getEntity().getContent());
+ InputStream jsonStream = response.getEntity().getContent();
try {
- resources = objectMapper.readValue(jsonStream, JsonNode.class);
+ resources = objectMapper.readValue(jsonStream, KorapResource[].class);
}
catch (JsonParseException | JsonMappingException e) {
throw e;
@@ -298,7 +297,7 @@
params.add(
new BasicNameValuePair("offset", String.valueOf(startRecord)));
- URIBuilder builder = new URIBuilder(serviceUri + "search");
+ URIBuilder builder = new URIBuilder(serviceUri + "/search");
builder.addParameters(params);
URI uri = builder.build();
@@ -409,7 +408,7 @@
StringBuilder sb = new StringBuilder();
sb.append(serviceUri);
- sb.append("corpus/");
+ sb.append("/corpus/");
sb.append(resourceId);
sb.append("/");
sb.append(documentId);
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java b/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
index 10e4412..22a133f 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapEndpointDescription.java
@@ -1,20 +1,18 @@
package de.ids_mannheim.korap.sru;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import eu.clarin.sru.server.SRUConfigException;
import eu.clarin.sru.server.SRUConstants;
import eu.clarin.sru.server.SRUException;
@@ -47,7 +45,8 @@
private Layer textLayer;
private List<AnnotationLayer> annotationLayers;
- private ObjectMapper mapper = new ObjectMapper();
+
+ public KorapEndpointDescription () {}
public KorapEndpointDescription (ServletContext context)
throws SRUConfigException {
@@ -118,33 +117,24 @@
List<ResourceInfo> resourceList = new ArrayList<ResourceInfo>();
- Map<String, String> title;
Map<String, String> description;
- JsonNode resources;
-
+ KorapResource[] resources;
try {
- // resources = KorapSRU.korapClient.retrieveResources();
- InputStream is = getClass().getClassLoader()
- .getResourceAsStream("resources.json");
- resources = mapper.readTree(is);
+ resources = KorapSRU.korapClient.retrieveResources();
}
- catch ( // URISyntaxException |
- IOException e) {
+ catch (URISyntaxException | IOException e) {
throw new SRUException(SRUConstants.SRU_GENERAL_SYSTEM_ERROR,
"Failed retrieving resources.");
}
- for (JsonNode r : resources) {
- title = new HashMap<String, String>();
- title.put("de", r.get("name").asText());
- title.put("en", r.get("name").asText());
-
+ for (KorapResource r : resources) {
description = new HashMap<String, String>();
- description.put("de", r.get("description").asText());
+ description.put("de", r.getDescription());
- ResourceInfo ri = new ResourceInfo(r.get("id").asText(), title,
- description, KorapSRU.KORAP_WEB_URL, languages, dataviews,
+ ResourceInfo ri = new ResourceInfo(r.getResourceId(), r.getTitles(),
+ description, KorapSRU.KORAP_WEB_URL,
+ Arrays.asList(r.getLanguages()), dataviews,
this.getSupportedLayers(), null);
resourceList.add(ri);
}
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapResource.java b/src/main/java/de/ids_mannheim/korap/sru/KorapResource.java
new file mode 100644
index 0000000..ef22102
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapResource.java
@@ -0,0 +1,43 @@
+package de.ids_mannheim.korap.sru;
+
+import java.util.Map;
+
+public class KorapResource {
+
+ private String resourceId;
+ private Map<String, String> titles;
+ private String description;
+ private String[] languages;
+ private Map<Integer, String> layers;
+ public String getResourceId () {
+ return resourceId;
+ }
+ public void setResourceId (String resourceId) {
+ this.resourceId = resourceId;
+ }
+ public Map<String, String> getTitles () {
+ return titles;
+ }
+ public void setTitles (Map<String, String> titles) {
+ this.titles = titles;
+ }
+ public String getDescription () {
+ return description;
+ }
+ public void setDescription (String description) {
+ this.description = description;
+ }
+ public String[] getLanguages () {
+ return languages;
+ }
+ public void setLanguages (String[] languages) {
+ this.languages = languages;
+ }
+ public Map<Integer, String> getLayers () {
+ return layers;
+ }
+ public void setLayers (Map<Integer, String> layers) {
+ this.layers = layers;
+ }
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java b/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
index f115436..deea936 100644
--- a/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
+++ b/src/main/java/de/ids_mannheim/korap/sru/KorapSRU.java
@@ -33,7 +33,7 @@
public class KorapSRU extends SimpleEndpointSearchEngineBase {
public static final String CLARIN_FCS_RECORD_SCHEMA = "http://clarin.eu/fcs/resource";
- public static final String KORAP_WEB_URL = "http://korap.ids-mannheim.de/";
+ public static final String KORAP_WEB_URL = "https://korap.ids-mannheim.de/";
public static String redirectBaseURI;
public static KorapClient korapClient;
diff --git a/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
index a2de639..388670f 100644
--- a/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapJerseyTest.java
@@ -27,7 +27,7 @@
.initParam("eu.clarin.sru.server.maximumRecords", "50")
.contextParam("de.ids_mannheim.korap.endpointDescription",
"/src/main/webapp/WEB-INF/endpoint-description.xml")
- .contextParam("korap.service.uri", "http://localhost:8089/api/v1.0/")
+ .contextParam("korap.service.uri", "http://localhost:8089/api/v1.0")
.build();
}
diff --git a/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java b/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
index fdd0c8b..4d41ae2 100644
--- a/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
+++ b/src/test/java/de/ids_mannheim/korap/test/KorapSRUTest.java
@@ -43,10 +43,23 @@
ClientResponse response = resource().queryParam("operation", "searchRetrieve")
.queryParam("query", "fein")
.get(ClientResponse.class);
-
+
InputStream entity = response.getEntity(InputStream.class);
checkSRUSearchRetrieveResponse(entity);
- }
+ }
+
+ @Test
+ public void searchRetrieveCQLTestWithStartRecord() throws IOException, SAXException{
+ ClientResponse response = resource().queryParam("operation", "searchRetrieve")
+ .queryParam("query", "der")
+ .queryParam("startRecord", "51")
+ .get(ClientResponse.class);
+ InputStream entity = response.getEntity(InputStream.class);
+ Document doc = docBuilder.parse(entity);
+
+ NodeList nodelist = doc.getElementsByTagName("sruResponse:recordPosition");
+ assertEquals("51", nodelist.item(0).getTextContent());
+ }
@Test
public void searchRetrieveFCSQLTest() throws IOException, SAXException{