1. refactored method signatures
2. used desired compatibility level for 'Guidelines' field in emails
3. enabled async error logs
This commit is contained in:
Konstantinos Spyrou 2023-01-30 18:56:34 +02:00
parent de2ac5631f
commit d3bcea79c0
8 changed files with 94 additions and 89 deletions

View File

@ -20,7 +20,7 @@ public class AsyncConfiguration implements AsyncConfigurer {
@Override
public void handleUncaughtException(Throwable throwable, Method method, Object... objects) {
//logger.error("Async error", throwable);
logger.error("Async error", throwable);
}
};
}

View File

@ -26,7 +26,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -63,7 +62,7 @@ public class RepositoryController {
@ResponseBody
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
@PathVariable("mode") String mode,
@RequestParam(value = "managed", required = false) Boolean managed) throws JSONException, IOException {
@RequestParam(value = "managed", required = false) Boolean managed) {
return repositoryService.getRepositoriesByCountry(country, mode, managed);
}
@ -83,7 +82,7 @@ public class RepositoryController {
public void updateRepositoriesTerms(@RequestBody List<RepositoryTerms> repositoriesTerms) throws Exception {
Date date = new Date();
if (repositoriesTerms != null) {
for (RepositoryTerms terms : repositoriesTerms) {
for (RepositoryTerms terms : repositoriesTerms) {
Repository repository = repositoryService.getRepositoryById(terms.getId());
repository.setConsentTermsOfUse(terms.getConsentTermsOfUse());
repository.setFullTextDownload(terms.getFullTextDownload());
@ -104,7 +103,7 @@ public class RepositoryController {
@RequestParam("requestSortBy") String requestSortBy,
@RequestParam("order") String order,
@PathVariable("page") int page,
@PathVariable("size") int pageSize) throws Exception {
@PathVariable("size") int pageSize) {
return repositoryService.searchRegisteredRepositories(country, typology, englishName, officialName, requestSortBy, order, page, pageSize);
}
@ -113,13 +112,13 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PostAuthorize("hasAnyAuthority('SUPER_ADMINISTRATOR', 'CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id) or (returnObject.registeredby==null and hasAuthority('REGISTERED_USER'))")
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException, ResourceNotFoundException {
public Repository getRepositoryById(@PathVariable("id") String id) throws ResourceNotFoundException {
Repository repo = repositoryService.getRepositoryById(id);
if (repo != null)
logger.info("Returning repository " + repo.getId() + " registered by " + repo.getRegisteredby());
logger.info("Returning repository {} registered by {}", repo.getId(), repo.getRegisteredby());
else
logger.info("Requested repository " + id + " not found");
logger.info("Requested repository {} not found", id);
return repo;
}
@ -142,7 +141,7 @@ public class RepositoryController {
@ResponseBody
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
@PathVariable("size") String size) {
return repositoryService.getRepositoriesByName(name, page, size);
}
@ -150,7 +149,7 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PostAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id) or (@repositoryService.getRepositoryById(#id).registeredby==null and hasAuthority('REGISTERED_USER'))")
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) {
return repositoryService.getRepositoryInterface(id);
}
@ -160,7 +159,7 @@ public class RepositoryController {
// @PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or (hasAuthority(@authorizationService.convertRepoIdToRoleId(#repository.id)) or hasAuthority(@authorizationService.convertRepoIdToRoleId(returnObject.id)))")
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or hasAuthority('REGISTERED_USER')")
public Repository addRepository(@RequestParam("datatype") String datatype,
@RequestBody Repository repository) throws Exception {
@RequestBody Repository repository) {
return repositoryService.addRepository(datatype, repository);
}
@ -193,7 +192,7 @@ public class RepositoryController {
consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#repository.id)")
public Repository updateRepository(@RequestBody Repository repository, Authentication authentication) throws Exception {
public Repository updateRepository(@RequestBody Repository repository, Authentication authentication) {
return repositoryService.updateRepository(repository, authentication);
}
@ -261,7 +260,7 @@ public class RepositoryController {
@RequestMapping(value = "/getListLatestUpdate/{mode}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) {
return repositoryService.getListLatestUpdate(mode);
}

View File

@ -32,38 +32,38 @@ public interface EmailUtils {
void sendUserRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
@Async
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
/****FAILURE REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
/****SUCCESSFUL UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
/****FAILURE UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication);
/****FAILURE UPDATE INTERFACE COMPLIANCE****/
@Async
@ -91,10 +91,10 @@ public interface EmailUtils {
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
@Async
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication);
@Async
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation);
@ -102,6 +102,7 @@ public interface EmailUtils {
@Async
void sendUponJobCompletion(String repoId,
String repoInterfaceId,
String compatibility,
int scoreUsage,
int scoreContent,
boolean isSuccess,

View File

@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
@ -21,6 +22,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Component("emailUtils")
@Async
public class EmailUtilsImpl implements EmailUtils {
private final static Logger logger = LoggerFactory.getLogger(EmailUtilsImpl.class);
@ -203,7 +205,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -212,7 +214,7 @@ public class EmailUtilsImpl implements EmailUtils {
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null)
@ -235,7 +237,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -243,7 +245,7 @@ public class EmailUtilsImpl implements EmailUtils {
"We received a request to add the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" +
"to " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null) {
@ -265,7 +267,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -279,7 +281,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -294,7 +296,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -308,7 +310,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nDesired Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -324,7 +326,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -337,7 +339,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -352,7 +354,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -366,7 +368,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -382,7 +384,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -394,7 +396,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -409,7 +411,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -421,7 +423,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -437,7 +439,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -451,7 +453,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -466,7 +468,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, String desiredCompatibility, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -480,7 +482,7 @@ public class EmailUtilsImpl implements EmailUtils {
"\nOfficial Name:" + repository.getOfficialname() +
"\n\nBase URL: " + repositoryInterface.getBaseurl() +
"\n\nValidation Set: " + repositoryInterface.getAccessSet() +
"\n\nGuidelines: " + repositoryInterface.getCompatibilityOverride() +
"\n\nGuidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() +
"\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" +
@ -596,8 +598,11 @@ public class EmailUtilsImpl implements EmailUtils {
String subject = "OpenAIRE validator - job failure";
String message =
"the validation job that was automatically submitted for the update/registration of the interface " + repositoryInterface.getId() + " (" + repositoryInterface.getBaseurl() + ", " + repositoryInterface.getAccessSet() + ") of the repository " + repository.getId() + " (" + repository.getOfficialname() + ") failed to complete." +
"This message has been generated automatically.";
"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.";
message = createAdminMail(message);
this.sendMail(this.provideAdminEmail, subject, message);
@ -614,7 +619,8 @@ public class EmailUtilsImpl implements EmailUtils {
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
String message =
"We received a request to update the basic information for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n\n" +
"We received a request to update the basic information for " + repository.getEoscDatasourceType()
+ "[" + repository.getOfficialname() + "].\n\n" +
"Please do not reply to this message\n" +
"This message has been generated automatically.";
message = createAdminMail(message);
@ -647,7 +653,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -656,7 +662,7 @@ public class EmailUtilsImpl implements EmailUtils {
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null)
@ -677,7 +683,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, String desiredCompatibility, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -686,7 +692,7 @@ public class EmailUtilsImpl implements EmailUtils {
"We received a request to update the following interface: \n\n" +
"Base URL: " + repositoryInterface.getBaseurl() + "\n" +
"Set: " + repositoryInterface.getAccessSet() + "\n" +
"Guidelines: " + repositoryInterface.getCompatibilityOverride() + "\n\n" +
"Guidelines: " + desiredCompatibility != null ? desiredCompatibility : repositoryInterface.getCompatibility() + "\n\n" +
"for " + repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "].\n";
if (comment != null) {
@ -729,6 +735,7 @@ public class EmailUtilsImpl implements EmailUtils {
public void sendUponJobCompletion(
String repoId,
String repoInterfaceId,
String compatibility,
int scoreUsage,
int scoreContent,
boolean isSuccess,
@ -745,11 +752,11 @@ public class EmailUtilsImpl implements EmailUtils {
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());
this.sendUserRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendUserRegistrationResultsFailureEmail(jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendUserRegistrationResultsFailureEmail(jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminRegistrationResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
}
} else {
this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
@ -757,11 +764,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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());
this.sendUserUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsSuccessEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
} else {
this.sendUserUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendUserUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
this.sendAdminUpdateResultsFailureEmail(issuerEmail, jobId, repositoryInterface, compatibility, repository, SecurityContextHolder.getContext().getAuthentication());
}
} else {
this.sendAdminGeneralFailure(issuerEmail, jobId, repositoryInterface, repository, SecurityContextHolder.getContext().getAuthentication());

View File

@ -6,7 +6,6 @@ import eu.dnetlib.repo.manager.exception.ResourceConflictException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.repository.InterfaceComplianceRequestsRepository;
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
@ -50,7 +49,7 @@ public class InterfaceComplianceService {
List<User> repositoryAdmins = authorizationService.getAdminsOfRepo(request.getRepositoryId());
emailUtils.sendUserUpdateInterfaceComplianceFailure(repositoryAdmins.stream().map(User::getEmail).collect(Collectors.toList()), repo, iFace, request);
emailUtils.sendAdminUpdateInterfaceComplianceFailure(repo, iFace, request);
} catch (JSONException | ResourceNotFoundException e) {
} catch (ResourceNotFoundException e) {
logger.error("Error", e);
}
}

View File

@ -16,15 +16,15 @@ public interface RepositoryService {
// TODO: move this elsewhere
Country[] getCountries();
List<Repository> getRepositories(List<String> ids) throws JSONException;
List<Repository> getRepositories(List<String> ids);
List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException;
List<Repository> getRepositories(List<String> ids, int page, int size);
List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) throws Exception;
List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception;
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed);
// TODO: remove?
List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException, IOException;
@ -38,23 +38,23 @@ public interface RepositoryService {
List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception;
RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException;
RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException;
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
Repository getRepositoryById(String id) throws ResourceNotFoundException;
List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException;
String size);
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order,
int page, int pageSize) throws Exception;
int page, int pageSize);
Integer getTotalRegisteredRepositories();
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
List<RepositoryInterface> getRepositoryInterface(String id);
Repository addRepository(String datatype, Repository repository) throws Exception;
Repository addRepository(String datatype, Repository repository);
void deleteRepositoryInterface(String id, String registeredBy);
@ -70,7 +70,7 @@ public interface RepositoryService {
List<Timezone> getTimezones();
Repository updateRepository(Repository repository, Authentication authentication) throws Exception;
Repository updateRepository(Repository repository, Authentication authentication);
List<String> getUrlsOfUserRepos(String user_email,
String page,

View File

@ -21,7 +21,6 @@ import eu.dnetlib.repo.manager.utils.Converter;
import eu.dnetlib.repo.manager.utils.DateUtils;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import org.apache.commons.codec.digest.DigestUtils;
import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -40,7 +39,6 @@ import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -92,7 +90,6 @@ public class RepositoryServiceImpl implements RepositoryService {
VocabularyLoader vocabularyLoader,
RestTemplate restTemplate,
ObjectMapper objectMapper,
// Converter converter,
@Lazy EmailUtils emailUtils,
@Lazy ValidatorService validatorService,
@Lazy PiWikService piWikService,
@ -161,7 +158,7 @@ public class RepositoryServiceImpl implements RepositoryService {
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
// another way for paging must be implemented.
@Override
public List<Repository> getRepositories(List<String> ids) throws JSONException {
public List<Repository> getRepositories(List<String> ids) {
return getRepositories(ids, 0, 10);
}
@ -233,7 +230,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<RepositorySnippet> getRepositoriesByCountry(String country,
String mode,
Boolean managed) throws IOException {
Boolean managed) {
logger.debug("Getting repositories by country!");
int page = 0;
int size = 100;
@ -256,7 +253,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
String officialName, String requestSortBy, String order, int page, int pageSize) {
logger.debug("Searching registered repositories");
@ -289,7 +286,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
public List<Repository> getRepositoriesOfUser(String page, String size) {
logger.debug("Retrieving repositories of authenticated user : {}",
((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail());
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
@ -297,7 +294,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) {
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail));
return getRepositories(new ArrayList<>(repoIds));
@ -363,7 +360,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositoriesByName(String name,
String page,
String size) throws JSONException {
String size) {
logger.debug("Retrieving repositories with official name : {}", name);
UriComponents uriComponents = searchDatasourceUri("0", "100");
@ -402,7 +399,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public Repository addRepository(String datatype, Repository repository) throws Exception {
public Repository addRepository(String datatype, Repository repository) {
logger.debug("storing '{}' repository with id: {}", datatype, repository.getId());
@ -486,7 +483,7 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
public Repository updateRepository(Repository repository, Authentication authentication) {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/update/")
.build()
@ -507,7 +504,7 @@ public class RepositoryServiceImpl implements RepositoryService {
return repository;
}
private void storeRepository(Repository repository, Authentication authentication) throws Exception {
private void storeRepository(Repository repository, Authentication authentication) {
Date utilDate = new Date();
Timestamp date = new Timestamp(utilDate.getTime());
@ -564,8 +561,8 @@ public class RepositoryServiceImpl implements RepositoryService {
// Explicitly update validation set (updating the interface does not allow updating the set value)
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
@ -593,8 +590,8 @@ public class RepositoryServiceImpl implements RepositoryService {
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);

View File

@ -310,10 +310,11 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public void onComplete(String repoId, String interfaceId, String jobId, String issuerEmail, boolean isUpdate, boolean isSuccess, int scoreUsage, int scoreContent) throws Exception {
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
InterfaceComplianceRequestId requestId = InterfaceComplianceRequestId.of(repoId, interfaceId);
Optional<InterfaceComplianceRequest> request = interfaceComplianceService.getById(requestId);
String compatibility = null;
if (request.isPresent()) {
compatibility = request.get().getDesiredCompatibilityLevel();
logger.info("Changing compatibility level. Request: {}", request);
if (scoreContent > 50) {
@ -321,6 +322,7 @@ public class ValidatorServiceImpl implements ValidatorService {
}
interfaceComplianceService.delete(requestId);
}
emailUtils.sendUponJobCompletion(repoId,interfaceId,compatibility,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
}
}