Added delete setting controller & handled no resource found (issue #37)
Change-Id: Ib24692a204b6ef1f329522aac2b8c4abc823014e
diff --git a/core/Changes b/core/Changes
index 4aaa3b2..edb5954 100644
--- a/core/Changes
+++ b/core/Changes
@@ -20,6 +20,8 @@
- Added default setting key validation & fixed UserdataTest (margaretha)
28/01/2019
- Updated Rewrite handler (margaretha)
+29/01/2019
+ - Handled "no resource found" cases (margaretha, issue #37)
version 0.61.4
14/11/2018
diff --git a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
index ec2a148..72b8cfc 100644
--- a/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
+++ b/core/src/main/java/de/ids_mannheim/korap/exceptions/StatusCodes.java
@@ -27,6 +27,7 @@
public static final int INVALID_ALGORITHM = 111;
public static final int UNSUPPORTED_API_VERSION = 112;
public static final int NON_UNIQUE_RESULT_FOUND = 113;
+ public static final int NO_RESOURCE_FOUND = 114;
/**
* 200 status codes general JSON serialization error
diff --git a/core/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java b/core/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
index 94c2498..50aa378 100644
--- a/core/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
+++ b/core/src/main/java/de/ids_mannheim/korap/service/AnnotationService.java
@@ -89,7 +89,7 @@
}
else {
throw new KustvaktException(StatusCodes.NO_RESULT_FOUND,
- "No result found.", "");
+ "No result found", "");
}
}
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
index 2a398e7..23ff8e6 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/CoreResponseHandler.java
@@ -94,6 +94,10 @@
case StatusCodes.STATUS_OK:
status = Response.Status.OK;
break;
+ // EM: Added
+ case StatusCodes.NO_RESOURCE_FOUND:
+ status = Response.Status.NOT_FOUND;
+ break;
}
return status;
}
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java b/core/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
index 63e19de..fd6fd1a 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/controller/AnnotationController.java
@@ -109,15 +109,10 @@
throw kustvaktResponseHandler.throwit(new KustvaktException(
StatusCodes.INVALID_ARGUMENT, "Bad argument:", json));
}
- if (codes == null) {
+ if (codes == null || codes.isEmpty()) {
throw kustvaktResponseHandler.throwit(
new KustvaktException(StatusCodes.MISSING_ATTRIBUTE,
- "Missing attribute:", "codes"));
- }
- else if (codes.isEmpty()) {
- throw kustvaktResponseHandler
- .throwit(new KustvaktException(StatusCodes.NO_RESULT_FOUND,
- "No result found.", "codes:[]"));
+ "codes is null or empty", "codes"));
}
try {
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java b/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
index ff21813..7082fb8 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/controller/StatisticController.java
@@ -37,11 +37,10 @@
*/
@Controller
@Path("{version}/statistics/")
-@ResourceFilters({APIVersionFilter.class, PiwikFilter.class })
+@ResourceFilters({ APIVersionFilter.class, PiwikFilter.class })
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public class StatisticController {
-
private static final boolean DEBUG = false;
private static Logger jlog =
LogManager.getLogger(StatisticController.class);
@@ -50,7 +49,6 @@
@Autowired
private SearchKrill searchKrill;
-
/**
* Returns statistics of the virtual corpus defined by the given
* corpusQuery parameter.
@@ -71,26 +69,26 @@
KoralCollectionQueryBuilder builder = new KoralCollectionQueryBuilder();
- String stats;
- if (corpusQuery != null && !corpusQuery.isEmpty()) {
- builder.with(corpusQuery);
- String json = null;
- try {
- json = builder.toJSON();
- }
- catch (KustvaktException e) {
- throw kustvaktResponseHandler.throwit(e);
- }
- stats = searchKrill.getStatistics(json);
- }
- else {
- stats = searchKrill.getStatistics(null);
- };
+ String stats;
+ if (corpusQuery != null && !corpusQuery.isEmpty()) {
+ builder.with(corpusQuery);
+ String json = null;
+ try {
+ json = builder.toJSON();
+ }
+ catch (KustvaktException e) {
+ throw kustvaktResponseHandler.throwit(e);
+ }
+ stats = searchKrill.getStatistics(json);
+ }
+ else {
+ stats = searchKrill.getStatistics(null);
+ };
- if (stats.contains("-1")){
+ if (stats.contains("-1")) {
throw kustvaktResponseHandler.throwit(StatusCodes.NO_RESULT_FOUND);
}
- if (DEBUG){
+ if (DEBUG) {
jlog.debug("Stats: " + stats);
}
return Response.ok(stats).build();