Skip to content

Commit

Permalink
MODHAADM-105 avoid potential for hanging log purge requests (#126)
Browse files Browse the repository at this point in the history
- due to issues with mod-settings/mod-configuration look-ups
  • Loading branch information
nielserik authored Nov 20, 2024
1 parent 3fb2942 commit 89111bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,26 +17,14 @@ public class ConfigurationsClient {
protected static final Logger logger =
LogManager.getLogger(ConfigurationsClient.class);

public static Future<String> getStringValue (RoutingContext routingContext, String moduleName, String configName) {
String query = "module==" + moduleName + " and configName==" + configName + " and enabled=true";
Promise<String> 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<String> 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()));
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,26 +16,15 @@ public class SettingsClient {
protected static final Logger logger =
LogManager.getLogger(SettingsClient.class);

public static Future<String> getStringValue (RoutingContext routingContext, String scope, String key) {
String query = "scope==" + scope + " and key==" + key;
Promise<String> 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<String> 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()));
}

}

0 comments on commit 89111bf

Please sign in to comment.