diff --git a/src/main/java/org/folio/circulation/domain/CreateRequestService.java b/src/main/java/org/folio/circulation/domain/CreateRequestService.java index b13236b603..8a5c794692 100644 --- a/src/main/java/org/folio/circulation/domain/CreateRequestService.java +++ b/src/main/java/org/folio/circulation/domain/CreateRequestService.java @@ -3,8 +3,6 @@ import static org.folio.circulation.support.Result.of; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.function.Function; import org.folio.circulation.domain.policy.RequestPolicyRepository; import org.folio.circulation.domain.validation.RequestLoanValidator; @@ -44,7 +42,8 @@ public CompletableFuture> createRequest( .next(RequestServiceUtility::refuseWhenUserHasAlreadyRequestedItem) .after(requestLoanValidator::refuseWhenUserHasAlreadyBeenLoanedItem) .thenComposeAsync(r -> r.after(requestPolicyRepository::lookupRequestPolicy)) - .thenComposeAsync(getTimeZoneForRequestRelatedRecords()) + .thenComposeAsync(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, + RequestAndRelatedRecords::withTimeZone)) .thenApply(r -> r.next(RequestServiceUtility::refuseWhenRequestCannotBeFulfilled)) .thenComposeAsync(r -> r.after(updateUponRequest.updateItem::onRequestCreateOrUpdate)) .thenComposeAsync(r -> r.after(updateUponRequest.updateLoanActionHistory::onRequestCreateOrUpdate)) @@ -54,9 +53,4 @@ public CompletableFuture> createRequest( .thenApply(r -> r.next(requestNoticeSender::sendNoticeOnRequestCreated)); } - private Function, CompletionStage>> getTimeZoneForRequestRelatedRecords() { - return r -> r.combineAfter( - unused -> configurationRepository.findTimeZoneConfiguration(), - RequestAndRelatedRecords::withTimeZone); - } } diff --git a/src/main/java/org/folio/circulation/domain/LoanAndRelatedRecords.java b/src/main/java/org/folio/circulation/domain/LoanAndRelatedRecords.java index 150ebc8daf..bcf4ff186c 100644 --- a/src/main/java/org/folio/circulation/domain/LoanAndRelatedRecords.java +++ b/src/main/java/org/folio/circulation/domain/LoanAndRelatedRecords.java @@ -42,7 +42,7 @@ public LoanAndRelatedRecords withItem(Item newItem) { return withLoan(loan.withItem(newItem)); } - LoanAndRelatedRecords withTimeZone(DateTimeZone newTimeZone) { + public LoanAndRelatedRecords withTimeZone(DateTimeZone newTimeZone) { return new LoanAndRelatedRecords(loan, requestQueue, newTimeZone); } diff --git a/src/main/java/org/folio/circulation/domain/MoveRequestService.java b/src/main/java/org/folio/circulation/domain/MoveRequestService.java index b8640bb89b..8c380de9cd 100644 --- a/src/main/java/org/folio/circulation/domain/MoveRequestService.java +++ b/src/main/java/org/folio/circulation/domain/MoveRequestService.java @@ -4,8 +4,6 @@ import static org.folio.circulation.support.Result.of; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.function.Function; import org.folio.circulation.domain.policy.RequestPolicyRepository; import org.folio.circulation.domain.validation.RequestLoanValidator; @@ -45,7 +43,8 @@ public CompletableFuture> moveRequest( .thenComposeAsync(r -> r.after(moveRequestProcessAdapter::getDestinationRequestQueue)) .thenApply(r -> r.map(this::pagedRequestIfDestinationItemAvailable)) .thenCompose(r -> r.after(this::validateUpdateRequest)) - .thenComposeAsync(getTimeZoneForRequestRelatedRecords()) + .thenComposeAsync(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, + RequestAndRelatedRecords::withTimeZone)) .thenCompose(r -> r.after(updateUponRequest.updateRequestQueue::onMovedTo)) .thenComposeAsync(r -> r.after(this::updateRelatedObjects)) .thenCompose(r -> r.after(requestRepository::update)) @@ -91,10 +90,4 @@ private CompletableFuture> updateRelatedObjects .thenComposeAsync(r -> r.after(updateUponRequest.updateLoanActionHistory::onRequestCreateOrUpdate)) .thenComposeAsync(r -> r.after(updateUponRequest.updateLoan::onRequestCreateOrUpdate)); } - - private Function, CompletionStage>> getTimeZoneForRequestRelatedRecords() { - return r -> r.combineAfter( - unused -> configurationRepository.findTimeZoneConfiguration(), - RequestAndRelatedRecords::withTimeZone); - } } diff --git a/src/main/java/org/folio/circulation/domain/notice/schedule/ScheduledDueDateNoticeHandler.java b/src/main/java/org/folio/circulation/domain/notice/schedule/ScheduledDueDateNoticeHandler.java index c2fa560d35..4da2838da5 100644 --- a/src/main/java/org/folio/circulation/domain/notice/schedule/ScheduledDueDateNoticeHandler.java +++ b/src/main/java/org/folio/circulation/domain/notice/schedule/ScheduledDueDateNoticeHandler.java @@ -72,7 +72,8 @@ private CompletableFuture> handleDueDateNotice(Scheduled return loanRepository.getById(notice.getLoanId()) .thenApply(r -> r.map(LoanAndRelatedRecords::new)) .thenCompose(r -> r.after(loanPolicyRepository::lookupLoanPolicy)) - .thenCompose(configurationRepository::lookupTimeZoneForLoanRelatedRecords) + .thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, + LoanAndRelatedRecords::withTimeZone)) .thenCompose(r -> r.after(records -> sendNotice(records, notice))) .thenCompose(r -> r.after(relatedRecords -> updateNotice(relatedRecords, notice))); } diff --git a/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java b/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java index 1b6b975ff9..f0142370bf 100644 --- a/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java +++ b/src/main/java/org/folio/circulation/resources/CheckOutByBarcodeResource.java @@ -156,7 +156,8 @@ private void checkOut(RoutingContext routingContext) { .thenComposeAsync(r -> r.after(openLoanValidator::refuseWhenHasOpenLoan)) .thenComposeAsync(r -> r.after(requestQueueRepository::get)) .thenApply(requestedByAnotherPatronValidator::refuseWhenRequestedByAnotherPatron) - .thenComposeAsync(configurationRepository::lookupTimeZoneForLoanRelatedRecords) + .thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, + LoanAndRelatedRecords::withTimeZone)) .thenComposeAsync(r -> r.after(loanPolicyRepository::lookupLoanPolicy)) .thenComposeAsync(r -> r.after(relatedRecords -> checkOutStrategy.checkOut(relatedRecords, request, clients))) .thenComposeAsync(r -> r.after(requestQueueUpdate::onCheckOut)) diff --git a/src/main/java/org/folio/circulation/resources/RenewalResource.java b/src/main/java/org/folio/circulation/resources/RenewalResource.java index daade97772..ee94ceee68 100644 --- a/src/main/java/org/folio/circulation/resources/RenewalResource.java +++ b/src/main/java/org/folio/circulation/resources/RenewalResource.java @@ -78,7 +78,8 @@ private void renew(RoutingContext routingContext) { .thenApply(r -> r.map(LoanAndRelatedRecords::new)) .thenComposeAsync(r -> r.after(loanPolicyRepository::lookupLoanPolicy)) .thenComposeAsync(r -> r.after(requestQueueRepository::get)) - .thenComposeAsync(configurationRepository::lookupTimeZoneForLoanRelatedRecords) + .thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, + LoanAndRelatedRecords::withTimeZone)) .thenComposeAsync(r -> r.after(records -> renewalStrategy.renew(records, bodyAsJson, clients))) .thenComposeAsync(r -> r.after(loanRepository::updateLoan)) .thenComposeAsync(r -> r.after(scheduledNoticeService::rescheduleDueDateNotices))