Fixed various issues with the new externalUrls restTemplate

This commit is contained in:
George Kalampokis 2020-10-05 16:21:42 +03:00
parent c02157be8c
commit ae03077795
4 changed files with 20 additions and 25 deletions

View File

@ -190,11 +190,10 @@ public class RemoteFetcher {
if (funderId.toCharArray()[0] == ':') {
funderId = externalUrlCriteria.getFunderId();
}
try {
funderId = URLEncoder.encode(funderId, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
/*
try { funderId = URLEncoder.encode(funderId, "UTF-8"); } catch
(UnsupportedEncodingException e) { logger.error(e.getMessage(), e); }
*/
completedPath = completedPath.replace("{funderId}", funderId);
}
if (externalUrlCriteria.getPage() != null) {
@ -260,12 +259,12 @@ public class RemoteFetcher {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<String> entity;
ResponseEntity response;
ResponseEntity<String> response;
/*
URL url = new URL(urlString.replaceAll(" ", "%20"));
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
* URL url = new URL(urlString.replaceAll(" ", "%20"));
*
* HttpURLConnection con = (HttpURLConnection) url.openConnection();
* con.setRequestMethod("GET");
*/
if (contentType != null && !contentType.isEmpty()) {
headers.setAccept(Collections.singletonList(MediaType.valueOf(contentType)));
@ -273,11 +272,7 @@ public class RemoteFetcher {
entity = new HttpEntity<>("parameters", headers);
if (contentType.contains("json")) {
response = restTemplate.exchange(urlString, HttpMethod.GET, entity, Object.class);
} else {
response = restTemplate.exchange(urlString, HttpMethod.GET, entity, String.class);
}
if (response.getStatusCode() == HttpStatus.OK) { // success
//do here all the parsing
Results results = new Results();
@ -387,7 +382,7 @@ public class RemoteFetcher {
Class<?> aClass = Class.forName(jsonDataPath.getParseClass());
JAXBContext jaxbContext = JAXBContext.newInstance(aClass);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader stringReader = new StringReader(response.getBody().toString());
StringReader stringReader = new StringReader(response.getBody());
Object data = unmarshaller.unmarshal(stringReader);
Method reader = null;
if (jsonDataPath.getParseField() != null && !jsonDataPath.getParseField().isEmpty()) {

View File

@ -149,8 +149,8 @@
<key>openaire</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype%20exact%20project)%20and%20((projectcode_nt%20exact%20%22{like}%22)or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder%20exact%20%22{funderId}%22)</funderQuery>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype exact project) and ((projectcode_nt exact "{like}")or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder exact "{funderId}")</funderQuery>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
@ -228,7 +228,7 @@
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype%20exact%20project)%20and%20((projectcode_nt%20exact%20%22*%22)or(*)))&amp;fq=(funder%20exact%20{funderId})&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype exact project) and ((projectcode_nt exact "*")or(*)))&amp;fq=(funder exact {funderId})&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>
@ -501,7 +501,7 @@
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/datasources?q={like}&amp;fq=datasourcetypeuiname%20exact%20%22Data%20Repository%22&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<url>https://services.openaire.eu/search/v2/api/datasources?q={like}&amp;fq=datasourcetypeuiname exact "Data Repository"&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json;charset=UTF-8</contenttype>
<data>
@ -519,7 +519,7 @@
<label>OpenAIRE Alternative</label>
<ordinal>1</ordinal>
<type>External</type>
<url>https://services.openaire.eu/search/v2/api/resources?query=oaftype%20exact%20datasource%20and%20{like}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<url>https://services.openaire.eu/search/v2/api/resources?query=oaftype exact datasource and {like}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<firstPage>0</firstPage>
<contenttype>application/json;charset=UTF-8</contenttype>
<data>

View File

@ -58,8 +58,8 @@
<key>openAIRE</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype%20exact%20project)%20and%20((projectcode_nt%20exact%20%22{like}%22)or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder%20exact%20%22{funderId}%22)</funderQuery>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype exact project) and ((projectcode_nt exact "{like}")or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder exact "{funderId}")</funderQuery>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>

View File

@ -61,8 +61,8 @@
<key>openAIRE</key>
<label>OpenAIRE</label>
<ordinal>1</ordinal>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype%20exact%20project)%20and%20((projectcode_nt%20exact%20%22{like}%22)or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder%20exact%20%22{funderId}%22)</funderQuery>
<url>https://services.openaire.eu/search/v2/api/resources?query=((oaftype exact project) and ((projectcode_nt exact "{like}")or({like}))){funderQuery}&amp;page={page}&amp;size={pageSize}&amp;format=json</url>
<funderQuery>&amp;fq=(funder exact "{funderId}")</funderQuery>
<firstPage>0</firstPage>
<contenttype>application/json; charset=utf-8</contenttype>
<data>