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