2019-02-16 11:04:41 +01:00
|
|
|
package eu.dnetlib.repo.manager.service;
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
2019-02-16 11:04:41 +01:00
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2021-07-21 13:51:18 +02:00
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
import com.google.gson.JsonElement;
|
2019-07-19 11:31:23 +02:00
|
|
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
2019-02-16 11:04:41 +01:00
|
|
|
import eu.dnetlib.domain.enabling.Vocabulary;
|
2019-07-19 11:31:23 +02:00
|
|
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
2019-11-28 12:25:56 +01:00
|
|
|
import eu.dnetlib.repo.manager.domain.*;
|
2022-11-10 18:34:23 +01:00
|
|
|
import eu.dnetlib.repo.manager.domain.dto.User;
|
2022-08-05 10:48:16 +02:00
|
|
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
2019-02-16 11:04:41 +01:00
|
|
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
2021-07-21 13:51:18 +02:00
|
|
|
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
|
|
|
|
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
|
|
|
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
|
2019-02-16 11:04:41 +01:00
|
|
|
import eu.dnetlib.repo.manager.utils.Converter;
|
2022-11-30 19:58:08 +01:00
|
|
|
import eu.dnetlib.repo.manager.utils.DateUtils;
|
2019-02-16 11:04:41 +01:00
|
|
|
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
2021-07-21 13:51:18 +02:00
|
|
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
2023-01-13 17:06:30 +01:00
|
|
|
import org.slf4j.Logger;
|
2023-01-11 17:50:31 +01:00
|
|
|
import org.slf4j.LoggerFactory;
|
2019-02-16 11:04:41 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2021-07-21 13:51:18 +02:00
|
|
|
import org.springframework.context.annotation.Lazy;
|
2019-02-16 11:04:41 +01:00
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
|
import org.springframework.http.*;
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
import org.springframework.security.core.Authentication;
|
2023-02-17 15:17:37 +01:00
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
2019-02-16 11:04:41 +01:00
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
import org.springframework.web.util.UriComponents;
|
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2023-02-17 15:17:37 +01:00
|
|
|
import java.util.stream.Collectors;
|
2022-11-30 19:58:08 +01:00
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
@Service("repositoryService")
|
|
|
|
public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
2023-01-11 17:50:31 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(RepositoryServiceImpl.class);
|
2021-07-21 13:51:18 +02:00
|
|
|
|
|
|
|
private final AuthorizationService authorizationService;
|
|
|
|
private final RoleMappingService roleMappingService;
|
|
|
|
private final AaiRegistryService registryCalls;
|
|
|
|
private final RestTemplate restTemplate;
|
2022-12-20 19:40:37 +01:00
|
|
|
private final ObjectMapper objectMapper;
|
2021-07-21 13:51:18 +02:00
|
|
|
private final VocabularyLoader vocabularyLoader;
|
|
|
|
private final PiWikService piWikService;
|
|
|
|
private final EmailUtils emailUtils;
|
|
|
|
private final ValidatorService validatorService;
|
2023-01-16 19:30:09 +01:00
|
|
|
private final InterfaceComplianceService interfaceComplianceService;
|
2021-07-21 13:51:18 +02:00
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.clients.dsm}")
|
2019-02-16 11:04:41 +01:00
|
|
|
private String baseAddress;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.adminEmail}")
|
2019-07-19 11:31:23 +02:00
|
|
|
private String adminEmail;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.usageStatisticsDiagramsBaseURL}")
|
2019-02-16 11:04:41 +01:00
|
|
|
private String usageStatisticsDiagramsBaseURL;
|
|
|
|
|
2021-10-26 13:46:08 +02:00
|
|
|
@Value("${services.provide.usageStatisticsNumbersBaseURL}")
|
2019-02-16 11:04:41 +01:00
|
|
|
private String usageStatisticsNumbersBaseURL;
|
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
|
|
|
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2019-07-19 11:31:23 +02:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
private final String[] vocabularyNames = {"dnet:countries", "dnet:eosc_datasource_types", "dnet:compatibilityLevel"};
|
2021-07-21 13:51:18 +02:00
|
|
|
private final Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<>();
|
|
|
|
private final Map<String, String> countriesMap = new HashMap<>();
|
|
|
|
private final Map<String, String> inverseCountriesMap = new HashMap<>();
|
|
|
|
private HttpHeaders httpHeaders;
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
@Autowired
|
|
|
|
public RepositoryServiceImpl(AuthorizationService authorizationService,
|
|
|
|
RoleMappingService roleMappingService,
|
|
|
|
AaiRegistryService registryCalls,
|
|
|
|
VocabularyLoader vocabularyLoader,
|
|
|
|
RestTemplate restTemplate,
|
2022-12-20 19:40:37 +01:00
|
|
|
ObjectMapper objectMapper,
|
2021-07-21 13:51:18 +02:00
|
|
|
@Lazy EmailUtils emailUtils,
|
|
|
|
@Lazy ValidatorService validatorService,
|
2023-01-16 19:30:09 +01:00
|
|
|
@Lazy PiWikService piWikService,
|
|
|
|
@Lazy InterfaceComplianceService interfaceComplianceService) {
|
2021-07-21 13:51:18 +02:00
|
|
|
this.authorizationService = authorizationService;
|
|
|
|
this.roleMappingService = roleMappingService;
|
|
|
|
this.registryCalls = registryCalls;
|
|
|
|
this.vocabularyLoader = vocabularyLoader;
|
|
|
|
this.piWikService = piWikService;
|
|
|
|
this.emailUtils = emailUtils;
|
|
|
|
this.validatorService = validatorService;
|
|
|
|
this.restTemplate = restTemplate;
|
2022-12-20 19:40:37 +01:00
|
|
|
this.objectMapper = objectMapper;
|
2023-01-16 19:30:09 +01:00
|
|
|
this.interfaceComplianceService = interfaceComplianceService;
|
2021-07-21 13:51:18 +02:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
private void init() {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Initialization method of repository api! Updated version!");
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-04-20 12:26:28 +02:00
|
|
|
for (String key : this.getVocabulary("dnet:datasource_typologies").getAsMap().keySet()) {
|
|
|
|
if (key.contains("aggregator")) {
|
|
|
|
dataSourceClass.putIfAbsent("aggregator", new ArrayList<>());
|
|
|
|
dataSourceClass.get("aggregator").add(key);
|
|
|
|
} else if (key.contains("crissystem")) {
|
2022-08-05 10:48:16 +02:00
|
|
|
dataSourceClass.putIfAbsent("dris", new ArrayList<>());
|
|
|
|
dataSourceClass.get("dris").add(key);
|
2022-04-20 12:26:28 +02:00
|
|
|
} else if (key.contains("pubsrepository::journal")) { // do not change order -->
|
|
|
|
dataSourceClass.putIfAbsent("journal", Collections.singletonList("pubsrepository::journal"));
|
|
|
|
} else if (key.contains("pubsrepository")) { // do not change order <--
|
|
|
|
dataSourceClass.putIfAbsent("opendoar", new ArrayList<>());
|
|
|
|
dataSourceClass.get("opendoar").add(key);
|
|
|
|
} else if (key.contains("datarepository")) {
|
|
|
|
dataSourceClass.putIfAbsent("re3data", Collections.singletonList("datarepository::unknown"));
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 14:58:01 +02:00
|
|
|
|
2022-04-20 12:26:28 +02:00
|
|
|
for (Map.Entry<String, List<String>> entry : dataSourceClass.entrySet()) {
|
|
|
|
entry.getValue().forEach(v -> invertedDataSourceClass.put(v, entry.getKey()));
|
|
|
|
}
|
2019-07-25 14:58:01 +02:00
|
|
|
|
2019-03-19 14:48:39 +01:00
|
|
|
httpHeaders = new HttpHeaders();
|
2023-01-23 17:26:19 +01:00
|
|
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
for (String vocName : vocabularyNames) {
|
|
|
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
|
|
|
}
|
|
|
|
|
|
|
|
Country[] countries = getCountries();
|
|
|
|
for (Country c : countries) {
|
|
|
|
countriesMap.put(c.getName(), c.getCode());
|
|
|
|
inverseCountriesMap.put(c.getCode(), c.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Country[] getCountries() {
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/countries")
|
|
|
|
.build().encode();
|
|
|
|
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
|
|
|
|
}
|
2022-12-20 19:40:37 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
|
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
@Override
|
2023-01-30 17:56:34 +01:00
|
|
|
public List<Repository> getRepositories(List<String> ids) {
|
2021-07-21 13:51:18 +02:00
|
|
|
return getRepositories(ids, 0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
|
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public List<Repository> getRepositories(List<String> ids, int page, int size) {
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids));
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchDatasourceUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
2021-07-21 13:51:18 +02:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
List<Repository> repos = new ArrayList<>();
|
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
for (String repoId : ids) {
|
|
|
|
requestFilter.setId(repoId);
|
2023-01-23 16:45:35 +01:00
|
|
|
repos.addAll(searchDatasource(uriComponents, requestFilter, Repository.class).getResults());
|
2021-07-21 13:51:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (Repository r : repos)
|
|
|
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
|
|
|
return repos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
|
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
@Override
|
2023-01-23 17:26:19 +01:00
|
|
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) {
|
2021-07-21 13:51:18 +02:00
|
|
|
return getRepositoriesSnippets(ids, 0, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
|
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
@Override
|
2023-01-23 17:26:19 +01:00
|
|
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) {
|
|
|
|
List<RepositorySnippet> resultSet = null;
|
2023-01-23 16:45:35 +01:00
|
|
|
List<DatasourceDetails> datasourceDetailsList = new ArrayList<>();
|
2021-07-21 13:51:18 +02:00
|
|
|
|
|
|
|
// here page should be 0
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
2021-07-21 13:51:18 +02:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
for (String repoId : ids) {
|
|
|
|
requestFilter.setId(repoId);
|
|
|
|
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
2023-01-23 16:54:51 +01:00
|
|
|
if (rs == null) {
|
2023-01-23 16:45:35 +01:00
|
|
|
logger.error("The \"DatasourceResponse\" is null!");
|
2023-01-23 16:54:51 +01:00
|
|
|
} else {
|
2023-01-23 16:45:35 +01:00
|
|
|
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
2021-07-21 13:51:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-23 17:26:19 +01:00
|
|
|
try {
|
|
|
|
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
|
|
|
|
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class));
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
|
logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet));
|
|
|
|
}
|
|
|
|
resultSet.parallelStream().forEach(repositorySnippet -> {
|
|
|
|
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
|
|
|
});
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
logger.error("Error deserializing.", e);
|
2023-01-23 16:45:35 +01:00
|
|
|
}
|
2021-07-21 13:51:18 +02:00
|
|
|
return resultSet;
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
|
|
|
String mode,
|
2023-01-30 17:56:34 +01:00
|
|
|
Boolean managed) {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Getting repositories by country!");
|
2019-02-16 11:04:41 +01:00
|
|
|
int page = 0;
|
2023-02-15 16:14:02 +01:00
|
|
|
int size = 10_000; // Include all repositories. Some countries have more than a thousand.
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
String filterKey = "UNKNOWN";
|
2022-08-05 10:48:16 +02:00
|
|
|
if (mode.equalsIgnoreCase("repository"))
|
|
|
|
filterKey = "Repository";
|
2022-04-20 12:26:28 +02:00
|
|
|
else if (mode.equalsIgnoreCase("cris"))
|
2022-08-05 10:48:16 +02:00
|
|
|
filterKey = "CRIS system";
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri(String.valueOf(page), String.valueOf(size));
|
2019-02-16 11:04:41 +01:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
requestFilter.setCountry(country);
|
2022-08-05 10:48:16 +02:00
|
|
|
requestFilter.setEoscDatasourceType(filterKey);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
return searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
2019-07-19 11:31:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
2023-01-30 17:56:34 +01:00
|
|
|
String officialName, String requestSortBy, String order, int page, int pageSize) {
|
2019-07-19 11:31:23 +02:00
|
|
|
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Searching registered repositories");
|
2019-07-19 11:31:23 +02:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchRegisteredDatasourceUri(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
2019-07-19 11:31:23 +02:00
|
|
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
requestFilter.setCountry(country);
|
|
|
|
requestFilter.setTypology(typology);
|
|
|
|
requestFilter.setOfficialname(officialName);
|
|
|
|
requestFilter.setEnglishname(englishName);
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
Paging<RepositorySnippet> snippets = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class);
|
2022-11-24 17:36:37 +01:00
|
|
|
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2021-10-12 15:30:38 +02:00
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public Integer getTotalRegisteredRepositories() throws NullPointerException {
|
2021-10-12 15:30:38 +02:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
|
|
|
.queryParam("fromDate", "1900-01-01")
|
|
|
|
.build().encode();
|
|
|
|
|
|
|
|
return restTemplate.getForObject(uriComponents.toUri(), Integer.class);
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private Repository updateRepositoryInfo(Repository r) {
|
2019-02-16 11:04:41 +01:00
|
|
|
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
|
|
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-30 17:56:34 +01:00
|
|
|
public List<Repository> getRepositoriesOfUser(String page, String size) {
|
2023-01-12 13:16:27 +01:00
|
|
|
logger.debug("Retrieving repositories of authenticated user : {}",
|
|
|
|
((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail());
|
2023-02-17 15:17:37 +01:00
|
|
|
Collection<String> repoIds = roleMappingService.getRepositoryIds(authorizationService.getUserRoles());
|
2021-07-21 13:51:18 +02:00
|
|
|
return getRepositories(new ArrayList<>(repoIds));
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
@Override
|
2023-01-30 17:56:34 +01:00
|
|
|
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) {
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Retrieving repositories of authenticated user : {}", userEmail);
|
2023-02-17 15:17:37 +01:00
|
|
|
Collection<String> repoIds = roleMappingService.getRepositoryIds(authorizationService.getUserRolesByEmail(userEmail));
|
2021-07-21 13:51:18 +02:00
|
|
|
return getRepositories(new ArrayList<>(repoIds));
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
@Override
|
2023-01-23 17:26:19 +01:00
|
|
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) {
|
2022-08-05 10:48:16 +02:00
|
|
|
return getRepositoriesSnippetsOfUser(null, page, size);
|
2021-07-21 13:51:18 +02:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
@Override
|
2023-01-23 17:26:19 +01:00
|
|
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) {
|
2022-08-05 10:48:16 +02:00
|
|
|
int from = Integer.parseInt(page) * Integer.parseInt(size);
|
|
|
|
int to = from + Integer.parseInt(size);
|
2023-02-17 15:17:37 +01:00
|
|
|
List<String> repoIds = getRepoIdsOfUser(userEmail);
|
2022-08-05 10:48:16 +02:00
|
|
|
|
|
|
|
if (repoIds.size() < from) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
} else if (repoIds.size() < to) {
|
|
|
|
to = repoIds.size();
|
|
|
|
}
|
|
|
|
return getRepositoriesSnippets(repoIds.subList(from, to)); // FIXME: returns less results if some repos are not found
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2019-12-13 14:40:55 +01:00
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException {
|
2019-12-13 14:40:55 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Retrieving repositories with id : {}", id);
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri("0", "100");
|
2019-12-13 14:40:55 +01:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
2021-07-21 13:51:18 +02:00
|
|
|
requestFilter.setId(id);
|
2019-12-13 14:40:55 +01:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
List<RepositorySnippet> repositories = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
2021-07-21 13:51:18 +02:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
if (repositories.isEmpty())
|
2021-10-22 13:32:44 +02:00
|
|
|
throw new ResourceNotFoundException();
|
2021-07-21 13:51:18 +02:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
return repositories.get(0);
|
2019-12-13 14:40:55 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public Repository getRepositoryById(String id) throws ResourceNotFoundException {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Retrieving repositories with id : {}", id);
|
2023-01-23 16:45:35 +01:00
|
|
|
|
|
|
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
2019-02-16 11:04:41 +01:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
requestFilter.setId(id);
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
List<Repository> datasources = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
|
|
|
if (datasources.isEmpty())
|
2021-10-22 13:32:44 +02:00
|
|
|
throw new ResourceNotFoundException();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
return updateRepositoryInfo(datasources.get(0));
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public List<Repository> getRepositoriesByName(String name,
|
|
|
|
String page,
|
2023-01-30 17:56:34 +01:00
|
|
|
String size) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Retrieving repositories with official name : {}", name);
|
2023-01-23 16:45:35 +01:00
|
|
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
2019-02-16 11:04:41 +01:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
requestFilter.setOfficialname(name);
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
List<Repository> repos = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
2021-10-22 13:32:44 +02:00
|
|
|
for (Repository r : repos)
|
|
|
|
updateRepositoryInfo(r);
|
|
|
|
return repos;
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public List<RepositoryInterface> getRepositoryInterface(String id) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
|
|
|
.path("/{id}")
|
|
|
|
.build().expand(id).encode();
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
List<RepositoryInterface> rs = searchApi(uriComponents, null, RepositoryInterface.class).getResults();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-10-10 18:04:06 +02:00
|
|
|
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
2023-01-23 16:45:35 +01:00
|
|
|
List<RepositoryInterface> repositoryInterfaces = new ArrayList<>();
|
|
|
|
for (RepositoryInterface det : rs) {
|
2022-12-07 12:37:55 +01:00
|
|
|
String protocol = det.getProtocol();
|
2023-01-17 15:57:14 +01:00
|
|
|
if (!protocol.equals("sword") &&
|
2022-12-07 12:37:55 +01:00
|
|
|
!protocol.equals("rest") &&
|
|
|
|
!protocol.equals("ftp")) {
|
2023-01-23 16:45:35 +01:00
|
|
|
repositoryInterfaces.add(det);
|
2022-11-08 19:37:51 +01:00
|
|
|
}
|
2022-10-10 13:27:28 +02:00
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
return repositoryInterfaces;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-30 17:56:34 +01:00
|
|
|
public Repository addRepository(String datatype, Repository repository) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("storing '{}' repository with id: {}", datatype, repository.getId());
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
repository.setActivationId(UUID.randomUUID().toString());
|
2022-08-05 10:48:16 +02:00
|
|
|
repository.setCollectedfrom("infrastruct_::openaire");
|
|
|
|
|
|
|
|
// Date now = new Date();
|
|
|
|
// repository.setRegistrationdate(now);
|
|
|
|
// repository.setConsentTermsOfUseDate(now);
|
|
|
|
// repository.setLastConsentTermsOfUseDate(now);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
if (datatype.equals("journal")) {
|
2022-08-05 10:48:16 +02:00
|
|
|
repository.setEoscDatasourceType("Journal archive");
|
2019-02-16 11:04:41 +01:00
|
|
|
repository.setId("openaire____::issn" + repository.getIssn());
|
2022-08-05 10:48:16 +02:00
|
|
|
repository.setNamespaceprefix("issn" + repository.getIssn());
|
2019-02-16 11:04:41 +01:00
|
|
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
2021-07-21 13:51:18 +02:00
|
|
|
} else if (datatype.equals("aggregator")) {
|
2022-08-05 10:48:16 +02:00
|
|
|
repository.setEoscDatasourceType("Aggregator");
|
|
|
|
repository.setId("openaire____::" + DigestUtils.md5Hex(repository.getOfficialname()));
|
|
|
|
repository.setNamespaceprefix(DigestUtils.md5Hex(repository.getOfficialname()).substring(0, 12));
|
2019-02-16 11:04:41 +01:00
|
|
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
2021-07-21 13:51:18 +02:00
|
|
|
} else {
|
2022-08-05 10:48:16 +02:00
|
|
|
if (repository.getTypology().contains("crissystem")) {
|
|
|
|
repository.setEoscDatasourceType("CRIS system");
|
|
|
|
} else {
|
|
|
|
repository.setEoscDatasourceType("Repository");
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication());
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:20:41 +01:00
|
|
|
authorizationService.createAndAssignRoleToAuthenticatedUser(repository.getId(), repository.getOfficialname());
|
2021-07-21 13:51:18 +02:00
|
|
|
|
2019-02-16 11:04:41 +01:00
|
|
|
return repository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update method acting as add -> send email with registration topic/body*/
|
2023-01-23 16:45:35 +01:00
|
|
|
private Repository latentUpdate(Repository repository, Authentication authentication) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
|
|
|
.build()
|
|
|
|
.encode();
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
2023-01-13 11:20:06 +01:00
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
2023-01-13 17:06:30 +01:00
|
|
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
|
|
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
2022-12-07 12:37:55 +01:00
|
|
|
} else {
|
|
|
|
Object responseBody = responseEntity.getBody();
|
2023-01-17 15:57:14 +01:00
|
|
|
if (responseBody != null)
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.error("Error updating repository: {}", responseBody);
|
2022-12-07 12:37:55 +01:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
return repository;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-30 17:56:34 +01:00
|
|
|
public Repository updateRepository(Repository repository, Authentication authentication) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
|
|
|
.build()
|
|
|
|
.encode();
|
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
2023-01-13 11:20:06 +01:00
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
2023-01-13 17:06:30 +01:00
|
|
|
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
|
|
|
|
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
|
2022-12-07 12:37:55 +01:00
|
|
|
} else {
|
|
|
|
Object responseBody = responseEntity.getBody();
|
2023-01-17 15:57:14 +01:00
|
|
|
if (responseBody != null)
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.error("Error updating repository: {}", responseBody);
|
2022-12-07 12:37:55 +01:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
return repository;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2023-01-30 17:56:34 +01:00
|
|
|
private void storeRepository(Repository repository, Authentication authentication) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
Date utilDate = new Date();
|
|
|
|
Timestamp date = new Timestamp(utilDate.getTime());
|
2022-08-05 10:48:16 +02:00
|
|
|
repository.setDateofcollection(date);
|
2019-02-16 11:04:41 +01:00
|
|
|
repository.setAggregator("OPENAIRE");
|
2022-08-05 10:48:16 +02:00
|
|
|
// repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/add/")
|
|
|
|
.build()
|
|
|
|
.encode();
|
2022-08-05 10:48:16 +02:00
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
2023-01-13 11:20:06 +01:00
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
2023-01-13 17:06:30 +01:00
|
|
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
|
|
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
2019-07-19 11:31:23 +02:00
|
|
|
} else {
|
2022-12-07 12:37:55 +01:00
|
|
|
Object responseBody = responseEntity.getBody();
|
2023-01-17 15:57:14 +01:00
|
|
|
if (responseBody != null)
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.error("Error storing repository: {}", responseBody);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-21 13:51:18 +02:00
|
|
|
public void deleteRepositoryInterface(String id,
|
|
|
|
String registeredBy) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
|
|
|
.path("/{id}")
|
|
|
|
.build().expand(id).encode();
|
2023-01-11 17:50:31 +01:00
|
|
|
logger.debug("{}", uriComponents.toUri());
|
2019-02-16 11:04:41 +01:00
|
|
|
restTemplate.delete(uriComponents.toUri());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public RepositoryInterface addRepositoryInterface(String datatype,
|
|
|
|
String repoId,
|
2023-01-16 19:30:09 +01:00
|
|
|
String comment,
|
|
|
|
RepositoryInterface repositoryInterface,
|
|
|
|
String desiredCompatibilityLevel) throws Exception {
|
2022-11-10 18:34:23 +01:00
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
2023-01-31 14:40:06 +01:00
|
|
|
Repository repo = this.getRepositoryById(repoId);
|
|
|
|
repositoryInterface = fillInterfaceFields(repo, repositoryInterface, datatype);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
2023-01-31 14:40:06 +01:00
|
|
|
.build().encode();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
2021-10-22 13:32:44 +02:00
|
|
|
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
2019-12-18 14:11:36 +01:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
// Explicitly update validation set (updating the interface does not allow updating the set value)
|
|
|
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
|
|
|
2023-01-31 14:40:06 +01:00
|
|
|
emailUtils.sendAdminRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
|
|
|
emailUtils.sendUserRegisterInterfaceEmail(repo, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
2019-12-18 14:11:36 +01:00
|
|
|
|
2023-01-31 14:40:06 +01:00
|
|
|
String prevCompatibilityLevel = repositoryInterface.getCompatibility();
|
2023-02-17 15:17:37 +01:00
|
|
|
if ((desiredCompatibilityLevel != null)
|
|
|
|
&& ((prevCompatibilityLevel == null) || !prevCompatibilityLevel.equals(desiredCompatibilityLevel))) {
|
2023-01-16 19:30:09 +01:00
|
|
|
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
|
|
|
|
interfaceComplianceService.create(request);
|
|
|
|
}
|
|
|
|
|
2023-01-31 14:40:06 +01:00
|
|
|
submitInterfaceValidation(repo, getAuthenticatedUser().getEmail(), repositoryInterface, false, desiredCompatibilityLevel);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
return repositoryInterface;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-19 11:31:23 +02:00
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public RepositoryInterface updateRepositoryInterface(String repoId,
|
2022-11-10 18:34:23 +01:00
|
|
|
String comment,
|
2023-01-13 17:06:30 +01:00
|
|
|
RepositoryInterface repositoryInterface,
|
2023-01-23 17:26:19 +01:00
|
|
|
String desiredCompatibilityLevel) throws ResourceNotFoundException, ValidatorServiceException {
|
2022-11-10 18:34:23 +01:00
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
2023-01-13 17:06:30 +01:00
|
|
|
Repository repository = this.getRepositoryById(repoId);
|
2023-01-20 18:17:06 +01:00
|
|
|
if (repositoryInterface.getId() != null) {
|
|
|
|
RepositoryInterface existing = getRepositoryInterface(repoId).stream().filter(iFace -> iFace.getId().equals(repositoryInterface.getId())).findFirst().orElse(null);
|
|
|
|
if (existing != null && (existing.getBaseurl() == null || "".equals(existing.getBaseurl()))) {
|
|
|
|
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseurl());
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 17:06:30 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
|
|
|
2023-01-30 17:56:34 +01:00
|
|
|
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
|
|
|
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, desiredCompatibilityLevel, authentication);
|
2019-12-18 14:11:36 +01:00
|
|
|
|
2023-01-19 11:15:30 +01:00
|
|
|
if (desiredCompatibilityLevel != null && (repositoryInterface.getCompatibility() == null || !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel))) {
|
2023-01-16 19:30:09 +01:00
|
|
|
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
|
|
|
|
interfaceComplianceService.create(request);
|
|
|
|
}
|
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
submitInterfaceValidation(getRepositoryById(repoId), getAuthenticatedUser().getEmail(), repositoryInterface, true, desiredCompatibilityLevel);
|
2019-12-18 14:11:36 +01:00
|
|
|
|
2019-07-19 11:31:23 +02:00
|
|
|
return repositoryInterface;
|
|
|
|
}
|
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
@Override
|
|
|
|
public void updateInterfaceCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
|
|
|
this.updateCompliance(repositoryId, repositoryInterfaceId, compliance);
|
|
|
|
}
|
|
|
|
|
2022-11-10 18:34:23 +01:00
|
|
|
private User getAuthenticatedUser() {
|
|
|
|
return User.from(((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo());
|
|
|
|
}
|
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting, String desiredCompatibilityLevel) throws ValidatorServiceException {
|
2019-07-19 11:31:23 +02:00
|
|
|
JobForValidation job = new JobForValidation();
|
|
|
|
|
|
|
|
job.setActivationId(UUID.randomUUID().toString());
|
|
|
|
job.setAdminEmails(Collections.singletonList(this.adminEmail));
|
2022-08-05 10:48:16 +02:00
|
|
|
job.setBaseUrl(iFace.getBaseurl());
|
2019-07-19 11:31:23 +02:00
|
|
|
job.setDatasourceId(repo.getId());
|
2023-01-13 17:06:30 +01:00
|
|
|
job.setDesiredCompatibilityLevel(desiredCompatibilityLevel);
|
2019-07-19 11:31:23 +02:00
|
|
|
job.setInterfaceId(iFace.getId());
|
2022-08-05 10:48:16 +02:00
|
|
|
job.setOfficialName(repo.getOfficialname());
|
|
|
|
job.setRepoType(repo.getEoscDatasourceType());
|
2019-07-19 11:31:23 +02:00
|
|
|
job.setUserEmail(userEmail);
|
2022-09-07 15:29:04 +02:00
|
|
|
String accessSet = iFace.getAccessSet();
|
|
|
|
|
|
|
|
job.setValidationSet((accessSet.isEmpty() ? "none" : accessSet));
|
2019-07-19 11:31:23 +02:00
|
|
|
job.setRecords(-1);
|
2019-09-04 14:21:53 +02:00
|
|
|
job.setRegistration(!updateExisting);
|
|
|
|
job.setUpdateExisting(updateExisting);
|
2019-07-19 11:31:23 +02:00
|
|
|
|
|
|
|
this.validatorService.submitJobForValidation(job);
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private RepositoryInterface fillInterfaceFields(Repository repo, RepositoryInterface iFace, String datatype) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
iFace.setDatasource(repo.getId());
|
|
|
|
iFace.setContentdescription("metadata");
|
2023-01-13 17:06:30 +01:00
|
|
|
|
|
|
|
logger.warn("Compatibility level: {}", iFace.getCompatibility());
|
2023-01-17 12:49:00 +01:00
|
|
|
if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) {
|
2023-01-13 17:06:30 +01:00
|
|
|
iFace.setCompatibility("UNKNOWN");
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
if (datatype.equals("re3data"))
|
|
|
|
iFace.setAccessFormat("oai_datacite");
|
|
|
|
else
|
|
|
|
iFace.setAccessFormat("oai_dc");
|
|
|
|
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
// TODO: is this the correct functionality?
|
2022-08-05 10:48:16 +02:00
|
|
|
if (repo.getEoscDatasourceType() != null && !repo.getEoscDatasourceType().isEmpty())
|
|
|
|
iFace.setTypology(repo.getEoscDatasourceType());
|
2019-02-16 11:04:41 +01:00
|
|
|
else if (datatype.equalsIgnoreCase("journal"))
|
|
|
|
iFace.setTypology("pubsrepository::journal");
|
|
|
|
else if (datatype.equalsIgnoreCase("aggregator"))
|
|
|
|
iFace.setTypology("aggregator::pubsrepository::unknown");
|
|
|
|
else if (datatype.equalsIgnoreCase("opendoar"))
|
|
|
|
iFace.setTypology("pubsrepository::unknown");
|
|
|
|
else if (datatype.equalsIgnoreCase("re3data"))
|
|
|
|
iFace.setTypology("datarepository::unknown");
|
|
|
|
|
|
|
|
iFace.setRemovable(true);
|
2022-08-05 10:48:16 +02:00
|
|
|
iFace.setProtocol("oai");
|
2019-02-16 11:04:41 +01:00
|
|
|
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
|
|
|
|
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
|
2019-07-25 13:54:21 +02:00
|
|
|
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("set is empty: {}", iFace.getAccessSet());
|
2019-07-25 13:54:21 +02:00
|
|
|
iFace.setAccessSet("none");
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
return iFace;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getDnetCountries() {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.debug("Getting dnet-countries!");
|
2023-01-23 16:45:35 +01:00
|
|
|
return Converter.readFile("countries.txt");
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getTypologies() {
|
2023-01-23 16:45:35 +01:00
|
|
|
return Converter.readFile("typologies.txt");
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Timezone> getTimezones() {
|
2023-01-23 16:45:35 +01:00
|
|
|
List<String> timezones = Converter.readFile("timezones.txt");
|
|
|
|
return Converter.toTimezones(timezones);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public List<String> getUrlsOfUserRepos(String userEmail,
|
|
|
|
String page,
|
2021-07-21 13:51:18 +02:00
|
|
|
String size) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/api/baseurl/")
|
|
|
|
.path("/{page}/{size}")
|
2021-07-21 13:51:18 +02:00
|
|
|
.build().expand(page, size).encode();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-10-22 13:32:44 +02:00
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
requestFilter.setRegisteredby(userEmail);
|
2023-01-30 15:25:21 +01:00
|
|
|
String[] result = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class);
|
|
|
|
return (result != null) ? Arrays.asList(result) : null;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private Vocabulary getVocabulary(String vocName) {
|
|
|
|
|
|
|
|
if (!vocabularyMap.containsKey(vocName)) {
|
|
|
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
|
|
|
}
|
|
|
|
return vocabularyMap.get(vocName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-07-21 13:51:18 +02:00
|
|
|
public Map<String, String> getCompatibilityClasses(String mode) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Getting compatibility classes for mode: {}", mode);
|
2023-01-23 17:26:19 +01:00
|
|
|
Map<String, String> retMap = new HashMap<>();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
|
|
|
|
boolean foundData = false;
|
|
|
|
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
|
|
|
|
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
|
|
|
|
return compatibilityClasses;
|
|
|
|
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
|
2023-01-17 15:57:14 +01:00
|
|
|
if (ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches()) {
|
2019-02-16 11:04:41 +01:00
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
foundData = true;
|
|
|
|
}
|
2023-01-17 15:57:14 +01:00
|
|
|
} else if (mode.equalsIgnoreCase("cris")) {
|
2022-04-20 12:26:28 +02:00
|
|
|
if (entry.getKey().contains("openaire-cris")) {
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
foundData = true;
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
} else {
|
2023-01-17 15:57:14 +01:00
|
|
|
if (ValidatorServiceImpl.OPENAIRE_OR_DRIVER_REGEX.matcher(entry.getKey()).matches())
|
2019-02-16 11:04:41 +01:00
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
|
2022-09-06 15:55:05 +02:00
|
|
|
if ((mode.equalsIgnoreCase("repository") || mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) && !foundData)
|
2019-02-16 11:04:41 +01:00
|
|
|
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
|
|
|
|
|
|
|
|
return retMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-21 13:51:18 +02:00
|
|
|
public Map<String, String> getDatasourceClasses(String mode) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-13 17:06:30 +01:00
|
|
|
logger.debug("Getting datasource classes for mode: {}", mode);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2023-01-23 17:26:19 +01:00
|
|
|
Map<String, String> retMap = new HashMap<>();
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
// TODO: refactor (remove?)
|
2019-02-16 11:04:41 +01:00
|
|
|
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
|
|
|
|
if (mode.equalsIgnoreCase("aggregator")) {
|
|
|
|
if (entry.getKey().contains("aggregator"))
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
} else if (mode.equalsIgnoreCase("journal")) {
|
|
|
|
if (entry.getKey().contains("journal"))
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
} else if (mode.equalsIgnoreCase("opendoar")) {
|
|
|
|
if (entry.getKey().contains("pubsrepository"))
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
} else if (mode.equalsIgnoreCase("re3data")) {
|
|
|
|
if (entry.getKey().contains("datarepository"))
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
2022-08-05 10:48:16 +02:00
|
|
|
} else if (mode.equalsIgnoreCase("dris")) {
|
2022-04-20 12:26:28 +02:00
|
|
|
if (entry.getKey().contains("crissystem"))
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
2022-08-05 10:48:16 +02:00
|
|
|
if (mode.equalsIgnoreCase("fairsharing")) {
|
|
|
|
retMap.put(entry.getKey(), entry.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mode.equals("fairsharing")) {
|
|
|
|
return retMap;
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
2021-07-21 13:51:18 +02:00
|
|
|
return filterResults(retMap, mode);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
private Map<String, String> filterResults(Map<String, String> map, String mode) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
HashMap<String, String> filteredMap = new HashMap<>();
|
2022-08-05 10:48:16 +02:00
|
|
|
if (map != null && mode != null) {
|
|
|
|
for (String key : map.keySet())
|
|
|
|
if (dataSourceClass.get(mode).contains(key))
|
|
|
|
filteredMap.put(key, map.get(key));
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
return filteredMap;
|
|
|
|
}
|
|
|
|
return Collections.emptyMap();
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCountryName(String countryCode) {
|
|
|
|
return inverseCountriesMap.get(countryCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-07-25 13:54:21 +02:00
|
|
|
public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
|
2019-02-16 11:04:41 +01:00
|
|
|
try {
|
|
|
|
MetricsInfo metricsInfo = new MetricsInfo();
|
|
|
|
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
|
|
|
|
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
|
|
|
|
return metricsInfo;
|
|
|
|
} catch (Exception e) {
|
2022-12-14 15:33:12 +01:00
|
|
|
logger.error("Error while getting metrics info for repository: ", e);
|
2019-02-16 11:04:41 +01:00
|
|
|
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-23 16:45:35 +01:00
|
|
|
public Map<String, String> getListLatestUpdate(String mode) {
|
2022-08-05 10:48:16 +02:00
|
|
|
Map<String, String> dates = new HashMap<>();
|
|
|
|
if (mode.equals("repository")) {
|
2022-11-30 19:58:08 +01:00
|
|
|
dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
|
|
|
|
dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
|
2022-08-05 15:24:32 +02:00
|
|
|
// create re3data last collection date
|
2023-01-23 16:45:35 +01:00
|
|
|
// dates.put("re3data", Converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate()));
|
2022-08-05 15:24:32 +02:00
|
|
|
List<RepositoryInterface> re3interfaces = getRepositoryInterface("openaire____::re3data");
|
|
|
|
String re3Date = null;
|
|
|
|
for (RepositoryInterface interf : re3interfaces) {
|
|
|
|
if (interf.getLastCollectionDate() != null) {
|
2022-11-30 19:58:08 +01:00
|
|
|
re3Date = DateUtils.toString(interf.getLastCollectionDate());
|
2022-08-05 15:24:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dates.put("re3data", re3Date);
|
|
|
|
|
2022-08-05 10:48:16 +02:00
|
|
|
return dates;
|
2023-01-17 15:57:14 +01:00
|
|
|
} else if (mode.equals("cris"))
|
2022-11-30 19:58:08 +01:00
|
|
|
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("eurocrisdris::dris").get(0).getLastCollectionDate()));
|
2022-08-05 10:48:16 +02:00
|
|
|
else if (mode.equals("opendoar")) // TODO: remove this and else clause
|
2022-11-30 19:58:08 +01:00
|
|
|
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
|
2019-02-16 11:04:41 +01:00
|
|
|
else
|
|
|
|
/*
|
2021-07-21 13:51:18 +02:00
|
|
|
* first api of re3data has null value on collection date
|
|
|
|
* */
|
2022-11-30 19:58:08 +01:00
|
|
|
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2023-01-23 17:26:19 +01:00
|
|
|
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("dsId", repositoryId)
|
|
|
|
.queryParam("apiId", repositoryInterfaceId)
|
|
|
|
.queryParam("oaiSet", validationSet)
|
2019-02-16 11:04:41 +01:00
|
|
|
.build().encode();
|
2021-07-21 13:51:18 +02:00
|
|
|
restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, null, ResponseEntity.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) {
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/baseurl")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("dsId", repositoryId)
|
|
|
|
.queryParam("apiId", repositoryInterfaceId)
|
|
|
|
.queryParam("baseUrl", baseUrl)
|
2019-02-16 11:04:41 +01:00
|
|
|
.build().encode();
|
2021-07-21 13:51:18 +02:00
|
|
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
private void updateCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
2019-02-16 11:04:41 +01:00
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/compliance")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("dsId", repositoryId)
|
|
|
|
.queryParam("apiId", repositoryInterfaceId)
|
|
|
|
.queryParam("compliance", compliance)
|
2019-02-16 11:04:41 +01:00
|
|
|
.build().encode();
|
2021-07-21 13:51:18 +02:00
|
|
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private MetricsNumbers getMetricsNumbers(String openAIREID) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
//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;
|
2021-10-22 13:32:44 +02:00
|
|
|
|
|
|
|
//communicate with endpoint
|
|
|
|
resp = template.exchange(
|
|
|
|
builder.build().encode().toUri(),
|
|
|
|
HttpMethod.GET,
|
|
|
|
null,
|
|
|
|
new ParameterizedTypeReference<MetricsNumbers>() {
|
|
|
|
});
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
return resp.getBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getOpenAIREId(String repoId) {
|
|
|
|
|
|
|
|
if (repoId != null && repoId.contains("::")) {
|
|
|
|
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:01:08 +02:00
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private UriComponents searchDatasourceUri(String page, String size) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
return UriComponentsBuilder
|
2022-03-15 12:33:49 +01:00
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
2019-02-16 11:04:41 +01:00
|
|
|
.path("/{page}/{size}/")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("requestSortBy", "officialname")
|
|
|
|
.queryParam("order", "ASCENDING")
|
2019-02-16 11:04:41 +01:00
|
|
|
.build().expand(page, size).encode();
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private UriComponents searchDatasourceSnippetUri(String page, String size) {
|
2019-02-16 11:04:41 +01:00
|
|
|
|
|
|
|
return UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
|
|
|
.path("/{page}/{size}/")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("requestSortBy", "officialname")
|
|
|
|
.queryParam("order", "ASCENDING")
|
2019-02-16 11:04:41 +01:00
|
|
|
.build().expand(page, size).encode();
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private UriComponents searchRegisteredDatasourceUri(String requestSortBy, String order, String page, String size) {
|
2019-07-19 11:31:23 +02:00
|
|
|
|
|
|
|
return UriComponentsBuilder
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
|
|
|
.path("/{page}/{size}/")
|
2021-07-21 13:51:18 +02:00
|
|
|
.queryParam("requestSortBy", requestSortBy)
|
|
|
|
.queryParam("order", order)
|
2019-07-19 11:31:23 +02:00
|
|
|
.build().expand(page, size).encode();
|
|
|
|
}
|
|
|
|
|
2023-01-23 16:45:35 +01:00
|
|
|
private <T> Paging<T> searchDatasource(UriComponents uriComponents, RequestFilter requestFilter, Class<T> clazz) {
|
|
|
|
Paging<T> repositories = new Paging<>();
|
|
|
|
ResponseEntity<Map> rs;
|
|
|
|
rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, new HttpEntity<>(requestFilter), Map.class);
|
|
|
|
if (!rs.getStatusCode().is2xxSuccessful()) {
|
|
|
|
logger.error("Api call not successful. Code: {} | Body: {}", rs.getStatusCode(), rs.getBody());
|
|
|
|
}
|
|
|
|
if (rs.getBody() == null) {
|
|
|
|
logger.error("DSM response is null : [url={}]", uriComponents.toUri());
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Header header = objectMapper.readValue(objectMapper.writeValueAsString(rs.getBody().get("header")), Header.class);
|
|
|
|
repositories = Paging.of(header,
|
|
|
|
objectMapper.readValue(
|
|
|
|
objectMapper.writeValueAsString(rs.getBody().get("datasourceInfo")),
|
|
|
|
objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)));
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
logger.error("Error in objectMapper", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return repositories;
|
|
|
|
}
|
|
|
|
|
|
|
|
private <T> Paging<T> searchApi(UriComponents uriComponents, RequestFilter requestFilter, Class<T> clazz) {
|
|
|
|
Paging<T> repositories = new Paging<>();
|
|
|
|
ResponseEntity<Map> rs;
|
|
|
|
rs = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, new HttpEntity<>(requestFilter), Map.class);
|
|
|
|
if (!rs.getStatusCode().is2xxSuccessful()) {
|
|
|
|
logger.error("Api call not successful. Code: {} | Body: {}", rs.getStatusCode(), rs.getBody());
|
|
|
|
}
|
|
|
|
if (rs.getBody() == null) {
|
|
|
|
logger.error("DSM response is null : [url={}]", uriComponents.toUri());
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Header header = objectMapper.readValue(objectMapper.writeValueAsString(rs.getBody().get("header")), Header.class);
|
|
|
|
repositories = Paging.of(header,
|
|
|
|
objectMapper.readValue(
|
|
|
|
objectMapper.writeValueAsString(rs.getBody().get("api")),
|
|
|
|
objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)));
|
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
logger.error("Error in objectMapper", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return repositories;
|
|
|
|
}
|
|
|
|
|
2023-02-17 15:17:37 +01:00
|
|
|
private List<String> getRepoIdsOfUser(String userEmail) {
|
|
|
|
List<String> repoIds;
|
|
|
|
if (userEmail != null && !"".equals(userEmail)) {
|
|
|
|
repoIds = new ArrayList<>(roleMappingService.getRepositoryIds(authorizationService.getUserRolesByEmail(userEmail)));
|
|
|
|
} else {
|
|
|
|
Collection<?> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
|
|
|
|
repoIds = authorities
|
|
|
|
.stream()
|
|
|
|
.map(a -> roleMappingService.authorityToRepositoryId((GrantedAuthority) a))
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
return repoIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2021-07-21 13:51:18 +02:00
|
|
|
private String getRepositoryType(String typology) {
|
2019-02-16 11:04:41 +01:00
|
|
|
return invertedDataSourceClass.get(typology);
|
|
|
|
}
|
|
|
|
|
2023-02-17 15:17:37 +01:00
|
|
|
@Deprecated
|
2021-07-21 13:51:18 +02:00
|
|
|
private List<String> getRoleIdsFromUserRoles(String userEmail) {
|
2023-01-20 18:15:59 +01:00
|
|
|
List<Integer> coPersonId = registryCalls.getCoPersonIdsByEmail(userEmail);
|
2021-07-21 13:51:18 +02:00
|
|
|
JsonArray roles;
|
|
|
|
ArrayList<String> roleIds = new ArrayList<>();
|
|
|
|
ArrayList<Integer> couIds = new ArrayList<>();
|
|
|
|
if (coPersonId != null) {
|
|
|
|
roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE);
|
|
|
|
for (JsonElement role : roles) {
|
2023-02-02 17:54:46 +01:00
|
|
|
JsonElement couId = role.getAsJsonObject().get("CouId");
|
|
|
|
if (couId != null)
|
|
|
|
couIds.add(couId.getAsInt());
|
2021-07-21 13:51:18 +02:00
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
|
2021-07-21 13:51:18 +02:00
|
|
|
roleIds.addAll(registryCalls.getCouNames(couIds).values());
|
|
|
|
}
|
|
|
|
return roleIds;
|
|
|
|
}
|
2019-02-16 11:04:41 +01:00
|
|
|
}
|