diff src/main/java/edu/harvard/iq/dataverse/SuperUserPage.java @ 10:a50cf11e5178

Rewrite LGDataverse completely upgrading to dataverse4.0
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 08 Sep 2015 17:00:21 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/edu/harvard/iq/dataverse/SuperUserPage.java	Tue Sep 08 17:00:21 2015 +0200
@@ -0,0 +1,64 @@
+package edu.harvard.iq.dataverse;
+
+import edu.harvard.iq.dataverse.authorization.users.User;
+import edu.harvard.iq.dataverse.search.IndexAllServiceBean;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import javax.ejb.EJB;
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.json.JsonObjectBuilder;
+
+@SessionScoped
+@Named("SuperUserPage")
+public class SuperUserPage implements java.io.Serializable {
+
+    @Inject
+    DataverseSession session;
+
+    @EJB
+    IndexServiceBean indexService;
+    @EJB
+    IndexAllServiceBean indexAllService;
+
+    private String indexAllStatus = "No status available";
+
+    private Future<JsonObjectBuilder> indexAllFuture;
+
+    // modeled off http://docs.oracle.com/javaee/7/tutorial/ejb-async002.htm
+    public String getIndexAllStatus() {
+        if (indexAllFuture != null) {
+            if (indexAllFuture.isDone()) {
+                try {
+                    JsonObjectBuilder status = indexAllFuture.get();
+                    indexAllStatus = status.build().toString();
+                } catch (ExecutionException | CancellationException | InterruptedException ex) {
+                    indexAllStatus = ex.getCause().toString();
+                }
+            } else {
+                indexAllStatus = "Index all is running...";
+            }
+        }
+        return indexAllStatus;
+    }
+
+    public void startIndexAll() {
+        User user = session.getUser();
+        if (user.isSuperuser()) {
+            long numPartitions = 1;
+            long partitionId = 0;
+            boolean previewOnly = false;
+            indexAllFuture = indexAllService.indexAllOrSubset(numPartitions, partitionId, false, previewOnly);
+            indexAllStatus = "Index all started...";
+        } else {
+            indexAllStatus = "Only a superuser can run index all";
+        }
+    }
+
+    public void updateIndexAllStatus() {
+        getIndexAllStatus();
+    }
+
+}