Skip to content

Commit

Permalink
jsonHarvester: extract uuid from identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Sep 9, 2021
1 parent c42d4ca commit 332ff96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ public HarvestResult harvest(Logger log) throws Exception {
log.debug("Number of records in response: " + nodes.size());

nodes.forEach(record -> {
Element xml = convertRecordToXml(record);
uuids.put(record.get(params.recordIdPath).asText(), xml);
String uuid = this.extractUuidFromIdentifier(record.get(params.recordIdPath).asText());
Element xml = convertRecordToXml(record, uuid);
uuids.put(uuid, xml);
});
aligner.align(uuids, errors);
allUuids.putAll(uuids);
Expand Down Expand Up @@ -168,6 +169,14 @@ public HarvestResult harvest(Logger log) throws Exception {
return result;
}

private String extractUuidFromIdentifier(final String identifier ) {
String uuid = identifier;
if (Lib.net.isUrlValid(uuid)) {
uuid = uuid.replaceFirst(".*/([^/?]+).*", "$1");
}
return uuid;
}

@VisibleForTesting
protected List<String> buildListOfUrl(SimpleUrlParams params, int numberOfRecordsToHarvest) {
List<String> urlList = new ArrayList<String>();
Expand Down Expand Up @@ -217,14 +226,15 @@ protected List<String> buildListOfUrl(SimpleUrlParams params, int numberOfRecord
return urlList;
}

private Element convertRecordToXml(JsonNode record) {
private Element convertRecordToXml(JsonNode record, String uuid) {
ObjectMapper objectMapper = new ObjectMapper();
try {
String recordAsXml = XML.toString(
new JSONObject(
objectMapper.writeValueAsString(record)), "record");
recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml).replace("<@", "<").replace("</@", "</");
Element recordAsElement = Xml.loadString(recordAsXml, false);
recordAsElement.addContent(new Element("uuid").setText(uuid));
Path importXsl = context.getAppPath().resolve(Geonet.Path.IMPORT_STYLESHEETS);
final Path xslPath = importXsl.resolve(params.toISOConversion + ".xsl");
return Xml.transform(recordAsElement, xslPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<mcc:MD_Identifier>
<mcc:code>
<gco:CharacterString>
<xsl:value-of select="identifier"/>
<xsl:value-of select="uuid"/>
</gco:CharacterString>
</mcc:code>
</mcc:MD_Identifier>
Expand Down

0 comments on commit 332ff96

Please sign in to comment.