Skip to content

Commit

Permalink
CIRC-2182 Intermediate request support (#1520)
Browse files Browse the repository at this point in the history
* CIRC-2182 Add support for intermediate request

* CIRC-2182 Add missing permissions

* CIRC-2182 Add missing permissions

* CIRC-2182 Add missing permissions

* CIRC-2182 Refactoring and logging

* CIRC-2182 Extend test

(cherry picked from commit 7d6bfe8)
  • Loading branch information
OleksandrVidinieiev authored and roman-barannyk committed Dec 12, 2024
1 parent 6b4d0cf commit a1ce1da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
6 changes: 5 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,10 @@
"mod-settings.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.global.read.mod-circulation",
"mod-settings.global.read.circulation"
"mod-settings.global.read.circulation",
"manualblocks.item.get",
"manualblocks.collection.get",
"patron-blocks.automated-patron-blocks.collection.get"
],
"visible": false
},
Expand All @@ -1920,6 +1923,7 @@
"circulation-storage.fixed-due-date-schedules.item.get",
"circulation-storage.fixed-due-date-schedules.collection.get",
"circulation-storage.patron-notice-policies.item.get",
"circulation-storage.request-batch.item.post",
"circulation.rules.notice-policy.get",
"circulation.rules.loan-policy.get",
"circulation.rules.request-policy.get",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.folio.circulation.domain;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.folio.circulation.domain.EcsRequestPhase.INTERMEDIATE;
import static org.folio.circulation.domain.EcsRequestPhase.PRIMARY;
import static org.folio.circulation.domain.RequestLevel.TITLE;
import static org.folio.circulation.domain.representations.RequestProperties.INSTANCE_ID;
import static org.folio.circulation.domain.representations.RequestProperties.ITEM_ID;
Expand Down Expand Up @@ -227,8 +229,9 @@ private CompletableFuture<Result<RequestAndRelatedRecords>> checkPolicy(
boolean tlrFeatureEnabled = request.getTlrSettingsConfiguration().isTitleLevelRequestsFeatureEnabled();

if (tlrFeatureEnabled && request.isTitleLevel() && request.isHold()) {
if (request.getEcsRequestPhase() == EcsRequestPhase.PRIMARY) {
log.warn("checkPolicy:: ECS TLR primary Hold detected, skipping policy check");
EcsRequestPhase ecsRequestPhase = request.getEcsRequestPhase();
if (ecsRequestPhase == PRIMARY || ecsRequestPhase == INTERMEDIATE) {
log.warn("checkPolicy:: ECS TLR Hold with phase {} detected, skipping policy check", ecsRequestPhase);
return ofAsync(() -> records);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public enum EcsRequestPhase {
NONE(""),
PRIMARY("Primary"),
SECONDARY("Secondary");
SECONDARY("Secondary"),
INTERMEDIATE("Intermediate");

public final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.folio.circulation.domain.EcsRequestPhase.INTERMEDIATE;
import static org.folio.circulation.domain.EcsRequestPhase.PRIMARY;
import static org.folio.circulation.domain.RequestLevel.ITEM;
import static org.folio.circulation.domain.RequestLevel.TITLE;
import static org.folio.circulation.domain.RequestType.RECALL;
Expand Down Expand Up @@ -253,9 +255,11 @@ private CompletableFuture<Result<RequestAndRelatedRecords>> fetchItemAndLoan(
Request request = records.getRequest();
Function<RequestAndRelatedRecords, CompletableFuture<Result<Request>>>
itemAndLoanFetchingFunction;
log.info("fetchItemAndLoan:: Request phase is {}", request.getEcsRequestPhase().value);
if (request.getEcsRequestPhase() == EcsRequestPhase.PRIMARY) {
log.info("fetchItemAndLoan:: Primary ECS request detected, using default item fetcher");
EcsRequestPhase ecsRequestPhase = request.getEcsRequestPhase();
log.info("fetchItemAndLoan:: ECS request phase is {}", ecsRequestPhase);
if (ecsRequestPhase == PRIMARY || ecsRequestPhase == INTERMEDIATE) {
log.info("fetchItemAndLoan:: ECS request phase {} detected, using default item fetcher",
ecsRequestPhase);
itemAndLoanFetchingFunction = this::fetchItemAndLoanDefault;
}
else if (request.isTitleLevel() && request.isPage()) {
Expand Down Expand Up @@ -543,8 +547,9 @@ private Result<Request> refuseToCreateTlrLinkedToAnItem(Result<Request> request)
}

private Result<Request> validateAbsenceOfItemLinkInTlr(Request request) {
if (request.getEcsRequestPhase() == EcsRequestPhase.PRIMARY) {
log.info("validateAbsenceOfItemLinkInTlr:: Primary ECS request detected, skipping");
EcsRequestPhase ecsRequestPhase = request.getEcsRequestPhase();
if (ecsRequestPhase == PRIMARY || ecsRequestPhase == INTERMEDIATE) {
log.info("validateAbsenceOfItemLinkInTlr:: ECS request phase {} detected, skipping", ecsRequestPhase);
return of(() -> request);
}

Expand Down
17 changes: 10 additions & 7 deletions src/test/java/api/requests/RequestsAPICreationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3960,8 +3960,11 @@ void titleLevelPageRequestIsCreatedForItemClosestToPickupServicePoint(int testCa
assertThat(request.getJson().getString("itemId"), is(expectedItemId));
}

@Test
void primaryTlrCreationSkipsClosestServicePointLogicAndPoliciesIgnoredForHoldTlr() {
@ParameterizedTest
@ValueSource(strings = {"Primary", "Intermediate"})
void tlrCreationSkipsClosestServicePointLogicAndPoliciesIgnoredForHoldTlr(
String ecsRequestPhase) {

settingsFixture.configureTlrFeature(true, true, null, null, null);

policiesActivation.use(new RequestPolicyBuilder(
Expand Down Expand Up @@ -4032,9 +4035,9 @@ void primaryTlrCreationSkipsClosestServicePointLogicAndPoliciesIgnoredForHoldTlr
// Request without ECS phase should fail
requestsFixture.attemptPlace(requestBuilder);

// The same request with Primary ECS phase should succeed because validation is skipped
// The same request with Primary/Intermediate ECS phase should succeed because validation is skipped
IndividualResource request = requestsFixture.place(
requestBuilder.withEcsRequestPhase("Primary"));
requestBuilder.withEcsRequestPhase(ecsRequestPhase));

assertThat(request.getJson().getString("itemId"), is(expectedItemId));

Expand All @@ -4043,7 +4046,7 @@ void primaryTlrCreationSkipsClosestServicePointLogicAndPoliciesIgnoredForHoldTlr
requestBuilder
.withRequesterId(usersFixture.jessica().getId())
.withItemId(closestItemId)
.withEcsRequestPhase("Primary"));
.withEcsRequestPhase(ecsRequestPhase));

// Placing TLR Hold request
var requestBuilderTlrHold = new RequestBuilder()
Expand All @@ -4060,8 +4063,8 @@ void primaryTlrCreationSkipsClosestServicePointLogicAndPoliciesIgnoredForHoldTlr
// Request without ECS phase should fail
requestsFixture.attemptPlace(requestBuilderTlrHold);

// The same request with Primary ECS phase should succeed because policy check is skipped
requestsFixture.place(requestBuilderTlrHold.withEcsRequestPhase("Primary"));
// The same request with Primary/Intermediate ECS phase should succeed because policy check is skipped
requestsFixture.place(requestBuilderTlrHold.withEcsRequestPhase(ecsRequestPhase));
}

@Test
Expand Down

0 comments on commit a1ce1da

Please sign in to comment.