Skip to content

Commit

Permalink
Harvester / Simple URL / Add support for JSON document containing onl…
Browse files Browse the repository at this point in the history
…y one record. eg. zenodo
  • Loading branch information
fxprunayre committed Dec 18, 2024
1 parent 7a47468 commit 31a2f5b
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,7 +209,17 @@ public HarvestResult harvest(Logger log) throws Exception {
private void collectRecordsFromJson(JsonNode jsonObj,
Map<String, Element> 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 -> {
Expand Down

0 comments on commit 31a2f5b

Please sign in to comment.