Skip to content

Commit

Permalink
jsonHarvester: add api& nodeUrl in XML for transfo
Browse files Browse the repository at this point in the history
used by ODS to compute exports links
  • Loading branch information
fgravin committed Sep 10, 2021
1 parent c80c493 commit 98f941a
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -137,8 +139,16 @@ public HarvestResult harvest(Logger log) throws Exception {

nodes.forEach(record -> {
String uuid = this.extractUuidFromIdentifier(record.get(params.recordIdPath).asText());
Element xml = convertRecordToXml(record, uuid);
uuids.put(uuid, xml);
String apiUrl = params.url.split("\\?")[0];
URL url = null;
try {
url = new URL(apiUrl);
String nodeUrl = new StringBuilder(url.getProtocol()).append("://").append(url.getAuthority()).toString();
Element xml = convertRecordToXml(record, uuid, apiUrl, nodeUrl);
uuids.put(uuid, xml);
} catch (MalformedURLException e) {
log.warning("Failed to parse Node URL");
}
});
aligner.align(uuids, errors);
allUuids.putAll(uuids);
Expand Down Expand Up @@ -226,7 +236,7 @@ protected List<String> buildListOfUrl(SimpleUrlParams params, int numberOfRecord
return urlList;
}

private Element convertRecordToXml(JsonNode record, String uuid) {
private Element convertRecordToXml(JsonNode record, String uuid, String apiUrl, String nodeUrl) {
ObjectMapper objectMapper = new ObjectMapper();
try {
String recordAsXml = XML.toString(
Expand All @@ -235,6 +245,8 @@ private Element convertRecordToXml(JsonNode record, String uuid) {
recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml).replace("<@", "<").replace("</@", "</");
Element recordAsElement = Xml.loadString(recordAsXml, false);
recordAsElement.addContent(new Element("uuid").setText(uuid));
recordAsElement.addContent(new Element("apiUrl").setText(apiUrl));
recordAsElement.addContent(new Element("nodeUrl").setText(nodeUrl));
Path importXsl = context.getAppPath().resolve(Geonet.Path.IMPORT_STYLESHEETS);
final Path xslPath = importXsl.resolve(params.toISOConversion + ".xsl");
return Xml.transform(recordAsElement, xslPath);
Expand Down

0 comments on commit 98f941a

Please sign in to comment.