From 89111bfea2bcea337cf3255a031c573bf40169bd Mon Sep 17 00:00:00 2001 From: Niels Erik Date: Thu, 21 Nov 2024 00:40:28 +0100 Subject: [PATCH] MODHAADM-105 avoid potential for hanging log purge requests (#126) - due to issues with mod-settings/mod-configuration look-ups --- .../foliodata/ConfigurationsClient.java | 30 +++++------------- .../foliodata/SettingsClient.java | 31 ++++++------------- 2 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/folio/harvesteradmin/foliodata/ConfigurationsClient.java b/src/main/java/org/folio/harvesteradmin/foliodata/ConfigurationsClient.java index b8489ca..f902daa 100644 --- a/src/main/java/org/folio/harvesteradmin/foliodata/ConfigurationsClient.java +++ b/src/main/java/org/folio/harvesteradmin/foliodata/ConfigurationsClient.java @@ -1,10 +1,8 @@ package org.folio.harvesteradmin.foliodata; import io.vertx.core.Future; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; -import io.vertx.reactivex.core.Promise; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -19,26 +17,14 @@ public class ConfigurationsClient { protected static final Logger logger = LogManager.getLogger(ConfigurationsClient.class); - public static Future getStringValue (RoutingContext routingContext, String moduleName, String configName) { - String query = "module==" + moduleName + " and configName==" + configName + " and enabled=true"; - Promise promise = Promise.promise(); - Folio.okapiClient(routingContext).get(CONFIGURATIONS_PATH + - "?query=(" + URLEncoder.encode(query, StandardCharsets.UTF_8) +")") - .onSuccess(response -> { - JsonObject json = new JsonObject(response); - JsonArray entries = json.getJsonArray(RECORDS); - if (entries.isEmpty()) { - promise.complete(null); - - } else { - JsonObject entry = entries.getJsonObject(0); - promise.complete(entry.getString("value")); - } - }).onFailure(response -> { - logger.info("Could not obtain settings by module " + moduleName + " and config " + configName + ": " + response.getMessage()); - promise.complete(null); - }); - return promise.future(); + public static Future getStringValue(RoutingContext routingContext, String moduleName, String configName) { + String query = "module==\"" +moduleName+ "\" and configName==\"" +configName+"\" and enabled=true\""; + return Folio.okapiClient(routingContext).get(CONFIGURATIONS_PATH + + "?query=" + URLEncoder.encode(query, StandardCharsets.UTF_8)) + .map(response -> + new JsonObject(response).getJsonArray(RECORDS).getJsonObject(0).getString("value")) + .onFailure(e -> logger.error("Could not obtain settings by module " + moduleName + + " and config " + configName + ": " + e.getMessage())); } } diff --git a/src/main/java/org/folio/harvesteradmin/foliodata/SettingsClient.java b/src/main/java/org/folio/harvesteradmin/foliodata/SettingsClient.java index b283316..1d4db71 100644 --- a/src/main/java/org/folio/harvesteradmin/foliodata/SettingsClient.java +++ b/src/main/java/org/folio/harvesteradmin/foliodata/SettingsClient.java @@ -1,10 +1,8 @@ package org.folio.harvesteradmin.foliodata; import io.vertx.core.Future; -import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; -import io.vertx.reactivex.core.Promise; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -18,26 +16,15 @@ public class SettingsClient { protected static final Logger logger = LogManager.getLogger(SettingsClient.class); - public static Future getStringValue (RoutingContext routingContext, String scope, String key) { - String query = "scope==" + scope + " and key==" + key; - Promise promise = Promise.promise(); - Folio.okapiClient(routingContext).get(SETTINGS_PATH + - "?query=(" + URLEncoder.encode(query, StandardCharsets.UTF_8) +")") - .onSuccess(response -> { - JsonObject json = new JsonObject(response); - JsonArray entries = json.getJsonArray(RECORDS); - if (entries.isEmpty()) { - promise.complete(null); - - } else { - JsonObject entry = entries.getJsonObject(0); - promise.complete(entry.getString("value")); - } - }).onFailure(response -> { - logger.error("Could not obtain settings by scope " + scope + " and key " + key + ": " + response.getMessage()); - promise.complete(null); - }); - return promise.future(); + public static Future getStringValue(RoutingContext routingContext, String scope, String key) { + String query = "scope==\"" + scope + "\" and key==\"" + key + "\""; + return Folio.okapiClient(routingContext).get(SETTINGS_PATH + + "?query=" + URLEncoder.encode(query, StandardCharsets.UTF_8)) + .map(response -> + new JsonObject(response).getJsonArray(RECORDS).getJsonObject(0).getString("value")) + .onFailure(e -> + logger.error("Could not obtain settings by scope " + scope + + " and key " + key + ": " + e.getMessage())); } }