added the option to send emails to users

This commit is contained in:
Antonis Lempesis 2020-07-29 11:35:35 +00:00
parent b91330455d
commit 2e9657cb61
5 changed files with 48 additions and 30 deletions

View File

@ -170,8 +170,9 @@ public class RepositoryController {
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestParam("comment") String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.addRepositoryInterface(datatype, repoId, registeredBy, repositoryInterface);
return repositoryService.addRepositoryInterface(datatype, repoId, registeredBy, comment, repositoryInterface);
}
@RequestMapping(value = "/getUrlsOfUserRepos/{page}/{size}/",method = RequestMethod.GET,
@ -226,7 +227,8 @@ public class RepositoryController {
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_PROVIDE_ADMIN') or ((@repositoryService.getRepositoryById(#repoId).registeredBy==authentication.userInfo.email or @repositoryService.getRepositoryById(#repoId).registeredBy=='null') and hasRole('ROLE_USER'))")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestParam("comment") String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.updateRepositoryInterface(repoId, registeredBy, repositoryInterface);
return repositoryService.updateRepositoryInterface(repoId, registeredBy, comment, repositoryInterface);
}
}

View File

@ -24,9 +24,9 @@ public interface EmailUtils {
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
@ -61,9 +61,9 @@ public interface EmailUtils {
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;

View File

@ -256,7 +256,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
@ -267,8 +267,12 @@ public class EmailUtilsImpl implements EmailUtils {
"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 " +
"to " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n";
if (comment != null)
comment += "\nThe users comment was '" + comment + "'\n";
message += "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() + ")" +
@ -287,20 +291,24 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserRegisterInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, 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 " +
"to " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n";
if (comment != null) {
comment += "\n Your comment was '" + comment + "'\n";
}
message += "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" +
@ -688,7 +696,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
@ -699,8 +707,12 @@ public class EmailUtilsImpl implements EmailUtils {
"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" +
"for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n";
if (comment != null)
comment += "\nThe users comment was '" + comment + "'\n";
message += "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" +
@ -717,7 +729,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserUpdateInterfaceEmail(Repository repository, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getDatasourceType() + "[" + repository.getEnglishName() + "]";
@ -729,8 +741,13 @@ public class EmailUtilsImpl implements EmailUtils {
"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" +
"for " + repository.getDatasourceType() + "[" + repository.getEnglishName() + "].\n";
if (comment != null) {
comment += "\n Your comment was '" + comment + "'\n";
}
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" +

View File

@ -1,6 +1,5 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.*;
@ -48,7 +47,7 @@ public interface RepositoryService {
RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface iFace) throws Exception;
String comment, RepositoryInterface repositoryInterface) throws Exception;
List<String> getDnetCountries();
@ -74,6 +73,6 @@ public interface RepositoryService {
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
RepositoryInterface updateRepositoryInterface(String repositoryId, String registeredBy, RepositoryInterface repositoryInterface) throws Exception;
RepositoryInterface updateRepositoryInterface(String repoId, String registeredBy, String comment, RepositoryInterface repositoryInterface) throws Exception;
}

View File

@ -552,7 +552,7 @@ public class RepositoryServiceImpl implements RepositoryService {
public RepositoryInterface addRepositoryInterface(String datatype,
String repoId,
String registeredBy,
RepositoryInterface repositoryInterface) throws Exception {
String comment, RepositoryInterface repositoryInterface) throws Exception {
try {
Repository e = this.getRepositoryById(repoId);
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
@ -568,9 +568,9 @@ public class RepositoryServiceImpl implements RepositoryService {
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());
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
submitInterfaceValidation(e, registeredBy, repositoryInterface, false);
return repositoryInterface;
@ -589,15 +589,15 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositoryInterface updateRepositoryInterface(String repoId,
String registeredBy,
RepositoryInterface repositoryInterface) throws Exception {
String comment, RepositoryInterface repositoryInterface) throws Exception {
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());
emailUtils.sendAdminUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
emailUtils.sendUserUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
submitInterfaceValidation(getRepositoryById(repoId),registeredBy,repositoryInterface,true);
return repositoryInterface;