removed try-catch and reused existing restTemplate

This commit is contained in:
Konstantinos Spyrou 2024-09-23 12:15:32 +03:00
parent 5010b8d04f
commit 768004de62
1 changed files with 6 additions and 16 deletions

View File

@ -774,16 +774,11 @@ public class RepositoryServiceImpl implements RepositoryService {
}
@Override
public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
try {
MetricsInfo metricsInfo = new MetricsInfo();
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
return metricsInfo;
} catch (Exception e) {
logger.error("Error while getting metrics info for repository: ", e);
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
}
public MetricsInfo getMetricsInfoForRepository(String repoId) {
MetricsInfo metricsInfo = new MetricsInfo();
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
return metricsInfo;
}
@Override
@ -853,13 +848,8 @@ public class RepositoryServiceImpl implements RepositoryService {
//build the uri params
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
//create new template engine
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<MetricsNumbers> resp;
//communicate with endpoint
resp = template.exchange(
ResponseEntity<MetricsNumbers> resp = restTemplate.exchange(
builder.build().encode().toUri(),
HttpMethod.GET,
null,