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