|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package eu.dnetlib.repo.manager.service;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
@ -10,7 +11,6 @@ import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
|
|
|
|
import eu.dnetlib.repo.manager.domain.*;
|
|
|
|
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
|
|
|
|
import eu.dnetlib.repo.manager.domain.dto.User;
|
|
|
|
|
import eu.dnetlib.repo.manager.exception.BrokerException;
|
|
|
|
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
|
|
|
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
|
|
|
|
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
|
|
|
|
@ -21,9 +21,7 @@ import eu.dnetlib.repo.manager.utils.Converter;
|
|
|
|
|
import eu.dnetlib.repo.manager.utils.DateUtils;
|
|
|
|
|
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -76,8 +74,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
@Value("${services.provide.usageStatisticsNumbersBaseURL}")
|
|
|
|
|
private String usageStatisticsNumbersBaseURL;
|
|
|
|
|
|
|
|
|
|
private final Converter converter;
|
|
|
|
|
|
|
|
|
|
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
|
|
|
|
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
|
|
|
|
|
|
|
|
@ -96,7 +92,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
VocabularyLoader vocabularyLoader,
|
|
|
|
|
RestTemplate restTemplate,
|
|
|
|
|
ObjectMapper objectMapper,
|
|
|
|
|
Converter converter,
|
|
|
|
|
// Converter converter,
|
|
|
|
|
@Lazy EmailUtils emailUtils,
|
|
|
|
|
@Lazy ValidatorService validatorService,
|
|
|
|
|
@Lazy PiWikService piWikService,
|
|
|
|
@ -107,7 +103,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
this.authoritiesUpdater = authoritiesUpdater;
|
|
|
|
|
this.vocabularyLoader = vocabularyLoader;
|
|
|
|
|
this.piWikService = piWikService;
|
|
|
|
|
this.converter = converter;
|
|
|
|
|
this.emailUtils = emailUtils;
|
|
|
|
|
this.validatorService = validatorService;
|
|
|
|
|
this.restTemplate = restTemplate;
|
|
|
|
@ -174,21 +169,18 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
|
@Override
|
|
|
|
|
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
|
|
|
|
List<Repository> repos = new ArrayList<>();
|
|
|
|
|
public List<Repository> getRepositories(List<String> ids, int page, int size) {
|
|
|
|
|
logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids));
|
|
|
|
|
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
|
|
|
|
UriComponents uriComponents = searchDatasourceUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
|
|
|
|
|
List<Repository> repos = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (String repoId : ids) {
|
|
|
|
|
requestFilter.setId(repoId);
|
|
|
|
|
List rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
|
|
|
|
|
|
|
|
|
|
// repos.addAll(converter.toRepositoryList(new JSONObject(rs)));
|
|
|
|
|
repos.addAll(searchDatasource(uriComponents, requestFilter, Repository.class).getResults());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO - "repos" is EMPTY!!
|
|
|
|
|
|
|
|
|
|
for (Repository r : repos)
|
|
|
|
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
|
|
|
|
return repos;
|
|
|
|
@ -207,31 +199,30 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
// another way for paging must be implemented.
|
|
|
|
|
@Override
|
|
|
|
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
|
|
|
|
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
|
|
|
|
List<RepositorySnippet> resultSet;
|
|
|
|
|
List<DatasourceDetails> datasourceDetailsList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
// here page should be 0
|
|
|
|
|
UriComponents uriComponents = searchSnippetDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
|
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (String repoId : ids) {
|
|
|
|
|
requestFilter.setId(repoId);
|
|
|
|
|
for (String repoId : ids) {
|
|
|
|
|
requestFilter.setId(repoId);
|
|
|
|
|
|
|
|
|
|
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
|
|
|
|
if (rs == null) {
|
|
|
|
|
logger.error("The \"DatasourceResponse\" is null!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()),
|
|
|
|
|
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
|
|
|
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
|
|
|
|
if (rs == null) {
|
|
|
|
|
logger.error("The \"DatasourceResponse\" is null!");
|
|
|
|
|
} else {
|
|
|
|
|
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.debug("resultSet: {}", resultSet);
|
|
|
|
|
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()));
|
|
|
|
|
});
|
|
|
|
@ -242,13 +233,10 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
|
|
|
|
String mode,
|
|
|
|
|
Boolean managed) throws JSONException, IOException {
|
|
|
|
|
|
|
|
|
|
Boolean managed) throws IOException {
|
|
|
|
|
logger.debug("Getting repositories by country!");
|
|
|
|
|
int page = 0;
|
|
|
|
|
int size = 100;
|
|
|
|
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
String filterKey = "UNKNOWN";
|
|
|
|
|
if (mode.equalsIgnoreCase("repository"))
|
|
|
|
@ -259,17 +247,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
|
|
|
|
|
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
|
|
|
|
|
|
|
|
|
|
UriComponents uriComponents = searchSnippetDatasource(String.valueOf(page), String.valueOf(size));
|
|
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri(String.valueOf(page), String.valueOf(size));
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
requestFilter.setCountry(country);
|
|
|
|
|
requestFilter.setEoscDatasourceType(filterKey);
|
|
|
|
|
|
|
|
|
|
Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class);
|
|
|
|
|
if (rs != null) {
|
|
|
|
|
resultSet.addAll(mapper.readValue(mapper.writeValueAsString(rs.get("datasourceInfo")),
|
|
|
|
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
|
|
|
}
|
|
|
|
|
return resultSet;
|
|
|
|
|
return searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
|
|
|
@ -277,10 +260,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
|
|
|
|
|
logger.debug("Searching registered repositories");
|
|
|
|
|
|
|
|
|
|
Paging<RepositorySnippet> snippets = null;
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
|
|
|
|
UriComponents uriComponents = searchRegisteredDatasourceUri(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
|
|
|
|
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
requestFilter.setCountry(country);
|
|
|
|
@ -288,27 +268,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
requestFilter.setOfficialname(officialName);
|
|
|
|
|
requestFilter.setEnglishname(englishName);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class);
|
|
|
|
|
if (rs == null) {
|
|
|
|
|
logger.error("DSM response is null : [url={}]", uriComponents.toUri());
|
|
|
|
|
} else {
|
|
|
|
|
Header header = mapper.readValue(mapper.writeValueAsString(rs.get("header")), Header.class);
|
|
|
|
|
snippets = Paging.of(header,
|
|
|
|
|
mapper.readValue(
|
|
|
|
|
mapper.writeValueAsString(rs.get("datasourceInfo")),
|
|
|
|
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error searching registered datasources", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
Paging<RepositorySnippet> snippets = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class);
|
|
|
|
|
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getTotalRegisteredRepositories() throws NullPointerException {
|
|
|
|
|
public Integer getTotalRegisteredRepositories() throws NullPointerException {
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
|
|
|
|
.queryParam("fromDate", "1900-01-01")
|
|
|
|
@ -317,7 +282,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
return restTemplate.getForObject(uriComponents.toUri(), Integer.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Repository updateRepositoryInfo(Repository r) throws JSONException {
|
|
|
|
|
private Repository updateRepositoryInfo(Repository r) {
|
|
|
|
|
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
|
|
|
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
|
|
|
|
return r;
|
|
|
|
@ -363,57 +328,35 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
|
|
|
|
public RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException {
|
|
|
|
|
|
|
|
|
|
logger.debug("Retrieving repositories with id : {}", id);
|
|
|
|
|
RepositorySnippet repo;
|
|
|
|
|
UriComponents uriComponents = searchSnippetDatasource("0", "100");
|
|
|
|
|
UriComponents uriComponents = searchDatasourceSnippetUri("0", "100");
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
requestFilter.setId(id);
|
|
|
|
|
|
|
|
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
|
|
|
if (rs == null) {
|
|
|
|
|
logger.error("The result is null!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
List<RepositorySnippet> repositories = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
|
|
|
|
|
|
|
|
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
|
|
|
|
|
|
|
|
|
if (jsonArray.length() == 0)
|
|
|
|
|
if (repositories.isEmpty())
|
|
|
|
|
throw new ResourceNotFoundException();
|
|
|
|
|
|
|
|
|
|
repo = converter.toRepositorySnippet(jsonArray.getJSONObject(0));
|
|
|
|
|
return repo;
|
|
|
|
|
return repositories.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
|
|
|
|
public Repository getRepositoryById(String id) throws ResourceNotFoundException {
|
|
|
|
|
|
|
|
|
|
logger.debug("Retrieving repositories with id : {}", id);
|
|
|
|
|
Repository repo;
|
|
|
|
|
UriComponents uriComponents = searchDatasource("0", "100");
|
|
|
|
|
|
|
|
|
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
requestFilter.setId(id);
|
|
|
|
|
|
|
|
|
|
// String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
|
|
|
// JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
|
|
|
|
|
|
|
|
|
DatasourceResponse response;
|
|
|
|
|
response = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
|
|
|
|
if (response == null) {
|
|
|
|
|
logger.error("The response is null!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DatasourceDetails> datasources = response.getDatasourceInfo();
|
|
|
|
|
if (datasources.size() == 0)
|
|
|
|
|
List<Repository> datasources = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
|
|
|
|
if (datasources.isEmpty())
|
|
|
|
|
throw new ResourceNotFoundException();
|
|
|
|
|
|
|
|
|
|
// repo = converter.toRepository(jsonArray.getJSONObject(0));
|
|
|
|
|
// return updateRepositoryInfo(repo);
|
|
|
|
|
|
|
|
|
|
return updateRepositoryInfo(converter.toRepository(datasources.get(0)));
|
|
|
|
|
|
|
|
|
|
return updateRepositoryInfo(datasources.get(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -423,12 +366,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
String size) throws JSONException {
|
|
|
|
|
|
|
|
|
|
logger.debug("Retrieving repositories with official name : {}", name);
|
|
|
|
|
UriComponents uriComponents = searchDatasource("0", "100");
|
|
|
|
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
|
|
|
|
RequestFilter requestFilter = new RequestFilter();
|
|
|
|
|
requestFilter.setOfficialname(name);
|
|
|
|
|
|
|
|
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
|
|
|
List<Repository> repos = converter.toRepositoryList(new JSONObject(rs));
|
|
|
|
|
List<Repository> repos = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
|
|
|
|
for (Repository r : repos)
|
|
|
|
|
updateRepositoryInfo(r);
|
|
|
|
|
return repos;
|
|
|
|
@ -436,33 +378,27 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
|
|
|
|
|
public List<RepositoryInterface> getRepositoryInterface(String id) {
|
|
|
|
|
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
|
|
|
|
.path("/{id}")
|
|
|
|
|
.build().expand(id).encode();
|
|
|
|
|
|
|
|
|
|
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
|
|
|
|
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
|
|
|
|
|
if (rs == null) {
|
|
|
|
|
logger.error("The ApiDetailsResponse was null!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
List<RepositoryInterface> rs = searchApi(uriComponents, null, RepositoryInterface.class).getResults();
|
|
|
|
|
|
|
|
|
|
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
|
|
|
|
List<ApiDetails> res = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (ApiDetails det : rs.getApi()) {
|
|
|
|
|
List<RepositoryInterface> repositoryInterfaces = new ArrayList<>();
|
|
|
|
|
for (RepositoryInterface det : rs) {
|
|
|
|
|
String protocol = det.getProtocol();
|
|
|
|
|
if (!protocol.equals("sword") &&
|
|
|
|
|
!protocol.equals("rest") &&
|
|
|
|
|
!protocol.equals("ftp")) {
|
|
|
|
|
res.add(det);
|
|
|
|
|
repositoryInterfaces.add(det);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return converter.toRepositoryInterfaceList(res);
|
|
|
|
|
return repositoryInterfaces;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -528,17 +464,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update method acting as add -> send email with registration topic/body*/
|
|
|
|
|
private Repository latentUpdate(Repository repository, Authentication authentication) throws Exception {
|
|
|
|
|
private Repository latentUpdate(Repository repository, Authentication authentication) {
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
|
|
|
|
.build()
|
|
|
|
|
.encode();
|
|
|
|
|
|
|
|
|
|
// FIXME: problematic
|
|
|
|
|
// String json_repository = converter.toJson(repository);
|
|
|
|
|
// logger.debug("JSON to add(update) -> " + json_repository);
|
|
|
|
|
|
|
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders); // TODO: check if it works (Repository contains extra fields)
|
|
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
|
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
|
|
|
|
|
|
|
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
|
|
|
@ -560,10 +492,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.build()
|
|
|
|
|
.encode();
|
|
|
|
|
|
|
|
|
|
// FIXME: problematic
|
|
|
|
|
// String json_repository = converter.toJson(repository);
|
|
|
|
|
// logger.debug("JSON to update -> " + json_repository);
|
|
|
|
|
|
|
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
|
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
|
|
|
|
|
|
|
@ -591,7 +519,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/add/")
|
|
|
|
|
.build()
|
|
|
|
|
.encode();
|
|
|
|
|
// String json_repository = converter.toJson(repository);
|
|
|
|
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
|
|
|
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
|
|
|
|
|
|
|
@ -624,8 +551,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
String desiredCompatibilityLevel) throws Exception {
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
Repository e = this.getRepositoryById(repoId);
|
|
|
|
|
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
|
|
|
|
// String json_interface = converter.toJson(e, repositoryInterface);
|
|
|
|
|
repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype);
|
|
|
|
|
|
|
|
|
|
UriComponents uriComponents = UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
|
|
|
@ -633,9 +559,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.encode();
|
|
|
|
|
|
|
|
|
|
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
|
|
|
|
|
|
|
|
|
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
|
|
|
|
|
|
|
|
|
// Explicitly update validation set (updating the interface does not allow updating the set value)
|
|
|
|
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
|
|
|
|
|
|
|
|
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
|
|
|
|
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
|
|
|
|
|
|
|
|
@ -656,6 +584,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
String desiredCompatibilityLevel) throws Exception {
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
Repository repository = this.getRepositoryById(repoId);
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
|
|
|
|
|
|
|
@ -703,12 +637,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
this.validatorService.submitJobForValidation(job);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
|
|
|
|
|
private RepositoryInterface fillInterfaceFields(Repository repo, RepositoryInterface iFace, String datatype) {
|
|
|
|
|
|
|
|
|
|
iFace.setDatasource(repo.getId());
|
|
|
|
|
iFace.setContentdescription("metadata");
|
|
|
|
|
|
|
|
|
|
// TODO: double check me
|
|
|
|
|
logger.warn("Compatibility level: {}", iFace.getCompatibility());
|
|
|
|
|
if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) {
|
|
|
|
|
iFace.setCompatibility("UNKNOWN");
|
|
|
|
@ -720,7 +653,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
iFace.setAccessFormat("oai_dc");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: this will probably not work
|
|
|
|
|
// TODO: is this the correct functionality?
|
|
|
|
|
if (repo.getEoscDatasourceType() != null && !repo.getEoscDatasourceType().isEmpty())
|
|
|
|
|
iFace.setTypology(repo.getEoscDatasourceType());
|
|
|
|
|
else if (datatype.equalsIgnoreCase("journal"))
|
|
|
|
@ -746,18 +679,18 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getDnetCountries() {
|
|
|
|
|
logger.debug("Getting dnet-countries!");
|
|
|
|
|
return converter.readFile("countries.txt");
|
|
|
|
|
return Converter.readFile("countries.txt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getTypologies() {
|
|
|
|
|
return converter.readFile("typologies.txt");
|
|
|
|
|
return Converter.readFile("typologies.txt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Timezone> getTimezones() {
|
|
|
|
|
List<String> timezones = converter.readFile("timezones.txt");
|
|
|
|
|
return converter.toTimezones(timezones);
|
|
|
|
|
List<String> timezones = Converter.readFile("timezones.txt");
|
|
|
|
|
return Converter.toTimezones(timezones);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -888,13 +821,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
|
|
|
|
|
public Map<String, String> getListLatestUpdate(String mode) {
|
|
|
|
|
Map<String, String> dates = new HashMap<>();
|
|
|
|
|
if (mode.equals("repository")) {
|
|
|
|
|
dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
|
|
|
|
|
dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
|
|
|
|
|
// create re3data last collection date
|
|
|
|
|
// dates.put("re3data", converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate()));
|
|
|
|
|
// dates.put("re3data", Converter.toString(getRepositoryInterface("openaire____::re3data").get(1).getLastCollectionDate()));
|
|
|
|
|
List<RepositoryInterface> re3interfaces = getRepositoryInterface("openaire____::re3data");
|
|
|
|
|
String re3Date = null;
|
|
|
|
|
for (RepositoryInterface interf : re3interfaces) {
|
|
|
|
@ -949,7 +882,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
|
|
|
|
|
private MetricsNumbers getMetricsNumbers(String openAIREID) {
|
|
|
|
|
|
|
|
|
|
//build the uri params
|
|
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
|
|
|
|
@ -980,7 +913,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UriComponents searchDatasource(String page, String size) {
|
|
|
|
|
private UriComponents searchDatasourceUri(String page, String size) {
|
|
|
|
|
|
|
|
|
|
return UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
|
|
|
@ -990,7 +923,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.build().expand(page, size).encode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UriComponents searchSnippetDatasource(String page, String size) {
|
|
|
|
|
private UriComponents searchDatasourceSnippetUri(String page, String size) {
|
|
|
|
|
|
|
|
|
|
return UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
|
|
|
@ -1000,7 +933,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.build().expand(page, size).encode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) {
|
|
|
|
|
private UriComponents searchRegisteredDatasourceUri(String requestSortBy, String order, String page, String size) {
|
|
|
|
|
|
|
|
|
|
return UriComponentsBuilder
|
|
|
|
|
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
|
|
|
@ -1010,6 +943,52 @@ public class RepositoryServiceImpl implements RepositoryService {
|
|
|
|
|
.build().expand(page, size).encode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getRepositoryType(String typology) {
|
|
|
|
|
return invertedDataSourceClass.get(typology);
|
|
|
|
|
}
|
|
|
|
|