Included KoralQuery in VC lists & improved KoralQueries in DB test data.
Change-Id: I85062ff8ee022ec6a3455bc45583687a185b24a1
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
index f75d5d6..f69f19d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/VirtualCorpusDto.java
@@ -12,8 +12,8 @@
private String type;
private String status;
private String description;
- private String access;
+ private String requiredAccess;
private String createdBy;
private int numberOfDoc;
-}
+ private String koralQuery;}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
index 8aa7a6e..e05f203 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/VirtualCorpusConverter.java
@@ -19,10 +19,11 @@
dto.setId(vc.getId());
dto.setName(vc.getName());
dto.setCreatedBy(vc.getCreatedBy());
- dto.setAccess(vc.getRequiredAccess().name());
+ dto.setRequiredAccess(vc.getRequiredAccess().name());
dto.setStatus(vc.getStatus());
dto.setDescription(vc.getDescription());
dto.setType(vc.getType().displayName());
+ dto.setKoralQuery(vc.getCollectionQuery());
JsonNode node = JsonUtils.readTree(statistics);
int numberOfDoc = node.at("/documents").asInt();
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 03c7091..921ee60 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
@@ -26,6 +26,7 @@
import de.ids_mannheim.korap.user.User.CorpusAccess;
import de.ids_mannheim.korap.utils.JsonUtils;
import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder;
+import de.ids_mannheim.korap.utils.ParameterChecker;
import de.ids_mannheim.korap.web.SearchKrill;
import de.ids_mannheim.korap.web.controller.VirtualCorpusController;
import de.ids_mannheim.korap.web.input.VirtualCorpusJson;
@@ -54,11 +55,14 @@
@Autowired
private VirtualCorpusConverter converter;
- public void storeVC (VirtualCorpusJson vc, String username)
+ public void createVC (VirtualCorpusJson vc, String username)
throws KustvaktException {
-
+
+ ParameterChecker.checkObjectValue(vc.getType(), "type");
+
User user = authManager.getUser(username);
// EM: how about VirtualCorpusType.PUBLISHED?
+
if (vc.getType().equals(VirtualCorpusType.PREDEFINED)
&& !user.isAdmin()) {
throw new KustvaktException(StatusCodes.AUTHORIZATION_FAILED,
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 cfef7fb..8cab1af 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
@@ -56,9 +56,9 @@
private VirtualCorpusService service;
@POST
- @Path("store")
+ @Path("create")
@Consumes("application/json")
- public Response storeVC (@Context SecurityContext securityContext,
+ public Response createVC (@Context SecurityContext securityContext,
VirtualCorpusJson vc) {
try {
jlog.debug(vc.toString());
@@ -67,7 +67,7 @@
TokenContext context =
(TokenContext) securityContext.getUserPrincipal();
- service.storeVC(vc, context.getUsername());
+ service.createVC(vc, context.getUsername());
}
catch (KustvaktException e) {
throw responseHandler.throwit(e);
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java b/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
index 58379e9..76a55ac 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/input/VirtualCorpusJson.java
@@ -1,15 +1,26 @@
package de.ids_mannheim.korap.web.input;
+
import de.ids_mannheim.korap.constant.VirtualCorpusType;
import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.service.VirtualCorpusService;
import de.ids_mannheim.korap.utils.ParameterChecker;
+import de.ids_mannheim.korap.web.controller.VirtualCorpusController;
import lombok.Getter;
import lombok.Setter;
+/** Java POJO of JSON input of the virtual corpus service for
+ * creating virtual corpora.
+ *
+ * @author margaretha
+ * @see VirtualCorpusController#createVC(javax.ws.rs.core.SecurityContext, VirtualCorpusJson)
+ * @see VirtualCorpusService#createVC(VirtualCorpusJson, String)
+ */
@Getter
@Setter
public class VirtualCorpusJson {
+ // required
private String name;
private VirtualCorpusType type;
private String createdBy;
@@ -20,6 +31,11 @@
private String description;
private String status;
+ public void setType (VirtualCorpusType type) throws KustvaktException {
+ ParameterChecker.checkObjectValue(type, "VirtualCorpusType");
+ this.type = type;
+ }
+
public void setName (String name) throws KustvaktException {
ParameterChecker.checkStringValue(name, "name");
this.name = name;
diff --git a/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql b/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
index bad2b01..70becc8 100644
--- a/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
+++ b/full/src/main/resources/db/insert/V3.1__insert_virtual_corpus.sql
@@ -45,11 +45,11 @@
-- virtual corpora
INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, collection_query)
VALUES ("dory VC", "PRIVATE", "FREE", "dory", "test vc", "experimental",
- '{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
+ '{"collection": { "@type": "koral:docGroup", "operands": [ { "@type": "koral:doc", "key": "corpusSigle", "match": "match:eq", "value": "GOE" }, { "@type": "koral:doc", "key": "creationDate", "match": "match:geq", "type": "type:date", "value": "1820" } ], "operation": "operation:and" }}');
INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, collection_query)
VALUES ("group VC", "PROJECT", "PUB", "dory", "test vc", "experimental",
- '{"collection":{"@type":"koral:doc","value":"GOE","match":"match:eq","key":"corpusSigle"}}');
+ '{"collection": { "@type": "koral:docGroup", "operands": [ { "@type": "koral:doc", "key": "corpusSigle", "match": "match:eq", "value": "GOE" }, { "@type": "koral:doc", "key": "creationDate", "match": "match:leq", "type": "type:date", "value": "1810" } ], "operation": "operation:and" }}');
INSERT INTO virtual_corpus(name, type, required_access, created_by, description, status, collection_query)
VALUES ("system VC", "PREDEFINED", "ALL", "system", "test vc", "experimental",
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
index e467180..3b3bc6e 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/service/full/VirtualCorpusServiceTest.java
@@ -66,7 +66,7 @@
.get(ClientResponse.class);
String entity = response.getEntity(String.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
- // System.out.println(entity);
+ System.out.println(entity);
JsonNode node = JsonUtils.readTree(entity);
assertEquals(3, node.size());
}
@@ -92,12 +92,12 @@
}
@Test
- public void testStoreDeleteVC () throws KustvaktException {
+ public void testCreateDeleteVC () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
+ "\"test class\",\"collectionQuery\": \"corpusSigle=GOE\"}";
- ClientResponse response = resource().path("vc").path("store")
+ ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
handler.createBasicAuthorizationHeaderValue(
"test class", "pass"))
@@ -152,7 +152,7 @@
}
@Test
- public void testStoreVCWithExpiredToken ()
+ public void testCreateVCWithExpiredToken ()
throws IOException, KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
@@ -164,7 +164,7 @@
String authToken = reader.readLine();
- ClientResponse response = resource().path("vc").path("store")
+ ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
AuthenticationScheme.API.displayName() + " "
+ authToken)
@@ -184,12 +184,12 @@
}
@Test
- public void testStoreVCUnauthorized () throws KustvaktException {
+ public void testCreateVCUnauthorized () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVATE\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"pubDate eq 1982\"}";
+ + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path("vc").path("store")
+ ClientResponse response = resource().path("vc").path("create")
.header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
.entity(json).post(ClientResponse.class);
@@ -206,12 +206,35 @@
}
@Test
- public void testStoreVCWithWrongType () throws KustvaktException {
+ public void testCreateVCWithoutType () throws KustvaktException {
+ String json =
+ "{\"name\": \"new vc\",\"createdBy\": "
+ + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
+
+ ClientResponse response = resource().path("vc").path("create")
+ .header(Attributes.AUTHORIZATION,
+ handler.createBasicAuthorizationHeaderValue(
+ "test class", "pass"))
+ .header(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON)
+ .entity(json).post(ClientResponse.class);
+ String entity = response.getEntity(String.class);
+// System.out.println(entity);
+ assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
+
+ JsonNode node = JsonUtils.readTree(entity);
+ assertEquals(StatusCodes.INVALID_ARGUMENT,
+ node.at("/errors/0/0").asInt());
+ assertEquals("type",node.at("/errors/0/1").asText());
+ assertEquals("null",node.at("/errors/0/2").asText());
+ }
+
+ @Test
+ public void testCreateVCWithWrongType () throws KustvaktException {
String json =
"{\"name\": \"new vc\",\"type\": \"PRIVAT\",\"createdBy\": "
- + "\"test class\",\"collectionQuery\": \"pubDate eq 1982\"}";
+ + "\"test class\",\"collectionQuery\": \"creationDate since 1820\"}";
- ClientResponse response = resource().path("vc").path("store")
+ ClientResponse response = resource().path("vc").path("create")
.header(Attributes.AUTHORIZATION,
handler.createBasicAuthorizationHeaderValue(
"test class", "pass"))