Added an admin service to load and cache system vc (solved #268)
Change-Id: I67e4ba5d5972d6a099203e6f5e6a123090c61c93
diff --git a/full/Changes b/full/Changes
index ea0bc02..7948154 100644
--- a/full/Changes
+++ b/full/Changes
@@ -1,6 +1,7 @@
# version 0.69.3
- Moved the service path of VC admin services to admin/vc (closed #543)
+- Added an admin service to load and cache system vc (solved #268)
# version 0.69.2
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAdminController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAdminController.java
index 14de314..9a79535 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAdminController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/VirtualCorpusAdminController.java
@@ -8,10 +8,13 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import de.ids_mannheim.korap.config.NamedVCLoader;
import de.ids_mannheim.korap.constant.QueryType;
import de.ids_mannheim.korap.constant.ResourceType;
import de.ids_mannheim.korap.dto.QueryDto;
@@ -33,6 +36,19 @@
@Autowired
private QueryService service;
+ @Autowired
+ private NamedVCLoader vcLoader;
+
+ @POST
+ @Path("load-cache")
+ public Response loadAndCacheSystemVC () {
+ Thread t = new Thread(vcLoader);
+ t.start();
+
+ return Response.status(Status.OK).build();
+ }
+
+
/**
* Lists virtual corpora by creator and type. This is a controller
* for system admin requiring valid system admin authentication.
diff --git a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
index 1816a19..9c55449 100644
--- a/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/cache/NamedVCLoaderTest.java
@@ -1,5 +1,6 @@
package de.ids_mannheim.korap.cache;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -8,9 +9,17 @@
import java.io.IOException;
import java.util.Map;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Form;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import com.google.common.net.HttpHeaders;
+
import de.ids_mannheim.korap.collection.DocBits;
import de.ids_mannheim.korap.config.NamedVCLoader;
import de.ids_mannheim.korap.config.SpringJerseyTest;
@@ -45,4 +54,24 @@
vc = dao.retrieveQueryByName(vcId, "system");
assertNull(vc);
}
+
+ @Test
+ public void testLoadCacheVC () throws KustvaktException, InterruptedException {
+ assertFalse(VirtualCorpusCache.contains("named-vc1"));
+ Form f = new Form();
+ f.param("token", "secret");
+
+ Response response = target().path(API_VERSION).path("admin").path("vc")
+ .path("load-cache").request()
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
+ .post(Entity.form(f));
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ Thread.sleep(100);
+ assertTrue(VirtualCorpusCache.contains("named-vc1"));
+
+ VirtualCorpusCache.reset();
+ assertFalse(VirtualCorpusCache.contains("named-vc1"));
+ }
}
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 7038d4c..21be515 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
@@ -31,7 +31,6 @@
private String admin = "admin";
private String testUser = "VirtualCorpusControllerAdminTest";
-
private void testResponseUnauthorized (Response response) throws KustvaktException {
assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
@@ -159,8 +158,6 @@
Response response = target().path(API_VERSION).path("admin").path("vc")
.path("list").request()
- .header(Attributes.AUTHORIZATION, HttpAuthorizationHandler
- .createBasicAuthorizationHeaderValue(admin, "pass"))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED)
.post(Entity.form(f));