- 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.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<String, Term> topics = new HashMap<>();
|
||||
private final HashMap<String, Term> 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<String, Long> 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<String, String> headers = new LinkedMultiValueMap<>();
|
||||
advQueryObject.setPage(Long.parseLong(page));
|
||||
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders);
|
||||
ResponseEntity<EventsPage> resp;
|
||||
try {
|
||||
|
@ -144,8 +143,7 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
builder.buildAndExpand(uriParams).encode().toUri(),
|
||||
HttpMethod.POST,
|
||||
entity,
|
||||
new ParameterizedTypeReference<EventsPage>() {
|
||||
}
|
||||
new ParameterizedTypeReference<EventsPage>() {}
|
||||
);
|
||||
} 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<Map<String, List<SimpleSubscriptionDesc>>> resp;
|
||||
try {
|
||||
resp = restTemplate.exchange(
|
||||
builder.build().encode().toUri(),
|
||||
uri,
|
||||
HttpMethod.GET,
|
||||
null,
|
||||
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
|
||||
|
@ -228,10 +225,9 @@ public class BrokerServiceImpl implements BrokerService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) throws BrokerException {
|
||||
Map<String, List<SimpleSubscriptionDesc>> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail);
|
||||
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUserByRepoId(String userEmail, String repoId) { //throws BrokerException {
|
||||
throw new NotImplementedException();
|
||||
// return null;
|
||||
//Map<String, List<SimpleSubscriptionDesc>> subscriptionsOfUser = getSimpleSubscriptionsOfUser(userEmail);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,41 +39,50 @@ public class DashboardServiceImpl implements DashboardService {
|
|||
|
||||
try {
|
||||
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.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<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20);
|
||||
List<AggregationInfo> 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<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialname());
|
||||
List<BrowseEntry> 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);
|
||||
|
|
|
@ -58,7 +58,7 @@ public class InterfaceComplianceService {
|
|||
|
||||
private Set<InterfaceComplianceRequest> getOutdated() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -7);
|
||||
calendar.add(Calendar.DATE, -7); // 7-days-old
|
||||
return this.repository.findAllBySubmissionDateBefore(calendar.getTime());
|
||||
}
|
||||
|
||||
|
|
|
@ -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 //
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue