comparison 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
comparison
equal deleted inserted replaced
9:5926d6419569 10:a50cf11e5178
1 package edu.harvard.iq.dataverse;
2
3 import edu.harvard.iq.dataverse.authorization.users.User;
4 import edu.harvard.iq.dataverse.search.IndexAllServiceBean;
5 import java.util.concurrent.CancellationException;
6 import java.util.concurrent.ExecutionException;
7 import java.util.concurrent.Future;
8 import javax.ejb.EJB;
9 import javax.enterprise.context.SessionScoped;
10 import javax.inject.Inject;
11 import javax.inject.Named;
12 import javax.json.JsonObjectBuilder;
13
14 @SessionScoped
15 @Named("SuperUserPage")
16 public class SuperUserPage implements java.io.Serializable {
17
18 @Inject
19 DataverseSession session;
20
21 @EJB
22 IndexServiceBean indexService;
23 @EJB
24 IndexAllServiceBean indexAllService;
25
26 private String indexAllStatus = "No status available";
27
28 private Future<JsonObjectBuilder> indexAllFuture;
29
30 // modeled off http://docs.oracle.com/javaee/7/tutorial/ejb-async002.htm
31 public String getIndexAllStatus() {
32 if (indexAllFuture != null) {
33 if (indexAllFuture.isDone()) {
34 try {
35 JsonObjectBuilder status = indexAllFuture.get();
36 indexAllStatus = status.build().toString();
37 } catch (ExecutionException | CancellationException | InterruptedException ex) {
38 indexAllStatus = ex.getCause().toString();
39 }
40 } else {
41 indexAllStatus = "Index all is running...";
42 }
43 }
44 return indexAllStatus;
45 }
46
47 public void startIndexAll() {
48 User user = session.getUser();
49 if (user.isSuperuser()) {
50 long numPartitions = 1;
51 long partitionId = 0;
52 boolean previewOnly = false;
53 indexAllFuture = indexAllService.indexAllOrSubset(numPartitions, partitionId, false, previewOnly);
54 indexAllStatus = "Index all started...";
55 } else {
56 indexAllStatus = "Only a superuser can run index all";
57 }
58 }
59
60 public void updateIndexAllStatus() {
61 getIndexAllStatus();
62 }
63
64 }