From 332ff96ad28f7d97c680db799f512bed9393a0ef Mon Sep 17 00:00:00 2001 From: Florent gravin Date: Thu, 9 Sep 2021 10:02:50 +0200 Subject: [PATCH] jsonHarvester: extract uuid from identifier https://data-atmo-hdf.opendata.arcgis.com/datasets/bac17d7d05a34242a8b22c535ecdb13d will extract bac17d7d05a34242a8b22c535ecdb13d --- .../harvest/harvester/simpleUrl/Harvester.java | 16 +++++++++++++--- .../iso19115-3.2018/convert/fromJsonLdEsri.xsl | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java b/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java index 9d928fd7748..088611c999b 100644 --- a/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java +++ b/harvesters/src/main/java/org/fao/geonet/kernel/harvest/harvester/simpleUrl/Harvester.java @@ -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); @@ -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 buildListOfUrl(SimpleUrlParams params, int numberOfRecordsToHarvest) { List urlList = new ArrayList(); @@ -217,7 +226,7 @@ protected List 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( @@ -225,6 +234,7 @@ private Element convertRecordToXml(JsonNode record) { objectMapper.writeValueAsString(record)), "record"); recordAsXml = Xml.stripNonValidXMLCharacters(recordAsXml).replace("<@", "<").replace(" - +