Added API info web-service.
Change-Id: I8ff91cd5dccca0824146d38a361964cc284cd196
diff --git a/core/Changes b/core/Changes
index cab5c5b..3861484 100644
--- a/core/Changes
+++ b/core/Changes
@@ -3,6 +3,8 @@
- Updated Flyway (margaretha)
21/01/2021
- Fixed running pipe and updated tests with mockserver (margaretha)
+19/02/2021
+ - Enabled API info web-service (margaretha)
# version 0.62.4
24/01/2020
diff --git a/core/pom.xml b/core/pom.xml
index a14de06..30e7d79 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -14,12 +14,15 @@
<hibernate.version>5.4.25.Final</hibernate.version>
<flyway.version>7.4.0</flyway.version>
<log4j.version>2.13.3</log4j.version>
+ <krill.version>[0.59.3,)</krill.version>
+ <koral.version>[0.37,)</koral.version>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
+ <filtering>true</filtering>
</resource>
</resources>
<testResources>
@@ -248,7 +251,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Koral</artifactId>
- <version>[0.37,)</version>
+ <version>${koral.version}</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
@@ -310,7 +313,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Krill</artifactId>
- <version>[0.59.3,)</version>
+ <version>${krill.version}</version>
<exclusions>
<exclusion>
<groupId>org.glassfish.jersey.containers</groupId>
diff --git a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
index 36d04e0..913da7b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
+++ b/core/src/main/java/de/ids_mannheim/korap/config/KustvaktConfiguration.java
@@ -139,10 +139,15 @@
apiWelcomeMessage = properties.getProperty("api.welcome.message", "Welcome to KorAP API!");
currentVersion = properties.getProperty("current.api.version", "v1.0");
+
String supportedVersions =
- properties.getProperty("supported.api.version", "");
+ properties.getProperty("supported.api.versions", "");
- this.supportedVersions = new HashSet<>(Arrays.asList(supportedVersions.split(" ")));
+ this.supportedVersions = new HashSet<>();
+ if (!supportedVersions.isEmpty()){
+ List<String> versionArray = Arrays.asList(supportedVersions.split(" "));
+ this.supportedVersions.addAll(versionArray);
+ }
this.supportedVersions.add(currentVersion);
maxhits = new Integer(properties.getProperty("maxhits", "50000"));
diff --git a/core/src/main/java/de/ids_mannheim/korap/utils/ServiceInfo.java b/core/src/main/java/de/ids_mannheim/korap/utils/ServiceInfo.java
index 947f69d..f2691da 100644
--- a/core/src/main/java/de/ids_mannheim/korap/utils/ServiceInfo.java
+++ b/core/src/main/java/de/ids_mannheim/korap/utils/ServiceInfo.java
@@ -31,6 +31,11 @@
private String cache_store;
+ @Getter
+ private String krillVersion;
+ @Getter
+ private String koralVersion;
+
private ServiceInfo () {
load();
}
@@ -48,6 +53,9 @@
this.logger = (String) props.get("kustvakt.logging");
this.cacheable = Boolean.valueOf((String) props.get("kustvakt.cache"));
this.cache_store = (String) props.get("kustvakt.cache_store");
+
+ this.krillVersion=(String) props.get("krill.version");
+ this.koralVersion=(String) props.get("koral.version");
}
catch (IOException e) {
this.version = UNKNOWN;
@@ -56,12 +64,15 @@
this.config = UNKNOWN;
this.cacheable = false;
this.cache_store = UNKNOWN;
+
+ this.koralVersion = UNKNOWN;
+ this.krillVersion = UNKNOWN;
}
}
private static InputStream getStream () throws IOException {
- String path = "kustvakt.info";
+ String path = "service.properties";
InputStream stream = ConfigLoader.loadConfigStream(path);
if (stream == null)
throw new IOException("stream for resource " + path
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java b/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
index e3967b4..2760810 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/controller/SearchController.java
@@ -1,9 +1,11 @@
package de.ids_mannheim.korap.web.controller;// package
// de.ids_mannheim.korap.ext.web;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
@@ -34,6 +36,8 @@
import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
import de.ids_mannheim.korap.security.context.TokenContext;
import de.ids_mannheim.korap.service.SearchService;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.utils.ServiceInfo;
import de.ids_mannheim.korap.web.KustvaktResponseHandler;
import de.ids_mannheim.korap.web.filter.APIVersionFilter;
import de.ids_mannheim.korap.web.filter.AuthenticationFilter;
@@ -77,6 +81,24 @@
.build();
}
+ @GET
+ @Path("{version}/info")
+ @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
+ public Response info (){
+ Map<String, Object> m = new HashMap<>();
+ m.put("latest_api_version", config.getCurrentVersion());
+ m.put("supported_api_versions", config.getSupportedVersions());
+ m.put("kustvakt_version", ServiceInfo.getInfo().getVersion());
+ m.put("krill_version", ServiceInfo.getInfo().getKrillVersion());
+ m.put("koral_version", ServiceInfo.getInfo().getKoralVersion());
+ try {
+ return Response.ok(JsonUtils.toJSON(m)).build();
+ }
+ catch (KustvaktException e) {
+ throw kustvaktResponseHandler.throwit(e);
+ }
+ }
+
@POST
@Path("{version}/index/close")
public Response closeIndexReader (@FormParam("token") String token){
diff --git a/core/src/main/resources/service.properties b/core/src/main/resources/service.properties
new file mode 100644
index 0000000..cf2899d
--- /dev/null
+++ b/core/src/main/resources/service.properties
@@ -0,0 +1,3 @@
+kustvakt.version=${project.version}
+krill.version=${krill.version}
+koral.version=${koral.version}
\ No newline at end of file
diff --git a/full/Changes b/full/Changes
index beb2de3..04fa3cc 100644
--- a/full/Changes
+++ b/full/Changes
@@ -26,6 +26,8 @@
- Added query and query language in virtual corpus table (margaretha)
18/02/2021
- Set corpus access public for stored query (margaretha)
+19/02/2021
+ - Enabled API info web-service (margaretha)
# version 0.62.4
diff --git a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
index 8d17105..3204656 100644
--- a/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/service/VirtualCorpusService.java
@@ -348,7 +348,7 @@
String koralQuery, String definition, String description,
String status, boolean isCached, String username, String query,
String queryLanguage) throws KustvaktException {
- ParameterChecker.checkNameValue(queryName, "name");
+ ParameterChecker.checkNameValue(queryName, "queryName");
ParameterChecker.checkObjectValue(type, "type");
if (!queryNamePattern.matcher(queryName).matches()) {
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/KustvaktController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/KustvaktController.java
deleted file mode 100644
index 230afe1..0000000
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/KustvaktController.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package de.ids_mannheim.korap.web.controller;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-
-import de.ids_mannheim.korap.config.KustvaktConfiguration;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.utils.JsonUtils;
-import de.ids_mannheim.korap.utils.ServiceInfo;
-import de.ids_mannheim.korap.web.CoreResponseHandler;
-
-/**
- * Created by hanl on 29.04.16.
- */
-@Controller
-@Path("kustvakt")
-@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
-public class KustvaktController {
-
- @Autowired
- private CoreResponseHandler kustvaktResponseHandler;
-
- @Autowired
- private KustvaktConfiguration config;
-
- @GET
- @Path("info")
- public Response getInfo () {
-
- Map m = new HashMap();
- m.put("version", ServiceInfo.getInfo().getVersion());
- m.put("supported_api_version(s)", config.getSupportedVersions());
- m.put("service_name", ServiceInfo.getInfo().getName());
- try {
- return Response.ok(JsonUtils.toJSON(m)).build();
- }
- catch (KustvaktException e) {
- throw kustvaktResponseHandler.throwit(e);
- }
- }
-
-}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
new file mode 100644
index 0000000..783e417
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/InfoControllerTest.java
@@ -0,0 +1,44 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.ClientResponse.Status;
+
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.utils.ServiceInfo;
+
+public class InfoControllerTest extends SpringJerseyTest {
+
+ @Autowired
+ private KustvaktConfiguration config;
+
+ @Test
+ public void testInfo () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("info")
+ .get(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ String entity = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(config.getCurrentVersion(),
+ node.at("/latest_api_version").asText());
+ assertEquals(config.getSupportedVersions().size(),
+ node.at("/supported_api_versions").size());
+
+ assertEquals(ServiceInfo.getInfo().getVersion(),
+ node.at("/kustvakt_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKrillVersion(),
+ node.at("/krill_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKoralVersion(),
+ node.at("/koral_version").asText());
+ }
+}
diff --git a/lite/Changes b/lite/Changes
index be5532b..291e7fe 100644
--- a/lite/Changes
+++ b/lite/Changes
@@ -5,6 +5,8 @@
- Updated Flyway (margaretha)
21/01/2021
- Fixed running pipe and updated tests with mockserver (margaretha)
+19/02/2021
+ - Enabled API info web-service (margaretha)
# version 0.62.4
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java
new file mode 100644
index 0000000..53a76b4
--- /dev/null
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/InfoControllerTest.java
@@ -0,0 +1,44 @@
+package de.ids_mannheim.korap.web.service;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.ClientResponse.Status;
+
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
+import de.ids_mannheim.korap.config.LiteJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+import de.ids_mannheim.korap.utils.ServiceInfo;
+
+public class InfoControllerTest extends LiteJerseyTest {
+
+ @Autowired
+ private KustvaktConfiguration config;
+
+ @Test
+ public void testInfo () throws KustvaktException {
+ ClientResponse response = resource().path(API_VERSION).path("info")
+ .get(ClientResponse.class);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ String entity = response.getEntity(String.class);
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(config.getCurrentVersion(),
+ node.at("/latest_api_version").asText());
+ assertEquals(config.getSupportedVersions().size(),
+ node.at("/supported_api_versions").size());
+
+ assertEquals(ServiceInfo.getInfo().getVersion(),
+ node.at("/kustvakt_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKrillVersion(),
+ node.at("/krill_version").asText());
+ assertEquals(ServiceInfo.getInfo().getKoralVersion(),
+ node.at("/koral_version").asText());
+ }
+}