develop #1

Merged
antonis.lempesis merged 36 commits from develop into master 2023-01-19 12:41:45 +01:00
8 changed files with 127 additions and 70 deletions
Showing only changes of commit a40c1b3e44 - Show all commits

View File

@ -1,7 +1,7 @@
# This script can create the local "dnet-repository" and copy the "settings-dnet.xml" file there. # This script can create the local "dnet-repository" and copy the "settings-dnet.xml" file there.
# It also builds the project, using the aforementioned settings file. # It also builds the project, using the aforementioned settings file.
# Then it can run the project locally. # Then it can run the project locally.
# By giving different options, the user can either install and run locally, just install or just run the project. # By giving different options, the user can either install and run locally, just install (arg: 2) or just run (arg: 1) the project.
# For error-handling, we cannot use the "set -e" since: it has problems https://mywiki.wooledge.org/BashFAQ/105 # For error-handling, we cannot use the "set -e" since: it has problems https://mywiki.wooledge.org/BashFAQ/105

View File

@ -7,10 +7,7 @@ import eu.dnetlib.repo.manager.domain.RepositorySummaryInfo;
import eu.dnetlib.repo.manager.domain.UsageSummary; import eu.dnetlib.repo.manager.domain.UsageSummary;
import eu.dnetlib.repo.manager.exception.BrokerException; import eu.dnetlib.repo.manager.exception.BrokerException;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.service.BrokerService; import eu.dnetlib.repo.manager.service.*;
import eu.dnetlib.repo.manager.service.DashboardService;
import eu.dnetlib.repo.manager.service.PiWikService;
import eu.dnetlib.repo.manager.service.RepositoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.json.JSONException; import org.json.JSONException;
import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.mitre.openid.connect.model.OIDCAuthenticationToken;
@ -33,6 +30,9 @@ public class DashboardController {
@Autowired @Autowired
private RepositoryService repositoryService; private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired @Autowired
private BrokerService brokerService; private BrokerService brokerService;
@ -57,12 +57,12 @@ public class DashboardController {
@PathVariable("repoId") String repoId, @PathVariable("repoId") String repoId,
@RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException { @RequestParam(name = "size", required = false, defaultValue = "20") int size) throws JSONException {
List<AggregationInfo> aggregationInfo = repositoryService.getRepositoryAggregations(repoId, 0, size); List<AggregationInfo> aggregationInfo = aggregationService.getRepositoryAggregations(repoId, 0, size);
CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary(); CollectionMonitorSummary collectionMonitorSummary = new CollectionMonitorSummary();
collectionMonitorSummary.setAggregationInfo(aggregationInfo); collectionMonitorSummary.setAggregationInfo(aggregationInfo);
size = 0; size = 0;
do { do {
aggregationInfo = repositoryService.getRepositoryAggregations(repoId, size, size + 50); aggregationInfo = aggregationService.getRepositoryAggregations(repoId, size, size + 50);
for (AggregationInfo aggregationDetail : aggregationInfo) { for (AggregationInfo aggregationDetail : aggregationInfo) {
if (aggregationDetail.isIndexedVersion()) { if (aggregationDetail.isIndexedVersion()) {
collectionMonitorSummary.setLastIndexedVersion(aggregationDetail); collectionMonitorSummary.setLastIndexedVersion(aggregationDetail);

View File

@ -6,6 +6,7 @@ import eu.dnetlib.repo.manager.domain.dto.RepositoryTerms;
import eu.dnetlib.repo.manager.domain.dto.User; import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.service.AggregationService;
import eu.dnetlib.repo.manager.service.RepositoryService; import eu.dnetlib.repo.manager.service.RepositoryService;
import eu.dnetlib.repo.manager.service.security.AuthorizationService; import eu.dnetlib.repo.manager.service.security.AuthorizationService;
import eu.dnetlib.repo.manager.utils.JsonUtils; import eu.dnetlib.repo.manager.utils.JsonUtils;
@ -37,12 +38,16 @@ public class RepositoryController {
private static final Logger logger = Logger.getLogger(RepositoryController.class); private static final Logger logger = Logger.getLogger(RepositoryController.class);
private final RepositoryService repositoryService; private final RepositoryService repositoryService;
private final AggregationService aggregationService;
private final AuthorizationService authorizationService; private final AuthorizationService authorizationService;
@Autowired @Autowired
RepositoryController(RepositoryService repositoryService, RepositoryController(RepositoryService repositoryService,
AuthorizationService authorizationService) { AggregationService aggregationService, AuthorizationService authorizationService) {
this.repositoryService = repositoryService; this.repositoryService = repositoryService;
this.aggregationService = aggregationService;
this.authorizationService = authorizationService; this.authorizationService = authorizationService;
} }
@ -121,14 +126,14 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public List<AggregationInfo> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException { public List<AggregationInfo> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryAggregations(id, 0, 20); return aggregationService.getRepositoryAggregations(id, 0, 20);
} }
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET, @RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException { public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
return repositoryService.getRepositoryAggregationsByYear(id); return aggregationService.getRepositoryAggregationsByYear(id);
} }
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET, @RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,

View File

@ -0,0 +1,16 @@
package eu.dnetlib.repo.manager.service;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import java.util.List;
import java.util.Map;
public interface AggregationService {
List<AggregationInfo> getRepositoryAggregations(String id);
List<AggregationInfo> getRepositoryAggregations(String id, int from, int size);
Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(String id);
}

View File

@ -0,0 +1,92 @@
package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.AggregationHistoryResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
@Service("aggregationService")
public class AggregationServiceImpl implements AggregationService {
private static final Logger logger = Logger.getLogger(AggregationServiceImpl.class);
@Value("${services.provide.clients.dsm}")
private String baseAddress;
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;
public AggregationServiceImpl(RestTemplate restTemplate, ObjectMapper objectMapper) {
this.restTemplate = restTemplate;
this.objectMapper = objectMapper;
}
@Override
public List<AggregationInfo> getRepositoryAggregations(String id) throws RestClientException {
logger.debug("Retrieving aggregations for repository with id : " + id);
UriComponents uriComponents = getAggregationHistory(id);
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
return rs != null ? rs.getAggregationInfo() : null;
}
@Override
public List<AggregationInfo> getRepositoryAggregations(String id, int from, int size) throws RestClientException {
List<AggregationInfo> res = getRepositoryAggregations(id);
return (res != null) ? res.subList(from, Math.min(from + size, res.size())) : null;
}
@Override
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(String id) throws RestClientException {
logger.debug("Retrieving aggregations (by year) for repository with id : " + id);
List<AggregationInfo> aggregationHistory = getRepositoryAggregations(id);
if ( aggregationHistory != null ) {
Map<String, List<AggregationInfo>> aggregationByYear = new HashMap<>();
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
} else
return null;
}
private UriComponents getAggregationHistory(String repoId) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
.path(repoId)
.build().expand(repoId).encode();
}
private Map<String, List<AggregationInfo>> createYearMap(List<AggregationInfo> aggregationHistory) {
aggregationHistory = aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationInfo::getDate).reversed())
.collect(Collectors.toList());
return aggregationHistory.stream()
.collect(Collectors.groupingBy(item -> getYear(item.getDate())));
}
}

View File

@ -23,6 +23,9 @@ public class DashboardServiceImpl implements DashboardService {
@Autowired @Autowired
private RepositoryService repositoryService; private RepositoryService repositoryService;
@Autowired
private AggregationService aggregationService;
@Autowired @Autowired
private BrokerService brokerService; private BrokerService brokerService;
@ -43,7 +46,7 @@ public class DashboardServiceImpl implements DashboardService {
//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?
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<AggregationInfo> aggregationInfoList = repositoryService.getRepositoryAggregations(repository.getId(), 0, 20); List<AggregationInfo> aggregationInfoList = aggregationService.getRepositoryAggregations(repository.getId(), 0, 20);
for (AggregationInfo aggregationInfo : aggregationInfoList) { for (AggregationInfo aggregationInfo : aggregationInfoList) {
if (aggregationInfo.isIndexedVersion()) { if (aggregationInfo.isIndexedVersion()) {
repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords()); repositorySummaryInfo.setRecordsCollected(aggregationInfo.getNumberOfRecords());
@ -68,7 +71,6 @@ public class DashboardServiceImpl implements DashboardService {
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: " + repository.getId(), e);
} }

View File

@ -1,6 +1,5 @@
package eu.dnetlib.repo.manager.service; package eu.dnetlib.repo.manager.service;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*; import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.exception.RepositoryServiceException; import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
@ -43,12 +42,6 @@ public interface RepositoryService {
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException; Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
List<AggregationInfo> getRepositoryAggregations(String id) throws JSONException;
List<AggregationInfo> getRepositoryAggregations(String id, int from, int size) throws JSONException;
Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(String id) throws JSONException;
List<Repository> getRepositoriesByName(String name, List<Repository> getRepositoriesByName(String name,
String page, String page,
String size) throws JSONException; String size) throws JSONException;

View File

@ -7,7 +7,6 @@ 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;
import eu.dnetlib.enabling.datasources.common.AggregationInfo;
import eu.dnetlib.repo.manager.domain.*; import eu.dnetlib.repo.manager.domain.*;
import eu.dnetlib.repo.manager.domain.dto.Role; import eu.dnetlib.repo.manager.domain.dto.Role;
import eu.dnetlib.repo.manager.domain.dto.User; import eu.dnetlib.repo.manager.domain.dto.User;
@ -46,9 +45,6 @@ import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static eu.dnetlib.repo.manager.utils.DateUtils.getYear;
@Service("repositoryService") @Service("repositoryService")
public class RepositoryServiceImpl implements RepositoryService { public class RepositoryServiceImpl implements RepositoryService {
@ -409,47 +405,6 @@ public class RepositoryServiceImpl implements RepositoryService {
} }
@Override
public List<AggregationInfo> getRepositoryAggregations(String id) {
LOGGER.debug("Retrieving aggregations for repository with id : " + id);
UriComponents uriComponents = getAggregationHistory(id);
AggregationHistoryResponse rs = restTemplate.getForObject(uriComponents.toUri(), AggregationHistoryResponse.class);
return rs != null ? rs.getAggregationInfo() : null;
}
@Override
public List<AggregationInfo> getRepositoryAggregations(String id, int from, int size) {
List<AggregationInfo> res = getRepositoryAggregations(id);
return (res != null) ? res.subList(from, Math.min(from + size, res.size())) : null;
}
@Override
public Map<String, List<AggregationInfo>> getRepositoryAggregationsByYear(String id) {
LOGGER.debug("Retrieving aggregations (by year) for repository with id : " + id);
List<AggregationInfo> aggregationHistory = getRepositoryAggregations(id);
if ( aggregationHistory != null ) {
Map<String, List<AggregationInfo>> aggregationByYear = new HashMap<>();
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
} else
return null;
}
private Map<String, List<AggregationInfo>> createYearMap(List<AggregationInfo> aggregationHistory) {
aggregationHistory = aggregationHistory.stream()
.sorted(Comparator.comparing(AggregationInfo::getDate).reversed())
.collect(Collectors.toList());
return aggregationHistory.stream()
.collect(Collectors.groupingBy(item -> getYear(item.getDate())));
}
@Override @Override
public List<Repository> getRepositoriesByName(String name, public List<Repository> getRepositoriesByName(String name,
String page, String page,
@ -1023,12 +978,6 @@ public class RepositoryServiceImpl implements RepositoryService {
return null; return null;
} }
private UriComponents getAggregationHistory(String repoId) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/aggregationhistory/")
.path(repoId)
.build().expand(repoId).encode();
}
private UriComponents searchDatasource(String page, String size) { private UriComponents searchDatasource(String page, String size) {