More thorought implementation for the email notifications when registering/updating repositories

This commit is contained in:
Stefania Martziou 2019-12-18 13:11:36 +00:00
parent 6edd5ffca7
commit 61fec177ef
4 changed files with 170 additions and 31 deletions

View File

@ -24,6 +24,10 @@ public interface EmailUtils {
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
@ -53,9 +57,13 @@ public interface EmailUtils {
void sendAdminGeneralFailure(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;

View File

@ -8,6 +8,7 @@ import eu.dnetlib.repo.manager.config.CascadingPropertyLoader;
import eu.dnetlib.repo.manager.domain.ValidationServiceException;
import eu.dnetlib.utils.MailLibrary;
import org.apache.log4j.Logger;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.Authentication;
@ -205,15 +206,15 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request started for " +
String subject = "OpenAIRE content provider registration for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"A validation process against the OpenAIRE guidelines compatibility " +
"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" +
@ -231,7 +232,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request started for " +
String subject = "OpenAIRE content provider registration for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
@ -239,8 +240,6 @@ public class EmailUtilsImpl implements EmailUtils {
"\n" +
"We received a request to register the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]" +
" to the OpenAIRE compliant list of content providers. " +
"A validation process against the OpenAIRE guidelines compatibility " +
"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" +
@ -256,10 +255,71 @@ public class EmailUtilsImpl implements EmailUtils {
}
}
@Override
public void sendAdminRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
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" +
"to " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n" +
"A validation process for this interface against the OpenAIRE guidelines compatibility " +
"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";
this.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration of interface notification email to the administrator", e);
throw e;
}
}
@Override
public void sendUserRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
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" +
"to " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n" +
"A validation process for this interface against the OpenAIRE guidelines compatibility " +
"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.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredBy(), e);
throw e;
}
}
@Override
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (success) for " +
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
@ -292,7 +352,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (success) for " +
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear admin ,\n" +
@ -325,7 +385,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (failure) for " +
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
@ -357,7 +417,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (failure) for " +
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear admin,\n" +
@ -390,7 +450,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (success) for " +
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
@ -421,7 +481,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider registration request - results (success) for " +
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear admin,\n" +
@ -452,7 +512,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request - results (failure) for " +
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
@ -485,7 +545,7 @@ public class EmailUtilsImpl implements EmailUtils {
@Override
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request - results (failure) for " +
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear admin,\n" +
@ -545,7 +605,7 @@ public class EmailUtilsImpl implements EmailUtils {
String message = "Dear admin,\n" +
"\n" +
"the validation request you have submitted has finished. You can retrieve the results by following this url: "+ valBaseUrl+"" + jobId+" .\n\n" +
"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" +
@ -582,15 +642,14 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request started for " +
String subject = "OpenAIRE content provider update information for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
String message = "Dear administrator" + ",\n" +
"\n" +
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\n\n" +
"We received a request to update the basic information for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.\n\n" +
"Regards,\n" +
@ -605,15 +664,72 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserUpdateRepositoryEmail(Repository repository, Authentication authentication) throws Exception {
public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE content provider update request started for " +
String subject = "OpenAIRE content provider update information for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\n" +
"\n" +
"We received a request to update the " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "]." +
"We received a request to update the basic information for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\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";
this.sendMail(repository.getRegisteredBy(), subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e);
throw e;
}
}
@Override
public void sendAdminUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
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" +
"for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n" +
"A new iteration process of the validation against the OpenAIRE guidelines compatibility has been started.\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.sendMail(this.provideAdminEmail, subject, message, false, null);
} catch (Exception e) {
LOGGER.error("Error while sending registration notification email to the administrator", e);
throw e;
}
}
@Override
public void sendUserUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
// String message = "Dear " + ((OIDCAuthenticationToken) authentication).getUserInfo().getName() + ",\n" +
String message = "Dear user,\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" +
"for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n" +
"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" +

View File

@ -48,7 +48,7 @@ public interface RepositoryService {
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface iFace) throws JSONException, ResourceNotFoundException, ValidatorServiceException;
RepositoryInterface iFace) throws Exception;
List<String> getDnetCountries();

View File

@ -500,8 +500,8 @@ public class RepositoryServiceImpl implements RepositoryService {
, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendUserUpdateRepositoryEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryEmail(repository, authentication);
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} else
LOGGER.debug(responseEntity.getBody().toString());
@ -552,7 +552,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface repositoryInterface) throws JSONException, ResourceNotFoundException, ValidatorServiceException {
RepositoryInterface repositoryInterface) throws Exception {
try {
Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
@ -564,10 +564,20 @@ public class RepositoryServiceImpl implements RepositoryService {
.encode();
HttpEntity<String> httpEntity = new HttpEntity <> (json_interface,httpHeaders);
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
submitInterfaceValidation(e, registeredBy, repositoryInterface, false);
return repositoryInterface;
ResponseEntity responseEntity = restTemplate.postForObject(uriComponents.toUri(),httpEntity,ResponseEntity.class);
if(responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendAdminRegisterInterfaceEmail(e, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
emailUtils.sendUserRegisterInterfaceEmail(e, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
submitInterfaceValidation(e, registeredBy, repositoryInterface, false);
return repositoryInterface;
} else {
LOGGER.debug(responseEntity.getBody().toString());
throw new Exception("Registering" + baseAddress + " returned " + responseEntity.getStatusCode());
}
} catch (JSONException | ValidatorServiceException e) {
LOGGER.debug("Exception on addRepositoryInterface" , e);
@ -584,7 +594,12 @@ public class RepositoryServiceImpl implements RepositoryService {
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
Repository e = this.getRepositoryById(repoId);
emailUtils.sendAdminUpdateInterfaceEmail(e, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
emailUtils.sendUserUpdateInterfaceEmail(e, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
submitInterfaceValidation(getRepositoryById(repoId),registeredBy,repositoryInterface,true);
return repositoryInterface;
}