1
|
package gr.uoa.di.validator.api.listeners;
|
2
|
|
3
|
import gr.uoa.di.validator.api.OpenAIREValidator;
|
4
|
import gr.uoa.di.validator.database.OpenDoarRepositoryFactory;
|
5
|
import gr.uoa.di.validator.execution.CompletedTask;
|
6
|
import gr.uoa.di.validator.execution.JobListener;
|
7
|
import gr.uoa.di.validatorweb.email.Emailer;
|
8
|
|
9
|
import java.util.ArrayList;
|
10
|
import java.util.List;
|
11
|
import java.util.Map;
|
12
|
|
13
|
import javax.sql.DataSource;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
public class OpenAIREValidatorRegistrationListener implements JobListener{
|
18
|
|
19
|
private Emailer emailer = null;
|
20
|
private String valBaseUrl = null;
|
21
|
private DataSource openaireDataSource = null;
|
22
|
private OpenAIREValidator openAIREValidator;
|
23
|
private OpenDoarRepositoryFactory openDoarRepositoryFactory = null;
|
24
|
|
25
|
private int jobId1, jobId2;
|
26
|
private String activationId, userMail, officialName, baseUrl, datasourceId, interfaceId, validationSet, desiredCompLevel;
|
27
|
private List<String> adminEmails;
|
28
|
|
29
|
private boolean job1Success = false;
|
30
|
private boolean job2Success = false;
|
31
|
|
32
|
private boolean critFailDone = false;
|
33
|
|
34
|
private int score1 = 0, score2 = 0;
|
35
|
|
36
|
private static Logger logger = Logger.getLogger(OpenAIREValidatorRegistrationListener.class);
|
37
|
|
38
|
|
39
|
public OpenAIREValidatorRegistrationListener() {
|
40
|
logger.debug("Creating a pre-registration listener for job "+jobId1+" and "+jobId2+" on repo "+baseUrl);
|
41
|
}
|
42
|
|
43
|
public synchronized void jobSuccess(int jodId, int score) {
|
44
|
logger.debug("Pregistration job "+jodId+" finished");
|
45
|
if (score > 50) {
|
46
|
if (jodId == jobId1) {
|
47
|
job1Success = true;
|
48
|
score1 = score;
|
49
|
} else if (jodId == jobId2) {
|
50
|
job2Success = true;
|
51
|
score2 = score;
|
52
|
} else {
|
53
|
logger.error("a job finished that was not one of the preregistration jobs!");
|
54
|
}
|
55
|
|
56
|
if (job1Success == job2Success == true) {
|
57
|
this.criticalSuccess();
|
58
|
}
|
59
|
} else {
|
60
|
if(!critFailDone)
|
61
|
this.criticalFailure();
|
62
|
critFailDone = true;
|
63
|
}
|
64
|
}
|
65
|
|
66
|
|
67
|
public synchronized void jobFailure(int jobId, String error) {
|
68
|
logger.debug("Pregistration job "+jobId+" failed with exception: "+error);
|
69
|
if(!critFailDone)
|
70
|
this.criticalFailure();
|
71
|
critFailDone = true;
|
72
|
}
|
73
|
|
74
|
private void criticalSuccess() {
|
75
|
try {
|
76
|
|
77
|
String msgOpenaireV2 = "OpenAIRE v2, please consider to upgrade to OpenAIRE Guidelines v3. Link: https://guidelines.openaire.eu/wiki/OpenAIRE_Guidelines:_For_Literature_repositories";
|
78
|
String msgDriver = "OpenAIRE Basic (ex DRIVER) Guidelines, please consider to upgrade to OpenAIRE Guidelines v3. Link: https://guidelines.openaire.eu/wiki/OpenAIRE_Guidelines:_For_Literature_repositories";
|
79
|
String msgOpenaireV3 = "OpenAIRE Guidelines v3 (for literature)";
|
80
|
String msgOpenaireV3_data = "OpenAIRE Guidelines v3 (for data archives)";
|
81
|
String msgVersion = msgOpenaireV3;
|
82
|
String msg100 = "\n\nWe also encourage you to display the following logo at your repository's/journal's homepage to indicate that it is 100% OpenAIRE compliant: " + valBaseUrl + "/jsps/images/compliant.png";
|
83
|
String msgInformUser = "An email has been send to the repository's/journal's administrators to inform them about this registration";
|
84
|
String msgInformAdmins = "The repository/journal was registered by user: " + userMail + " , who is not listed as repository's/journal's administrator. If you have any concerns, please visit " + valBaseUrl + " to edit your repository's/journal's information. Please Sign in or Register with this email address.";
|
85
|
String msgGuidelines = "OpenAIRE Guidelines v3 (for literature)";
|
86
|
logger.debug("Critical Success of pre-registration validations on repo: "+baseUrl+" and set: " + validationSet + " with scores ("+score1+", "+score2+")");
|
87
|
if (this.desiredCompLevel.equalsIgnoreCase("openaire2.0")) {
|
88
|
msgVersion = msgOpenaireV2;
|
89
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 2.0)";
|
90
|
} else if (this.desiredCompLevel.equalsIgnoreCase("driver")) {
|
91
|
msgVersion = msgDriver;
|
92
|
msgGuidelines = "OpenAIRE For Literature Repositories (Basic - ex DRIVER)";
|
93
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0_data")) {
|
94
|
msgVersion = msgOpenaireV3_data;
|
95
|
msgGuidelines = "OpenAIRE For Data Archives (OpenAIRE 3.0)";
|
96
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0")) {
|
97
|
msgVersion = msgOpenaireV3;
|
98
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 3.0)";
|
99
|
}
|
100
|
if (score1 == 100 && score2 == 100)
|
101
|
emailer.sendMail(this.adminEmails, "Request to Join OpenAIRE - Test Results", "Congratulations!! Your repository/journal has successfully passed the test to become compliant with " + msgVersion + "." + msg100, false, null);
|
102
|
else
|
103
|
emailer.sendMail(this.adminEmails, "Request to Join OpenAIRE - Test Results", "Congratulations!! Your repository/journal has successfully passed the test to become compliant with " + msgVersion + ".", false, null);
|
104
|
|
105
|
|
106
|
openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, desiredCompLevel, validationSet, baseUrl, null);
|
107
|
this.getOpenAIREValidator().deleteJobForRegistration(activationId);
|
108
|
|
109
|
|
110
|
// mail to user informing him of the success
|
111
|
List<String> rec = new ArrayList<String>();
|
112
|
rec.add(this.userMail);
|
113
|
if (adminEmails.contains(userMail)) {
|
114
|
emailer.sendMail(rec, "Request to Join OpenAIRE - Results", "The compatibility test of your repository/journal was successful. Nevertheless, some erros might still exist. We strongly recommend reviewing the results and correcting any errors found:\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId1 + "&groupBy=all" + "\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId2 + "&groupBy=all", false, null);
|
115
|
}
|
116
|
else {
|
117
|
emailer.sendMail(rec, "Request to Join OpenAIRE - Results", "The compatibility test of your repository/journal was successful. Nevertheless, some erros might still exist. We strongly recommend reviewing the results and correcting any errors found:\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId1 + "&groupBy=all" + "\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId2 + "&groupBy=all" + "\n\n" + msgInformUser, false, null);
|
118
|
rec.clear();
|
119
|
rec.addAll(adminEmails);
|
120
|
emailer.sendMail(rec, "Request to Join OpenAIRE - Results", "The compatibility test of your repository/journal was successful. Nevertheless, some erros might still exist. We strongly recommend reviewing the results and correcting any errors found:\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId1 + "&groupBy=all" + "\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId2 + "&groupBy=all" + "\n\n" + msgInformAdmins, false, null);
|
121
|
}
|
122
|
|
123
|
// mail to specials informing them of the new repository
|
124
|
// registration
|
125
|
rec.clear();
|
126
|
emailer.sendMail(rec, "Request to Join OpenAIRE - Results (success)", "A new repository/journal is ready to be added in the list of OpenAIRE compliant repositories/journals." + "\n\nOfficial Name: " + this.officialName + "\n\nBase URL: " + this.baseUrl + "\n\nValidation Set: " + this.validationSet + "\n\nGuidelines: " + msgGuidelines, true, null);
|
127
|
} catch (Exception e) {
|
128
|
logger.error("", e);
|
129
|
}
|
130
|
}
|
131
|
|
132
|
private void criticalFailure() {
|
133
|
try {
|
134
|
String msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 3.0)";
|
135
|
if (this.desiredCompLevel.equalsIgnoreCase("openaire2.0")) {
|
136
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 2.0)";
|
137
|
} else if (this.desiredCompLevel.equalsIgnoreCase("driver")) {
|
138
|
msgGuidelines = "OpenAIRE For Literature Repositories (Basic - ex DRIVER)";
|
139
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0_data")) {
|
140
|
msgGuidelines = "OpenAIRE For Data Archives (OpenAIRE 3.0)";
|
141
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0")) {
|
142
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 3.0)";
|
143
|
}
|
144
|
logger.debug("Critical Failure of pre-registration validations on repo "+baseUrl);
|
145
|
// mail to inform user of failure
|
146
|
List<String> rec = new ArrayList<String>();
|
147
|
rec.add(this.userMail);
|
148
|
emailer.sendMail(rec, "Request to Join OpenAIRE - Results", "The compatibility test of your repository/journal on repo: "+baseUrl+" and set: " + validationSet + " was unsuccessful and the join process has failed. \n" + "Your Scores: " + score1 + "/100 and " + score2 + "/100 . Score required to pass: >50 \n" +" Please review the results and correct any errors: \n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId1 + "&groupBy=all" + "\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId2 + "&groupBy=all", false, null);
|
149
|
emailer.sendMail(new ArrayList<String>(), "Join OpenAIRE - Results (failure)", "The compatibility test on "+officialName+" was unsuccessful and the join process has failed. "+ "\n\nBase URL: " + this.baseUrl + "\n\nValidation Set: " + this.validationSet + "\n\nGuidelines: " + msgGuidelines + "\n\nReview the validation results here: \n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId1 + "&groupBy=all" + "\n" + valBaseUrl + "/prepareSummary.action?jobId=" + this.jobId2 + "&groupBy=all", true, null);
|
150
|
|
151
|
// openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, "notCompatible");
|
152
|
openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, "notCompatible", validationSet, baseUrl, null);
|
153
|
|
154
|
this.getOpenAIREValidator().deleteJobForRegistration(activationId);
|
155
|
|
156
|
} catch (Exception e) {
|
157
|
logger.error("", e);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
public Emailer getEmailer() {
|
162
|
return emailer;
|
163
|
}
|
164
|
|
165
|
public void setEmailer(Emailer emailer) {
|
166
|
this.emailer = emailer;
|
167
|
}
|
168
|
|
169
|
public String getValBaseUrl() {
|
170
|
return valBaseUrl;
|
171
|
}
|
172
|
|
173
|
public void setValBaseUrl(String valBaseUrl) {
|
174
|
this.valBaseUrl = valBaseUrl;
|
175
|
}
|
176
|
|
177
|
public int getJobId1() {
|
178
|
return jobId1;
|
179
|
}
|
180
|
|
181
|
|
182
|
public void setJobId1(int jobId1) {
|
183
|
this.jobId1 = jobId1;
|
184
|
}
|
185
|
|
186
|
|
187
|
public int getJobId2() {
|
188
|
return jobId2;
|
189
|
}
|
190
|
|
191
|
|
192
|
public void setJobId2(int jobId2) {
|
193
|
this.jobId2 = jobId2;
|
194
|
}
|
195
|
|
196
|
|
197
|
public String getActivationId() {
|
198
|
return activationId;
|
199
|
}
|
200
|
|
201
|
|
202
|
public void setActivationId(String activationId) {
|
203
|
this.activationId = activationId;
|
204
|
}
|
205
|
|
206
|
|
207
|
public String getUserMail() {
|
208
|
return userMail;
|
209
|
}
|
210
|
|
211
|
|
212
|
public void setUserMail(String userMail) {
|
213
|
this.userMail = userMail;
|
214
|
}
|
215
|
|
216
|
|
217
|
public String getOfficialName() {
|
218
|
return officialName;
|
219
|
}
|
220
|
|
221
|
|
222
|
public void setOfficialName(String officialName) {
|
223
|
this.officialName = officialName;
|
224
|
}
|
225
|
|
226
|
|
227
|
public String getBaseUrl() {
|
228
|
return baseUrl;
|
229
|
}
|
230
|
|
231
|
|
232
|
public void setBaseUrl(String baseUrl) {
|
233
|
this.baseUrl = baseUrl;
|
234
|
}
|
235
|
|
236
|
public String getDatasourceId() {
|
237
|
return datasourceId;
|
238
|
}
|
239
|
|
240
|
public void setDatasourceId(String datasourceId) {
|
241
|
this.datasourceId = datasourceId;
|
242
|
}
|
243
|
|
244
|
public String getInterfaceId() {
|
245
|
return interfaceId;
|
246
|
}
|
247
|
|
248
|
public void setInterfaceId(String interfaceId) {
|
249
|
this.interfaceId = interfaceId;
|
250
|
}
|
251
|
|
252
|
public String getValidationSet() {
|
253
|
return validationSet;
|
254
|
}
|
255
|
|
256
|
public void setValidationSet(String validationSet) {
|
257
|
this.validationSet = validationSet;
|
258
|
}
|
259
|
|
260
|
public List<String> getAdminEmails() {
|
261
|
return adminEmails;
|
262
|
}
|
263
|
|
264
|
|
265
|
public void setAdminEmails(List<String> adminEmails) {
|
266
|
this.adminEmails = adminEmails;
|
267
|
}
|
268
|
|
269
|
public DataSource getOpenaireDataSource() {
|
270
|
return openaireDataSource;
|
271
|
}
|
272
|
|
273
|
public void setOpenaireDataSource(DataSource openaireDataSource) {
|
274
|
this.openaireDataSource = openaireDataSource;
|
275
|
}
|
276
|
|
277
|
public OpenAIREValidator getOpenAIREValidator() {
|
278
|
return openAIREValidator;
|
279
|
}
|
280
|
|
281
|
public void setOpenAIREValidator(OpenAIREValidator openAIREValidator) {
|
282
|
this.openAIREValidator = openAIREValidator;
|
283
|
}
|
284
|
|
285
|
public OpenDoarRepositoryFactory getOpenDoarRepositoryFactory() {
|
286
|
return openDoarRepositoryFactory;
|
287
|
}
|
288
|
|
289
|
public void setOpenDoarRepositoryFactory(OpenDoarRepositoryFactory openDoarRepositoryFactory) {
|
290
|
this.openDoarRepositoryFactory = openDoarRepositoryFactory;
|
291
|
}
|
292
|
|
293
|
@Override
|
294
|
public synchronized void currentResults(List<CompletedTask> tasks, int jobId,
|
295
|
Object object, Map<String, Object> recordContext, Throwable t) {
|
296
|
// TODO Auto-generated method stub
|
297
|
|
298
|
}
|
299
|
|
300
|
@Override
|
301
|
public synchronized void currentResults(List<CompletedTask> tasks, int jobId,
|
302
|
Object object, Map<String, Object> recordContext) {
|
303
|
// TODO Auto-generated method stub
|
304
|
|
305
|
}
|
306
|
|
307
|
@Override
|
308
|
public synchronized void finished(int jobId, Map<String, Object> jobContext) {
|
309
|
this.jobSuccess((Integer) jobContext.get("jobSubmittedId"),(Integer) jobContext.get("score"));
|
310
|
|
311
|
}
|
312
|
|
313
|
@Override
|
314
|
public synchronized void failed(int jobId, Map<String, Object> jobContext, Throwable t) {
|
315
|
this.jobFailure((Integer) jobContext.get("jobSubmittedId"),t.getMessage());
|
316
|
}
|
317
|
|
318
|
public String getDesiredCompLevel() {
|
319
|
return desiredCompLevel;
|
320
|
}
|
321
|
|
322
|
public void setDesiredCompLevel(String desiredCompLevel) {
|
323
|
this.desiredCompLevel = desiredCompLevel;
|
324
|
}
|
325
|
|
326
|
|
327
|
|
328
|
|
329
|
|
330
|
}
|