From 31a2f5b01dd3810a0f013d13610a891699cde7a2 Mon Sep 17 00:00:00 2001 From: Francois Prunayre Date: Fri, 25 Oct 2024 19:01:15 +0200 Subject: [PATCH] Harvester / Simple URL / Add support for JSON document containing only one record. eg. zenodo --- .../harvest/harvester/simpleurl/Harvester.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 254fac91f84..2c2cbf052f3 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 @@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.annotations.VisibleForTesting; import com.google.common.io.CharStreams; import jeeves.server.context.ServiceContext; @@ -208,7 +209,17 @@ public HarvestResult harvest(Logger log) throws Exception { private void collectRecordsFromJson(JsonNode jsonObj, Map uuids, Aligner aligner) { - JsonNode nodes = jsonObj.at(params.loopElement); + JsonNode nodes = null; + if (".".equals(params.loopElement)) { + ObjectMapper objectMapper = new ObjectMapper(); + ArrayNode jsonNodes = objectMapper.createArrayNode(); + jsonNodes.add(jsonObj); + nodes = jsonNodes; + } else { + nodes = jsonObj.at(params.loopElement); + } + + log.debug(String.format("%d records found in JSON response.", nodes.size())); nodes.forEach(jsonRecord -> {