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)")
|
@PreAuthorize("hasAuthority('SUPER_ADMINISTRATOR') or hasAuthority('CONTENT_PROVIDER_DASHBOARD_ADMINISTRATOR') or @authorizationService.isMemberOfInterface(#id)")
|
||||||
public void deleteRepositoryInterface(@RequestParam("id") String id,
|
public void deleteRepositoryInterface(@RequestParam("id") String id,
|
||||||
@RequestParam("registeredBy") String registeredBy) {
|
@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,
|
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
|
||||||
|
|
|
@ -50,7 +50,7 @@ public interface RepositoryService {
|
||||||
String officialName, String requestSortBy, String order,
|
String officialName, String requestSortBy, String order,
|
||||||
int page, int pageSize) throws Exception;
|
int page, int pageSize) throws Exception;
|
||||||
|
|
||||||
int getTotalRegisteredRepositories();
|
Integer getTotalRegisteredRepositories();
|
||||||
|
|
||||||
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
|
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public interface RepositoryService {
|
||||||
|
|
||||||
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
|
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;
|
RepositoryInterface updateRepositoryInterface(String repoId, String comment, RepositoryInterface repositoryInterface, String desiredCompatibilityLevel) throws Exception;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.repo.manager.service;
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
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.*;
|
||||||
import eu.dnetlib.repo.manager.domain.dto.Role;
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
||||||
import eu.dnetlib.repo.manager.domain.dto.User;
|
import eu.dnetlib.repo.manager.domain.dto.User;
|
||||||
import eu.dnetlib.repo.manager.exception.BrokerException;
|
|
||||||
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
import eu.dnetlib.repo.manager.exception.RepositoryServiceException;
|
||||||
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
||||||
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
|
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 eu.dnetlib.repo.manager.utils.DateUtils;
|
||||||
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -76,8 +74,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Value("${services.provide.usageStatisticsNumbersBaseURL}")
|
@Value("${services.provide.usageStatisticsNumbersBaseURL}")
|
||||||
private String usageStatisticsNumbersBaseURL;
|
private String usageStatisticsNumbersBaseURL;
|
||||||
|
|
||||||
private final Converter converter;
|
|
||||||
|
|
||||||
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
||||||
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
||||||
|
|
||||||
|
@ -96,7 +92,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
VocabularyLoader vocabularyLoader,
|
VocabularyLoader vocabularyLoader,
|
||||||
RestTemplate restTemplate,
|
RestTemplate restTemplate,
|
||||||
ObjectMapper objectMapper,
|
ObjectMapper objectMapper,
|
||||||
Converter converter,
|
// Converter converter,
|
||||||
@Lazy EmailUtils emailUtils,
|
@Lazy EmailUtils emailUtils,
|
||||||
@Lazy ValidatorService validatorService,
|
@Lazy ValidatorService validatorService,
|
||||||
@Lazy PiWikService piWikService,
|
@Lazy PiWikService piWikService,
|
||||||
|
@ -107,7 +103,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
this.authoritiesUpdater = authoritiesUpdater;
|
this.authoritiesUpdater = authoritiesUpdater;
|
||||||
this.vocabularyLoader = vocabularyLoader;
|
this.vocabularyLoader = vocabularyLoader;
|
||||||
this.piWikService = piWikService;
|
this.piWikService = piWikService;
|
||||||
this.converter = converter;
|
|
||||||
this.emailUtils = emailUtils;
|
this.emailUtils = emailUtils;
|
||||||
this.validatorService = validatorService;
|
this.validatorService = validatorService;
|
||||||
this.restTemplate = restTemplate;
|
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,
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
||||||
// another way for paging must be implemented.
|
// another way for paging must be implemented.
|
||||||
@Override
|
@Override
|
||||||
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
public List<Repository> getRepositories(List<String> ids, int page, int size) {
|
||||||
List<Repository> repos = new ArrayList<>();
|
|
||||||
logger.debug("Retrieving repositories with ids : {}", String.join(", ", ids));
|
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();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
|
||||||
|
List<Repository> repos = new ArrayList<>();
|
||||||
|
|
||||||
for (String repoId : ids) {
|
for (String repoId : ids) {
|
||||||
requestFilter.setId(repoId);
|
requestFilter.setId(repoId);
|
||||||
List rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, List.class);
|
repos.addAll(searchDatasource(uriComponents, requestFilter, Repository.class).getResults());
|
||||||
|
|
||||||
// repos.addAll(converter.toRepositoryList(new JSONObject(rs)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - "repos" is EMPTY!!
|
|
||||||
|
|
||||||
for (Repository r : repos)
|
for (Repository r : repos)
|
||||||
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
||||||
return repos;
|
return repos;
|
||||||
|
@ -207,31 +199,30 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
// another way for paging must be implemented.
|
// another way for paging must be implemented.
|
||||||
@Override
|
@Override
|
||||||
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
|
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
|
// 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();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
|
|
||||||
try {
|
|
||||||
for (String repoId : ids) {
|
for (String repoId : ids) {
|
||||||
requestFilter.setId(repoId);
|
requestFilter.setId(repoId);
|
||||||
|
|
||||||
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
|
||||||
if (rs == null) {
|
if (rs == null) {
|
||||||
logger.error("The \"DatasourceResponse\" is null!");
|
logger.error("The \"DatasourceResponse\" is null!");
|
||||||
return null;
|
} else {
|
||||||
|
datasourceDetailsList.addAll(rs.getDatasourceInfo());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet.addAll(objectMapper.readValue(objectMapper.writeValueAsString(rs.getDatasourceInfo()),
|
resultSet = objectMapper.readValue(objectMapper.writeValueAsString(datasourceDetailsList),
|
||||||
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
objectMapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class));
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.debug("Exception on getRepositoriesSnippetOfUser", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.debug("resultSet: {}", resultSet);
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("resultSet: {}", objectMapper.writeValueAsString(resultSet));
|
||||||
|
}
|
||||||
resultSet.parallelStream().forEach(repositorySnippet -> {
|
resultSet.parallelStream().forEach(repositorySnippet -> {
|
||||||
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
||||||
});
|
});
|
||||||
|
@ -242,13 +233,10 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
||||||
String mode,
|
String mode,
|
||||||
Boolean managed) throws JSONException, IOException {
|
Boolean managed) throws IOException {
|
||||||
|
|
||||||
logger.debug("Getting repositories by country!");
|
logger.debug("Getting repositories by country!");
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int size = 100;
|
int size = 100;
|
||||||
List<RepositorySnippet> resultSet = new ArrayList<>();
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
|
|
||||||
String filterKey = "UNKNOWN";
|
String filterKey = "UNKNOWN";
|
||||||
if (mode.equalsIgnoreCase("repository"))
|
if (mode.equalsIgnoreCase("repository"))
|
||||||
|
@ -259,17 +247,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
|
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 requestFilter = new RequestFilter();
|
||||||
requestFilter.setCountry(country);
|
requestFilter.setCountry(country);
|
||||||
requestFilter.setEoscDatasourceType(filterKey);
|
requestFilter.setEoscDatasourceType(filterKey);
|
||||||
|
|
||||||
Map rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, Map.class);
|
return searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
||||||
if (rs != null) {
|
|
||||||
resultSet.addAll(mapper.readValue(mapper.writeValueAsString(rs.get("datasourceInfo")),
|
|
||||||
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
||||||
}
|
|
||||||
return resultSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
||||||
|
@ -277,10 +260,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
|
|
||||||
logger.debug("Searching registered repositories");
|
logger.debug("Searching registered repositories");
|
||||||
|
|
||||||
Paging<RepositorySnippet> snippets = null;
|
UriComponents uriComponents = searchRegisteredDatasourceUri(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
|
|
||||||
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
|
||||||
|
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setCountry(country);
|
requestFilter.setCountry(country);
|
||||||
|
@ -288,27 +268,12 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
requestFilter.setOfficialname(officialName);
|
requestFilter.setOfficialname(officialName);
|
||||||
requestFilter.setEnglishname(englishName);
|
requestFilter.setEnglishname(englishName);
|
||||||
|
|
||||||
try {
|
Paging<RepositorySnippet> snippets = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class);
|
||||||
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;
|
|
||||||
}
|
|
||||||
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
return snippets != null ? snippets.getResults() : null; // TODO: return paging when ui is compatible
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTotalRegisteredRepositories() throws NullPointerException {
|
public Integer getTotalRegisteredRepositories() throws NullPointerException {
|
||||||
UriComponents uriComponents = UriComponentsBuilder
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
.fromHttpUrl(baseAddress + "/ds/countregistered")
|
||||||
.queryParam("fromDate", "1900-01-01")
|
.queryParam("fromDate", "1900-01-01")
|
||||||
|
@ -317,7 +282,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
return restTemplate.getForObject(uriComponents.toUri(), Integer.class);
|
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.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||||
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
||||||
return r;
|
return r;
|
||||||
|
@ -363,57 +328,35 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
public RepositorySnippet getRepositorySnippetById(String id) throws ResourceNotFoundException {
|
||||||
|
|
||||||
logger.debug("Retrieving repositories with id : {}", id);
|
logger.debug("Retrieving repositories with id : {}", id);
|
||||||
RepositorySnippet repo;
|
UriComponents uriComponents = searchDatasourceSnippetUri("0", "100");
|
||||||
UriComponents uriComponents = searchSnippetDatasource("0", "100");
|
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setId(id);
|
requestFilter.setId(id);
|
||||||
|
|
||||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
List<RepositorySnippet> repositories = searchDatasource(uriComponents, requestFilter, RepositorySnippet.class).getResults();
|
||||||
if (rs == null) {
|
|
||||||
logger.error("The result is null!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
if (repositories.isEmpty())
|
||||||
|
|
||||||
if (jsonArray.length() == 0)
|
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
|
|
||||||
repo = converter.toRepositorySnippet(jsonArray.getJSONObject(0));
|
return repositories.get(0);
|
||||||
return repo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
public Repository getRepositoryById(String id) throws ResourceNotFoundException {
|
||||||
|
|
||||||
logger.debug("Retrieving repositories with id : {}", id);
|
logger.debug("Retrieving repositories with id : {}", id);
|
||||||
Repository repo;
|
|
||||||
UriComponents uriComponents = searchDatasource("0", "100");
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setId(id);
|
requestFilter.setId(id);
|
||||||
|
|
||||||
// String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
List<Repository> datasources = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
||||||
// JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
if (datasources.isEmpty())
|
||||||
|
|
||||||
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)
|
|
||||||
throw new ResourceNotFoundException();
|
throw new ResourceNotFoundException();
|
||||||
|
|
||||||
// repo = converter.toRepository(jsonArray.getJSONObject(0));
|
return updateRepositoryInfo(datasources.get(0));
|
||||||
// return updateRepositoryInfo(repo);
|
|
||||||
|
|
||||||
return updateRepositoryInfo(converter.toRepository(datasources.get(0)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -423,12 +366,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
String size) throws JSONException {
|
String size) throws JSONException {
|
||||||
|
|
||||||
logger.debug("Retrieving repositories with official name : {}", name);
|
logger.debug("Retrieving repositories with official name : {}", name);
|
||||||
UriComponents uriComponents = searchDatasource("0", "100");
|
UriComponents uriComponents = searchDatasourceUri("0", "100");
|
||||||
RequestFilter requestFilter = new RequestFilter();
|
RequestFilter requestFilter = new RequestFilter();
|
||||||
requestFilter.setOfficialname(name);
|
requestFilter.setOfficialname(name);
|
||||||
|
|
||||||
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
List<Repository> repos = searchDatasource(uriComponents, requestFilter, Repository.class).getResults();
|
||||||
List<Repository> repos = converter.toRepositoryList(new JSONObject(rs));
|
|
||||||
for (Repository r : repos)
|
for (Repository r : repos)
|
||||||
updateRepositoryInfo(r);
|
updateRepositoryInfo(r);
|
||||||
return repos;
|
return repos;
|
||||||
|
@ -436,33 +378,27 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
|
public List<RepositoryInterface> getRepositoryInterface(String id) {
|
||||||
|
|
||||||
UriComponents uriComponents = UriComponentsBuilder
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/api/")
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
||||||
.path("/{id}")
|
.path("/{id}")
|
||||||
.build().expand(id).encode();
|
.build().expand(id).encode();
|
||||||
|
|
||||||
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
List<RepositoryInterface> rs = searchApi(uriComponents, null, RepositoryInterface.class).getResults();
|
||||||
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
|
|
||||||
if (rs == null) {
|
|
||||||
logger.error("The ApiDetailsResponse was null!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
|
||||||
List<ApiDetails> res = new ArrayList<>();
|
List<RepositoryInterface> repositoryInterfaces = new ArrayList<>();
|
||||||
|
for (RepositoryInterface det : rs) {
|
||||||
for (ApiDetails det : rs.getApi()) {
|
|
||||||
String protocol = det.getProtocol();
|
String protocol = det.getProtocol();
|
||||||
if (!protocol.equals("sword") &&
|
if (!protocol.equals("sword") &&
|
||||||
!protocol.equals("rest") &&
|
!protocol.equals("rest") &&
|
||||||
!protocol.equals("ftp")) {
|
!protocol.equals("ftp")) {
|
||||||
res.add(det);
|
repositoryInterfaces.add(det);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return converter.toRepositoryInterfaceList(res);
|
return repositoryInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -528,17 +464,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update method acting as add -> send email with registration topic/body*/
|
/* 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
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/update/")
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
||||||
.build()
|
.build()
|
||||||
.encode();
|
.encode();
|
||||||
|
|
||||||
// FIXME: problematic
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||||
// 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)
|
|
||||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
||||||
|
|
||||||
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
||||||
|
@ -560,10 +492,6 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.build()
|
.build()
|
||||||
.encode();
|
.encode();
|
||||||
|
|
||||||
// FIXME: problematic
|
|
||||||
// String json_repository = converter.toJson(repository);
|
|
||||||
// logger.debug("JSON to update -> " + json_repository);
|
|
||||||
|
|
||||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
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/")
|
.fromHttpUrl(baseAddress + "/ds/add/")
|
||||||
.build()
|
.build()
|
||||||
.encode();
|
.encode();
|
||||||
// String json_repository = converter.toJson(repository);
|
|
||||||
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
HttpEntity<Repository> httpEntity = new HttpEntity<>(repository, httpHeaders);
|
||||||
ResponseEntity<ResponseEntity> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
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 {
|
String desiredCompatibilityLevel) throws Exception {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
Repository e = this.getRepositoryById(repoId);
|
Repository e = this.getRepositoryById(repoId);
|
||||||
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
repositoryInterface = fillInterfaceFields(e, repositoryInterface, datatype);
|
||||||
// String json_interface = converter.toJson(e, repositoryInterface);
|
|
||||||
|
|
||||||
UriComponents uriComponents = UriComponentsBuilder
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
||||||
|
@ -633,9 +559,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.encode();
|
.encode();
|
||||||
|
|
||||||
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
HttpEntity<RepositoryInterface> httpEntity = new HttpEntity<>(repositoryInterface, httpHeaders);
|
||||||
|
|
||||||
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
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.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
||||||
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
|
||||||
|
|
||||||
|
@ -709,12 +637,11 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
this.validatorService.submitJobForValidation(job);
|
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.setDatasource(repo.getId());
|
||||||
iFace.setContentdescription("metadata");
|
iFace.setContentdescription("metadata");
|
||||||
|
|
||||||
// TODO: double check me
|
|
||||||
logger.warn("Compatibility level: {}", iFace.getCompatibility());
|
logger.warn("Compatibility level: {}", iFace.getCompatibility());
|
||||||
if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) {
|
if (iFace.getCompatibility() == null || iFace.getCompatibility().equals("")) {
|
||||||
iFace.setCompatibility("UNKNOWN");
|
iFace.setCompatibility("UNKNOWN");
|
||||||
|
@ -726,7 +653,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
iFace.setAccessFormat("oai_dc");
|
iFace.setAccessFormat("oai_dc");
|
||||||
|
|
||||||
|
|
||||||
// FIXME: this will probably not work
|
// TODO: is this the correct functionality?
|
||||||
if (repo.getEoscDatasourceType() != null && !repo.getEoscDatasourceType().isEmpty())
|
if (repo.getEoscDatasourceType() != null && !repo.getEoscDatasourceType().isEmpty())
|
||||||
iFace.setTypology(repo.getEoscDatasourceType());
|
iFace.setTypology(repo.getEoscDatasourceType());
|
||||||
else if (datatype.equalsIgnoreCase("journal"))
|
else if (datatype.equalsIgnoreCase("journal"))
|
||||||
|
@ -752,18 +679,18 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
@Override
|
@Override
|
||||||
public List<String> getDnetCountries() {
|
public List<String> getDnetCountries() {
|
||||||
logger.debug("Getting dnet-countries!");
|
logger.debug("Getting dnet-countries!");
|
||||||
return converter.readFile("countries.txt");
|
return Converter.readFile("countries.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTypologies() {
|
public List<String> getTypologies() {
|
||||||
return converter.readFile("typologies.txt");
|
return Converter.readFile("typologies.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Timezone> getTimezones() {
|
public List<Timezone> getTimezones() {
|
||||||
List<String> timezones = converter.readFile("timezones.txt");
|
List<String> timezones = Converter.readFile("timezones.txt");
|
||||||
return converter.toTimezones(timezones);
|
return Converter.toTimezones(timezones);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -894,13 +821,13 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
|
public Map<String, String> getListLatestUpdate(String mode) {
|
||||||
Map<String, String> dates = new HashMap<>();
|
Map<String, String> dates = new HashMap<>();
|
||||||
if (mode.equals("repository")) {
|
if (mode.equals("repository")) {
|
||||||
dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
|
dates.put("opendoar", DateUtils.toString(getRepositoryInterface("openaire____::opendoar").get(0).getLastCollectionDate()));
|
||||||
dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
|
dates.put("fairsharing", DateUtils.toString(getRepositoryInterface("openaire____::fairsharing").get(0).getLastCollectionDate()));
|
||||||
// create re3data last collection date
|
// 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");
|
List<RepositoryInterface> re3interfaces = getRepositoryInterface("openaire____::re3data");
|
||||||
String re3Date = null;
|
String re3Date = null;
|
||||||
for (RepositoryInterface interf : re3interfaces) {
|
for (RepositoryInterface interf : re3interfaces) {
|
||||||
|
@ -955,7 +882,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
|
private MetricsNumbers getMetricsNumbers(String openAIREID) {
|
||||||
|
|
||||||
//build the uri params
|
//build the uri params
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
|
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
|
return UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
.fromHttpUrl(baseAddress + "/ds/searchdetails/")
|
||||||
|
@ -996,7 +923,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.build().expand(page, size).encode();
|
.build().expand(page, size).encode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UriComponents searchSnippetDatasource(String page, String size) {
|
private UriComponents searchDatasourceSnippetUri(String page, String size) {
|
||||||
|
|
||||||
return UriComponentsBuilder
|
return UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
||||||
|
@ -1006,7 +933,7 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.build().expand(page, size).encode();
|
.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
|
return UriComponentsBuilder
|
||||||
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
||||||
|
@ -1016,6 +943,52 @@ public class RepositoryServiceImpl implements RepositoryService {
|
||||||
.build().expand(page, size).encode();
|
.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) {
|
private String getRepositoryType(String typology) {
|
||||||
return invertedDataSourceClass.get(typology);
|
return invertedDataSourceClass.get(typology);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,9 @@
|
||||||
package eu.dnetlib.repo.manager.utils;
|
package eu.dnetlib.repo.manager.utils;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import eu.dnetlib.repo.manager.domain.Timezone;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -18,61 +12,14 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Converter {
|
public class Converter {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Converter.class);
|
private static final Logger logger = LoggerFactory.getLogger(Converter.class);
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private Converter() {
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositorySnippet toRepositorySnippet(JSONObject repositorySnippetObject) {
|
public static List<String> readFile(String filename) {
|
||||||
|
|
||||||
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) {
|
|
||||||
String line;
|
String line;
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
@ -88,7 +35,7 @@ public class Converter {
|
||||||
return list; // It may be empty.
|
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<>();
|
List<Timezone> tmz = new ArrayList<>();
|
||||||
for (String t : timezones) {
|
for (String t : timezones) {
|
||||||
|
@ -98,17 +45,17 @@ public class Converter {
|
||||||
return tmz;
|
return tmz;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getOpenaireId(String repositoryId) {
|
public static String getOpenaireId(String repositoryId) {
|
||||||
if (repositoryId != null && repositoryId.contains("::"))
|
if (repositoryId != null && repositoryId.contains("::"))
|
||||||
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
|
return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean convertStringToBoolean(String value) {
|
public static Boolean convertStringToBoolean(String value) {
|
||||||
return value.equals("null") ? null : Boolean.valueOf(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"))
|
if (Objects.equals(number, "null"))
|
||||||
return 0.0;
|
return 0.0;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue