Make API welcome message configurable
This allows flexible, informal messages and, if necessary, terms of
service to be displayed. For RKorAPClient this is nice because the
welcome message will be displayed on connect.
Change-Id: I9d3c6cef7b1f0205a23fe847909bca0de982bc0f
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 f66f196..36d04e0 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
@@ -79,6 +79,7 @@
private String default_orthography;
private String default_dep;
private String default_const;
+ private String apiWelcomeMessage;
private String defaultStructureFoundry;
private ArrayList<String> foundries;
private ArrayList<String> layers;
@@ -135,7 +136,8 @@
*/
protected void load (Properties properties) throws Exception {
loadBasicProperties(properties);
-
+
+ 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", "");
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 5bbcfeb..3329a4f 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
@@ -28,6 +28,7 @@
import com.sun.jersey.spi.container.ResourceFilters;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.constant.OAuth2Scope;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.oauth2.service.OAuth2ScopeService;
@@ -64,12 +65,13 @@
private SearchService searchService;
@Autowired
private OAuth2ScopeService scopeService;
-
+ @Autowired
+ private KustvaktConfiguration config;
@GET
@Path("{version}")
public Response index (){
- return Response.ok("Welcome to KorAP API!").build();
+ return Response.ok(config.getApiWelcomeMessage()).build();
}
@POST
diff --git a/full/src/main/resources/kustvakt.conf b/full/src/main/resources/kustvakt.conf
index 62546c6..a9086ba 100644
--- a/full/src/main/resources/kustvakt.conf
+++ b/full/src/main/resources/kustvakt.conf
@@ -12,6 +12,7 @@
ldap.config = file-path-to-ldap-config
# Kustvakt
+api.welcome.message = Welcome to KorAP API!
current.api.version = v1.0
# multiple versions separated by space
# supported.api.version = v1.0
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
index 18e2c35..a97ab50 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/SearchControllerTest.java
@@ -8,6 +8,7 @@
import javax.ws.rs.core.MediaType;
+import de.ids_mannheim.korap.config.KustvaktConfiguration;
import org.junit.Ignore;
import org.junit.Test;
@@ -22,6 +23,7 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
import de.ids_mannheim.korap.utils.JsonUtils;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* @author hanl, margaretha
@@ -30,6 +32,9 @@
*/
public class SearchControllerTest extends SpringJerseyTest {
+ @Autowired
+ private KustvaktConfiguration config;
+
private JsonNode requestSearchWithFields(String fields) throws KustvaktException{
ClientResponse response = resource().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")
@@ -50,7 +55,17 @@
s.setQuery("Wasser", "poliqarp");
return s.toJSON();
}
-
+
+ @Test
+ public void testApiWelcomeMessage () {
+ ClientResponse response = resource().path(API_VERSION).path("")
+ .get(ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String message = response.getEntity(String.class);
+ assertEquals(message, config.getApiWelcomeMessage());
+ }
+
@Test
public void testSearchWithField () throws KustvaktException {
JsonNode node = requestSearchWithFields("author");
diff --git a/lite/src/main/resources/kustvakt-lite.conf b/lite/src/main/resources/kustvakt-lite.conf
index e78f993..9dc83b5 100644
--- a/lite/src/main/resources/kustvakt-lite.conf
+++ b/lite/src/main/resources/kustvakt-lite.conf
@@ -13,6 +13,7 @@
# Kustvakt settings
+api.welcome.message = Welcome to KorAP API!
current.api.version = v1.0
# multiple versions separated by space
supported.api.version = v1.0
diff --git a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
index 6463ce9..54367ab 100644
--- a/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
+++ b/lite/src/test/java/de/ids_mannheim/korap/web/service/LiteSearchControllerTest.java
@@ -25,6 +25,7 @@
import de.ids_mannheim.korap.authentication.http.HttpAuthorizationHandler;
import de.ids_mannheim.korap.config.Attributes;
+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.exceptions.StatusCodes;
@@ -36,7 +37,9 @@
@Autowired
private SearchKrill searchKrill;
-
+ @Autowired
+ private KustvaktConfiguration config;
+
// EM: The API is disabled
@Ignore
@Test
@@ -82,6 +85,16 @@
}
@Test
+ public void testApiWelcomeMessage () {
+ ClientResponse response = resource().path(API_VERSION).path("")
+ .get(ClientResponse.class);
+ assertEquals(ClientResponse.Status.OK.getStatusCode(),
+ response.getStatus());
+ String message = response.getEntity(String.class);
+ assertEquals(message, config.getApiWelcomeMessage());
+ }
+
+ @Test
public void testQueryGet () throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("search")
.queryParam("q", "[orth=das]").queryParam("ql", "poliqarp")