1. removed exceptions from emails

2. changed update repository interface
3. wip: after validation completes change interface compliance
This commit is contained in:
Konstantinos Spyrou 2023-01-13 18:06:30 +02:00
parent 720ee5a9a4
commit e947fe3fec
8 changed files with 132 additions and 163 deletions

View File

@ -220,9 +220,10 @@ public class RepositoryController {
@ResponseBody
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOf(#id)")
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String id,
@RequestParam(required = false, name = "desiredCompatibilityLevel") String desiredCompatibilityLevel,
@RequestParam(value = "comment", required = false) String comment,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
return repositoryService.updateRepositoryInterface(id, comment, repositoryInterface);
return repositoryService.updateRepositoryInterface(id, comment, repositoryInterface, desiredCompatibilityLevel);
}
@RequestMapping(value = "/getUrlsOfUserRepos/{page}/{size}/", method = RequestMethod.GET,

View File

@ -112,8 +112,8 @@ public class ValidatorController {
@RequestMapping(value = "/complete" , method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void validationCompleted(
@RequestParam(value = "interfaceId") String interfaceId,
@RequestParam(value = "repoId") String repoId,
@RequestParam(value = "interfaceId") String interfaceId,
@RequestParam(value = "jobId") String jobId,
@RequestParam(value = "issuerEmail") String issuerEmail,
@RequestParam(value = "isUpdate") boolean isUpdate,
@ -121,7 +121,7 @@ public class ValidatorController {
@RequestParam(value = "scoreUsage") int scoreUsage,
@RequestParam(value = "scoreContent") int scoreContent) throws Exception {
emailUtils.sendUponJobCompletion(repoId,interfaceId,scoreUsage,scoreContent,isSuccess,isUpdate,issuerEmail, jobId);
validatorService.onComplete(repoId, interfaceId, jobId, issuerEmail, isUpdate, isSuccess, scoreUsage, scoreContent);
}

View File

@ -10,84 +10,84 @@ import org.springframework.security.core.Authentication;
public interface EmailUtils {
@Async
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo);
@Async
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception;
void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo);
@Async
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo);
@Async
void sendUserMetricsEnabled(PiwikInfo piwikInfo) throws Exception;
void sendUserMetricsEnabled(PiwikInfo piwikInfo);
/****USER REGISTRATION REQUEST EMAILS****/
@Async
void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendUserRegistrationEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationEmail(Repository repository, Authentication authentication);
@Async
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
/****SUCCESSFUL REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE REGISTRATION RESULTS EMAILS****/
@Async
void sendUserRegistrationResultsFailureEmail(String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserRegistrationResultsFailureEmail(String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****SUCCESSFUL UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateResultsSuccessEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****FAILURE UPDATE RESULTS EMAILS****/
@Async
void sendUserUpdateResultsFailureEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateResultsFailureEmail(String issuer, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****VALIDATION OF CONTENT PROVIDER EMAILS****/
@Async
void sendUserValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendUserValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminValidationResults(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
/****GENERAL FAILURE OF VALIDATOR****/
@Async
void sendAdminGeneralFailure(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) throws Exception;
void sendAdminGeneralFailure(String issuer,String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication);
@Async
void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception;
void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication);
@Async
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception;
void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication);
@Async
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) throws Exception;
void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation);
@Async
void sendUponJobCompletion(String repoId,

View File

@ -46,7 +46,7 @@ public class EmailUtilsImpl implements EmailUtils {
}
@Override
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception {
public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] New request to enable usage statistics";
@ -67,12 +67,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Your request to enable usage statistics";
@ -104,12 +103,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdministratorMetricsEnabled(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
@ -128,12 +126,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserMetricsEnabled(PiwikInfo piwikInfo) {
try {
String subject = "[OpenAIRE-Usage Statistics] Usage statistics have been enabled";
@ -156,12 +153,11 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e);
throw e;
}
}
@Override
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) throws Exception {
public void sendAdminRegistrationEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -180,12 +176,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserRegistrationEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider registration for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -203,12 +198,11 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
}
}
@Override
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -236,12 +230,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserRegisterInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -267,12 +260,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserRegistrationResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -297,12 +289,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminRegistrationResultsSuccessEmail(String issuerEmail, String jobId,RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -328,12 +319,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserRegistrationResultsFailureEmail(String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -357,12 +347,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminRegistrationResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE new interface registration request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -388,12 +377,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserUpdateResultsSuccessEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -416,12 +404,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminUpdateResultsSuccessEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (success) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -445,12 +432,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserUpdateResultsFailureEmail(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -475,12 +461,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminUpdateResultsFailureEmail(String issuerEmail, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request - results (failure) for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -506,12 +491,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - Test results ";
@ -526,12 +510,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminValidationResults(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - Test results ";
@ -547,12 +530,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendAdminGeneralFailure(String issuer, String jobId, RepositoryInterface repositoryInterface, Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE validator - job failure";
@ -565,12 +547,11 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending validation submission notification email to user: " + issuer, e);
throw e;
}
}
@Override
public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) throws Exception {
public void sendAdminUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -585,12 +566,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendUserUpdateRepositoryInfoEmail(Repository repository, Authentication authentication) {
try {
String subject = "OpenAIRE content provider update information for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -606,12 +586,11 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
throw e;
}
}
@Override
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendAdminUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -637,12 +616,11 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending registration notification email to the administrator", e);
throw e;
}
}
@Override
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) throws Exception {
public void sendUserUpdateInterfaceEmail(Repository repository, String comment, RepositoryInterface repositoryInterface, Authentication authentication) {
try {
String subject = "OpenAIRE interface update request started for " +
repository.getEoscDatasourceType() + "[" + repository.getOfficialname() + "]";
@ -668,12 +646,11 @@ public class EmailUtilsImpl implements EmailUtils {
} 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 {
public void sendSubmitJobForValidationEmail(Authentication authentication, JobForValidation jobForValidation) {
try {
String subject = "OpenAIRE validator - Test submission ";
@ -688,7 +665,6 @@ public class EmailUtilsImpl implements EmailUtils {
} catch (Exception e) {
logger.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e);
throw e;
}
}
@ -703,7 +679,7 @@ public class EmailUtilsImpl implements EmailUtils {
String issuerEmail,
String jobId) throws Exception {
List<RepositoryInterface> repositoryInterfaces = repositoryService.getRepositoryInterface(repoId);
if(repositoryInterfaces.size()==0)
if(repositoryInterfaces.isEmpty())
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);
@ -737,17 +713,16 @@ public class EmailUtilsImpl implements EmailUtils {
}
private void sendMail(String email, String subject, String message) throws Exception {
private void sendMail(String email, String subject, String message) {
this.sendMail(Collections.singletonList(email), subject, message);
}
public void sendMail(List<String> recipients, String subject, String message) throws Exception {
public void sendMail(List<String> recipients, String subject, String message) {
try {
logger.debug("Sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message);
logger.debug("Sending e-mail\nRecipients: {}\nSubject: {}\nMessage: {}", recipients, subject, message);
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);
} catch (Exception e) {
logger.error("Error sending e-mail\nRecipients: " + recipients + "\nSubject: " + subject + "\nMessage: " + message, e);
throw e;
}
}

View File

@ -5,6 +5,8 @@ import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import org.json.JSONException;
import org.springframework.security.core.Authentication;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.io.IOException;
import java.util.List;
@ -84,6 +86,7 @@ public interface RepositoryService {
Map<String, String> getListLatestUpdate(String mode) throws JSONException;
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface) throws Exception;
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception;
void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance);
}

View File

@ -21,11 +21,11 @@ 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.slf4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -175,7 +175,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
List<Repository> repos = new ArrayList<>();
logger.debug("Retrieving repositories with ids : " + String.join(", ", ids));
logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids));
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
RequestFilter requestFilter = new RequestFilter();
@ -224,7 +224,7 @@ public class RepositoryServiceImpl implements RepositoryService {
throw e;
}
logger.debug("resultSet:" + resultSet);
logger.debug("resultSet: {}", resultSet);
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
@ -250,7 +250,7 @@ public class RepositoryServiceImpl implements RepositoryService {
filterKey = "CRIS system";
logger.debug("Country code equals : " + country + " | Filter mode equals : " + filterKey);
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
@ -290,7 +290,7 @@ public class RepositoryServiceImpl implements RepositoryService {
try {
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
if (rs == null) {
logger.error(String.format("DSM response is null : [url=%s]", uriComponents.toUri()));
logger.error("DSM response is null : [url={}]", uriComponents.toUri());
} else {
JSONObject response = new JSONObject(rs);
JSONArray jsonArray = (JSONArray) response.get("datasourceInfo");
@ -334,7 +334,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
logger.debug("Retrieving repositories of authenticated user : " + userEmail);
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRolesByEmail(userEmail));
return getRepositories(new ArrayList<>(repoIds));
}
@ -366,7 +366,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
logger.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : {}", id);
RepositorySnippet repo;
UriComponents uriComponents = searchSnipperDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
@ -385,7 +385,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
logger.debug("Retrieving repositories with id : " + id);
logger.debug("Retrieving repositories with id : {}", id);
Repository repo;
UriComponents uriComponents = searchDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
@ -413,7 +413,7 @@ public class RepositoryServiceImpl implements RepositoryService {
String page,
String size) throws JSONException {
logger.debug("Retrieving repositories with official name : " + name);
logger.debug("Retrieving repositories with official name : {}", name);
UriComponents uriComponents = searchDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setOfficialname(name);
@ -459,7 +459,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Repository addRepository(String datatype, Repository repository) throws Exception {
logger.debug("storing " + datatype + " repository with id: " + repository.getId());
logger.debug("storing '{}' repository with id: {}", datatype, repository.getId());
repository.setActivationId(UUID.randomUUID().toString());
repository.setCollectedfrom("infrastruct_::openaire");
@ -509,16 +509,10 @@ public class RepositoryServiceImpl implements RepositoryService {
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
if (couId != null) {
Integer role = registryCalls.getRoleId(coPersonId, couId);
try {
registryCalls.assignMemberRole(coPersonId, couId, role);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
} catch (Exception e) {
logger.debug("Exception on assign role to user during add repository", e);
throw e;
}
registryCalls.assignMemberRole(coPersonId, couId, role);
// Add role to current user authorities
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
}
return repository;
@ -539,16 +533,12 @@ public class RepositoryServiceImpl implements RepositoryService {
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
logger.error("Error sending email", e);
}
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
logger.error("Error updating repository: " + responseBody);
logger.error("Error updating repository: {}", responseBody);
}
return repository;
@ -569,16 +559,12 @@ public class RepositoryServiceImpl implements RepositoryService {
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} catch (Exception e) {
logger.error("Error sending emails: " + e);
}
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
logger.error("Error updating repository: " + responseBody);
logger.error("Error updating repository: {}", responseBody);
}
return repository;
@ -601,16 +587,12 @@ public class RepositoryServiceImpl implements RepositoryService {
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
try {
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} catch (Exception e) {
logger.error("Error sending emails: " + e);
}
emailUtils.sendUserRegistrationEmail(repository, authentication);
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
logger.error("Error storing repository: " + responseBody);
logger.error("Error storing repository: {}", responseBody);
}
}
@ -643,14 +625,10 @@ public class RepositoryServiceImpl implements RepositoryService {
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
try {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
} catch (Exception ex) {
logger.error("Error sending emails: " + ex);
}
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false);
submitInterfaceValidation(e, getAuthenticatedUser().getEmail(), repositoryInterface, false, repositoryInterface.getCompatibility());
return repositoryInterface;
}
@ -658,41 +636,39 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public RepositoryInterface updateRepositoryInterface(String repoId,
String comment,
RepositoryInterface repositoryInterface) throws Exception {
RepositoryInterface repositoryInterface,
String desiredCompatibilityLevel) throws Exception {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl());
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompatibility());
Repository repository = this.getRepositoryById(repoId);
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
Repository repository = this.getRepositoryById(repoId);
try {
try {
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
} catch (Exception e) {
logger.error("Error sending emails: " + e);
}
} catch (Exception e) {
logger.warn("Could not send emails", e);
}
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true);
logger.warn("Create entry in DB for requesting another compatibility level");
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true, desiredCompatibilityLevel);
return repositoryInterface;
}
@Override
public void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
this.updateCompliance(repositoryId, repositoryInterfaceId, compliance);
}
private User getAuthenticatedUser() {
return User.from(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo());
}
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException {
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting, String desiredCompatibilityLevel) throws ValidatorServiceException {
JobForValidation job = new JobForValidation();
job.setActivationId(UUID.randomUUID().toString());
job.setAdminEmails(Collections.singletonList(this.adminEmail));
job.setBaseUrl(iFace.getBaseurl());
job.setDatasourceId(repo.getId());
job.setDesiredCompatibilityLevel(iFace.getCompatibilityOverride());
job.setDesiredCompatibilityLevel(desiredCompatibilityLevel);
job.setInterfaceId(iFace.getId());
job.setOfficialName(repo.getOfficialname());
job.setRepoType(repo.getEoscDatasourceType());
@ -711,7 +687,12 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setDatasource(repo.getId());
iFace.setContentdescription("metadata");
iFace.setCompatibility("UNKNOWN");
// TODO: double check me
logger.warn("Compatibility level: {}", iFace.getCompatibility());
if (iFace.getCompatibility() != null && iFace.getCompatibility().equals("")) {
iFace.setCompatibility("UNKNOWN");
}
if (datatype.equals("re3data"))
iFace.setAccessFormat("oai_datacite");
@ -736,8 +717,7 @@ public class RepositoryServiceImpl implements RepositoryService {
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
logger.debug("set is empty: " + iFace.getAccessSet());
// iFace.removeAccessSet();
logger.debug("set is empty: {}", iFace.getAccessSet());
iFace.setAccessSet("none");
}
return iFace;
@ -787,7 +767,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Map<String, String> getCompatibilityClasses(String mode) {
logger.debug("Getting compatibility classes for mode: " + mode);
logger.debug("Getting compatibility classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<String, String>();
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
@ -822,7 +802,7 @@ public class RepositoryServiceImpl implements RepositoryService {
@Override
public Map<String, String> getDatasourceClasses(String mode) {
logger.debug("Getting datasource classes for mode: " + mode);
logger.debug("Getting datasource classes for mode: {}", mode);
Map<String, String> retMap = new HashMap<String, String>();

View File

@ -42,4 +42,6 @@ public interface ValidatorService {
InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException;
List<StoredJob> getJobsSummary(String repoId, int limit) throws ValidatorServiceException, ResourceNotFoundException, JSONException;
void onComplete(String repoId, String interfaceId, String jobId, String issuerEmail, boolean isUpdate, boolean isSuccess, int scoreUsage, int scoreContent) throws Exception;
}

View File

@ -132,13 +132,9 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
@PreAuthorize("hasAuthority('REGISTERED_USER')")
public JobForValidation submitJobForValidation(JobForValidation jobForValidation) throws ValidatorServiceException {
logger.debug("Submit job for validation with id : " + jobForValidation.getDatasourceId());
logger.debug("Submit job for validation with id : {}", jobForValidation.getDatasourceId());
try {
try {
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
} catch (Exception e) {
logger.error("Error sending email ", e);
}
emailUtils.sendSubmitJobForValidationEmail(SecurityContextHolder.getContext().getAuthentication(), jobForValidation);
/////////////////////////////////////////////////////////////////////////////////////////
// FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly //
/////////////////////////////////////////////////////////////////////////////////////////
@ -163,7 +159,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public ResponseEntity<Object> reSubmitJobForValidation(String email,
String jobId) throws JSONException, ValidatorServiceException {
logger.debug("Resubmit validation job with id : " + jobId);
logger.debug("Resubmit validation job with id : {}", jobId);
StoredJob job = monitorApi.getJobSummary(jobId, "all");
Set<Integer> contentRules = new HashSet<Integer>();
Set<Integer> usageRules = new HashSet<Integer>();
@ -198,20 +194,20 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public List<RuleSet> getRuleSets(String mode) {
logger.info("Getting rulesets for mode: " + mode);
logger.info("Getting rulesets for mode: {}", mode);
return rulesetMap.get(mode);
}
@Override
public List<String> getSetsOfRepository(String url) {
logger.debug("Getting sets of repository with url : " + url);
logger.debug("Getting sets of repository with url : {}", url);
List<String> sets = null;
try {
sets = OaiTools.getSetsOfRepo(url);
} catch (Exception e) {
logger.error("Exception on getSetsOfRepository" , e);
logger.error("Exception on getSetsOfRepository", e);
}
return sets;
@ -219,7 +215,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public boolean identifyRepo(String url) {
logger.debug("Identify repository with url : " + url);
logger.debug("Identify repository with url : {}", url);
try {
return OaiTools.identifyRepository(url);
} catch (Exception e) {
@ -230,7 +226,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public RuleSet getRuleSet(String acronym) {
logger.debug("Getting ruleset with acronym : " + acronym);
logger.debug("Getting ruleset with acronym : {}", acronym);
RuleSet ruleSet = null;
try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
@ -281,7 +277,7 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override
public InterfaceInformation getInterfaceInformation(String baseUrl) throws ValidationServiceException {
try {
logger.debug("Getting interface information with url: " + baseUrl);
logger.debug("Getting interface information with url: {}", baseUrl);
InterfaceInformation interfaceInformation = new InterfaceInformation();
interfaceInformation.setIdentified(this.identifyRepo(baseUrl));
if (interfaceInformation.isIdentified())
@ -303,4 +299,16 @@ public class ValidatorServiceImpl implements ValidatorService {
.collect(Collectors.toList()), limit);
}
@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);
String compliance = ""; // FIXME: search DB for change in compatibility request
// TODO: delete table entry if exists
logger.warn("Missing implementation for changing compatibility level");
if (scoreContent > 50) {
// TODO: update compliance
repositoryService.updateInterfaceCompliance(repoId, interfaceId, compliance);
}
}
}