From ab5e04698c087ca7f2092ea98de818b132b1c519 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Tue, 7 Dec 2021 19:33:10 +0200 Subject: [PATCH] - Fix a bug, causing the "fileLocation" to be set to the value of the "errorCause", when the docFile was not retrieved. - Leave the "fileLocation" to be NULL, when the DocFile was not retrieved. Previously, the value "File not retrieved" was assigned (only in theory, because the bug above caused the related check to always fail). - Verify that the "ControllerBaseUrl" given by the user is not malformed. --- .../urls_worker/UrlsWorkerApplication.java | 14 ++++++++++++-- .../plugins/PublicationsRetrieverPlugin.java | 8 +++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java index e6f12c3..d282875 100644 --- a/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java +++ b/src/main/java/eu/openaire/urls_worker/UrlsWorkerApplication.java @@ -21,6 +21,8 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import javax.annotation.PreDestroy; import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; @@ -128,6 +130,14 @@ public class UrlsWorkerApplication { maxAssignmentsLimitPerBatch = WorkerConstants.ASSIGNMENTS_LIMIT; } controllerBaseUrl = data[2].trim(); + try { + new URL(controllerBaseUrl); + } catch (MalformedURLException mue) { + String errorMsg = "The given \"controllerBaseUrl\" (\"" + controllerBaseUrl + "\") was malformed! Please restart the program and give a valid URL."; + logger.error(errorMsg); + System.err.println(errorMsg); + System.exit(62); + } if ( !controllerBaseUrl.endsWith("/") ) controllerBaseUrl += "/"; // Make sure the other urls will not break later. } @@ -136,7 +146,7 @@ public class UrlsWorkerApplication { String errorMsg = "No \"workerId\" or/and \"maxAssignmentsLimitPerBatch\" or/and \"controllerBaseUrl\" could be retrieved from the file: " + inputDataFilePath; logger.error(errorMsg); System.err.println(errorMsg); - System.exit(62); + System.exit(63); } logger.info("workerId: " + workerId + ", maxAssignmentsLimitPerBatch: " + maxAssignmentsLimitPerBatch + ", controllerBaseUrl: " + controllerBaseUrl); // It's safe and helpful to show them in the logs. @@ -145,7 +155,7 @@ public class UrlsWorkerApplication { String errorMsg = "An error prevented the retrieval of the workerId and the controllerBaseUrl from the file: " + inputDataFilePath + "\n" + e.getMessage(); logger.error(errorMsg, e); System.err.println(errorMsg); - System.exit(63); + System.exit(64); } finally { if ( myReader != null ) myReader.close(); diff --git a/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java b/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java index 9df3ee7..32e81c3 100644 --- a/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java +++ b/src/main/java/eu/openaire/urls_worker/plugins/PublicationsRetrieverPlugin.java @@ -133,7 +133,7 @@ public class PublicationsRetrieverPlugin { } - private static final String DocFileNotRetrievedExceptionName = DocFileNotRetrievedException.class.getName(); // Keep it here for easily spot if the exception changes inside the PublicationsRetriever library. + private static final String DocFileNotRetrievedExceptionName = DocFileNotRetrievedException.class.getSimpleName(); // Keep it here for easily spot if the exception changes inside the PublicationsRetriever library. public static void addUrlReportsToWorkerReport() { @@ -165,10 +165,8 @@ public class PublicationsRetrieverPlugin { } // TODO - The case where the "twin-ID" is not found, should "never" happen. But should we check? How to handle if that is the case..? } - else if ( comment.contains(DocFileNotRetrievedExceptionName) ) - fileLocation = "File not retrieved"; - else { - fileLocation = comment; + else if ( ! comment.contains(DocFileNotRetrievedExceptionName) ) { // If it was downloaded without an error. + fileLocation = comment; // This is the full-file-path. mimeType = "application/pdf"; } error = new Error(null, null); // We do not want to send a "null" object, since it just adds more complicated handling in the controller..