fixed content type missmatch error when converting response from json to string in method getRepositoriesByCountry

This commit is contained in:
Konstantinos Spyrou 2023-01-17 16:57:14 +02:00
parent e551a7a783
commit 49cc3d74e8
1 changed files with 22 additions and 40 deletions

View File

@ -210,7 +210,7 @@ public class RepositoryServiceImpl implements RepositoryService {
List<RepositorySnippet> resultSet = new ArrayList<>();
// here page should be 0
UriComponents uriComponents = searchSnipperDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
UriComponents uriComponents = searchSnippetDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
RequestFilter requestFilter = new RequestFilter();
try {
@ -218,7 +218,7 @@ public class RepositoryServiceImpl implements RepositoryService {
requestFilter.setId(repoId);
DatasourceResponse rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
if ( rs == null ) {
if (rs == null) {
logger.error("The \"DatasourceResponse\" is null!");
return null;
}
@ -259,31 +259,15 @@ public class RepositoryServiceImpl implements RepositoryService {
logger.debug("Country code equals : {} | Filter mode equals : {}", country, filterKey);
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
UriComponents uriComponents = searchSnippetDatasource(String.valueOf(page), String.valueOf(size));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(country);
requestFilter.setEoscDatasourceType(filterKey);
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
if ( rs == null ) {
logger.error("The result is null!");
return null;
}
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
while (jsonArray.length() > 0) {
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
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)));
page += 1;
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
if ( rs == null ) {
logger.error("The result is null!");
break;
}
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
}
return resultSet;
}
@ -385,12 +369,12 @@ public class RepositoryServiceImpl implements RepositoryService {
logger.debug("Retrieving repositories with id : {}", id);
RepositorySnippet repo;
UriComponents uriComponents = searchSnipperDatasource("0", "100");
UriComponents uriComponents = searchSnippetDatasource("0", "100");
RequestFilter requestFilter = new RequestFilter();
requestFilter.setId(id);
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
if ( rs == null ) {
if (rs == null) {
logger.error("The result is null!");
return null;
}
@ -418,7 +402,7 @@ public class RepositoryServiceImpl implements RepositoryService {
DatasourceResponse response;
response = restTemplate.postForObject(uriComponents.toUri(), requestFilter, DatasourceResponse.class);
if ( response == null ) {
if (response == null) {
logger.error("The response is null!");
return null;
}
@ -463,7 +447,7 @@ public class RepositoryServiceImpl implements RepositoryService {
// String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
ApiDetailsResponse rs = restTemplate.getForObject(uriComponents.toUri(), ApiDetailsResponse.class);
if ( rs == null ) {
if (rs == null) {
logger.error("The ApiDetailsResponse was null!");
return null;
}
@ -471,9 +455,9 @@ public class RepositoryServiceImpl implements RepositoryService {
// TODO STOP FILTERING OUT "sword", "rest" AND FIX UI!
List<ApiDetails> res = new ArrayList<>();
for (ApiDetails det: rs.getApi()) {
for (ApiDetails det : rs.getApi()) {
String protocol = det.getProtocol();
if ( !protocol.equals("sword") &&
if (!protocol.equals("sword") &&
!protocol.equals("rest") &&
!protocol.equals("ftp")) {
res.add(det);
@ -564,7 +548,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
if (responseBody != null)
logger.error("Error updating repository: {}", responseBody);
}
@ -590,7 +574,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
if (responseBody != null)
logger.error("Error updating repository: {}", responseBody);
}
@ -618,7 +602,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminRegistrationEmail(repository, authentication);
} else {
Object responseBody = responseEntity.getBody();
if ( responseBody != null )
if (responseBody != null)
logger.error("Error storing repository: {}", responseBody);
}
}
@ -657,7 +641,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, authentication);
if (desiredCompatibilityLevel!= null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) {
if (desiredCompatibilityLevel != null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
@ -680,7 +664,7 @@ public class RepositoryServiceImpl implements RepositoryService {
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, authentication);
if (desiredCompatibilityLevel!= null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) {
if (desiredCompatibilityLevel != null && !repositoryInterface.getCompatibility().equals(desiredCompatibilityLevel)) {
InterfaceComplianceRequest request = new InterfaceComplianceRequest(repoId, repositoryInterface.getId(), desiredCompatibilityLevel);
interfaceComplianceService.create(request);
}
@ -814,18 +798,17 @@ public class RepositoryServiceImpl implements RepositoryService {
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
return compatibilityClasses;
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
if ( ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches() ) {
if (ValidatorServiceImpl.OPENAIRE_DATA_REGEX.matcher(entry.getKey()).matches()) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
}
else if (mode.equalsIgnoreCase("cris")) {
} else if (mode.equalsIgnoreCase("cris")) {
if (entry.getKey().contains("openaire-cris")) {
retMap.put(entry.getKey(), entry.getValue());
foundData = true;
}
} else {
if ( ValidatorServiceImpl.OPENAIRE_OR_DRIVER_REGEX.matcher(entry.getKey()).matches() )
if (ValidatorServiceImpl.OPENAIRE_OR_DRIVER_REGEX.matcher(entry.getKey()).matches())
retMap.put(entry.getKey(), entry.getValue());
}
}
@ -925,8 +908,7 @@ public class RepositoryServiceImpl implements RepositoryService {
dates.put("re3data", re3Date);
return dates;
}
else if (mode.equals("cris"))
} else if (mode.equals("cris"))
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("eurocrisdris::dris").get(0).getLastCollectionDate()));
else if (mode.equals("opendoar")) // TODO: remove this and else clause
return Collections.singletonMap("lastCollectionDate", DateUtils.toString(getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate()));
@ -1010,7 +992,7 @@ public class RepositoryServiceImpl implements RepositoryService {
.build().expand(page, size).encode();
}
private UriComponents searchSnipperDatasource(String page, String size) {
private UriComponents searchSnippetDatasource(String page, String size) {
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")