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 48fb2f8..d4506d2 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/BrokerServiceImpl.java @@ -8,7 +8,6 @@ import eu.dnetlib.repo.manager.domain.Tuple; import eu.dnetlib.repo.manager.domain.broker.*; import eu.dnetlib.repo.manager.exception.BrokerException; import org.apache.commons.lang.NotImplementedException; -import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -17,8 +16,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.*; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.stereotype.Service; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponents; @@ -27,6 +24,7 @@ import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.PostConstruct; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -52,7 +50,7 @@ public class BrokerServiceImpl implements BrokerService { private HttpHeaders httpHeaders; - private HashMap topics = new HashMap<>(); + private final HashMap topics = new HashMap<>(); @PostConstruct private void initDnetTopicsMap() { @@ -78,7 +76,7 @@ public class BrokerServiceImpl implements BrokerService { @Override - public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws JSONException { + public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) { long start = System.currentTimeMillis(); DatasourcesBroker ret = new DatasourcesBroker(); try { @@ -96,7 +94,7 @@ public class BrokerServiceImpl implements BrokerService { logger.error("Exception on getDatasourcesOfUser", e); } long end = System.currentTimeMillis(); - System.out.println("Getting datasources of user in " + (end - start) + "ms"); + logger.debug("Getting datasources of user in " + (end - start) + "ms"); return ret; } @@ -129,14 +127,15 @@ public class BrokerServiceImpl implements BrokerService { final String service = "/events/{page}/{pageSize}"; + long pageNum = Long.parseLong(page); + advQueryObject.setPage(pageNum); + Map uriParams = new HashMap<>(); - uriParams.put("page", Long.parseLong(page)); + uriParams.put("page", pageNum); uriParams.put("pageSize", Long.parseLong(size)); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service); - MultiValueMap headers = new LinkedMultiValueMap<>(); - advQueryObject.setPage(Long.parseLong(page)); HttpEntity entity = new HttpEntity<>(advQueryObject, httpHeaders); ResponseEntity resp; try { @@ -144,8 +143,7 @@ public class BrokerServiceImpl implements BrokerService { builder.buildAndExpand(uriParams).encode().toUri(), HttpMethod.POST, entity, - new ParameterizedTypeReference() { - } + new ParameterizedTypeReference() {} ); } catch (RestClientException e) { throw new BrokerException(e); @@ -171,8 +169,7 @@ public class BrokerServiceImpl implements BrokerService { // sort the collection by the second field of the tuple which is size entries.sort((e1, e2) -> (int) (e2.getFirst().getSize() - e1.getFirst().getSize())); long stop = System.currentTimeMillis(); - System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms "); - + logger.debug("getDatasourcesOfUserType returned in " + (stop - start) + "ms "); return entries; } @@ -180,7 +177,7 @@ public class BrokerServiceImpl implements BrokerService { public EventsPage showEvents(String datasourceName, String topic, String page, - String size) throws BrokerException, JSONException { + String size) throws BrokerException { final String service = "/events"; @@ -209,14 +206,14 @@ public class BrokerServiceImpl implements BrokerService { final String service = "/subscriptions"; - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) - .queryParam("email", userEmail); + URI uri = UriComponentsBuilder.fromHttpUrl(openairePath + service) + .queryParam("email", userEmail).build().encode().toUri(); - logger.debug("{}", builder.build().encode().toUri()); + logger.debug("{}", uri); ResponseEntity>> resp; try { resp = restTemplate.exchange( - builder.build().encode().toUri(), + uri, HttpMethod.GET, null, new ParameterizedTypeReference>>() { @@ -228,10 +225,9 @@ public class BrokerServiceImpl implements BrokerService { } @Override - public Map> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) throws BrokerException { - Map> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail); + public Map> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) { //throws BrokerException { throw new NotImplementedException(); -// return null; + //Map> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail); } @Override 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 a344fcc..38f15cc 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/DashboardServiceImpl.java @@ -39,41 +39,50 @@ public class DashboardServiceImpl implements DashboardService { try { List repositoriesOfUser = repositoryService.getRepositoriesSnippetsOfUser(userEmail, page, size); - for (RepositorySnippet repository : repositoriesOfUser) { + for (RepositorySnippet repository : repositoriesOfUser) + { + String repoId = repository.getId(); + String repoOfficialName = repository.getOfficialname(); + RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo(); - repositorySummaryInfo.setId(repository.getId()); - repositorySummaryInfo.setRepositoryName(repository.getOfficialname()); + repositorySummaryInfo.setId(repoId); + repositorySummaryInfo.setRepositoryName(repoOfficialName); repositorySummaryInfo.setLogoURL(repository.getLogoUrl()); //TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there? + boolean isIndexedVersionFound = false; long start = System.currentTimeMillis(); - List aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20); + List aggregationInfoList = aggregationService.getRepositoryAggregations(repoId, 0, 20); for (AggregationInfo aggregationInfo : aggregationInfoList) { if (aggregationInfo.isIndexedVersion()) { repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords()); repositorySummaryInfo.setLastIndexedVersion(DateUtils.toDate(aggregationInfo.getDate())); + isIndexedVersionFound = true; break; } } long end = System.currentTimeMillis(); - System.out.println("Got repo aggregations in " + (end - start) + "ms"); + if ( isIndexedVersionFound ) + logger.debug("Got repo aggregations in " + (end - start) + "ms"); + else + logger.warn("Could not find repo aggregations, after " + (end - start) + "ms!"); try { - MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId()); + MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repoId); repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads()); repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews()); } catch (RepositoryServiceException e) { - logger.error("Exception getting metrics info for repository: " + repository.getId(), e); + logger.error("Exception getting metrics info for repository: {}, {} ", repoId, repoOfficialName, e); } try { - List events = brokerService.getTopicsForDatasource(repository.getOfficialname()); + List events = brokerService.getTopicsForDatasource(repoOfficialName); Long totalEvents = 0L; for (BrowseEntry browseEntry : events) totalEvents += browseEntry.getSize(); repositorySummaryInfo.setEnrichmentEvents(totalEvents); } catch (BrokerException e) { - logger.error("Exception getting broker events for repository: " + repository.getId(), e); + logger.error("Exception getting broker events for repository: {}, {} ", repoId, repoOfficialName, e); } repositorySummaryInfoList.add(repositorySummaryInfo); diff --git a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java index df414b2..2a59c31 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/InterfaceComplianceService.java @@ -58,7 +58,7 @@ public class InterfaceComplianceService { private Set getOutdated() { Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DATE, -7); + calendar.add(Calendar.DATE, -7); // 7-days-old return this.repository.findAllBySubmissionDateBefore(calendar.getTime()); } diff --git a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java index f4156cd..e5e9339 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/MonitorServiceImpl.java @@ -52,7 +52,7 @@ public class MonitorServiceImpl implements MonitorService { String dateFrom, String dateTo, String validationStatus, - String includeJobsTotal) throws JSONException, ValidatorServiceException { + String includeJobsTotal) throws ValidatorServiceException, NumberFormatException { ///////////////////////////////////////////////////////////////////////////////////////// // FIXME: this is a hack for CRIS Jan Dvorak Validator, should be implemented properly // 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 3cdf396..05faa63 100644 --- a/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java +++ b/src/main/java/eu/dnetlib/repo/manager/service/RepositoryServiceImpl.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import eu.dnetlib.api.functionality.ValidatorServiceException; import eu.dnetlib.domain.enabling.Vocabulary; import eu.dnetlib.domain.functionality.validator.JobForValidation; @@ -997,15 +996,12 @@ public class RepositoryServiceImpl implements RepositoryService { if (coPersonId != null) { roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE); for (JsonElement role : roles) { - JsonObject object = role.getAsJsonObject(); - if (object.get("CouId") == null) { - continue; - } - couIds.add(object.get("CouId").getAsInt()); + JsonElement couId = role.getAsJsonObject().get("CouId"); + if (couId != null) + couIds.add(couId.getAsInt()); } roleIds.addAll(registryCalls.getCouNames(couIds).values()); - } return roleIds; } diff --git a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java index 7fbb870..245fc58 100644 --- a/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java +++ b/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java @@ -90,7 +90,7 @@ public class HttpUtils { String responseBody = responseEntity.getBody(); if ( responseBody != null ) { - logger.debug(responseBody); + logger.trace(responseBody); try { return new JsonParser().parse(responseBody); } catch (Exception e) { diff --git a/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java b/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java index 897aaea..381558d 100644 --- a/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java +++ b/src/test/java/eu/dnetlib/repo/manager/integration/metrics/PrometheusTest.java @@ -11,6 +11,7 @@ import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @@ -51,7 +52,7 @@ public class PrometheusTest { @Test public void testPiwikMetrics() { - assertTrue(piWikService.getValidated(false).equals(TOTAL - VALIDATED)); + assertEquals((long) piWikService.getValidated(false), (TOTAL - VALIDATED)); String report = prometheusController.getPiwikMetrics(); assertTrue(report.contains("provide_repositories_registered_total " + TOTAL)); assertTrue(report.contains("provide_usagecounts_repositories_registered_total " + TOTAL)); diff --git a/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java b/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java index 8a19e7d..a84ccb6 100644 --- a/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java +++ b/src/test/java/eu/dnetlib/repo/manager/integration/service/InterfaceComplianceRequestTests.java @@ -40,17 +40,17 @@ class InterfaceComplianceRequestTests { } private InterfaceComplianceRequestId createRequestId() { - InterfaceComplianceRequestId id = new InterfaceComplianceRequestId(); - id.setRepositoryId("repository"); - id.setInterfaceId("interface"); - return id; + InterfaceComplianceRequestId requestId = new InterfaceComplianceRequestId(); + requestId.setRepositoryId("repository"); + requestId.setInterfaceId("interface"); + return requestId; } private InterfaceComplianceRequest createRequest(String compatibilityLevel) { InterfaceComplianceRequest request = new InterfaceComplianceRequest(); - InterfaceComplianceRequestId id = createRequestId(); - request.setRepositoryId(id.getRepositoryId()); - request.setInterfaceId(id.getInterfaceId()); + InterfaceComplianceRequestId requestId = createRequestId(); + request.setRepositoryId(requestId.getRepositoryId()); + request.setInterfaceId(requestId.getInterfaceId()); request.setDesiredCompatibilityLevel(compatibilityLevel); request.setSubmissionDate(new Date()); return request;