Merge branch 'master' of code-repo.d4science.org:MaDgIK/uoa-repository-manager-service
This commit is contained in:
commit
ccf826ee42
|
@ -201,7 +201,8 @@ public class RepositoryController {
|
|||
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOfInterface(#id)")
|
||||
public void deleteRepositoryInterface(@RequestParam("id") String id,
|
||||
@RequestParam("registeredBy") String registeredBy) {
|
||||
repositoryService.deleteRepositoryInterface(id, registeredBy);
|
||||
// repositoryService.deleteRepositoryInterface(id, registeredBy);
|
||||
logger.warn("User attempted delete on Interface with ID: {}", id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
|
||||
|
|
|
@ -50,7 +50,7 @@ public interface RepositoryService {
|
|||
String officialName, String requestSortBy, String order,
|
||||
int page, int pageSize) throws Exception;
|
||||
|
||||
int getTotalRegisteredRepositories();
|
||||
Integer getTotalRegisteredRepositories();
|
||||
|
||||
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
|
||||
|
||||
|
@ -84,7 +84,7 @@ public interface RepositoryService {
|
|||
|
||||
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
|
||||
|
||||
Map<String, String> getListLatestUpdate(String mode) throws JSONException;
|
||||
Map<String, String> getListLatestUpdate(String mode);
|
||||
|
||||
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||
if (rs == null) {
|
||||
logger.error("The \"DatasourceResponse\" is null!");
|
||||
return null;
|
||||
} else {
|
||||
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
||||
}
|
||||
}
|
||||
|
||||
resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()),
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
|
||||
throw e;
|
||||
}
|
||||
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
|
||||
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class));
|
||||
|
||||
logger.debug("resultSet: {}", resultSet);
|
||||
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);
|
||||
|
||||
|
@ -709,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");
|
||||
|
@ -726,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"))
|
||||
|
@ -752,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
|
||||
|
@ -894,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) {
|
||||
|
@ -955,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");
|
||||
|
@ -986,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/")
|
||||
|
@ -996,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/")
|
||||
|
@ -1006,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/")
|
||||
|
@ -1016,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);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
package eu.dnetlib.repo.manager.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.dnetlib.repo.manager.domain.*;
|
||||
import eu.dnetlib.repo.manager.domain.Timezone;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
|
@ -18,61 +12,14 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class Converter {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Converter.class);
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public Converter() {
|
||||
objectMapper = new ObjectMapper()/*.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)*/;
|
||||
}
|
||||
public Repository toRepository(Object repositoryObject) {
|
||||
|
||||
Repository repository = objectMapper.convertValue(repositoryObject, Repository.class);
|
||||
|
||||
return repository;
|
||||
private Converter() {
|
||||
}
|
||||
|
||||
public RepositorySnippet toRepositorySnippet(JSONObject repositorySnippetObject) {
|
||||
|
||||
RepositorySnippet snippet = objectMapper.convertValue(repositorySnippetObject, RepositorySnippet.class);
|
||||
|
||||
return snippet;
|
||||
}
|
||||
|
||||
public List<Repository> toRepositoryList(JSONObject json) throws JSONException {
|
||||
|
||||
List<Repository> resultSet = new ArrayList<>();
|
||||
JSONArray rs = json.getJSONArray("datasourceInfo");
|
||||
for (int i = 0; i < rs.length(); i++)
|
||||
resultSet.add(toRepository(rs.getJSONObject(i)));
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
public List<RepositoryInterface> toRepositoryInterfaceList(List<ApiDetails> apiDetailsList) {
|
||||
|
||||
List<RepositoryInterface> resultSet = new ArrayList<>();
|
||||
|
||||
for (ApiDetails entry : apiDetailsList)
|
||||
resultSet.add(toRepositoryInterface(entry));
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
public RepositoryInterface toRepositoryInterface(Object repositoryInterfaceObject) {
|
||||
|
||||
RepositoryInterface repoInterface = objectMapper.convertValue(repositoryInterfaceObject, RepositoryInterface.class);
|
||||
|
||||
return repoInterface;
|
||||
}
|
||||
|
||||
public String toJson(Repository repository) throws JsonProcessingException {
|
||||
|
||||
return objectMapper.writeValueAsString(repository);
|
||||
}
|
||||
|
||||
public List<String> readFile(String filename) {
|
||||
public static List<String> readFile(String filename) {
|
||||
String line;
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
|
@ -88,7 +35,7 @@ public class Converter {
|
|||
return list; // It may be empty.
|
||||
}
|
||||
|
||||
public List<Timezone> toTimezones(List<String> timezones) {
|
||||
public static List<Timezone> toTimezones(List<String> timezones) {
|
||||
|
||||
List<Timezone> tmz = new ArrayList<>();
|
||||
for (String t : timezones) {
|
||||
|
@ -98,17 +45,17 @@ public class Converter {
|
|||
return tmz;
|
||||
}
|
||||
|
||||
private String getOpenaireId(String repositoryId) {
|
||||
public static String getOpenaireId(String repositoryId) {
|
||||
if (repositoryId != null && repositoryId.contains("::"))
|
||||
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Boolean convertStringToBoolean(String value) {
|
||||
public static Boolean convertStringToBoolean(String value) {
|
||||
return value.equals("null") ? null : Boolean.valueOf(value);
|
||||
}
|
||||
|
||||
private Double toDouble(String number) {
|
||||
public static Double toDouble(String number) {
|
||||
if (Objects.equals(number, "null"))
|
||||
return 0.0;
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue