Updated handling errors from Koral and fixed tests.
Change-Id: I7ff3caa35d247b4707c11315cf2e653eed9a689b
diff --git a/core/Changes b/core/Changes
index 378a85e..9b7e5b6 100644
--- a/core/Changes
+++ b/core/Changes
@@ -1,8 +1,10 @@
# version 0.61.6
-06/02/2018
+06/02/2019
- Added default foundry for structure layer (margaretha)
- Added authentication to metadata controller (margaretha, issue #38)
- Updated search krill error handling (margaretha)
+18/02/2019
+ - Updated handling errors from Koral (margaretha)
# version 0.61.5
17/12/2018
diff --git a/core/pom.xml b/core/pom.xml
index 109ef97..e4e6694 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -227,7 +227,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Koral</artifactId>
- <version>[0.31,)</version>
+ <version>[0.33,)</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
diff --git a/core/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java b/core/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
index aebfbf6..a6260cb 100644
--- a/core/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
+++ b/core/src/main/java/de/ids_mannheim/korap/utils/KoralCollectionQueryBuilder.java
@@ -1,8 +1,8 @@
package de.ids_mannheim.korap.utils;
+import java.util.HashMap;
import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
+import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -12,7 +12,6 @@
import de.ids_mannheim.korap.exceptions.StatusCodes;
import de.ids_mannheim.korap.query.serialize.CollectionQueryProcessor;
import de.ids_mannheim.korap.response.Notifications;
-import de.ids_mannheim.korap.web.CoreResponseHandler;
import edu.emory.mathcs.backport.java.util.Arrays;
/**
@@ -31,9 +30,6 @@
private JsonNode base;
private StringBuilder builder;
private String mergeOperator;
- @Autowired
- private CoreResponseHandler responseHandler;
-
public KoralCollectionQueryBuilder () {
this(false);
@@ -113,21 +109,27 @@
new CollectionQueryProcessor(this.verbose);
tree.process(this.builder.toString());
if (tree.getErrors().size() > 0) {
- Notifications notif = new Notifications();
- int code;
+ // legacy support
for (List<Object> e : tree.getErrors()) {
- code = (int) e.get(0);
- if (e.get(1) instanceof String) {
- notif.addError(code, (String) e.get(1));
- }
- else {
+ if (e.get(1) instanceof String[]) {
+ Notifications notif = new Notifications();
+ int code = (int) e.get(0);
notif.addError(code, (String[]) e.get(1));
+ String notificationStr = notif.toJsonString();
+ throw new KustvaktException(StatusCodes.SERIALIZATION_FAILED,
+ notificationStr, true);
+ }
+ else{
+ break;
}
}
-
- String notificationStr = notif.toJsonString();
+ // -- end of legacy support
+
+ Map<String, Object> map = new HashMap<>();
+ map.put("errors", tree.getErrors());
+ String errors = JsonUtils.toJSON(map);
throw new KustvaktException(StatusCodes.SERIALIZATION_FAILED,
- notificationStr, true);
+ errors, true);
}
request = JsonUtils.valueToTree(tree.getRequestMap());
}
diff --git a/full/Changes b/full/Changes
index 198aa7f..a1fd961 100644
--- a/full/Changes
+++ b/full/Changes
@@ -8,6 +8,9 @@
06/02/2019
- Updated a user setting test using array for multiple values (margaretha)
- Added metadata controller tests (margaretha)
+18/02/2019
+ - Fixed tests (margaretha)
+ - Updated handling errors from Koral (margaretha)
# version 0.61.5
17/12/2018
diff --git a/full/pom.xml b/full/pom.xml
index 325dbfe..5a13cc5 100644
--- a/full/pom.xml
+++ b/full/pom.xml
@@ -206,7 +206,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>[0.61.4,)</version>
+ <version>[0.61.6,)</version>
</dependency>
<!-- LDAP -->
<dependency>
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
index fb083bd..71a3fff 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/MetadataControllerTest.java
@@ -88,20 +88,20 @@
public void testMetadataAvailabilityAllUnauthorized ()
throws KustvaktException {
ClientResponse response = resource().path(API_VERSION).path("corpus")
- .path("GOE").path("AGI").path("00000")
+ .path("GOE").path("AGD").path("00000")
.header(Attributes.AUTHORIZATION,
HttpAuthorizationHandler
.createBasicAuthorizationHeaderValue("kustvakt",
"kustvakt2015"))
.header(HttpHeaders.X_FORWARDED_FOR, "170.27.0.32")
.get(ClientResponse.class);
-
+
JsonNode node = JsonUtils.readTree(response.getEntity(String.class));
assertEquals(StatusCodes.AUTHORIZATION_FAILED,
node.at("/errors/0/0").asInt());
assertEquals(
"Retrieving resource with ID "
- + "GOE/AGI/00000 is not allowed.",
+ + "GOE/AGD/00000 is not allowed.",
node.at("/errors/0/1").asText());
}
}
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
index 4ecbe72..be6c1d6 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/StatisticsControllerTest.java
@@ -104,9 +104,10 @@
.queryParam("corpusQuery", "creationDate >= 1810")
.get(ClientResponse.class);
+ String ent = response.getEntity(String.class);
assertEquals(ClientResponse.Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
- String ent = response.getEntity(String.class);
+
JsonNode node = mapper.readTree(ent);
assertEquals(node.at("/errors/0/0").asInt(), 305);
assertEquals(node.at("/errors/0/1").asText(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
index c04aee1..ba26d0c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/UserSettingControllerTest.java
@@ -59,13 +59,13 @@
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
int numOfResult = 25;
- String metadata = "[\"author\",\"title\",\"textSigle\","
- + "\"availability\"]";
+ String metadata =
+ "[\"author\",\"title\",\"textSigle\"," + "\"availability\"]";
- testRetrieveSettings(username, "opennlp", numOfResult, metadata);
+ testRetrieveSettings(username, "opennlp", numOfResult, metadata, true);
testDeleteKeyNotExist(username);
- testDeleteKey(username, numOfResult, metadata);
+ testDeleteKey(username, numOfResult, metadata, true);
testDeleteSetting(username);
}
@@ -81,7 +81,7 @@
assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
testRetrieveSettings(username2, "opennlp", 25,
- "author title textSigle availability");
+ "author title textSigle availability", false);
testUpdateSetting(username2);
testputRequestInvalidKey();
@@ -146,17 +146,18 @@
.get(ClientResponse.class);
assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
-
+
String entity = response.getEntity(String.class);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(StatusCodes.NO_RESOURCE_FOUND,
node.at("/errors/0/0").asInt());
- assertEquals("No default setting for username: " + username +" is found",
+ assertEquals(
+ "No default setting for username: " + username + " is found",
node.at("/errors/0/1").asText());
assertEquals(username, node.at("/errors/0/2").asText());
}
-
+
@Test
public void testDeleteSettingNotExist () throws KustvaktException {
String username = "tralala";
@@ -207,10 +208,12 @@
node.at("/errors/0/0").asInt());
assertEquals(username, node.at("/errors/0/2").asText());
}
-
- // EM: deleting a non-existing key does not throw an error, because
+
+ // EM: deleting a non-existing key does not throw an error,
+ // because
// the purpose of the request has been achieved.
- private void testDeleteKeyNotExist (String username) throws KustvaktException {
+ private void testDeleteKeyNotExist (String username)
+ throws KustvaktException {
ClientResponse response = resource().path(API_VERSION)
.path("~" + username).path("setting").path("lemma-foundry")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -221,7 +224,7 @@
}
private void testDeleteKey (String username, int numOfResult,
- String metadata) throws KustvaktException {
+ String metadata, boolean isMetadataArray) throws KustvaktException {
ClientResponse response = resource().path(API_VERSION)
.path("~" + username).path("setting").path("pos-foundry")
@@ -230,7 +233,8 @@
.delete(ClientResponse.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- testRetrieveSettings(username, null, numOfResult, metadata);
+ testRetrieveSettings(username, null, numOfResult, metadata,
+ isMetadataArray);
}
private void testUpdateSetting (String username) throws KustvaktException {
@@ -242,11 +246,12 @@
ClientResponse response = sendPutRequest(username, map);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- testRetrieveSettings(username, "malt", 15, "author title");
+ testRetrieveSettings(username, "malt", 15, "author title", false);
}
private void testRetrieveSettings (String username, String posFoundry,
- int numOfResult, String metadata) throws KustvaktException {
+ int numOfResult, String metadata, boolean isMetadataArray)
+ throws KustvaktException {
ClientResponse response = resource().path(API_VERSION)
.path("~" + username).path("setting")
.header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
@@ -255,7 +260,7 @@
.get(ClientResponse.class);
String entity = response.getEntity(String.class);
- System.out.println(entity);
+
JsonNode node = JsonUtils.readTree(entity);
if (posFoundry == null) {
assertTrue(node.at("/pos-foundry").isMissingNode());
@@ -264,7 +269,13 @@
assertEquals(posFoundry, node.at("/pos-foundry").asText());
}
assertEquals(numOfResult, node.at("/resultPerPage").asInt());
- assertEquals(metadata, node.at("/metadata").toString());
+
+ if (isMetadataArray) {
+ assertEquals(metadata, node.at("/metadata").toString());
+ }
+ else {
+ assertEquals(metadata, node.at("/metadata").asText());
+ }
}
}
diff --git a/lite/Changes b/lite/Changes
index 3c045ae..aa4374e 100644
--- a/lite/Changes
+++ b/lite/Changes
@@ -1,6 +1,8 @@
version 0.61.3
05/02/2019
- - Updated kustvakt-lite.conf
+ - Updated kustvakt-lite.conf (margaretha)
+18/02/2019
+ - Updated core version (margaretha)
version 0.61.2
14/11/2018
diff --git a/lite/pom.xml b/lite/pom.xml
index cacf4a6..0753db9 100644
--- a/lite/pom.xml
+++ b/lite/pom.xml
@@ -137,7 +137,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Kustvakt-core</artifactId>
- <version>[0.61.3,)</version>
+ <version>[0.61.6,)</version>
</dependency>
<!-- Jersey test framework -->
<dependency>