Improve support for External sources
This commit is contained in:
parent
0e89ec50a6
commit
effc3c8431
|
@ -118,11 +118,25 @@ public class DatasetProfileManager {
|
||||||
for (AutoCompleteData.AutoCompleteSingleData singleData: data.getAutoCompleteSingleDataList()) {
|
for (AutoCompleteData.AutoCompleteSingleData singleData: data.getAutoCompleteSingleDataList()) {
|
||||||
switch (AutoCompleteData.AutocompleteType.fromValue(singleData.getAutocompleteType())) {
|
switch (AutoCompleteData.AutocompleteType.fromValue(singleData.getAutocompleteType())) {
|
||||||
case UNCACHED:
|
case UNCACHED:
|
||||||
headers.setAccept(Collections.singletonList(MediaType.valueOf("application/vnd.api+json; charset=utf-8")));
|
|
||||||
|
String url = singleData.getUrl();
|
||||||
|
String mediaType = "";
|
||||||
|
if (url.contains("openaire")) {
|
||||||
|
mediaType = "application/json; charset=utf-8";
|
||||||
|
url = url.replace("{like}", like.equals("") ? "*" : like);
|
||||||
|
url = url.replace("%20", " ");
|
||||||
|
url = url.replace("%22", "\"");
|
||||||
|
url = url.replace("&", "&");
|
||||||
|
} else {
|
||||||
|
mediaType = "application/vnd.api+json; charset=utf-8";
|
||||||
|
url += "?search=" + like;
|
||||||
|
}
|
||||||
|
|
||||||
|
headers.setAccept(Collections.singletonList(MediaType.valueOf(mediaType)));
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
entity = new HttpEntity<>("parameters", headers);
|
entity = new HttpEntity<>("parameters", headers);
|
||||||
|
|
||||||
response = restTemplate.exchange(singleData.getUrl() + "?search=" + like, HttpMethod.GET, entity, Object.class);
|
response = restTemplate.exchange(url, HttpMethod.GET, entity, Object.class);
|
||||||
jsonContext = JsonPath.parse(response.getBody());
|
jsonContext = JsonPath.parse(response.getBody());
|
||||||
jsonItems = jsonContext.read(singleData.getOptionsRoot() + "['" + singleData.getAutoCompleteOptions().getLabel() + "','" + singleData.getAutoCompleteOptions().getValue() + "','" + singleData.getAutoCompleteOptions().getSource() + "','" + "uri" + "']");
|
jsonItems = jsonContext.read(singleData.getOptionsRoot() + "['" + singleData.getAutoCompleteOptions().getLabel() + "','" + singleData.getAutoCompleteOptions().getValue() + "','" + singleData.getAutoCompleteOptions().getSource() + "','" + "uri" + "']");
|
||||||
jsonItems.forEach(item -> result.add(new ExternalAutocompleteFieldModel(item.get(singleData.getAutoCompleteOptions().getValue()), item.get(singleData.getAutoCompleteOptions().getLabel()), item.get(singleData.getAutoCompleteOptions().getSource()), item.get("uri"))));
|
jsonItems.forEach(item -> result.add(new ExternalAutocompleteFieldModel(item.get(singleData.getAutoCompleteOptions().getValue()), item.get(singleData.getAutoCompleteOptions().getLabel()), item.get(singleData.getAutoCompleteOptions().getSource()), item.get("uri"))));
|
||||||
|
|
|
@ -268,6 +268,17 @@ public class RemoteFetcher {
|
||||||
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName()
|
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getName()
|
||||||
+ "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
|
+ "," + jsonDataPath.getFieldsUrlConfiguration().getId() + "]"),
|
||||||
new HashMap<>(1, 1));
|
new HashMap<>(1, 1));
|
||||||
|
List<Map<String, String>> fixedResults = results.getResults().stream().map(item -> {
|
||||||
|
String id = jsonDataPath.getFieldsUrlConfiguration().getId().replace("'", "");
|
||||||
|
if (! (item.get(id) instanceof String)) {
|
||||||
|
Object obj = item.get(id);
|
||||||
|
JSONArray jarr = (JSONArray) obj;
|
||||||
|
item.put(id, jarr.get(0).toString());
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
results = new Results(fixedResults, new HashMap<>(1, 1));
|
||||||
} else if (jsonDataPath.getFieldsUrlConfiguration().getPath() != null) {
|
} else if (jsonDataPath.getFieldsUrlConfiguration().getPath() != null) {
|
||||||
results = new Results(jsonContext.read(jsonDataPath.getPath()
|
results = new Results(jsonContext.read(jsonDataPath.getPath()
|
||||||
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getPath()
|
+ "[" + jsonDataPath.getFieldsUrlConfiguration().getPath()
|
||||||
|
@ -312,7 +323,8 @@ public class RemoteFetcher {
|
||||||
}
|
}
|
||||||
results.results = results.results.stream().map(e -> e.entrySet().stream().collect(Collectors.toMap(x -> this.transformKey(jsonDataPath,x.getKey()), Map.Entry::getValue)))
|
results.results = results.results.stream().map(e -> e.entrySet().stream().collect(Collectors.toMap(x -> this.transformKey(jsonDataPath,x.getKey()), Map.Entry::getValue)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else if (con.getHeaderField("Content-Type").contains("xml")) {
|
}
|
||||||
|
else if (con.getHeaderField("Content-Type").contains("xml")) {
|
||||||
Class<?> aClass = Class.forName(jsonDataPath.getParseClass());
|
Class<?> aClass = Class.forName(jsonDataPath.getParseClass());
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(aClass);
|
JAXBContext jaxbContext = JAXBContext.newInstance(aClass);
|
||||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
|
|
Loading…
Reference in New Issue