1
|
package eu.dnetlib.repo.manager.service;
|
2
|
|
3
|
import eu.dnetlib.domain.data.PiwikInfo;
|
4
|
import eu.dnetlib.domain.data.Repository;
|
5
|
import eu.dnetlib.domain.data.RepositoryInterface;
|
6
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
7
|
import eu.dnetlib.repo.manager.config.CascadingPropertyLoader;
|
8
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
9
|
import eu.dnetlib.repo.manager.shared.ValidationServiceException;
|
10
|
import eu.dnetlib.utils.MailLibrary;
|
11
|
import org.apache.log4j.Logger;
|
12
|
import org.json.JSONException;
|
13
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.beans.factory.annotation.Value;
|
16
|
import org.springframework.security.core.Authentication;
|
17
|
import org.springframework.security.core.context.SecurityContextHolder;
|
18
|
import org.springframework.stereotype.Component;
|
19
|
|
20
|
import javax.annotation.PostConstruct;
|
21
|
import java.io.PrintWriter;
|
22
|
import java.io.StringWriter;
|
23
|
import java.io.Writer;
|
24
|
import java.util.ArrayList;
|
25
|
import java.util.List;
|
26
|
import java.util.stream.Collectors;
|
27
|
|
28
|
|
29
|
@Component("emailUtils")
|
30
|
public class EmailUtilsImpl implements EmailUtils {
|
31
|
|
32
|
private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class);
|
33
|
|
34
|
private List<String> specialRecipients = new ArrayList<String>();
|
35
|
private boolean override = false, logonly = false;
|
36
|
private String overrideEmail = null, from = null;
|
37
|
|
38
|
@Autowired
|
39
|
private MailLibrary mailLibrary;
|
40
|
|
41
|
@Autowired
|
42
|
private CascadingPropertyLoader pLoader;
|
43
|
|
44
|
@Value("${services.repo-manager.baseUrl}")
|
45
|
private String baseUrl;
|
46
|
|
47
|
@Value("${services.repo-manager.adminEmail}")
|
48
|
private String adminEmail;
|
49
|
|
50
|
@Value("${services.repomanager.usagestats.adminEmail}")
|
51
|
private String usageStatsAdminEmail;
|
52
|
|
53
|
@Value("${services.provide.adminEmail}")
|
54
|
private String provideAdminEmail;
|
55
|
|
56
|
@Value("${validator.results.url}")
|
57
|
private String valBaseUrl;
|
58
|
|
59
|
@Autowired
|
60
|
private RepositoryService repositoryService;
|
61
|
|
62
|
|
63
|
@PostConstruct
|
64
|
public void init(){
|
65
|
System.out.println("url -> " + this.baseUrl);
|
66
|
}
|
67
|
|
68
|
|
69
|
@Override
|
70
|
public void reportException(Exception exception) {
|
71
|
Writer writer = new StringWriter();
|
72
|
PrintWriter printWriter = new PrintWriter(writer);
|
73
|
exception.printStackTrace(printWriter);
|
74
|
|
75
|
List<String> recipients = new ArrayList<String>();
|
76
|
|
77
|
try {
|
78
|
recipients.add(this.adminEmail);
|
79
|
String message = "An exception has occurred:\n"+writer.toString();
|
80
|
String subject = "Automatic Bug Report";
|
81
|
this.sendMail(recipients, subject, message, false, null);
|
82
|
} catch (Exception e) {
|
83
|
LOGGER.error("Error sending error report", e);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
|
89
|
|
90
|
try {
|
91
|
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
|
92
|
|
93
|
String message = "Dear administrator,\n" +
|
94
|
"\n" +
|
95
|
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
|
96
|
"\n" +
|
97
|
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
|
98
|
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
|
99
|
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
|
100
|
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
|
101
|
"\n" +
|
102
|
"For more information about this request, go here: \n" +
|
103
|
this.baseUrl + "/admin/metrics\n" +
|
104
|
"\n" +
|
105
|
"Best,\n" +
|
106
|
"The OpenAIRE team";
|
107
|
|
108
|
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
|
109
|
|
110
|
} catch (Exception e) {
|
111
|
LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e);
|
112
|
throw e;
|
113
|
}
|
114
|
}
|
115
|
|
116
|
@Override
|
117
|
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
|
118
|
|
119
|
try {
|
120
|
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
|
121
|
|
122
|
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
|
123
|
"\n" +
|
124
|
"we have received your request to enable the OpenAIRE usage statistics for your repository\n" +
|
125
|
"\n" +
|
126
|
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
|
127
|
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
|
128
|
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
|
129
|
"\n" +
|
130
|
"In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " +
|
131
|
"OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " +
|
132
|
"(https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " +
|
133
|
"(https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " +
|
134
|
"the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution.\n" +
|
135
|
"\n" +
|
136
|
"For more information about your request and configuration details, go here: \n" +
|
137
|
this.baseUrl + "/getImpact/instructions/" + piwikInfo.getRepositoryId() + "\n" +
|
138
|
"\n" +
|
139
|
"Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \n" +
|
140
|
"an email to repositoryusagestats@openaire.eu\n" +
|
141
|
"\n" +
|
142
|
"Best,\n" +
|
143
|
"The OpenAIRE team";
|
144
|
|
145
|
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
|
146
|
|
147
|
} catch (Exception e) {
|
148
|
LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e);
|
149
|
throw e;
|
150
|
}
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
|
155
|
|
156
|
try {
|
157
|
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
|
158
|
|
159
|
String message = "Dear administrator,\n" +
|
160
|
"\n" +
|
161
|
"The installation and configuration of OpenAIRE's tracking code for the following repository " +
|
162
|
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
|
163
|
"\n" +
|
164
|
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
|
165
|
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
|
166
|
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
|
167
|
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
|
168
|
"\n" +
|
169
|
"Best,\n" +
|
170
|
"The OpenAIRE team";
|
171
|
|
172
|
this.sendMail(this.usageStatsAdminEmail, subject, message, false, null);
|
173
|
|
174
|
} catch (Exception e) {
|
175
|
LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e);
|
176
|
throw e;
|
177
|
}
|
178
|
}
|
179
|
|
180
|
@Override
|
181
|
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception {
|
182
|
|
183
|
try {
|
184
|
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
|
185
|
|
186
|
String message = "Dear " + piwikInfo.getRequestorName() + ",\n" +
|
187
|
"\n" +
|
188
|
"The installation and configuration of OpenAIRE's tracking code for your repository \"" + piwikInfo.getRepositoryName() +
|
189
|
"\" has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
|
190
|
"\n" +
|
191
|
"You can preview the statistics in your repository's dashboard: \n" +
|
192
|
this.baseUrl + "/getImpact/" + piwikInfo.getRepositoryId() + "\n" +
|
193
|
"\n" +
|
194
|
" For more information and questions, you can contact the openaire support team by sending an email to " +
|
195
|
"repositoryusagestats@openaire.eu\n" +
|
196
|
"\n" +
|
197
|
"Best,\n" +
|
198
|
"The OpenAIRE team";
|
199
|
|
200
|
this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null);
|
201
|
|
202
|
} catch (Exception e) {
|
203
|
LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
|
204
|
throw e;
|
205
|
}
|
206
|
}
|
207
|
|
208
|
@Override
|
209
|
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
|
210
|
try {
|
211
|
String subject = "OpenAIRE content provider registration request started for " +
|
212
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
213
|
|
214
|
String message = "Dear administrator" + ",\n" +
|
215
|
"\n" +
|
216
|
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
|
217
|
" to the OpenAIRE compliant list of content providers. " +
|
218
|
"A validation process against the OpenAIRE guidelines compatibility " +
|
219
|
"has been started. You will be informed in another message once the process is finished." +
|
220
|
"\n\n" +
|
221
|
"Please do not reply to this message\n" +
|
222
|
"This message has been generated automatically.\n\n" +
|
223
|
"Regards,\n" +
|
224
|
"the OpenAIRE technical team\n";
|
225
|
|
226
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
227
|
|
228
|
} catch (Exception e) {
|
229
|
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
230
|
throw e;
|
231
|
}
|
232
|
}
|
233
|
|
234
|
@Override
|
235
|
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
|
236
|
try {
|
237
|
String subject = "OpenAIRE content provider registration request started for " +
|
238
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
239
|
|
240
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
241
|
String message = "Dear user,\n" +
|
242
|
"\n" +
|
243
|
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
|
244
|
" to the OpenAIRE compliant list of content providers. " +
|
245
|
"A validation process against the OpenAIRE guidelines compatibility " +
|
246
|
"has been started. You will be informed in another message once the process is finished." +
|
247
|
"\n\n" +
|
248
|
"Please do not reply to this message\n" +
|
249
|
"This message has been generated automatically.\n\n" +
|
250
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
251
|
"Regards,\n" +
|
252
|
"the OpenAIRE technical team\n";
|
253
|
|
254
|
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
|
255
|
|
256
|
} catch (Exception e) {
|
257
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
258
|
throw e;
|
259
|
}
|
260
|
}
|
261
|
|
262
|
@Override
|
263
|
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
264
|
try {
|
265
|
String subject = "OpenAIRE content provider registration request - results (success) for " +
|
266
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
267
|
|
268
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
269
|
String message = "Dear user,\n" +
|
270
|
"\n" +
|
271
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
272
|
" was successful and the datasource type \""+ repository.getDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
|
273
|
"\n\n" +
|
274
|
"Please note that it usually takes about 3-4 weeks until a data source is indexed and it’s metadata visible on openaire.eu.\n\n" +
|
275
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
276
|
"\nOfficial Name:" + repository.getOfficialName() +
|
277
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
278
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
279
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
280
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
281
|
"\n\n\nPlease do not reply to this email\n"+
|
282
|
"This message has been generated manually\n\n"+
|
283
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
284
|
"Regards,\n" +
|
285
|
"the OpenAIRE technical team\n";
|
286
|
|
287
|
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
|
288
|
|
289
|
} catch (Exception e) {
|
290
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
291
|
throw e;
|
292
|
}
|
293
|
}
|
294
|
|
295
|
@Override
|
296
|
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
297
|
try {
|
298
|
String subject = "OpenAIRE content provider registration request - results (success) for " +
|
299
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
300
|
|
301
|
String message = "Dear admin ,\n" +
|
302
|
"\n" +
|
303
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
304
|
" was successful and the datasource type \""+ repository.getDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
|
305
|
"\n\n" +
|
306
|
"Please note that it usually takes about 3-4 weeks until a data source is indexed and it’s metadata visible on openaire.eu.\n\n" +
|
307
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
308
|
"\nOfficial Name:" + repository.getOfficialName() +
|
309
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
310
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
311
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
312
|
"\n\nUser Contact:"+ issuerEmail +""+
|
313
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
314
|
"\n\n\nPlease do not reply to this email\n"+
|
315
|
"This message has been generated manually\n\n"+
|
316
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
317
|
"Regards,\n" +
|
318
|
"the OpenAIRE technical team\n";
|
319
|
|
320
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
321
|
|
322
|
} catch (Exception e) {
|
323
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
324
|
throw e;
|
325
|
}
|
326
|
}
|
327
|
|
328
|
@Override
|
329
|
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
330
|
try {
|
331
|
String subject = "OpenAIRE content provider registration request - results (failure) for " +
|
332
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
333
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
334
|
String message = "Dear user,\n" +
|
335
|
"\n" +
|
336
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
337
|
" was not successful and the registration process was interrupted."+
|
338
|
"\n\n" +
|
339
|
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
|
340
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
341
|
"\nOfficial Name:" + repository.getOfficialName() +
|
342
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
343
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
344
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
345
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
346
|
"\n\n\nPlease do not reply to this email\n"+
|
347
|
"This message has been generated manually\n\n"+
|
348
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
349
|
"Regards,\n" +
|
350
|
"the OpenAIRE technical team\n";
|
351
|
|
352
|
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
|
353
|
|
354
|
} catch (Exception e) {
|
355
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
356
|
throw e;
|
357
|
}
|
358
|
}
|
359
|
|
360
|
@Override
|
361
|
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
362
|
try {
|
363
|
String subject = "OpenAIRE content provider registration request - results (failure) for " +
|
364
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
365
|
|
366
|
String message = "Dear admin,\n" +
|
367
|
"\n" +
|
368
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
369
|
" was not successful and the registration process was interrupted."+
|
370
|
"\n\n" +
|
371
|
"We will check what caused the problem and get back to you within a couple of days.\n\n" +
|
372
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
373
|
"\nOfficial Name:" + repository.getOfficialName() +
|
374
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
375
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
376
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
377
|
"\n\nUser Contact:"+ issuerEmail +""+
|
378
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
379
|
"\n\n\nPlease do not reply to this email\n"+
|
380
|
"This message has been generated manually\n\n"+
|
381
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
382
|
"Regards,\n" +
|
383
|
"the OpenAIRE technical team\n";
|
384
|
|
385
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
386
|
|
387
|
} catch (Exception e) {
|
388
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
389
|
throw e;
|
390
|
}
|
391
|
}
|
392
|
|
393
|
@Override
|
394
|
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
395
|
try {
|
396
|
String subject = "OpenAIRE content provider registration request - results (success) for " +
|
397
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
398
|
|
399
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
400
|
String message = "Dear user,\n" +
|
401
|
"\n" +
|
402
|
"the compatibility test on [" + repository.getEnglishName()+"] has been successful\n\n" +
|
403
|
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
|
404
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
405
|
"\nOfficial Name:" + repository.getOfficialName() +
|
406
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
407
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
408
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
409
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
410
|
"\n\n\nPlease do not reply to this email\n"+
|
411
|
"This message has been generated manually\n\n"+
|
412
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
413
|
"Regards,\n" +
|
414
|
"the OpenAIRE technical team\n";
|
415
|
|
416
|
this.sendMail(issuer, subject, message, false, null);
|
417
|
|
418
|
} catch (Exception e) {
|
419
|
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
420
|
throw e;
|
421
|
}
|
422
|
}
|
423
|
|
424
|
@Override
|
425
|
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
426
|
try {
|
427
|
String subject = "OpenAIRE content provider registration request - results (success) for " +
|
428
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
429
|
|
430
|
String message = "Dear admin,\n" +
|
431
|
"\n" +
|
432
|
"the compatibility test on [" + repository.getEnglishName()+"] has been successful\n\n" +
|
433
|
"We will check your transmitted information and adjust the aggregation settings accordingly. Please note that it usually takes about 3-4 weeks until the changes are visible on openaire.eu."+"\n\n" +
|
434
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
435
|
"\nOfficial Name:" + repository.getOfficialName() +
|
436
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
437
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
438
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
439
|
"\n\nUser Contact:"+ issuerEmail +""+
|
440
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
441
|
"\n\n\nPlease do not reply to this email\n"+
|
442
|
"This message has been generated manually\n\n"+
|
443
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
444
|
"Regards,\n" +
|
445
|
"the OpenAIRE technical team\n";
|
446
|
|
447
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
448
|
|
449
|
} catch (Exception e) {
|
450
|
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
451
|
throw e;
|
452
|
}
|
453
|
}
|
454
|
|
455
|
@Override
|
456
|
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
457
|
try {
|
458
|
String subject = "OpenAIRE content provider update request - results (failure) for " +
|
459
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
460
|
|
461
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
462
|
String message = "Dear user,\n" +
|
463
|
"\n" +
|
464
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
465
|
" was not successful."+
|
466
|
"\n\n" +
|
467
|
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
|
468
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
469
|
"\nOfficial Name:" + repository.getOfficialName() +
|
470
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
471
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
472
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
473
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
474
|
"\n\n\nPlease do not reply to this email\n"+
|
475
|
"This message has been generated manually\n\n"+
|
476
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
477
|
"Regards,\n" +
|
478
|
"the OpenAIRE technical team\n";
|
479
|
|
480
|
this.sendMail(issuer, subject, message, false, null);
|
481
|
|
482
|
} catch (Exception e) {
|
483
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
484
|
throw e;
|
485
|
}
|
486
|
}
|
487
|
|
488
|
@Override
|
489
|
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
490
|
try {
|
491
|
String subject = "OpenAIRE content provider update request - results (failure) for " +
|
492
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
493
|
|
494
|
String message = "Dear admin,\n" +
|
495
|
"\n" +
|
496
|
"the compatibility test on " + "[" + repository.getEnglishName() + "]" +
|
497
|
" was not successful."+
|
498
|
"\n\n" +
|
499
|
"WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days.\n\n" +
|
500
|
"Registration identifier in OpenAIRE: "+ repository.getNamespacePrefix()+
|
501
|
"\nOfficial Name:" + repository.getOfficialName() +
|
502
|
"\n\nBase URL: "+ repositoryInterface.getBaseUrl() +
|
503
|
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
|
504
|
"\n\nGuidelines: "+ repositoryInterface.getDesiredCompatibilityLevel() +
|
505
|
"\n\nUser Contact:"+ issuerEmail +""+
|
506
|
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
|
507
|
"\n\n\nPlease do not reply to this email\n"+
|
508
|
"This message has been generated manually\n\n"+
|
509
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
510
|
"Regards,\n" +
|
511
|
"the OpenAIRE technical team\n";
|
512
|
|
513
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
514
|
|
515
|
} catch (Exception e) {
|
516
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
517
|
throw e;
|
518
|
}
|
519
|
}
|
520
|
|
521
|
@Override
|
522
|
public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
523
|
try {
|
524
|
String subject = "OpenAIRE validator - Test results ";
|
525
|
|
526
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
527
|
String message = "Dear user,\n" +
|
528
|
"\n" +
|
529
|
"the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
|
530
|
"Please do not reply to this message.\n" +
|
531
|
"This message has been generated automatically.\n" +
|
532
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
533
|
"Regards,\n" +
|
534
|
"the OpenAIRE technical team\n";
|
535
|
|
536
|
this.sendMail(issuer, subject, message, false, null);
|
537
|
|
538
|
} catch (Exception e) {
|
539
|
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
540
|
throw e;
|
541
|
}
|
542
|
}
|
543
|
|
544
|
@Override
|
545
|
public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
546
|
try {
|
547
|
String subject = "OpenAIRE validator - Test results ";
|
548
|
|
549
|
String message = "Dear admin,\n" +
|
550
|
"\n" +
|
551
|
"the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
|
552
|
"\n\nUser Contact:"+ issuer +""+
|
553
|
"Please do not reply to this message.\n" +
|
554
|
"This message has been generated automatically.\n" +
|
555
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
556
|
"Regards,\n" +
|
557
|
"the OpenAIRE technical team\n";
|
558
|
|
559
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
560
|
|
561
|
} catch (Exception e) {
|
562
|
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
563
|
throw e;
|
564
|
}
|
565
|
}
|
566
|
|
567
|
@Override
|
568
|
public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
|
569
|
try {
|
570
|
String subject = "OpenAIRE validator - job failure";
|
571
|
|
572
|
String message = "Dear admin,\n" +
|
573
|
"\n" +
|
574
|
"the validation job that was automatically submitted for the update/registration of the interface "+repositoryInterface.getId()+" ("+repositoryInterface.getBaseUrl()+", "+repositoryInterface.getAccessSet()+") of the repository "+repository.getId()+" ("+repository.getOfficialName()+") failed to complete." +
|
575
|
"This message has been generated automatically.\n\n" +
|
576
|
"Regards,\n" +
|
577
|
"the OpenAIRE technical team\n";
|
578
|
|
579
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
580
|
|
581
|
} catch (Exception e) {
|
582
|
LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e);
|
583
|
throw e;
|
584
|
}
|
585
|
}
|
586
|
|
587
|
@Override
|
588
|
public void sendAdminUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
|
589
|
try {
|
590
|
String subject = "OpenAIRE content provider update request started for " +
|
591
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
592
|
|
593
|
String message = "Dear administrator" + ",\n" +
|
594
|
"\n" +
|
595
|
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
|
596
|
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
|
597
|
"Please do not reply to this message\n" +
|
598
|
"This message has been generated automatically.\n\n" +
|
599
|
"Regards,\n" +
|
600
|
"the OpenAIRE technical team\n";
|
601
|
|
602
|
this.sendMail(this.provideAdminEmail, subject, message, false, null);
|
603
|
|
604
|
} catch (Exception e) {
|
605
|
LOGGER.error("Error while sending registration notification email to the administrator", e);
|
606
|
throw e;
|
607
|
}
|
608
|
}
|
609
|
|
610
|
@Override
|
611
|
public void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
|
612
|
try {
|
613
|
String subject = "OpenAIRE content provider update request started for " +
|
614
|
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
|
615
|
|
616
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
617
|
String message = "Dear user,\n" +
|
618
|
"\n" +
|
619
|
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
|
620
|
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
|
621
|
"Please do not reply to this message\n" +
|
622
|
"This message has been generated automatically.\n\n" +
|
623
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
624
|
"Regards,\n" +
|
625
|
"the OpenAIRE technical team\n";
|
626
|
|
627
|
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
|
628
|
|
629
|
} catch (Exception e) {
|
630
|
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
|
631
|
throw e;
|
632
|
}
|
633
|
}
|
634
|
|
635
|
@Override
|
636
|
public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception {
|
637
|
try {
|
638
|
String subject = "OpenAIRE validator - Test submission ";
|
639
|
|
640
|
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
|
641
|
String message = "Dear user,\n" +
|
642
|
"\n" +
|
643
|
"The validation request you have submitted has started.\n" +
|
644
|
"Please do not reply to this message.\n" +
|
645
|
"This message has been generated automatically.\n" +
|
646
|
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
|
647
|
"Regards,\n" +
|
648
|
"the OpenAIRE technical team\n";
|
649
|
|
650
|
this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null);
|
651
|
|
652
|
} catch (Exception e) {
|
653
|
LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
|
654
|
throw e;
|
655
|
}
|
656
|
}
|
657
|
|
658
|
@Override
|
659
|
public void sendUponJobCompletion(
|
660
|
String repoId,
|
661
|
String repoInterfaceId,
|
662
|
int scoreUsage,
|
663
|
int scoreContent,
|
664
|
boolean isSuccess,
|
665
|
boolean isUpdate,
|
666
|
String issuerEmail,
|
667
|
String jobId) throws Exception {
|
668
|
List<RepositoryInterface> repositoryInterfaces = repositoryService.getRepositoryInterface(repoId);
|
669
|
if(repositoryInterfaces.size()==0)
|
670
|
throw new ValidationServiceException("Repository interface with id \""+repoInterfaceId+"\" not found",ValidationServiceException.ErrorCode.GENERAL_ERROR);
|
671
|
|
672
|
RepositoryInterface repositoryInterface = repositoryInterfaces.stream().filter( repoInterface -> repoInterface.getId().equals(repoInterfaceId)).collect(Collectors.toList()).get(0);
|
673
|
Repository repository = repositoryService.getRepositoryById(repoId);
|
674
|
|
675
|
if(!isUpdate){
|
676
|
if(isSuccess){
|
677
|
if(scoreContent>=50 && scoreUsage >= 50){
|
678
|
this.sendUserRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
679
|
this.sendAdminRegistrationResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
|
680
|
}else{
|
681
|
this.sendUserRegistrationResultsFailureEmail(jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
682
|
this.sendAdminRegistrationResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
|
683
|
}
|
684
|
}else{
|
685
|
this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
|
686
|
}
|
687
|
}else{
|
688
|
if(isSuccess){
|
689
|
if(scoreContent>=50 && scoreUsage >= 50){
|
690
|
this.sendUserUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
691
|
this.sendAdminUpdateResultsSuccessEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
692
|
}else{
|
693
|
this.sendUserUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
694
|
this.sendAdminUpdateResultsFailureEmail(issuerEmail,jobId,repositoryInterface,repository, SecurityContextHolder.getContext().getAuthentication());
|
695
|
}
|
696
|
}else{
|
697
|
this.sendAdminGeneralFailure(issuerEmail,jobId,repositoryInterface,repository,SecurityContextHolder.getContext().getAuthentication());
|
698
|
}
|
699
|
}
|
700
|
|
701
|
}
|
702
|
|
703
|
|
704
|
private void sendMail(String email, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
|
705
|
ArrayList<String> to = new ArrayList<String>();
|
706
|
to.add(email);
|
707
|
this.sendMail(to,subject,message,sendToSpecial,repoAdminMails);
|
708
|
}
|
709
|
|
710
|
public void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
|
711
|
|
712
|
try {
|
713
|
if (sendToSpecial) {
|
714
|
recipients.addAll(this.specialRecipients);
|
715
|
}
|
716
|
|
717
|
if (repoAdminMails != null)
|
718
|
recipients.addAll(repoAdminMails);
|
719
|
|
720
|
if (this.override) {
|
721
|
recipients.clear();
|
722
|
recipients.add(overrideEmail);
|
723
|
}
|
724
|
if (!logonly)
|
725
|
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
|
726
|
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
|
727
|
} catch (Exception e) {
|
728
|
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
|
729
|
throw new Exception(e);
|
730
|
}
|
731
|
}
|
732
|
|
733
|
private String getEmailProperty(String key) {
|
734
|
return pLoader.getProperties().getProperty(key);
|
735
|
}
|
736
|
|
737
|
public void setSpecialRecipients(String specialRecipients) {
|
738
|
String[] recps = specialRecipients.split(",");
|
739
|
|
740
|
for (String recp : recps) {
|
741
|
recp = recp.trim();
|
742
|
|
743
|
this.specialRecipients.add(recp);
|
744
|
}
|
745
|
}
|
746
|
|
747
|
|
748
|
public void setOverride(boolean override) {
|
749
|
this.override = override;
|
750
|
}
|
751
|
|
752
|
public void setOverrideEmail(String overrideEmail) {
|
753
|
this.overrideEmail = overrideEmail;
|
754
|
}
|
755
|
|
756
|
public String getFrom() {
|
757
|
return from;
|
758
|
}
|
759
|
|
760
|
public void setFrom(String from) {
|
761
|
this.from = from;
|
762
|
}
|
763
|
|
764
|
public boolean isLogonly() {
|
765
|
return logonly;
|
766
|
}
|
767
|
|
768
|
public void setLogonly(boolean logonly) {
|
769
|
this.logonly = logonly;
|
770
|
}
|
771
|
|
772
|
}
|