From e20c5d2146e26653f619885cb00d0e9f72a8299f Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 11 Mar 2024 19:48:04 +0200 Subject: [PATCH] - Add error-handling for the case when no payloads could be associated with a specific url which should have been in the hashMultiMap in "addUrlReportsByMatchingRecordsFromBacklog". - Fix not cloning the payload, before changing it and adding it in the "prefilledPayloads"-list; instead, an object-reference was used. --- .../java/eu/openaire/urls_controller/models/Payload.java | 8 ++++++++ .../java/eu/openaire/urls_controller/util/FileUtils.java | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/openaire/urls_controller/models/Payload.java b/src/main/java/eu/openaire/urls_controller/models/Payload.java index c2e8cf9..143e73a 100644 --- a/src/main/java/eu/openaire/urls_controller/models/Payload.java +++ b/src/main/java/eu/openaire/urls_controller/models/Payload.java @@ -68,6 +68,14 @@ public class Payload { this.datasourceId = datasourceId; } + + public Payload clone() + { + // Return a new object with the same values. Clone whatever objects are not immutable.! + return new Payload(this.id, this.original_url, this.actual_url, (Timestamp) this.timestamp_acquired.clone(), this.mime_type, this.size, this.hash, + this.location, this.provenance, this.datasourceId); + } + public String getId() { return id; } diff --git a/src/main/java/eu/openaire/urls_controller/util/FileUtils.java b/src/main/java/eu/openaire/urls_controller/util/FileUtils.java index 8f9c1a3..24b455e 100644 --- a/src/main/java/eu/openaire/urls_controller/util/FileUtils.java +++ b/src/main/java/eu/openaire/urls_controller/util/FileUtils.java @@ -804,6 +804,10 @@ public class FileUtils { return; // Move to the next payload. } Set foundPayloads = urlToPayloadsMultimap.get(original_url); + if ( foundPayloads == null ) { + logger.error("No payloads associated with \"original_url\" = \"" + original_url + "\"!"); + return; + } // Select a random "foundPayload" to use its data to fill the "prefilledPayload" (in a "Set" the first element is pseudo-random). Optional optPayload = foundPayloads.stream().findFirst(); @@ -811,7 +815,7 @@ public class FileUtils { logger.error("Could not retrieve any payload for the \"original_url\": " + original_url); return; // Move to the next payload. } - Payload prefilledPayload = optPayload.get(); // We change just the id and the original_url. + Payload prefilledPayload = optPayload.get().clone(); // We take a clone of the original payload and change just the id and the original_url. prefilledPayload.setId(id); prefilledPayload.setOriginal_url(original_url); prefilledPayloads.add(prefilledPayload);