2019-02-16 11:04:41 +01:00
package eu.dnetlib.repo.manager.service ;
import eu.dnetlib.domain.data.PiwikInfo ;
import eu.dnetlib.domain.data.Repository ;
2019-09-04 14:21:53 +02:00
import eu.dnetlib.domain.data.RepositoryInterface ;
2019-02-16 11:04:41 +01:00
import eu.dnetlib.domain.functionality.validator.JobForValidation ;
2019-11-28 12:25:56 +01:00
import eu.dnetlib.repo.manager.domain.ValidationServiceException ;
2019-02-16 11:04:41 +01:00
import eu.dnetlib.utils.MailLibrary ;
import org.apache.log4j.Logger ;
2019-12-18 14:11:36 +01:00
import org.mitre.openid.connect.model.OIDCAuthenticationToken ;
2019-02-16 11:04:41 +01:00
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.security.core.Authentication ;
2019-09-04 14:21:53 +02:00
import org.springframework.security.core.context.SecurityContextHolder ;
2019-02-16 11:04:41 +01:00
import org.springframework.stereotype.Component ;
2021-10-22 13:32:44 +02:00
import java.util.Collections ;
2019-02-16 11:04:41 +01:00
import java.util.List ;
2019-09-04 14:21:53 +02:00
import java.util.stream.Collectors ;
2019-02-16 11:04:41 +01:00
@Component ( " emailUtils " )
public class EmailUtilsImpl implements EmailUtils {
2021-10-22 13:32:44 +02:00
private final static Logger LOGGER = Logger . getLogger ( EmailUtilsImpl . class ) ;
2019-02-16 11:04:41 +01:00
2021-07-21 13:51:18 +02:00
private final MailLibrary mailLibrary ;
private final RepositoryService repositoryService ;
2019-02-16 11:04:41 +01:00
2021-10-22 13:32:44 +02:00
@Value ( " ${services.repomanager.baseUrl} " )
2019-02-16 11:04:41 +01:00
private String baseUrl ;
@Value ( " ${services.repomanager.usagestats.adminEmail} " )
private String usageStatsAdminEmail ;
2021-10-22 13:32:44 +02:00
@Value ( " ${services.repomanager.provide.adminEmail} " )
2019-07-19 11:31:23 +02:00
private String provideAdminEmail ;
2019-09-04 14:21:53 +02:00
@Value ( " ${validator.results.url} " )
private String valBaseUrl ;
@Autowired
2021-10-22 13:32:44 +02:00
EmailUtilsImpl ( MailLibrary mailLibrary , RepositoryService repositoryService ) {
2021-07-21 13:51:18 +02:00
this . mailLibrary = mailLibrary ;
this . repositoryService = repositoryService ;
}
2019-09-04 14:21:53 +02:00
2019-02-16 11:04:41 +01:00
@Override
public void sendAdministratorRequestToEnableMetrics ( PiwikInfo piwikInfo ) throws Exception {
try {
String subject = " [OpenAIRE-Usage Statistics] New request to enable usage statistics " ;
String message = " Dear administrator, \ n " +
" \ n " +
" 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 " +
" Requestor - " + piwikInfo . getRequestorName ( ) + " , " + piwikInfo . getRequestorEmail ( ) + " \ n " +
2019-12-16 15:13:33 +01:00
" Matomo ID - " + piwikInfo . getSiteId ( ) + " \ n " +
2019-02-16 11:04:41 +01:00
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . usageStatsAdminEmail , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending request to enable metrics email to administrator: " + this . usageStatsAdminEmail , e ) ;
throw e ;
}
}
@Override
public void sendUserRequestToEnableMetrics ( PiwikInfo piwikInfo ) throws Exception {
try {
String subject = " [OpenAIRE-Usage Statistics] Your request to enable usage statistics " ;
String message = " Dear " + piwikInfo . getRequestorName ( ) + " , \ n " +
" \ n " +
" we have received your request to enable the OpenAIRE usage statistics for your repository \ n " +
" \ n " +
" Repository - " + piwikInfo . getRepositoryName ( ) + " , " + piwikInfo . getCountry ( ) + " ( " + piwikInfo . getRepositoryId ( ) + " ) \ n " +
2019-12-16 15:13:33 +01:00
" Matomo ID - " + piwikInfo . getSiteId ( ) + " \ n " +
2019-02-16 11:04:41 +01:00
" Authentication token - " + piwikInfo . getAuthenticationToken ( ) + " \ n " +
" \ n " +
" In order to enable the usage statistics, you must install the OpenAIRE's tracking code in your repository software. " +
" OpenAIRE's usage statistics service tracking code is maintained on Github as a patch for various versions of DSpace " +
" (https://github.com/openaire/OpenAIRE-Piwik-DSpace) and as an Eprints plugin for version 3 " +
" (https://github.com/openaire/EPrints-OAPiwik). In case the platform is different from DSpace or EPrints please contact " +
" the OpenAIRE team in repositoryusagestats@openaire.eu in order to find a solution. \ n " +
" \ n " +
" For more information about your request and configuration details, go here: \ n " +
this . baseUrl + " /getImpact/instructions/ " + piwikInfo . getRepositoryId ( ) + " \ n " +
" \ n " +
" Once you have finished configuring your repository or if you have any questions, please notify the OpenAIRE team by sending \ n " +
" an email to repositoryusagestats@openaire.eu \ n " +
" \ n " +
" Best, \ n " +
" The OpenAIRE team " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( piwikInfo . getRequestorEmail ( ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending request to enable metrics email to user: " + piwikInfo . getRequestorEmail ( ) , e ) ;
throw e ;
}
}
@Override
public void sendAdministratorMetricsEnabled ( PiwikInfo piwikInfo ) throws Exception {
try {
String subject = " [OpenAIRE-Usage Statistics] Usage statistics have been enabled " ;
String message = " Dear administrator, \ n " +
" \ n " +
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . usageStatsAdminEmail , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending metrics enabled notification email to administator: " + this . usageStatsAdminEmail , e ) ;
throw e ;
}
}
@Override
public void sendUserMetricsEnabled ( PiwikInfo piwikInfo ) throws Exception {
try {
String subject = " [OpenAIRE-Usage Statistics] Usage statistics have been enabled " ;
String message = " Dear " + piwikInfo . getRequestorName ( ) + " , \ n " +
" \ n " +
" The installation and configuration of OpenAIRE's tracking code for your repository \" " + piwikInfo . getRepositoryName ( ) +
" \" has been completed and validated and the usage statistics have been enabled in OpenAIRE. \ n " +
" \ n " +
" You can preview the statistics in your repository's dashboard: \ n " +
this . baseUrl + " /getImpact/ " + piwikInfo . getRepositoryId ( ) + " \ n " +
" \ n " +
" For more information and questions, you can contact the openaire support team by sending an email to " +
" repositoryusagestats@openaire.eu \ n " +
" \ n " +
" Best, \ n " +
" The OpenAIRE team " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( piwikInfo . getRequestorEmail ( ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending metrics enabled notification email to user: " + piwikInfo . getRequestorEmail ( ) , e ) ;
throw e ;
}
}
@Override
2019-07-19 11:31:23 +02:00
public void sendAdminRegistrationEmail ( Repository repository , Authentication authentication ) throws Exception {
2019-02-16 11:04:41 +01:00
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE content provider registration for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-02-16 11:04:41 +01:00
2019-07-19 11:31:23 +02:00
String message = " Dear administrator " + " , \ n " +
2019-02-16 11:04:41 +01:00
" \ n " +
2021-07-21 13:51:18 +02:00
" We received a request to register the " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " +
2019-07-19 11:31:23 +02:00
" to the OpenAIRE compliant list of content providers. " +
2019-12-18 14:11:36 +01:00
" \ n \ n " +
" User Contact: " + authentication . getName ( ) + " ( " + ( ( OIDCAuthenticationToken ) authentication ) . getUserInfo ( ) . getEmail ( ) + " ) " +
2019-07-19 11:31:23 +02:00
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-07-19 11:31:23 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to the administrator " , e ) ;
throw e ;
}
}
@Override
public void sendUserRegistrationEmail ( Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE content provider registration for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-07-19 11:31:23 +02:00
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
2019-09-26 13:09:24 +02:00
String message = " Dear " + SecurityContextHolder . getContext ( ) . getAuthentication ( ) . getName ( ) + " , \ n " +
2019-02-16 11:04:41 +01:00
" \ n " +
2021-07-21 13:51:18 +02:00
" We received a request to register the " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " +
2019-07-19 11:31:23 +02:00
" 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 " +
2019-02-16 11:04:41 +01:00
" If you have any questions, write to 'helpdesk@openaire.eu'. \ n \ n " +
" Regards, \ n " +
" the OpenAIRE technical team \ n " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
2019-12-18 14:11:36 +01:00
@Override
2020-07-29 13:35:35 +02:00
public void sendAdminRegisterInterfaceEmail ( Repository repository , String comment , RepositoryInterface repositoryInterface , Authentication authentication ) throws Exception {
2019-12-18 14:11:36 +01:00
try {
String subject = " OpenAIRE new interface registration request started for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-12-18 14:11:36 +01:00
String message = " Dear administrator " + " , \ n " +
" \ n " +
" We received a request to add the following interface: \ n \ n " +
" Base URL: " + repositoryInterface . getBaseUrl ( ) + " \ n " +
" Set: " + repositoryInterface . getAccessSet ( ) + " \ n " +
" Guidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) + " \ n \ n " +
2021-07-21 13:51:18 +02:00
" to " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n " ;
2020-07-29 13:35:35 +02:00
if ( comment ! = null )
2020-10-01 12:58:31 +02:00
message + = " \ nThe users comment was ' " + comment + " ' \ n " ;
2020-07-29 13:35:35 +02:00
message + = " A validation process for this interface against the OpenAIRE guidelines compatibility " +
2019-12-18 14:11:36 +01:00
" has been started. You will be informed in another message once the process is finished. " +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-12-18 14:11:36 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration of interface notification email to the administrator " , e ) ;
throw e ;
}
}
@Override
2020-07-29 13:35:35 +02:00
public void sendUserRegisterInterfaceEmail ( Repository repository , String comment , RepositoryInterface repositoryInterface , Authentication authentication ) throws Exception {
2019-12-18 14:11:36 +01:00
try {
String subject = " OpenAIRE new interface registration request started for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2020-07-30 13:49:24 +02:00
2019-12-18 14:11:36 +01:00
String message = " Dear " + SecurityContextHolder . getContext ( ) . getAuthentication ( ) . getName ( ) + " , \ n " +
" \ n " +
" We received a request to add the following interface: \ n \ n " +
" Base URL: " + repositoryInterface . getBaseUrl ( ) + " \ n " +
" Set: " + repositoryInterface . getAccessSet ( ) + " \ n " +
" Guidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) + " \ n \ n " +
2021-07-21 13:51:18 +02:00
" to " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n " ;
2020-07-29 13:35:35 +02:00
if ( comment ! = null ) {
2020-10-01 12:58:31 +02:00
message + = " \ n Your comment was ' " + comment + " ' \ n " ;
2020-07-29 13:35:35 +02:00
}
message + = " A validation process for this interface against the OpenAIRE guidelines compatibility " +
2019-12-18 14:11:36 +01:00
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-12-18 14:11:36 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration of interface notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
2019-09-04 14:21:53 +02:00
@Override
public void sendUserRegistrationResultsSuccessEmail ( String issuerEmail , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE new interface registration request - results (success) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was successful and the datasource type \" " + repository . getDatasourceType ( ) + " \" will be prepared for aggregation in OpenAIRE. " +
" \ n \ n " +
" 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 " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendAdminRegistrationResultsSuccessEmail ( String issuerEmail , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE new interface registration request - results (success) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
String message = " Dear admin , \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was successful and the datasource type \" " + repository . getDatasourceType ( ) + " \" will be prepared for aggregation in OpenAIRE. " +
" \ n \ n " +
" 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 " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ n \ nUser Contact: " + issuerEmail + " " +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendUserRegistrationResultsFailureEmail ( String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE new interface registration request - results (failure) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was not successful and the registration process was interrupted. " +
" \ n \ n " +
" We will check what caused the problem and get back to you within a couple of days. \ n \ n " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendAdminRegistrationResultsFailureEmail ( String issuerEmail , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE new interface registration request - results (failure) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
String message = " Dear admin, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was not successful and the registration process was interrupted. " +
" \ n \ n " +
" We will check what caused the problem and get back to you within a couple of days. \ n \ n " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ n \ nUser Contact: " + issuerEmail + " " +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendUserUpdateResultsSuccessEmail ( String issuer , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE interface update request - results (success) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on [ " + repository . getOfficialName ( ) + " ] has been successful \ n \ n " +
2019-09-04 14:21:53 +02:00
" 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 ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( issuer , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to the administrator " , e ) ;
throw e ;
}
}
@Override
public void sendAdminUpdateResultsSuccessEmail ( String issuerEmail , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE interface update request - results (success) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
String message = " Dear admin, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on [ " + repository . getOfficialName ( ) + " ] has been successful \ n \ n " +
2019-09-04 14:21:53 +02:00
" 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 ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ n \ nUser Contact: " + issuerEmail + " " +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to the administrator " , e ) ;
throw e ;
}
}
@Override
public void sendUserUpdateResultsFailureEmail ( String issuer , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE interface update request - results (failure) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was not successful. " +
" \ n \ n " +
" WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days. \ n \ n " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( issuer , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendAdminUpdateResultsFailureEmail ( String issuerEmail , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE interface update request - results (failure) for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-09-04 14:21:53 +02:00
String message = " Dear admin, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" the compatibility test on " + " [ " + repository . getOfficialName ( ) + " ] " +
2019-09-04 14:21:53 +02:00
" was not successful. " +
" \ n \ n " +
" WWe will check your transmitted information to see what caused the problem and get back to you within a couple of days. \ n \ n " +
" Registration identifier in OpenAIRE: " + repository . getNamespacePrefix ( ) +
" \ nOfficial Name: " + repository . getOfficialName ( ) +
" \ n \ nBase URL: " + repositoryInterface . getBaseUrl ( ) +
" \ n \ nValidation Set: " + repositoryInterface . getAccessSet ( ) +
" \ n \ nGuidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) +
" \ n \ nUser Contact: " + issuerEmail + " " +
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendUserValidationResults ( String issuer , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
String subject = " OpenAIRE validator - Test results " ;
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( issuer , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending validation submission notification email to user: " + issuer , e ) ;
throw e ;
}
}
@Override
public void sendAdminValidationResults ( String issuer , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
String subject = " OpenAIRE validator - Test results " ;
String message = " Dear admin, \ n " +
" \ n " +
2019-12-18 14:11:36 +01:00
" a validation request has finished. You can retrieve the results by following this url: " + valBaseUrl + " " + jobId + " . \ n \ n " +
2019-09-04 14:21:53 +02:00
" \ 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending validation submission notification email to user: " + issuer , e ) ;
throw e ;
}
}
@Override
public void sendAdminGeneralFailure ( String issuer , String jobId , RepositoryInterface repositoryInterface , Repository repository , Authentication authentication ) throws Exception {
try {
String subject = " OpenAIRE validator - job failure " ;
String message = " Dear admin, \ n " +
" \ n " +
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-09-04 14:21:53 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending validation submission notification email to user: " + issuer , e ) ;
throw e ;
}
}
2019-07-19 11:31:23 +02:00
@Override
2019-12-18 14:11:36 +01:00
public void sendAdminUpdateRepositoryInfoEmail ( Repository repository , Authentication authentication ) throws Exception {
2019-07-19 11:31:23 +02:00
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE content provider update information for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-07-19 11:31:23 +02:00
String message = " Dear administrator " + " , \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" We received a request to update the basic information for " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n \ n " +
2019-12-18 14:11:36 +01:00
" Please do not reply to this message \ n " +
" This message has been generated automatically. \ n \ n " +
" Regards, \ n " +
" the OpenAIRE technical team \ n " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-12-18 14:11:36 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to the administrator " , e ) ;
throw e ;
}
}
@Override
public void sendUserUpdateRepositoryInfoEmail ( Repository repository , Authentication authentication ) throws Exception {
try {
String subject = " OpenAIRE content provider update information for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-12-18 14:11:36 +01:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
" \ n " +
2021-07-21 13:51:18 +02:00
" We received a request to update the basic information for " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n \ n " +
2019-12-18 14:11:36 +01:00
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-12-18 14:11:36 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
2020-07-29 13:35:35 +02:00
public void sendAdminUpdateInterfaceEmail ( Repository repository , String comment , RepositoryInterface repositoryInterface , Authentication authentication ) throws Exception {
2019-12-18 14:11:36 +01:00
try {
String subject = " OpenAIRE interface update request started for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-12-18 14:11:36 +01:00
String message = " Dear administrator " + " , \ n " +
" \ n " +
" We received a request to update the following interface: \ n \ n " +
" Base URL: " + repositoryInterface . getBaseUrl ( ) + " \ n " +
" Set: " + repositoryInterface . getAccessSet ( ) + " \ n " +
" Guidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) + " \ n \ n " +
2021-07-21 13:51:18 +02:00
" for " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n " ;
2020-07-29 13:35:35 +02:00
if ( comment ! = null )
2020-10-01 12:58:31 +02:00
message + = " \ nThe users comment was ' " + comment + " ' \ n " ;
2020-07-29 13:35:35 +02:00
message + = " A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started. \ n \ n " +
2019-12-18 14:11:36 +01:00
" User Contact: " + authentication . getName ( ) + " ( " + ( ( OIDCAuthenticationToken ) authentication ) . getUserInfo ( ) . getEmail ( ) + " ) " +
" \ n \ n " +
2019-07-19 11:31:23 +02:00
" Please do not reply to this message \ n " +
" This message has been generated automatically. \ n \ n " +
" Regards, \ n " +
" the OpenAIRE technical team \ n " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( this . provideAdminEmail , subject , message ) ;
2019-07-19 11:31:23 +02:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to the administrator " , e ) ;
throw e ;
}
}
2019-02-16 11:04:41 +01:00
@Override
2020-07-29 13:35:35 +02:00
public void sendUserUpdateInterfaceEmail ( Repository repository , String comment , RepositoryInterface repositoryInterface , Authentication authentication ) throws Exception {
2019-02-16 11:04:41 +01:00
try {
2019-12-18 14:11:36 +01:00
String subject = " OpenAIRE interface update request started for " +
2021-07-21 13:51:18 +02:00
repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ] " ;
2019-02-16 11:04:41 +01:00
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
2019-02-16 11:04:41 +01:00
" \ n " +
2019-12-18 14:11:36 +01:00
" We received a request to update the following interface: \ n \ n " +
" Base URL: " + repositoryInterface . getBaseUrl ( ) + " \ n " +
" Set: " + repositoryInterface . getAccessSet ( ) + " \ n " +
" Guidelines: " + repositoryInterface . getDesiredCompatibilityLevel ( ) + " \ n \ n " +
2021-07-21 13:51:18 +02:00
" for " + repository . getDatasourceType ( ) + " [ " + repository . getOfficialName ( ) + " ]. \ n " ;
2020-07-29 13:35:35 +02:00
if ( comment ! = null ) {
2020-10-01 12:58:31 +02:00
message + = " \ n Your comment was ' " + comment + " ' \ n " ;
2020-07-29 13:35:35 +02:00
}
message + = " A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started. \ n \ n " +
2019-07-19 11:31:23 +02:00
" Please do not reply to this message \ n " +
" This message has been generated automatically. \ n \ n " +
2019-02-16 11:04:41 +01:00
" If you have any questions, write to 'helpdesk@openaire.eu'. \ n \ n " +
" Regards, \ n " +
" the OpenAIRE technical team \ n " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( repository . getRegisteredBy ( ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending registration notification email to user: " + repository . getRegisteredBy ( ) , e ) ;
throw e ;
}
}
@Override
public void sendSubmitJobForValidationEmail ( Authentication authentication , JobForValidation jobForValidation ) throws Exception {
try {
String subject = " OpenAIRE validator - Test submission " ;
2019-09-04 14:21:53 +02:00
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = " Dear user, \ n " +
2019-02-16 11:04:41 +01:00
" \ n " +
" 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 " ;
2021-10-22 13:32:44 +02:00
this . sendMail ( jobForValidation . getUserEmail ( ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error while sending validation submission notification email to user: " + jobForValidation . getUserEmail ( ) , e ) ;
throw e ;
}
}
2019-09-04 14:21:53 +02:00
@Override
public void sendUponJobCompletion (
String repoId ,
String repoInterfaceId ,
int scoreUsage ,
int scoreContent ,
boolean isSuccess ,
boolean isUpdate ,
String issuerEmail ,
String jobId ) throws Exception {
List < RepositoryInterface > repositoryInterfaces = repositoryService . getRepositoryInterface ( repoId ) ;
if ( repositoryInterfaces . size ( ) = = 0 )
throw new ValidationServiceException ( " Repository interface with id \" " + repoInterfaceId + " \" not found " , ValidationServiceException . ErrorCode . GENERAL_ERROR ) ;
RepositoryInterface repositoryInterface = repositoryInterfaces . stream ( ) . filter ( repoInterface - > repoInterface . getId ( ) . equals ( repoInterfaceId ) ) . collect ( Collectors . toList ( ) ) . get ( 0 ) ;
Repository repository = repositoryService . getRepositoryById ( repoId ) ;
if ( ! isUpdate ) {
if ( isSuccess ) {
if ( scoreContent > = 50 & & scoreUsage > = 50 ) {
this . sendUserRegistrationResultsSuccessEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
this . sendAdminRegistrationResultsSuccessEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
} else {
this . sendUserRegistrationResultsFailureEmail ( jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
this . sendAdminRegistrationResultsFailureEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
}
} else {
this . sendAdminGeneralFailure ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
}
} else {
if ( isSuccess ) {
if ( scoreContent > = 50 & & scoreUsage > = 50 ) {
this . sendUserUpdateResultsSuccessEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
this . sendAdminUpdateResultsSuccessEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
} else {
this . sendUserUpdateResultsFailureEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
this . sendAdminUpdateResultsFailureEmail ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
}
} else {
this . sendAdminGeneralFailure ( issuerEmail , jobId , repositoryInterface , repository , SecurityContextHolder . getContext ( ) . getAuthentication ( ) ) ;
}
}
}
2021-10-22 13:32:44 +02:00
private void sendMail ( String email , String subject , String message ) throws Exception {
this . sendMail ( Collections . singletonList ( email ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
}
2021-10-22 13:32:44 +02:00
public void sendMail ( List < String > recipients , String subject , String message ) throws Exception {
2019-02-16 11:04:41 +01:00
try {
LOGGER . debug ( " Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message ) ;
2021-10-22 13:32:44 +02:00
mailLibrary . sendEmail ( recipients . toArray ( new String [ ] { } ) , subject , message ) ;
2019-02-16 11:04:41 +01:00
} catch ( Exception e ) {
LOGGER . error ( " Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message , e ) ;
2021-10-22 13:32:44 +02:00
throw e ;
2019-02-16 11:04:41 +01:00
}
}
}