diff --git a/src/main/java/org/folio/circulation/domain/RequestServiceUtility.java b/src/main/java/org/folio/circulation/domain/RequestServiceUtility.java index 35b5c35dd2..635c83f27c 100644 --- a/src/main/java/org/folio/circulation/domain/RequestServiceUtility.java +++ b/src/main/java/org/folio/circulation/domain/RequestServiceUtility.java @@ -1,6 +1,7 @@ package org.folio.circulation.domain; import static java.lang.String.format; +import static org.folio.circulation.domain.RequestFulfillmentPreference.HOLD_SHELF; import static org.folio.circulation.domain.representations.RequestProperties.PICKUP_SERVICE_POINT_ID; import static org.folio.circulation.domain.representations.RequestProperties.REQUEST_TYPE; import static org.folio.circulation.support.ErrorCode.INSTANCE_ALREADY_REQUESTED; @@ -80,15 +81,17 @@ static Result refuseWhenRequestCannotBeFulfilled( return failureDisallowedForRequestType(requestType); } - if (!requestPolicy.allowsServicePoint(requestType, request.getPickupServicePointId())) { - log.warn("refuseWhenRequestCannotBeFulfilled:: requestPolicy does not allow servicePoint {}", - request.getPickupServicePointId()); - return failedValidation("One or more Pickup locations are no longer available", - Map.of(PICKUP_SERVICE_POINT_ID, request.getPickupServicePointId(), - REQUEST_TYPE, requestType.toString(), - "requestPolicyId", requestPolicy.getId()), - ErrorCode.REQUEST_PICKUP_SERVICE_POINT_IS_NOT_ALLOWED); - } + if (HOLD_SHELF == request.getfulfillmentPreference() && !requestPolicy.allowsServicePoint( + requestType, request.getPickupServicePointId())) { + + log.warn("refuseWhenRequestCannotBeFulfilled:: requestPolicy does not allow servicePoint {}", + request.getPickupServicePointId()); + return failedValidation("One or more Pickup locations are no longer available", + Map.of(PICKUP_SERVICE_POINT_ID, request.getPickupServicePointId(), + REQUEST_TYPE, requestType.toString(), + "requestPolicyId", requestPolicy.getId()), + ErrorCode.REQUEST_PICKUP_SERVICE_POINT_IS_NOT_ALLOWED); + } return succeeded(requestAndRelatedRecords); diff --git a/src/test/java/api/requests/RequestsAPICreationTests.java b/src/test/java/api/requests/RequestsAPICreationTests.java index 24a3bc3a9d..a7493260b7 100644 --- a/src/test/java/api/requests/RequestsAPICreationTests.java +++ b/src/test/java/api/requests/RequestsAPICreationTests.java @@ -4979,6 +4979,46 @@ void printAndFetchRequestWithPrintEventFeatureDisabled() { assertThat("printDetails should be null for request2 because the print event feature is disabled", requestRepresentation2.getJsonObject("printDetails"), Matchers.nullValue()); } + + @Test + void itemLevelRequestShouldBeCreatedWithDeliveryFulfillmentPreference() { + final UUID requestPolicyId = UUID.randomUUID(); + policiesActivation.use(new RequestPolicyBuilder( + requestPolicyId, + List.of(PAGE), + "Test request policy", + "Test description", + Map.of(PAGE, Set.of(servicePointsFixture.cd2().getId())))); + + final IndividualResource work = addressTypesFixture.work(); + ItemResource item = itemsFixture.basedUponSmallAngryPlanet(); + final IndividualResource charlotte = usersFixture.charlotte( + builder -> builder.withAddress( + new Address(work.getId(), + "Fake first address line", + "Fake second address line", + "Fake city", + "Fake region", + "Fake postal code", + "Fake country code"))); + + Response response = requestsClient.attemptCreate(new RequestBuilder() + .itemRequestLevel() + .withFulfillmentPreference("Delivery") + .withRequestType(PAGE.getValue()) + .withInstanceId(item.getInstanceId()) + .withHoldingsRecordId(item.getHoldingsRecordId()) + .withItemId(item.getId()) + .by(charlotte) + .withDeliveryAddressType(work.getId())); + + assertThat(response, hasStatus(HTTP_CREATED)); + assertThat(response.getJson().getString("requestLevel"), is(RequestLevel.ITEM.getValue())); + assertThat(response.getJson().getString("requestType"), is(PAGE.getValue())); + assertThat(response.getJson().getString("fulfillmentPreference"), is("Delivery")); + assertThat(response.getJson().getString("deliveryAddressTypeId"), is(work.getId())); + } + private void setUpNoticesForTitleLevelRequests(boolean isNoticeEnabledInTlrSettings, boolean isNoticeEnabledInNoticePolicy) {