Updated the response statuses of VC PUT requests.
Change-Id: Idf44bd941461c959e1076ef8272ae8e544d6642f
diff --git a/full/Changes b/full/Changes
index a7ff8d3..a2215a1 100644
--- a/full/Changes
+++ b/full/Changes
@@ -8,7 +8,9 @@
(margaretha)
- Fixed post requests with status OK and empty body (margaretha)
07/08/2019
- - Resolved #40 (margaretha)
+ - Resolved #40 (margaretha)
+15/08/2019
+ - Updated the response statuses of VC PUT requests (margaretha)
# version 0.62
28/02/2019
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 c4a7e35..48d2a62 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
@@ -7,6 +7,8 @@
import java.util.List;
import java.util.regex.Pattern;
+import javax.ws.rs.core.Response.Status;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -233,7 +235,7 @@
// editVC(vc, vcJson, vcJson.getName(), username);
// }
- public void handlePutRequest (String username, String vcCreator,
+ public Status handlePutRequest (String username, String vcCreator,
String vcName, VirtualCorpusJson vcJson) throws KustvaktException {
verifyUsername(username, vcCreator);
@@ -241,9 +243,11 @@
ParameterChecker.checkObjectValue(vcJson, "request entity");
if (vc == null) {
storeVC(vcJson, vcName, username);
+ return Status.CREATED;
}
else {
editVC(vc, vcJson, vcName, username);
+ return Status.NO_CONTENT;
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
index 3a55bc6..6c37850 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusController.java
@@ -14,6 +14,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.SecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
@@ -98,12 +99,14 @@
try {
scopeService.verifyScope(context, OAuth2Scope.EDIT_VC);
- service.handlePutRequest(context.getUsername(),vcCreator, vcName, vc);
+ Status status = service.handlePutRequest(context.getUsername(),
+ vcCreator, vcName, vc);
+ return Response.status(status).build();
}
catch (KustvaktException e) {
throw kustvaktResponseHandler.throwit(e);
}
- return Response.ok().build();
+
}
/**
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
index 33d2c26..cb868d3 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerAdminTest.java
@@ -113,7 +113,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).put(ClientResponse.class);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
JsonNode node = testListSystemVC();
assertEquals(1, node.size());
@@ -152,7 +152,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
JsonNode node = testListUserVC(username);
assertEquals(1, node.size());
@@ -192,7 +192,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
JsonNode node = testListUserVC(username);
assertEquals("edited vc", node.at("/0/description").asText());
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
index 9da6393..63ba359 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusControllerTest.java
@@ -306,7 +306,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// list user VC
JsonNode node = testListVC("VirtualCorpusControllerTest");
@@ -338,7 +338,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
// test list owner vc
JsonNode node = testListOwnerVC("VirtualCorpusControllerTest");
@@ -651,7 +651,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
// check VC
JsonNode node = testListVC("dory");
@@ -668,7 +668,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
// check VC
node = testListVC("dory");
@@ -688,7 +688,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
// check VC
JsonNode node = testListVC("dory");
@@ -743,7 +743,7 @@
.header(HttpHeaders.X_FORWARDED_FOR, "149.27.0.32")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
// check VC
node = testListOwnerVC("dory");
@@ -770,7 +770,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
node = testListOwnerVC("dory");
assertEquals(VirtualCorpusType.PROJECT.displayName(),
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
index 0ce1834..7246375 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/VirtualCorpusTestBase.java
@@ -49,7 +49,7 @@
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.put(ClientResponse.class, json);
- assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
JsonNode node = testSearchVC(username, vcCreator, vcName);
assertEquals(type.displayName(), node.at("/type").asText());