diff --git a/ramls/circulation.raml b/ramls/circulation.raml index 0618e6c63d..06f7e42b76 100644 --- a/ramls/circulation.raml +++ b/ramls/circulation.raml @@ -345,9 +345,9 @@ resourceTypes: required: false useStubItem: description: "Allows to apply circulation rules based on patron group only" - type: string - enum: ["true", "false"] - default: "false" + type: boolean + enum: [true, false] + default: false required: false responses: 200: diff --git a/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java b/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java index d6b3464887..75de70f03e 100644 --- a/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java +++ b/src/main/java/org/folio/circulation/domain/AllowedServicePointsRequest.java @@ -20,7 +20,7 @@ public class AllowedServicePointsRequest { private String instanceId; private String itemId; private String requestId; - private String useStubItem; + private boolean useStubItem; public boolean isForTitleLevelRequest() { return instanceId != null; diff --git a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java index 2f49592370..4b7c9e9f2d 100644 --- a/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java +++ b/src/main/java/org/folio/circulation/resources/AllowedServicePointsResource.java @@ -67,61 +67,39 @@ private static Result buildRequest(RoutingContext r .map(String::toUpperCase) .map(Request.Operation::valueOf) .orElse(null); - - AllowedServicePointsRequest request = new AllowedServicePointsRequest(operation, - queryParams.get("requesterId"), queryParams.get("instanceId"), queryParams.get("itemId"), - queryParams.get("requestId"), queryParams.get("useStubItem")); - - return validateAllowedServicePointsRequest(request); - } - - private static Result validateAllowedServicePointsRequest( - AllowedServicePointsRequest allowedServicePointsRequest) { - - log.debug("validateAllowedServicePointsRequest:: parameters allowedServicePointsRequest: {}", - allowedServicePointsRequest); - - Request.Operation operation = allowedServicePointsRequest.getOperation(); - String requesterId = allowedServicePointsRequest.getRequesterId(); - String instanceId = allowedServicePointsRequest.getInstanceId(); - String itemId = allowedServicePointsRequest.getItemId(); - String requestId = allowedServicePointsRequest.getRequestId(); - String useStubItem = allowedServicePointsRequest.getUseStubItem(); + String requesterId = queryParams.get("requesterId"); + String instanceId = queryParams.get("instanceId"); + String itemId = queryParams.get("itemId"); + String requestId = queryParams.get("requestId"); + String useStubItem = queryParams.get("useStubItem"); List errors = new ArrayList<>(); // Checking UUID validity - if (requesterId != null && !isUuid(requesterId)) { log.warn("validateAllowedServicePointsRequest:: requester ID is not a valid UUID: {}", requesterId); errors.add(String.format("Requester ID is not a valid UUID: %s.", requesterId)); } - if (instanceId != null && !isUuid(instanceId)) { log.warn("validateAllowedServicePointsRequest:: instance ID is not a valid UUID: {}", requesterId); errors.add(String.format("Instance ID is not a valid UUID: %s.", instanceId)); } - if (itemId != null && !isUuid(itemId)) { log.warn("validateAllowedServicePointsRequest:: item ID is not a valid UUID: {}", itemId); errors.add(String.format("Item ID is not a valid UUID: %s.", itemId)); } - if (requestId != null && !isUuid(requestId)) { log.warn("validateAllowedServicePointsRequest:: request ID is not a valid UUID: {}", 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)); } - // Checking parameter combinations - boolean allowedCombinationOfParametersDetected = false; if (operation == Request.Operation.CREATE && requesterId != null && instanceId != null && @@ -130,40 +108,36 @@ private static Result validateAllowedServicePointsR log.info("validateAllowedServicePointsRequest:: TLR request creation case"); allowedCombinationOfParametersDetected = true; } - if (operation == Request.Operation.CREATE && requesterId != null && instanceId == null && itemId != null && requestId == null) { log.info("validateAllowedServicePointsRequest:: ILR request creation case"); allowedCombinationOfParametersDetected = true; } - if (operation == Request.Operation.REPLACE && requesterId == null && instanceId == null && itemId == null && requestId != null) { log.info("validateAllowedServicePointsRequest:: request replacement case"); allowedCombinationOfParametersDetected = true; } - if (operation == Request.Operation.MOVE && requesterId == null && instanceId == null && itemId != null && requestId != null) { log.info("validateAllowedServicePointsRequest:: request movement case"); allowedCombinationOfParametersDetected = true; } - if (!allowedCombinationOfParametersDetected) { String errorMessage = "Invalid combination of query parameters"; errors.add(errorMessage); } - if (!errors.isEmpty()) { String errorMessage = String.join(" ", errors); log.error("validateRequest:: allowed service points request failed: {}", errorMessage); return failed(new BadRequestFailure(errorMessage)); } - return succeeded(allowedServicePointsRequest); + return succeeded(new AllowedServicePointsRequest(operation, requesterId, instanceId, itemId, + requestId, Boolean.parseBoolean(useStubItem))); } private static JsonObject toJson(Map> allowedServicePoints) { diff --git a/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java b/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java index 50e77a3052..74140f217a 100644 --- a/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java +++ b/src/main/java/org/folio/circulation/services/AllowedServicePointsService.java @@ -155,7 +155,7 @@ private CompletableFuture> fetchUser(AllowedServicePointsRequest re ? this::extractAllowedServicePointsIgnoringItemStatus : this::extractAllowedServicePointsConsideringItemStatus; - if ("true".equals(request.getUseStubItem())) { + if (request.isUseStubItem()) { return requestPolicyRepository.lookupRequestPolicy(user) .thenCompose(r -> r.after(policy -> extractAllowedServicePointsIgnoringItemStatus( policy, new HashSet<>()))); diff --git a/src/test/java/api/requests/AllowedServicePointsAPITests.java b/src/test/java/api/requests/AllowedServicePointsAPITests.java index 2b7bd9e508..a8da598cd2 100644 --- a/src/test/java/api/requests/AllowedServicePointsAPITests.java +++ b/src/test/java/api/requests/AllowedServicePointsAPITests.java @@ -768,23 +768,22 @@ void shouldUseStubItemParameterInCirculationRuleMatchingWhenPresent() { var response = getCreateOp(requesterId, instanceId, null, "true", HttpStatus.SC_OK).getJson(); assertThat(response, hasNoJsonPath(PAGE.getValue())); - - JsonArray allowedPageServicePoints = response.getJsonArray(HOLD.getValue()); - assertServicePointsMatch(allowedPageServicePoints, List.of(cd1, cd2, cd4, cd5)); - allowedPageServicePoints = response.getJsonArray(RECALL.getValue()); - assertServicePointsMatch(allowedPageServicePoints, List.of(cd1, cd2, cd4, cd5)); + JsonArray allowedServicePoints = response.getJsonArray(HOLD.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); + allowedServicePoints = response.getJsonArray(RECALL.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); response = getCreateOp(requesterId, instanceId, null, "false", HttpStatus.SC_OK).getJson(); assertThat(response, hasNoJsonPath(HOLD.getValue())); assertThat(response, hasNoJsonPath(RECALL.getValue())); - allowedPageServicePoints = response.getJsonArray(PAGE.getValue()); - assertServicePointsMatch(allowedPageServicePoints, List.of(cd1, cd2, cd4, cd5)); + allowedServicePoints = response.getJsonArray(PAGE.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); response = getCreateOp(requesterId, instanceId, null, HttpStatus.SC_OK).getJson(); assertThat(response, hasNoJsonPath(HOLD.getValue())); assertThat(response, hasNoJsonPath(RECALL.getValue())); - allowedPageServicePoints = response.getJsonArray(PAGE.getValue()); - assertServicePointsMatch(allowedPageServicePoints, List.of(cd1, cd2, cd4, cd5)); + allowedServicePoints = response.getJsonArray(PAGE.getValue()); + assertServicePointsMatch(allowedServicePoints, List.of(cd1, cd2, cd4, cd5)); Response errorResponse = getCreateOp(requesterId, instanceId, null, "invalid", HttpStatus.SC_BAD_REQUEST);