forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DashboardPage.java
193 lines (154 loc) · 6.38 KB
/
DashboardPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.harvard.iq.dataverse;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.harvest.client.HarvestingClient;
import edu.harvard.iq.dataverse.harvest.client.HarvestingClientServiceBean;
import edu.harvard.iq.dataverse.harvest.server.OAISet;
import edu.harvard.iq.dataverse.harvest.server.OAISetServiceBean;
import static edu.harvard.iq.dataverse.util.JsfHelper.JH;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.config.SystemConfig;
import java.util.List;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
/**
*
* @author Leonid Andreev
*/
@ViewScoped
@Named
public class DashboardPage implements java.io.Serializable {
private static final Logger logger = Logger.getLogger(DashboardPage.class.getCanonicalName());
@EJB
HarvestingClientServiceBean harvestingClientService;
@EJB
OAISetServiceBean oaiSetService;
@EJB
SystemConfig systemConfig;
@Inject
DataverseSession session;
@Inject
NavigationWrapper navigationWrapper;
/*
in breadcrumbs the dashboard page always appears as if it belongs to the
root dataverse ("Root Dataverse -> Dashboard") - because it is for the
top-level, site-wide controls only available to the site admin.
but it should still be possible to pass the id of the dataverse that was
current when the admin chose to go to the dashboard. This way certain values
can be pre-selected, etc. -- L.A. 4.5
*/
private Dataverse dataverse;
private Long dataverseId = null;
public String init() {
if (!isSessionUserAuthenticated()) {
return "/loginpage.xhtml" + navigationWrapper.getRedirectPage();
} else if (!isSuperUser()) {
return navigationWrapper.notAuthorized();
}
/*
use this to add some kind of a tooltip/info message to the top of the page:
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dashboard.title"), BundleUtil.getStringFromBundle("dashboard.toptip")));
- the values for "dashboard.title" and "dashboard.toptip" would need to be added to the resource bundle.
*/
return null;
}
public Dataverse getDataverse() {
return dataverse;
}
public void setDataverse(Dataverse dataverse) {
this.dataverse = dataverse;
}
public Long getDataverseId() {
return dataverseId;
}
public void setDataverseId(Long dataverseId) {
this.dataverseId = dataverseId;
}
public int getNumberOfConfiguredHarvestClients() {
List<HarvestingClient> configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
if (configuredHarvestingClients == null || configuredHarvestingClients.isEmpty()) {
return 0;
}
return configuredHarvestingClients.size();
}
public long getNumberOfHarvestedDatasets() {
List<HarvestingClient> configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
if (configuredHarvestingClients == null || configuredHarvestingClients.isEmpty()) {
return 0L;
}
Long numOfDatasets = harvestingClientService.getNumberOfHarvestedDatasetByClients(configuredHarvestingClients);
if (numOfDatasets != null && numOfDatasets > 0L) {
return numOfDatasets;
}
return 0L;
}
public boolean isHarvestServerEnabled() {
if (systemConfig.isOAIServerEnabled()) {
return true;
}
return false;
}
public int getNumberOfOaiSets() {
List<OAISet> configuredHarvestingSets = oaiSetService.findAll();
if (configuredHarvestingSets == null || configuredHarvestingSets.isEmpty()) {
return 0;
}
return configuredHarvestingSets.size();
}
@Deprecated
public String getHarvestClientsInfoLabel() {
List<HarvestingClient> configuredHarvestingClients = harvestingClientService.getAllHarvestingClients();
if (configuredHarvestingClients == null || configuredHarvestingClients.isEmpty()) {
return BundleUtil.getStringFromBundle("harvestclients.noClients.label");
}
String infoLabel;
if (configuredHarvestingClients.size() == 1) {
infoLabel = configuredHarvestingClients.size() + " configured harvesting client; ";
} else {
infoLabel = configuredHarvestingClients.size() + " harvesting clients configured; ";
}
Long numOfDatasets = harvestingClientService.getNumberOfHarvestedDatasetByClients(configuredHarvestingClients);
if (numOfDatasets != null && numOfDatasets > 0L) {
return infoLabel + numOfDatasets + " harvested datasets";
}
return infoLabel + "no datasets harvested.";
}
@Deprecated
public String getHarvestServerInfoLabel() {
if (!systemConfig.isOAIServerEnabled()) {
return "OAI server disabled.";
}
String infoLabel = "OAI server enabled; ";
List<OAISet> configuredHarvestingSets = oaiSetService.findAll();
if (configuredHarvestingSets == null || configuredHarvestingSets.isEmpty()) {
infoLabel = infoLabel.concat(BundleUtil.getStringFromBundle("harvestserver.service.empty"));
return infoLabel;
}
infoLabel = infoLabel.concat(configuredHarvestingSets.size() + " configured OAI sets. ");
return infoLabel;
}
public boolean isSessionUserAuthenticated() {
if (session == null) {
return false;
}
if (session.getUser() == null) {
return false;
}
if (session.getUser().isAuthenticated()) {
return true;
}
return false;
}
public boolean isSuperUser() {
return session.getUser().isSuperuser();
}
}