use of org.folio.circulation.resources.handlers.error.CirculationErrorHandler in project mod-circulation by folio-org.
the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod.
@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod() {
final var request = new RequestBuilder().hold().asDomainObject();
final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).withHolds(null, true, days(1)).asDomainObject();
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loanPolicy, request, errorHandler);
assertTrue(matchErrorReason(errorHandler, ALTERNATIVE_RENEWAL_PERIOD_FOR_HOLDS_IS_SPECIFIED));
}
use of org.folio.circulation.resources.handlers.error.CirculationErrorHandler in project mod-circulation by folio-org.
the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod.
@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod() {
final var request = new RequestBuilder().hold().asDomainObject();
final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).renewWith(days(10)).withHolds(null, true, null).asDomainObject();
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loanPolicy, request, errorHandler);
assertTrue(matchErrorReason(errorHandler, POLICY_HAS_FIXED_PROFILE_BUT_RENEWAL_PERIOD_IS_SPECIFIED));
}
use of org.folio.circulation.resources.handlers.error.CirculationErrorHandler in project mod-circulation by folio-org.
the class RegularRenewalTest method shouldNotAttemptToCalculateDueDateWhenPolicyIsNotRenewable.
@Test
void shouldNotAttemptToCalculateDueDateWhenPolicyIsNotRenewable() {
final var loanPolicy = spy(new LoanPolicyBuilder().rolling(days(1)).notRenewable().asDomainObject());
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loanPolicy, errorHandler);
assertTrue(matchErrorReason(errorHandler, LOAN_IS_NOT_RENEWABLE));
}
use of org.folio.circulation.resources.handlers.error.CirculationErrorHandler in project mod-circulation by folio-org.
the class RegularRenewalTest method cannotRenewWhenHoldRequestIsNotRenewable.
@Test
void cannotRenewWhenHoldRequestIsNotRenewable() {
final var request = new RequestBuilder().hold().asDomainObject();
final var loanPolicy = new LoanPolicyBuilder().withHolds(null, false, null).asDomainObject();
CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
renew(loanPolicy, request, errorHandler);
assertTrue(matchErrorReason(errorHandler, ITEMS_CANNOT_BE_RENEWED_ACTIVE_PENDING_HOLD_REQUEST));
}
use of org.folio.circulation.resources.handlers.error.CirculationErrorHandler in project mod-circulation by folio-org.
the class RenewByIdResource method findLoan.
@Override
protected CompletableFuture<Result<Loan>> findLoan(JsonObject request, LoanRepository loanRepository, ItemRepository itemRepository, UserRepository userRepository, CirculationErrorHandler errorHandler) {
final Result<RenewByIdRequest> requestResult = RenewByIdRequest.from(request);
final String itemId = requestResult.map(RenewByIdRequest::getItemId).orElse("unknown item ID");
final SingleOpenLoanForItemInStorageFinder singleOpenLoanFinder = new SingleOpenLoanForItemInStorageFinder(loanRepository, userRepository, false);
final ItemByIdInStorageFinder itemFinder = new ItemByIdInStorageFinder(itemRepository, noItemFoundForIdFailure(itemId));
return completedFuture(requestResult).thenCompose(r -> lookupItem(itemFinder, itemId, errorHandler)).thenCompose(r -> r.after(item -> lookupLoan(singleOpenLoanFinder, item, errorHandler))).thenApply(r -> r.next(loan -> refuseWhenUserNotFound(loan, errorHandler))).thenApply(r -> r.next(loan -> refuseWhenUserDoesNotMatch(loan, requestResult.value(), errorHandler)));
}
Aggregations