From 54823166599f14efbbdd7fa3446dbfc512351026 Mon Sep 17 00:00:00 2001 From: Roman_Barannyk Date: Fri, 12 Apr 2024 17:04:24 +0300 Subject: [PATCH] CIRC-2051 move common validation to separate method --- .../AllowedServicePointsResource.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java index f87482dc49..be103e5c11 100644 --- a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java +++ b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java @@ -96,18 +96,8 @@ private static Result buildRequest(RoutingContext r requestId); errors.add(String.format("Request ID is not a valid UUID: %s.", requestId)); } - if (useStubItem != null && !"true".equals(useStubItem) && !"false".equals(useStubItem)) { - log.warn("validateAllowedServicePointsRequest:: useStubItem is not a valid boolean: {}", - useStubItem); - errors.add(String.format("useStubItem is not a valid boolean: %s.", useStubItem)); - } - if (ecsRequestRouting != null && !"true".equals(ecsRequestRouting) - && !"false".equals(ecsRequestRouting)) { - - log.warn("validateAllowedServicePointsRequest:: ecsRequestRouting is not a valid boolean: {}", - ecsRequestRouting); - errors.add(String.format("ecsRequestRouting is not a valid boolean: %s.", ecsRequestRouting)); - } + validateBoolean(useStubItem, "useStubItem", errors); + validateBoolean(ecsRequestRouting, "ecsRequestRouting", errors); // Checking parameter combinations boolean allowedCombinationOfParametersDetected = false; @@ -149,6 +139,14 @@ private static Result buildRequest(RoutingContext r requestId, Boolean.parseBoolean(useStubItem), Boolean.parseBoolean(ecsRequestRouting))); } + private static void validateBoolean(String parameter, String parameterName, List errors) { + if (parameter != null && !"true".equals(parameter) && !"false".equals(parameter)) { + log.warn("validateBoolean:: {} is not a valid boolean: {}", + parameterName, parameter); + errors.add(String.format("%s is not a valid boolean: %s.", parameterName, parameter)); + } + } + private static JsonObject toJson(Map> allowedServicePoints) { log.debug("toJson:: parameters: allowedServicePoints={}", () -> asJson(allowedServicePoints)); JsonObject response = new JsonObject();