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