diff --git a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java index fd04871..e9e6817 100644 --- a/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java +++ b/src/main/java/eu/dnetlib/repo/manager/controllers/RepositoryController.java @@ -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); } } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java index accec82..63efbec 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java @@ -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; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index 0355d7f..e506dbb 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -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" + diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java index b989039..ea630e0 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryService.java @@ -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 getDnetCountries(); @@ -74,6 +73,6 @@ public interface RepositoryService { Map 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; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index cf77ab3..9b10f54 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -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;