From cca7a21d7b77bf0f151fc157a2540db457cd6325 Mon Sep 17 00:00:00 2001 From: Antonis Lempesis Date: Thu, 7 Oct 2021 14:13:04 +0000 Subject: [PATCH] mooore cleanup --- .../manager/service/BrokerServiceImpl.java | 27 ++----------------- .../manager/service/DashboardServiceImpl.java | 3 --- .../manager/service/PiWikServiceImpl.java | 7 ++--- .../manager/service/SushiliteServiceImpl.java | 26 ++++++------------ .../manager/service/ValidatorServiceImpl.java | 21 +++++++-------- 5 files changed, 21 insertions(+), 63 deletions(-) diff --git a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java index 5edd88c..c455e26 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java @@ -50,9 +50,6 @@ public class BrokerServiceImpl implements BrokerService { private HashMap topics = new HashMap(); - @Autowired - private EmailUtils emailUtils; - @PostConstruct private void initDnetTopicsMap() { @@ -66,8 +63,7 @@ public class BrokerServiceImpl implements BrokerService { for (JsonNode term : root.path("terms")) topics.put(term.path("code").textValue(), parseTerm(term)); } catch (IOException e) { - LOGGER.debug("Exception on initDnetTopicsMap", e); - emailUtils.reportException(e); + LOGGER.error("Exception on initDnetTopicsMap", e); } } @@ -93,8 +89,7 @@ public class BrokerServiceImpl implements BrokerService { // ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user))); // } } catch (Exception e) { - LOGGER.debug("Exception on getDatasourcesOfUser", e); - emailUtils.reportException(e); + LOGGER.error("Exception on getDatasourcesOfUser", e); } long end = System.currentTimeMillis(); System.out.println("Getting datasources of user in " + (end - start) + "ms"); @@ -117,8 +112,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference>() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on getTopicsForDatasource", e); - emailUtils.reportException(e); throw new BrokerException(e); } @@ -151,13 +144,9 @@ public class BrokerServiceImpl implements BrokerService { } ); } catch (RestClientException e) { - LOGGER.debug("Exception on advancedShowEvents", e); - emailUtils.reportException(e); throw new BrokerException(e); } return resp.getBody(); - - } @@ -210,8 +199,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on showEvents", e); - emailUtils.reportException(e); throw new BrokerException(e); } return resp.getBody(); @@ -236,8 +223,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference>>() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on getSimpleSubscriptionsOfUser", e); - emailUtils.reportException(e); throw new BrokerException(e); } return resp.getBody(); @@ -272,8 +257,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on OpenaireSubscription", e); - emailUtils.reportException(e); throw new BrokerException(e); } @@ -296,8 +279,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on unsubscribe", e); - emailUtils.reportException(e); throw new BrokerException(e); } return new ResponseEntity<>("OK", HttpStatus.OK); @@ -320,8 +301,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on getSubscription", e); - emailUtils.reportException(e); throw new BrokerException(e); } return resp.getBody(); @@ -351,8 +330,6 @@ public class BrokerServiceImpl implements BrokerService { new ParameterizedTypeReference() { }); } catch (RestClientException e) { - LOGGER.debug("Exception on getNotificationsBySubscriptionId", e); - emailUtils.reportException(e); throw new BrokerException(e); } return resp.getBody(); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java index 4a96da6..7e5ba3a 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java @@ -14,9 +14,6 @@ public class DashboardServiceImpl implements DashboardService { private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class); - @Autowired - private EmailUtils emailUtils; - @Autowired private RepositoryService repositoryService; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java index 4c3a995..986765d 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/PiWikServiceImpl.java @@ -169,11 +169,10 @@ public class PiWikServiceImpl implements PiWikService { } catch (EmptyResultDataAccessException e) { LOGGER.error("Error while approving piwik site: ", e); - emailUtils.reportException(e); throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR); } catch (Exception e) { LOGGER.error("Error while sending email to administrator or user about the enabling of metrics", e); - emailUtils.reportException(e); + throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR); } return new ResponseEntity<>("OK", HttpStatus.OK); } @@ -204,15 +203,13 @@ public class PiWikServiceImpl implements PiWikService { emailUtils.sendUserRequestToEnableMetrics(piwikInfo); } catch (UnsupportedEncodingException uee) { LOGGER.error("Error while creating piwikScript URL", uee); - emailUtils.reportException(uee); throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR); } catch (IOException ioe) { LOGGER.error("Error while creating piwik site", ioe); - emailUtils.reportException(ioe); throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR); } catch (Exception e) { LOGGER.error("Error while sending email to administrator or user about the request to enable metrics", e); - emailUtils.reportException(e); + throw new RepositoryServiceException(e, RepositoryServiceException.ErrorCode.GENERAL_ERROR); } return piwikInfo; } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java index a99a198..c7b0a0a 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/SushiliteServiceImpl.java @@ -2,7 +2,6 @@ package eu.dnetlib.repo.manager.service; import eu.dnetlib.usagestats.sushilite.domain.ReportItem; import eu.dnetlib.usagestats.sushilite.domain.ReportResponseWrapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; @@ -10,7 +9,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -24,9 +22,6 @@ public class SushiliteServiceImpl implements SushiliteService { @Value("${services.repomanager.usagestats.sushiliteEndpoint}") private String usagestatsSushiliteEndpoint; - @Autowired - private EmailUtils emailUtils; - private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(SushiliteServiceImpl.class); @@ -63,19 +58,14 @@ public class SushiliteServiceImpl implements SushiliteService { template.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); ResponseEntity resp; - try { - //communicate with endpoint - resp = template.exchange( - builder.build().encode().toUri(), - HttpMethod.GET, - null, - new ParameterizedTypeReference() { - }); - } catch (RestClientException e) { - LOGGER.debug("Exception on getReportResults" , e); - emailUtils.reportException(e); - throw e; - } + + //communicate with endpoint + resp = template.exchange( + builder.build().encode().toUri(), + HttpMethod.GET, + null, + new ParameterizedTypeReference() { + }); // check remote api's response System.out.println("sushi responded status " + resp.getStatusCode()); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java index f929437..1da32c3 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/ValidatorServiceImpl.java @@ -144,13 +144,10 @@ public class ValidatorServiceImpl implements ValidatorService { ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // this.getValidationService().submitValidationJob(jobForValidation); - } catch (ValidatorServiceException e) { - LOGGER.debug("Exception on submitJobForValidation" , e); - emailUtils.reportException(e); - throw e; } catch (Exception e) { - LOGGER.error(e); + throw new ValidatorServiceException(e); } + return jobForValidation; } @@ -200,13 +197,16 @@ public class ValidatorServiceImpl implements ValidatorService { @Override public List getSetsOfRepository(String url) { LOGGER.debug("Getting sets of repository with url : " + url); + + List sets = null; + try { - return OaiTools.getSetsOfRepo(url); + sets = OaiTools.getSetsOfRepo(url); } catch (Exception e) { - LOGGER.debug("Exception on getSetsOfRepository" , e); - emailUtils.reportException(e); + LOGGER.error("Exception on getSetsOfRepository" , e); } - return null; + + return sets; } @Override @@ -216,7 +216,6 @@ public class ValidatorServiceImpl implements ValidatorService { return OaiTools.identifyRepository(url); } catch (Exception e) { LOGGER.error("Error while identifying repository with url: " + url, e); - emailUtils.reportException(e); return false; } } @@ -236,7 +235,6 @@ public class ValidatorServiceImpl implements ValidatorService { return ruleSet; } catch (Exception e) { LOGGER.error("Error getting ruleset", e); - emailUtils.reportException(e); return null; } } @@ -284,7 +282,6 @@ public class ValidatorServiceImpl implements ValidatorService { return interfaceInformation; } catch (Exception e) { LOGGER.error("Error getting interface information with url: " + baseUrl, e); - emailUtils.reportException(e); throw new ValidationServiceException("login.generalError", ValidationServiceException.ErrorCode.GENERAL_ERROR); } }