diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java index 63efbec..3191033 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtils.java @@ -8,9 +8,6 @@ import org.springframework.security.core.Authentication; public interface EmailUtils { - - void reportException(Exception exception); - void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; void sendUserRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception; diff --git a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java index ae78561..14bced3 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/EmailUtilsImpl.java @@ -4,7 +4,6 @@ import eu.dnetlib.domain.data.PiwikInfo; import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.RepositoryInterface; import eu.dnetlib.domain.functionality.validator.JobForValidation; -import eu.dnetlib.repo.manager.config.CascadingPropertyLoader; import eu.dnetlib.repo.manager.domain.ValidationServiceException; import eu.dnetlib.utils.MailLibrary; import org.apache.log4j.Logger; @@ -15,76 +14,36 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.Writer; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; - @Component("emailUtils") public class EmailUtilsImpl implements EmailUtils { - private static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class); - - private List specialRecipients = new ArrayList(); - private boolean override = false, logonly = false; - private String overrideEmail = null, from = null; + private final static Logger LOGGER = Logger.getLogger(EmailUtilsImpl.class); private final MailLibrary mailLibrary; - private final CascadingPropertyLoader pLoader; private final RepositoryService repositoryService; - @Value("${services.repo-manager.baseUrl}") + @Value("${services.repomanager.baseUrl}") private String baseUrl; - @Value("${services.repo-manager.adminEmail}") - private String adminEmail; - @Value("${services.repomanager.usagestats.adminEmail}") private String usageStatsAdminEmail; - @Value("${services.provide.adminEmail}") + @Value("${services.repomanager.provide.adminEmail}") private String provideAdminEmail; @Value("${validator.results.url}") private String valBaseUrl; @Autowired - EmailUtilsImpl(MailLibrary mailLibrary, CascadingPropertyLoader pLoader, - RepositoryService repositoryService) { + EmailUtilsImpl(MailLibrary mailLibrary, RepositoryService repositoryService) { this.mailLibrary = mailLibrary; - this.pLoader = pLoader; this.repositoryService = repositoryService; } - - @PostConstruct - public void init(){ - System.out.println("url -> " + this.baseUrl); - } - - - @Override - public void reportException(Exception exception) { - Writer writer = new StringWriter(); - PrintWriter printWriter = new PrintWriter(writer); - exception.printStackTrace(printWriter); - - List recipients = new ArrayList(); - - try { - recipients.add(this.adminEmail); - String message = "An exception has occurred:\n"+writer.toString(); - String subject = "Automatic Bug Report"; - this.sendMail(recipients, subject, message, false, null); - } catch (Exception e) { - LOGGER.error("Error sending error report", e); - } - } - @Override public void sendAdministratorRequestToEnableMetrics(PiwikInfo piwikInfo) throws Exception { @@ -106,7 +65,7 @@ public class EmailUtilsImpl implements EmailUtils { "Best,\n" + "The OpenAIRE team"; - this.sendMail(this.usageStatsAdminEmail, subject, message, false, null); + this.sendMail(this.usageStatsAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending request to enable metrics email to administrator: " + this.usageStatsAdminEmail, e); @@ -143,7 +102,7 @@ public class EmailUtilsImpl implements EmailUtils { "Best,\n" + "The OpenAIRE team"; - this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); + this.sendMail(piwikInfo.getRequestorEmail(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending request to enable metrics email to user: " + piwikInfo.getRequestorEmail(), e); @@ -170,7 +129,7 @@ public class EmailUtilsImpl implements EmailUtils { "Best,\n" + "The OpenAIRE team"; - this.sendMail(this.usageStatsAdminEmail, subject, message, false, null); + this.sendMail(this.usageStatsAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending metrics enabled notification email to administator: " + this.usageStatsAdminEmail, e); @@ -198,7 +157,7 @@ public class EmailUtilsImpl implements EmailUtils { "Best,\n" + "The OpenAIRE team"; - this.sendMail(piwikInfo.getRequestorEmail(), subject, message, false, null); + this.sendMail(piwikInfo.getRequestorEmail(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending metrics enabled notification email to user: " + piwikInfo.getRequestorEmail(), e); @@ -224,7 +183,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to the administrator", e); @@ -250,7 +209,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -285,7 +244,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration of interface notification email to the administrator", e); @@ -319,7 +278,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredBy(), e); @@ -352,7 +311,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -385,7 +344,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -417,7 +376,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -450,7 +409,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -481,7 +440,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(issuer, subject, message, false, null); + this.sendMail(issuer, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to the administrator", e); @@ -512,7 +471,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to the administrator", e); @@ -545,7 +504,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(issuer, subject, message, false, null); + this.sendMail(issuer, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -578,7 +537,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -601,7 +560,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(issuer, subject, message, false, null); + this.sendMail(issuer, subject, message); } catch (Exception e) { LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e); @@ -624,7 +583,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e); @@ -644,7 +603,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending validation submission notification email to user: " + issuer, e); @@ -666,7 +625,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to the administrator", e); @@ -690,7 +649,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -723,7 +682,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(this.provideAdminEmail, subject, message, false, null); + this.sendMail(this.provideAdminEmail, subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to the administrator", e); @@ -757,7 +716,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(repository.getRegisteredBy(), subject, message, false, null); + this.sendMail(repository.getRegisteredBy(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending registration notification email to user: " + repository.getRegisteredBy(), e); @@ -780,7 +739,7 @@ public class EmailUtilsImpl implements EmailUtils { "Regards,\n" + "the OpenAIRE technical team\n"; - this.sendMail(jobForValidation.getUserEmail(), subject, message, false, null); + this.sendMail(jobForValidation.getUserEmail(), subject, message); } catch (Exception e) { LOGGER.error("Error while sending validation submission notification email to user: " + jobForValidation.getUserEmail(), e); @@ -833,73 +792,17 @@ public class EmailUtilsImpl implements EmailUtils { } - - private void sendMail(String email, String subject, String message, boolean sendToSpecial, List repoAdminMails) throws Exception { - ArrayList to = new ArrayList(); - to.add(email); - this.sendMail(to,subject,message,sendToSpecial,repoAdminMails); + private void sendMail(String email, String subject, String message) throws Exception { + this.sendMail(Collections.singletonList(email), subject, message); } - public void sendMail(List recipients, String subject, String message, boolean sendToSpecial, List repoAdminMails) throws Exception { - + public void sendMail(List recipients, String subject, String message) throws Exception { try { - if (sendToSpecial) { - recipients.addAll(this.specialRecipients); - } - - if (repoAdminMails != null) - recipients.addAll(repoAdminMails); - - if (this.override) { - recipients.clear(); - recipients.add(overrideEmail); - } - if (!logonly) - mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); LOGGER.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message); + mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); } catch (Exception e) { LOGGER.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e); - throw new Exception(e); + throw e; } } - - private String getEmailProperty(String key) { - return pLoader.getProperties().getProperty(key); - } - - public void setSpecialRecipients(String specialRecipients) { - String[] recps = specialRecipients.split(","); - - for (String recp : recps) { - recp = recp.trim(); - - this.specialRecipients.add(recp); - } - } - - - public void setOverride(boolean override) { - this.override = override; - } - - public void setOverrideEmail(String overrideEmail) { - this.overrideEmail = overrideEmail; - } - - public String getFrom() { - return from; - } - - public void setFrom(String from) { - this.from = from; - } - - public boolean isLogonly() { - return logonly; - } - - public void setLogonly(boolean logonly) { - this.logonly = logonly; - } - } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java index 7ab8347..16f3772 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -34,7 +34,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; @@ -176,17 +175,11 @@ public class RepositoryServiceImpl implements RepositoryService { UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size))); RequestFilter requestFilter = new RequestFilter(); - try { - for (String repoId : ids) { - requestFilter.setId(repoId); - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + for (String repoId : ids) { + requestFilter.setId(repoId); + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - repos.addAll(Converter.jsonToRepositoryList(new JSONObject(rs))); - } - } catch (JSONException e) { - LOGGER.debug("Exception on getRepositoriesOfUser", e); - emailUtils.reportException(e); - throw e; + repos.addAll(Converter.jsonToRepositoryList(new JSONObject(rs))); } for (Repository r : repos) @@ -262,23 +255,17 @@ public class RepositoryServiceImpl implements RepositoryService { requestFilter.setCountry(country); requestFilter.setCollectedfrom(filterKey); - try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - while (jsonArray.length() > 0) { - resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), - mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); - page += 1; - uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size)); - rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - } - return resultSet; - } catch (Exception e) { - LOGGER.debug("Exception on getRepositoriesByCountry", e); - emailUtils.reportException(e); - throw e; + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); + while (jsonArray.length() > 0) { + resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), + mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); + page += 1; + uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size)); + rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); } + return resultSet; } public List searchRegisteredRepositories(String country, String typology, String englishName, @@ -371,21 +358,14 @@ public class RepositoryServiceImpl implements RepositoryService { RequestFilter requestFilter = new RequestFilter(); requestFilter.setId(id); - try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - if (jsonArray.length() == 0) - throw new ResourceNotFoundException(); - - repo = Converter.jsonToRepositorySnippetObject(jsonArray.getJSONObject(0)); - return repo; - } catch (JSONException e) { - LOGGER.debug("Exception on getRepositoryById", e); - emailUtils.reportException(e); - throw e; - } + if (jsonArray.length() == 0) + throw new ResourceNotFoundException(); + repo = Converter.jsonToRepositorySnippetObject(jsonArray.getJSONObject(0)); + return repo; } @Override @@ -397,21 +377,14 @@ public class RepositoryServiceImpl implements RepositoryService { RequestFilter requestFilter = new RequestFilter(); requestFilter.setId(id); - try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); - if (jsonArray.length() == 0) - throw new ResourceNotFoundException(); - - repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); - return updateRepositoryInfo(repo); - } catch (JSONException e) { - LOGGER.debug("Exception on getRepositoryById", e); - emailUtils.reportException(e); - throw e; - } + if (jsonArray.length() == 0) + throw new ResourceNotFoundException(); + repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); + return updateRepositoryInfo(repo); } @@ -425,31 +398,25 @@ public class RepositoryServiceImpl implements RepositoryService { List aggregationHistory = new ArrayList<>(); - try { - long start = System.currentTimeMillis(); - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - long end = System.currentTimeMillis(); + long start = System.currentTimeMillis(); + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + long end = System.currentTimeMillis(); - System.out.println("Aggregations request through rest template took " + (end - start) + "ms"); - JSONObject repository = new JSONObject(rs); + System.out.println("Aggregations request through rest template took " + (end - start) + "ms"); + JSONObject repository = new JSONObject(rs); - if (repository.getJSONArray("datasourceInfo").length() == 0) - return aggregationHistory; + if (repository.getJSONArray("datasourceInfo").length() == 0) + return aggregationHistory; - start = System.currentTimeMillis(); - aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); - end = System.currentTimeMillis(); + start = System.currentTimeMillis(); + aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); + end = System.currentTimeMillis(); - System.out.println("Getting aggregations history from json " + (end - start) + "ms"); - return aggregationHistory.size() == 0 ? aggregationHistory : aggregationHistory.stream() - .sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) - .limit(size) - .collect(Collectors.toList()); - } catch (JSONException e) { - LOGGER.debug("Exception on getRepositoryAggregations", e); - emailUtils.reportException(e); - throw e; - } + System.out.println("Getting aggregations history from json " + (end - start) + "ms"); + return aggregationHistory.size() == 0 ? aggregationHistory : aggregationHistory.stream() + .sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) + .limit(size) + .collect(Collectors.toList()); } @@ -462,21 +429,15 @@ public class RepositoryServiceImpl implements RepositoryService { List aggregationHistory = new ArrayList<>(); Map> aggregationByYear = new HashMap<>(); - try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - JSONObject repository = new JSONObject(rs); - if (repository.getJSONArray("datasourceInfo").length() == 0) - return aggregationByYear; + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + JSONObject repository = new JSONObject(rs); - aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); - return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory); + if (repository.getJSONArray("datasourceInfo").length() == 0) + return aggregationByYear; - } catch (JSONException e) { - LOGGER.debug("Exception on getRepositoryAggregations", e); - emailUtils.reportException(e); - throw e; - } + aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); + return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory); } private Map> createYearMap(List aggregationHistory) { @@ -500,17 +461,11 @@ public class RepositoryServiceImpl implements RepositoryService { RequestFilter requestFilter = new RequestFilter(); requestFilter.setOfficialname(name); - try { - String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); - List repos = Converter.jsonToRepositoryList(new JSONObject(rs)); - for (Repository r : repos) - updateRepositoryInfo(r); - return repos; - } catch (Exception e) { - LOGGER.debug("Exception on getRepositoriesByName", e); - emailUtils.reportException(e); - throw e; - } + String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class); + List repos = Converter.jsonToRepositoryList(new JSONObject(rs)); + for (Repository r : repos) + updateRepositoryInfo(r); + return repos; } @@ -522,14 +477,8 @@ public class RepositoryServiceImpl implements RepositoryService { .path("/{id}") .build().expand(id).encode(); - try { - String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); - return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); - } catch (Exception e) { - LOGGER.debug("Exception on getRepositoryInterface", e); - emailUtils.reportException(e); - throw e; - } + String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); + return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); } @@ -599,25 +548,19 @@ public class RepositoryServiceImpl implements RepositoryService { .build() .encode(); - try { - String json_repository = Converter.repositoryObjectToJson(repository); - LOGGER.debug("JSON to add(update) -> " + json_repository); + String json_repository = Converter.repositoryObjectToJson(repository); + LOGGER.debug("JSON to add(update) -> " + json_repository); - HttpEntity httpEntity = new HttpEntity(json_repository, httpHeaders); - ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); + HttpEntity httpEntity = new HttpEntity(json_repository, httpHeaders); + ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class); - if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { - emailUtils.sendUserRegistrationEmail(repository, authentication); - emailUtils.sendAdminRegistrationEmail(repository, authentication); - } else - LOGGER.debug(responseEntity.getBody().toString()); + if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { + emailUtils.sendUserRegistrationEmail(repository, authentication); + emailUtils.sendAdminRegistrationEmail(repository, authentication); + } else + LOGGER.debug(responseEntity.getBody().toString()); - return repository; - } catch (Exception e) { - LOGGER.debug("Exception on updateRepository", e); - emailUtils.reportException(e); - throw e; - } + return repository; } @@ -629,27 +572,21 @@ public class RepositoryServiceImpl implements RepositoryService { .build() .encode(); - try { - String json_repository = Converter.repositoryObjectToJson(repository); + String json_repository = Converter.repositoryObjectToJson(repository); - LOGGER.debug("JSON to update -> " + json_repository); + LOGGER.debug("JSON to update -> " + json_repository); - HttpEntity httpEntity = new HttpEntity(json_repository, httpHeaders); - ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity - , ResponseEntity.class); + HttpEntity httpEntity = new HttpEntity(json_repository, httpHeaders); + ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity + , ResponseEntity.class); - if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { - emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication); - emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication); - } else - LOGGER.debug(responseEntity.getBody().toString()); + if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { + emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication); + emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication); + } else + LOGGER.debug(responseEntity.getBody().toString()); - return repository; - } catch (Exception e) { - LOGGER.debug("Exception on updateRepository", e); - emailUtils.reportException(e); - throw e; - } + return repository; } private void storeRepository(Repository repository, Authentication authentication) throws Exception { @@ -692,32 +629,25 @@ public class RepositoryServiceImpl implements RepositoryService { String repoId, String registeredBy, String comment, RepositoryInterface repositoryInterface) throws Exception { - try { - Repository e = this.getRepositoryById(repoId); - repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype); - String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface); + Repository e = this.getRepositoryById(repoId); + repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype); + String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface); - UriComponents uriComponents = UriComponentsBuilder - .fromHttpUrl(baseAddress + "/ds/api/add/") - .build() - .encode(); + UriComponents uriComponents = UriComponentsBuilder + .fromHttpUrl(baseAddress + "/ds/api/add/") + .build() + .encode(); - HttpEntity httpEntity = new HttpEntity<>(json_interface, httpHeaders); + HttpEntity httpEntity = new HttpEntity<>(json_interface, httpHeaders); - restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); + restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class); - emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); - emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); + emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); - submitInterfaceValidation(e, registeredBy, repositoryInterface, false); + submitInterfaceValidation(e, registeredBy, repositoryInterface, false); - return repositoryInterface; - - } catch (Exception e) { - LOGGER.error("Exception on addRepositoryInterface", e); - emailUtils.reportException(e); - throw e; - } + return repositoryInterface; } @Override @@ -822,15 +752,9 @@ public class RepositoryServiceImpl implements RepositoryService { .path("/{page}/{size}") .build().expand(page, size).encode(); - try { - RequestFilter requestFilter = new RequestFilter(); - requestFilter.setRegisteredby(userEmail); - return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class)); - } catch (Exception e) { - LOGGER.debug("Exception on addRepositoryInterface", e); - emailUtils.reportException(e); - throw e; - } + RequestFilter requestFilter = new RequestFilter(); + requestFilter.setRegisteredby(userEmail); + return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class)); } @Override @@ -947,7 +871,6 @@ public class RepositoryServiceImpl implements RepositoryService { } catch (Exception e) { LOGGER.error("Error while getting metrics info for repository: ", e); - emailUtils.reportException(e); throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR); } } @@ -1004,19 +927,14 @@ public class RepositoryServiceImpl implements RepositoryService { RestTemplate template = new RestTemplate(); 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 getMetricsNumbers", e); - emailUtils.reportException(e); - throw e; - } + + //communicate with endpoint + resp = template.exchange( + builder.build().encode().toUri(), + HttpMethod.GET, + null, + new ParameterizedTypeReference() { + }); return resp.getBody(); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1cfdbf7..0cd1c54 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -96,9 +96,9 @@ ValidatorService.url=http://estella.athenarc.gr:8080/validator-service/services/ #services.validator.ldap.usersDN = ou=users,dc=openaire,dc=eu #AAI-REDIS -redis.host = estella.athenarc.gr +redis.host = localhost redis.port = 6379 -redis.password = redis123 +redis.password = 2106875370 oidc.dev.home = http://localhost:8480/uoa-repository-manager-service/openid_connect_login webapp.dev.front = http://localhost:4200/dashboard @@ -133,10 +133,7 @@ search.api.baseAddress=https://beta.services.openaire.eu/search/v2/api search.api.usagestats=https://services.openaire.eu/usagestats search.api.usageEvents=http://beta.lbs.openaire.eu:8080/ajax/summary api.baseAddress=http://beta.services.openaire.eu/openaire -services.repo-manager.baseUrl=http://${container.hostname}:${container.port}/${container.context} -services.repo-manager.adminEmail=antleb@di.uoa.gr -services.repo-manager.repository.testing.mode=false -services.repo-manager.deploy.environment=development +services.repomanager.baseUrl=http://${container.hostname}:${container.port}/${container.context} services.repomanager.usageStatisticsDiagramsBaseURL=https://beta.openaire.eu/stats3/ services.repomanager.usageStatisticsNumbersBaseURL=https://beta.services.openaire.eu/usagestats/datasources/ services.repomanager.usagestats.adminEmail=antleb@di.uoa.gr @@ -144,12 +141,14 @@ services.repomanager.usagestats.sushiliteEndpoint=http://beta.services.openaire. services.repomanager.analyticsURL=https://analytics.openaire.eu/addsite.php? aai.mode=develop + #uoa-repository-manager-service #oidc.dev.home=http://88.197.53.69:8080/uoa-repository-manager-service/openid_connect_login #webapp.dev.front=http://88.197.53.69/landing + services.repo-manager.adminEmail=antleb@di.uoa.gr services.repomanager.usagestats.adminEmail=antleb@di.uoa.gr -services.provide.adminEmail=antleb@di.uoa.gr +services.repomanager.provide.adminEmail=antleb@di.uoa.gr validator.results.url=https://beta.provide.openaire.eu/compatibility/browseHistory/ topic_types.url=https://beta.services.openaire.eu/provision/mvc/vocabularies/dnet:topic_types.json services.broker.url=http://broker1-dev-dnet.d4science.org