Skip to content

Commit

Permalink
CIRC-2122 Bypass pickup SP check for Delivery requests (#1488)
Browse files Browse the repository at this point in the history
* CIRC-2122: check if fulfillment preference is Delivery

* CIRC-2122: fix by cove review

* CIRC-2122: fix by code review

* CIRC-2122: fix by code review

* CIRC-2122: fix by code review

* CIRC-2122: fix by code review

* CIRC-2122: fix by code review

* CIRC-2122: fix by code review
  • Loading branch information
Maksat-Galymzhan authored Aug 23, 2024
1 parent 5e3559d commit 1d3bbe2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -80,15 +81,17 @@ static Result<RequestAndRelatedRecords> 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);

Expand Down
40 changes: 40 additions & 0 deletions src/test/java/api/requests/RequestsAPICreationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down

0 comments on commit 1d3bbe2

Please sign in to comment.