1 |
19953
|
nikon.gasp
|
package gr.uoa.di.validator.api.listeners;
|
2 |
18311
|
nikon.gasp
|
|
3 |
19953
|
nikon.gasp
|
import gr.uoa.di.validator.api.OpenAIREValidator;
|
4 |
20840
|
nikon.gasp
|
import gr.uoa.di.validator.database.OpenDoarRepositoryFactory;
|
5 |
19953
|
nikon.gasp
|
import gr.uoa.di.validator.execution.CompletedTask;
|
6 |
|
|
import gr.uoa.di.validator.execution.JobListener;
|
7 |
18398
|
nikon.gasp
|
import gr.uoa.di.validatorweb.email.Emailer;
|
8 |
|
|
|
9 |
|
|
import java.util.ArrayList;
|
10 |
|
|
import java.util.List;
|
11 |
19953
|
nikon.gasp
|
import java.util.Map;
|
12 |
18398
|
nikon.gasp
|
|
13 |
|
|
import javax.sql.DataSource;
|
14 |
|
|
|
15 |
|
|
import org.apache.log4j.Logger;
|
16 |
|
|
|
17 |
19953
|
nikon.gasp
|
public class OpenAIREValidatorRegistrationListener implements JobListener{
|
18 |
18311
|
nikon.gasp
|
|
19 |
18398
|
nikon.gasp
|
private Emailer emailer = null;
|
20 |
|
|
private String valBaseUrl = null;
|
21 |
|
|
private DataSource openaireDataSource = null;
|
22 |
19953
|
nikon.gasp
|
private OpenAIREValidator openAIREValidator;
|
23 |
20840
|
nikon.gasp
|
private OpenDoarRepositoryFactory openDoarRepositoryFactory = null;
|
24 |
18311
|
nikon.gasp
|
|
25 |
18398
|
nikon.gasp
|
private int jobId1, jobId2;
|
26 |
25971
|
nikon.gasp
|
private String activationId, userMail, officialName, baseUrl, datasourceId, interfaceId, validationSet, desiredCompLevel;
|
27 |
18398
|
nikon.gasp
|
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 |
19953
|
nikon.gasp
|
private static Logger logger = Logger.getLogger(OpenAIREValidatorRegistrationListener.class);
|
37 |
18398
|
nikon.gasp
|
|
38 |
|
|
|
39 |
19953
|
nikon.gasp
|
public OpenAIREValidatorRegistrationListener() {
|
40 |
18398
|
nikon.gasp
|
logger.debug("Creating a pre-registration listener for job "+jobId1+" and "+jobId2+" on repo "+baseUrl);
|
41 |
|
|
}
|
42 |
|
|
|
43 |
19953
|
nikon.gasp
|
public synchronized void jobSuccess(int jodId, int score) {
|
44 |
18398
|
nikon.gasp
|
logger.debug("Pregistration job "+jodId+" finished");
|
45 |
26592
|
nikon.gasp
|
if (score > 50) {
|
46 |
18398
|
nikon.gasp
|
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 |
19953
|
nikon.gasp
|
this.criticalSuccess();
|
58 |
18398
|
nikon.gasp
|
}
|
59 |
|
|
} else {
|
60 |
|
|
if(!critFailDone)
|
61 |
19953
|
nikon.gasp
|
this.criticalFailure();
|
62 |
18398
|
nikon.gasp
|
critFailDone = true;
|
63 |
18311
|
nikon.gasp
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
18398
|
nikon.gasp
|
|
67 |
19953
|
nikon.gasp
|
public synchronized void jobFailure(int jobId, String error) {
|
68 |
18398
|
nikon.gasp
|
logger.debug("Pregistration job "+jobId+" failed with exception: "+error);
|
69 |
|
|
if(!critFailDone)
|
70 |
19953
|
nikon.gasp
|
this.criticalFailure();
|
71 |
18398
|
nikon.gasp
|
critFailDone = true;
|
72 |
18311
|
nikon.gasp
|
}
|
73 |
18398
|
nikon.gasp
|
|
74 |
19953
|
nikon.gasp
|
private void criticalSuccess() {
|
75 |
18398
|
nikon.gasp
|
try {
|
76 |
20534
|
nikon.gasp
|
|
77 |
20840
|
nikon.gasp
|
String msgOpenaireV2 = "OpenAIRE v2, please consider to upgrade to OpenAIRE Guidelines v3. Link: https://guidelines.openaire.eu/wiki/OpenAIRE_Guidelines:_For_Literature_repositories";
|
78 |
25971
|
nikon.gasp
|
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 |
20534
|
nikon.gasp
|
String msgOpenaireV3 = "OpenAIRE Guidelines v3 (for literature)";
|
80 |
25971
|
nikon.gasp
|
String msgOpenaireV3_data = "OpenAIRE Guidelines v3 (for data archives)";
|
81 |
20534
|
nikon.gasp
|
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 |
25829
|
nikon.gasp
|
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 |
27897
|
nikon.gasp
|
String msgGuidelines = "OpenAIRE Guidelines v3 (for literature)";
|
86 |
20840
|
nikon.gasp
|
logger.debug("Critical Success of pre-registration validations on repo: "+baseUrl+" and set: " + validationSet + " with scores ("+score1+", "+score2+")");
|
87 |
25971
|
nikon.gasp
|
if (this.desiredCompLevel.equalsIgnoreCase("openaire2.0")) {
|
88 |
20534
|
nikon.gasp
|
msgVersion = msgOpenaireV2;
|
89 |
27897
|
nikon.gasp
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 2.0)";
|
90 |
25971
|
nikon.gasp
|
} else if (this.desiredCompLevel.equalsIgnoreCase("driver")) {
|
91 |
20534
|
nikon.gasp
|
msgVersion = msgDriver;
|
92 |
27897
|
nikon.gasp
|
msgGuidelines = "OpenAIRE For Literature Repositories (Basic - ex DRIVER)";
|
93 |
25971
|
nikon.gasp
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0_data")) {
|
94 |
|
|
msgVersion = msgOpenaireV3_data;
|
95 |
27897
|
nikon.gasp
|
msgGuidelines = "OpenAIRE For Data Archives (OpenAIRE 3.0)";
|
96 |
25971
|
nikon.gasp
|
} else if (this.desiredCompLevel.equalsIgnoreCase("openaire3.0")) {
|
97 |
|
|
msgVersion = msgOpenaireV3;
|
98 |
27897
|
nikon.gasp
|
msgGuidelines = "OpenAIRE For Literature Repositories (OpenAIRE 3.0)";
|
99 |
20534
|
nikon.gasp
|
}
|
100 |
18610
|
nikon.gasp
|
if (score1 == 100 && score2 == 100)
|
101 |
20534
|
nikon.gasp
|
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 |
18610
|
nikon.gasp
|
else
|
103 |
20534
|
nikon.gasp
|
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 |
20840
|
nikon.gasp
|
|
105 |
26592
|
nikon.gasp
|
|
106 |
30461
|
nikon.gasp
|
openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, desiredCompLevel, validationSet, baseUrl, null);
|
107 |
24393
|
nikon.gasp
|
this.getOpenAIREValidator().deleteJobForRegistration(activationId);
|
108 |
18534
|
nikon.gasp
|
|
109 |
24393
|
nikon.gasp
|
|
110 |
18398
|
nikon.gasp
|
// mail to user informing him of the success
|
111 |
|
|
List<String> rec = new ArrayList<String>();
|
112 |
|
|
rec.add(this.userMail);
|
113 |
25829
|
nikon.gasp
|
if (adminEmails.contains(userMail)) {
|
114 |
29541
|
nikon.gasp
|
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 |
25829
|
nikon.gasp
|
}
|
116 |
|
|
else {
|
117 |
29541
|
nikon.gasp
|
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 |
25829
|
nikon.gasp
|
rec.clear();
|
119 |
|
|
rec.addAll(adminEmails);
|
120 |
29541
|
nikon.gasp
|
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 |
25829
|
nikon.gasp
|
}
|
122 |
|
|
|
123 |
18398
|
nikon.gasp
|
// mail to specials informing them of the new repository
|
124 |
|
|
// registration
|
125 |
|
|
rec.clear();
|
126 |
29542
|
nikon.gasp
|
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 |
18398
|
nikon.gasp
|
} catch (Exception e) {
|
128 |
|
|
logger.error("", e);
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
|
132 |
19953
|
nikon.gasp
|
private void criticalFailure() {
|
133 |
18398
|
nikon.gasp
|
try {
|
134 |
27897
|
nikon.gasp
|
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 |
18398
|
nikon.gasp
|
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 |
29454
|
nikon.gasp
|
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 |
18398
|
nikon.gasp
|
|
151 |
30461
|
nikon.gasp
|
// openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, "notCompatible");
|
152 |
|
|
openDoarRepositoryFactory.updateRepositoryInterfaceCompliance(officialName, datasourceId, interfaceId, "notCompatible", validationSet, baseUrl, null);
|
153 |
|
|
|
154 |
24393
|
nikon.gasp
|
this.getOpenAIREValidator().deleteJobForRegistration(activationId);
|
155 |
20840
|
nikon.gasp
|
|
156 |
18398
|
nikon.gasp
|
} 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 |
19999
|
nikon.gasp
|
public String getDatasourceId() {
|
237 |
|
|
return datasourceId;
|
238 |
|
|
}
|
239 |
18398
|
nikon.gasp
|
|
240 |
19999
|
nikon.gasp
|
public void setDatasourceId(String datasourceId) {
|
241 |
|
|
this.datasourceId = datasourceId;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
24316
|
nikon.gasp
|
public String getInterfaceId() {
|
245 |
|
|
return interfaceId;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
public void setInterfaceId(String interfaceId) {
|
249 |
|
|
this.interfaceId = interfaceId;
|
250 |
|
|
}
|
251 |
|
|
|
252 |
20534
|
nikon.gasp
|
public String getValidationSet() {
|
253 |
|
|
return validationSet;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
public void setValidationSet(String validationSet) {
|
257 |
|
|
this.validationSet = validationSet;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
18398
|
nikon.gasp
|
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 |
19953
|
nikon.gasp
|
|
277 |
|
|
public OpenAIREValidator getOpenAIREValidator() {
|
278 |
|
|
return openAIREValidator;
|
279 |
|
|
}
|
280 |
18398
|
nikon.gasp
|
|
281 |
19953
|
nikon.gasp
|
public void setOpenAIREValidator(OpenAIREValidator openAIREValidator) {
|
282 |
|
|
this.openAIREValidator = openAIREValidator;
|
283 |
18398
|
nikon.gasp
|
}
|
284 |
19953
|
nikon.gasp
|
|
285 |
20840
|
nikon.gasp
|
public OpenDoarRepositoryFactory getOpenDoarRepositoryFactory() {
|
286 |
|
|
return openDoarRepositoryFactory;
|
287 |
|
|
}
|
288 |
|
|
|
289 |
|
|
public void setOpenDoarRepositoryFactory(OpenDoarRepositoryFactory openDoarRepositoryFactory) {
|
290 |
|
|
this.openDoarRepositoryFactory = openDoarRepositoryFactory;
|
291 |
|
|
}
|
292 |
|
|
|
293 |
19953
|
nikon.gasp
|
@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 |
18398
|
nikon.gasp
|
|
300 |
19953
|
nikon.gasp
|
@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 |
18398
|
nikon.gasp
|
}
|
306 |
19953
|
nikon.gasp
|
|
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 |
25971
|
nikon.gasp
|
public String getDesiredCompLevel() {
|
319 |
|
|
return desiredCompLevel;
|
320 |
|
|
}
|
321 |
19953
|
nikon.gasp
|
|
322 |
25971
|
nikon.gasp
|
public void setDesiredCompLevel(String desiredCompLevel) {
|
323 |
|
|
this.desiredCompLevel = desiredCompLevel;
|
324 |
|
|
}
|
325 |
19953
|
nikon.gasp
|
|
326 |
|
|
|
327 |
25971
|
nikon.gasp
|
|
328 |
|
|
|
329 |
18398
|
nikon.gasp
|
|
330 |
18311
|
nikon.gasp
|
}
|