Skip to content

Commit

Permalink
CIRC-2051 move common validation to separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-barannyk committed Apr 12, 2024
1 parent c6ab23f commit 5482316
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,8 @@ private static Result<AllowedServicePointsRequest> 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;

Expand Down Expand Up @@ -149,6 +139,14 @@ private static Result<AllowedServicePointsRequest> buildRequest(RoutingContext r
requestId, Boolean.parseBoolean(useStubItem), Boolean.parseBoolean(ecsRequestRouting)));
}

private static void validateBoolean(String parameter, String parameterName, List<String> 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<RequestType, Set<AllowedServicePoint>> allowedServicePoints) {
log.debug("toJson:: parameters: allowedServicePoints={}", () -> asJson(allowedServicePoints));
JsonObject response = new JsonObject();
Expand Down

0 comments on commit 5482316

Please sign in to comment.