refactored mails

This commit is contained in:
Konstantinos Spyrou 2022-11-09 16:16:54 +00:00
parent ee01491995
commit cff16a2d7c
1 changed files with 91 additions and 125 deletions

View File

@ -50,8 +50,7 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
String message = "Dear administrator,\n" +
"\n" +
String message =
"we have received a request to enable the OpenAIRE usage statistics for the following repository \n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
@ -60,10 +59,8 @@ public class EmailUtilsImpl implements EmailUtils {
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"For more information about this request, go here: \n" +
this.baseUrl + "/admin/metrics\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
this.baseUrl + "/admin/metrics";
message = createAdminMail(message);
this.sendMail(this.usageStatsAdminEmail, subject, message);
@ -116,18 +113,15 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
String message = "Dear administrator,\n" +
"\n" +
String message =
"The installation and configuration of OpenAIRE's tracking code for the following repository " +
"has been completed and validated and the usage statistics have been enabled in OpenAIRE.\n" +
"\n" +
"Repository - " + piwikInfo.getRepositoryName() + ", " + piwikInfo.getCountry() + " (" + piwikInfo.getRepositoryId() + ")\n" +
"Requestor - " + piwikInfo.getRequestorName() + ", " + piwikInfo.getRequestorEmail() + "\n" +
"Piwik ID - " + piwikInfo.getSiteId() + "\n" +
"Authentication token - " + piwikInfo.getAuthenticationToken() + "\n" +
"\n" +
"Best,\n" +
"The OpenAIRE team";
"Authentication token - " + piwikInfo.getAuthenticationToken();
message = createAdminMail(message);
this.sendMail(this.usageStatsAdminEmail, subject, message);
@ -154,7 +148,7 @@ public class EmailUtilsImpl implements EmailUtils {
" For more information and questions, you can contact the openaire support team by sending an email to " +
"repositoryusagestats@openaire.eu\n" +
"\n" +
"Best,\n" +
"Best Regards,\n" +
"The OpenAIRE team";
this.sendMail(piwikInfo.getRequestorEmail(), subject, message);
@ -171,17 +165,15 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
String message =
"We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -197,17 +189,14 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear "+SecurityContextHolder.getContext().getAuthentication().getName()+",\n" +
"\n" +
String message =
"We received a request to register the " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -223,8 +212,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
String message =
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
@ -240,9 +228,8 @@ public class EmailUtilsImpl implements EmailUtils {
"User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -257,9 +244,7 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear "+SecurityContextHolder.getContext().getAuthentication().getName()+",\n" +
"\n" +
String message =
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
@ -274,9 +259,8 @@ public class EmailUtilsImpl implements EmailUtils {
"has been started. You will be informed in another message once the process is finished." +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -292,9 +276,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was successful and the datasource type \""+ repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
"\n\n" +
@ -307,9 +289,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -325,8 +306,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear admin ,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was successful and the datasource type \""+ repository.getEoscDatasourceType() + "\" will be prepared for aggregation in OpenAIRE."+
"\n\n" +
@ -340,9 +320,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -357,9 +336,7 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful and the registration process was interrupted."+
"\n\n" +
@ -372,9 +349,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -390,8 +366,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear admin,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful and the registration process was interrupted."+
"\n\n" +
@ -405,9 +380,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -423,9 +397,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"the compatibility test on [" + repository.getOfficialname()+"] has been successful\n\n" +
"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" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
@ -436,9 +408,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
@ -454,8 +425,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear admin,\n" +
"\n" +
String message =
"the compatibility test on [" + repository.getOfficialname()+"] has been successful\n\n" +
"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" +
"Registration identifier in OpenAIRE: "+ repository.getNamespaceprefix()+
@ -467,9 +437,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -485,9 +454,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful."+
"\n\n" +
@ -500,9 +467,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
@ -518,8 +484,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear admin,\n" +
"\n" +
String message =
"the compatibility test on " + "[" + repository.getOfficialname() + "]" +
" was not successful."+
"\n\n" +
@ -533,9 +498,8 @@ public class EmailUtilsImpl implements EmailUtils {
"\n\nYou can review the validation results here.\n" + valBaseUrl + "" + jobId +
"\n\n\nPlease do not reply to this email\n"+
"This message has been generated manually\n\n"+
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -550,15 +514,12 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE validator - Test results ";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(issuer, subject, message);
@ -573,15 +534,13 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE validator - Test results ";
String message = "Dear admin,\n" +
"\n" +
String message =
"a validation request has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
"\n\nUser Contact:"+ issuer +""+
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -596,12 +555,10 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE validator - job failure";
String message = "Dear admin,\n" +
"\n" +
String message =
"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." +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -617,13 +574,11 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
String message =
"We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -639,15 +594,12 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -663,8 +615,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
String message =
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
@ -678,9 +629,8 @@ public class EmailUtilsImpl implements EmailUtils {
"User Contact: " + authentication.getName() + " (" + ((OIDCAuthenticationToken) authentication).getUserInfo().getEmail() + ")" +
"\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"This message has been generated automatically.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -696,9 +646,7 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
@ -712,9 +660,8 @@ public class EmailUtilsImpl implements EmailUtils {
message += "A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message);
@ -729,15 +676,12 @@ public class EmailUtilsImpl implements EmailUtils {
try {
String subject = "OpenAIRE validator - Test submission ";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
String message =
"The validation request you have submitted has started.\n" +
"Please do not reply to this message.\n" +
"This message has been generated automatically.\n" +
"If you have any questions, write to 'helpdesk@openaire.eu'. \n\n" +
"Regards,\n" +
"the OpenAIRE technical team\n";
"If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication);
this.sendMail(jobForValidation.getUserEmail(), subject, message);
@ -798,11 +742,33 @@ public class EmailUtilsImpl implements EmailUtils {
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
try {
LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
LOGGER.debug("Sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message);
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
} catch (Exception e) {
LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
LOGGER.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
throw e;
}
}
private String createAdminMail(String body) {
body = "Dear administrator,\n\n" + body;
body += "\n\nBest Regards,\nthe OpenAIRE technical team\n";
return body;
}
private String createUserMail(String body, Authentication authentication) {
body = "Dear " + getUserName(authentication) + ",\n\n" + body;
body += "\n\nBest Regards,\nthe OpenAIRE technical team\n";
return body;
}
private String getUserName(Authentication authentication) {
String user = "user";
if (authentication != null) {
try {
user = ((OIDCAuthenticationToken) authentication).getUserInfo().getName();
} catch (NullPointerException ex) {}
}
return user;
}
}