1
|
package gr.uoa.di.validator.api.listeners;
|
2
|
|
3
|
import gr.uoa.di.validator.execution.CompletedTask;
|
4
|
import gr.uoa.di.validator.execution.JobListener;
|
5
|
import gr.uoa.di.validatorweb.email.Emailer;
|
6
|
|
7
|
import java.util.ArrayList;
|
8
|
import java.util.List;
|
9
|
import java.util.Map;
|
10
|
|
11
|
import org.apache.log4j.Logger;
|
12
|
|
13
|
public class OpenAIREValidatorCompatibilityTestListener implements JobListener{
|
14
|
private static Logger logger = Logger.getLogger(OpenAIREValidatorCompatibilityTestListener.class);
|
15
|
|
16
|
private Emailer emailer = null;
|
17
|
private String valBaseUrl = null;
|
18
|
private String validationSet = null;
|
19
|
private String guidelines = null;
|
20
|
|
21
|
@Override
|
22
|
public void finished(int jobId, Map<String, Object> jobContext) {
|
23
|
if ((Integer) jobContext.get("allJobsFinished") == 1 ) {
|
24
|
this.sendMail((Integer) jobContext.get("jobSubmittedId"), (String) jobContext.get("jobSubmittedUser"));
|
25
|
}
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public void failed(int jobId, Map<String, Object> jobContext, Throwable t) {
|
30
|
if ((Integer) jobContext.get("allJobsFinished") == 1 ) {
|
31
|
this.sendMail((Integer) jobContext.get("jobSubmittedId"), (String) jobContext.get("jobSubmittedUser"));
|
32
|
}
|
33
|
}
|
34
|
|
35
|
|
36
|
|
37
|
private void sendMail(int jobSubmittedId, String jobSubmittedUser) {
|
38
|
logger.debug("JOBID:"+jobSubmittedId+"# Sending email for finished job");
|
39
|
String mailTo = jobSubmittedUser;
|
40
|
List<String> recipients = new ArrayList<String>();
|
41
|
recipients.add(mailTo);
|
42
|
String msgUpgrade = "";
|
43
|
// if (this.validationSet != null && !this.validationSet.equalsIgnoreCase("openaire"))
|
44
|
if (this.guidelines.equalsIgnoreCase("openaire2.0") || this.guidelines.equalsIgnoreCase("driver"))
|
45
|
msgUpgrade = "\n\n Please consider to upgrade to OpenAIRE Guidelines v3. Link: https://guidelines.openaire.eu/wiki/OpenAIRE_Guidelines:_For_Literature_repositories";
|
46
|
String message = "The compatibility test you have submitted has finished. You can retrieve the results by following this url: " + valBaseUrl + "/prepareSummary.action?jobId=" + jobSubmittedId + "&groupBy=all" + msgUpgrade;
|
47
|
|
48
|
String subject = "OpenAIRE compatibility Test Results";
|
49
|
try {
|
50
|
emailer.sendMail(recipients, subject, message, false, null);
|
51
|
} catch (Exception e) {
|
52
|
logger.error("JOBID:"+jobSubmittedId+"# Error sending email for finished job", e);
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public void currentResults(List<CompletedTask> tasks, int jobId,
|
58
|
Object object, Map<String, Object> recordContext, Throwable t) {
|
59
|
// TODO Auto-generated method stub
|
60
|
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public void currentResults(List<CompletedTask> tasks, int jobId,
|
65
|
Object object, Map<String, Object> recordContext) {
|
66
|
// TODO Auto-generated method stub
|
67
|
|
68
|
}
|
69
|
|
70
|
public String getValBaseUrl() {
|
71
|
return valBaseUrl;
|
72
|
}
|
73
|
|
74
|
public void setValBaseUrl(String valBaseUrl) {
|
75
|
this.valBaseUrl = valBaseUrl;
|
76
|
}
|
77
|
|
78
|
public String getValidationSet() {
|
79
|
return validationSet;
|
80
|
}
|
81
|
|
82
|
public void setValidationSet(String validationSet) {
|
83
|
this.validationSet = validationSet;
|
84
|
}
|
85
|
|
86
|
public Emailer getEmailer() {
|
87
|
return emailer;
|
88
|
}
|
89
|
|
90
|
public void setEmailer(Emailer emailer) {
|
91
|
this.emailer = emailer;
|
92
|
}
|
93
|
|
94
|
public String getGuidelines() {
|
95
|
return guidelines;
|
96
|
}
|
97
|
|
98
|
public void setGuidelines(String guidelines) {
|
99
|
this.guidelines = guidelines;
|
100
|
}
|
101
|
|
102
|
}
|