use of org.folio.circulation.domain.policy.LoanPolicy in project mod-circulation by folio-org.
the class OverrideRenewalTest method shouldUseOverrideDateWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent.
@Test
void shouldUseOverrideDateWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent() {
final ZonedDateTime overrideDueDate = ClockUtil.getZonedDateTime().plusWeeks(2);
final LoanPolicy loanPolicy = LoanPolicy.from(rollingPolicy().limitedRenewals(1).create());
final Loan loan = Loan.from(new JsonObject().put("renewalCount", 2)).changeDueDate(ClockUtil.getZonedDateTime().plusWeeks(1).plusSeconds(1)).withItem(createCheckedOutItem()).withLoanPolicy(loanPolicy);
final Result<Loan> renewedLoan = renew(loan, overrideDueDate);
assertDueDate(overrideDueDate, renewedLoan);
assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
}
use of org.folio.circulation.domain.policy.LoanPolicy in project mod-circulation by folio-org.
the class OverrideRenewalTest method overrideDateIsRequiredWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent.
@Test
void overrideDateIsRequiredWhenReachedNumberOfRenewalsAndNewDueDateBeforeCurrent() {
final LoanPolicy loanPolicy = LoanPolicy.from(rollingPolicy().limitedRenewals(1).create());
final Loan loan = Loan.from(new JsonObject().put("renewalCount", 2)).changeDueDate(ClockUtil.getZonedDateTime().plusDays(8)).withLoanPolicy(loanPolicy);
final Result<Loan> renewedLoan = renew(loan, null);
assertThat(renewedLoan, hasValidationError(hasMessage(NEW_DUE_DATE_IS_REQUIRED_ERROR)));
}
use of org.folio.circulation.domain.policy.LoanPolicy in project mod-circulation by folio-org.
the class OverrideRenewalTest method nonLoanableAgedToLostItemShouldBeProperlyRenewed.
@Test
void nonLoanableAgedToLostItemShouldBeProperlyRenewed() {
final ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
final ZonedDateTime ageToLostDate = ClockUtil.getZonedDateTime();
final LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().withLoanable(false).create());
final Loan loan = Loan.from(new JsonObject()).withItem(createCheckedOutItem()).withLoanPolicy(loanPolicy);
loan.ageOverdueItemToLost(ageToLostDate).setAgedToLostDelayedBilling(false, ageToLostDate.plusDays(1));
final Result<Loan> renewedLoan = renew(loan, newDueDate);
assertDueDate(newDueDate, renewedLoan);
assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
assertThat(renewedLoan.value().asJson(), allOf(hasNoJsonPath("agedToLostDelayedBilling.lostItemHasBeenBilled"), hasNoJsonPath("agedToLostDelayedBilling.dateLostItemShouldBeBilled")));
}
use of org.folio.circulation.domain.policy.LoanPolicy in project mod-circulation by folio-org.
the class LoanService method truncateLoanWhenItemRecalled.
public CompletableFuture<Result<LoanAndRelatedRecords>> truncateLoanWhenItemRecalled(LoanAndRelatedRecords records) {
RequestQueue requestQueue = records.getRequestQueue();
Collection<Request> requests = requestQueue.getRequests();
if (requests.isEmpty()) {
return completedFuture(succeeded(records));
}
if (!requestQueue.containsRequestOfTypeForItem(RequestType.RECALL, records.getItem())) {
return completedFuture(succeeded(records));
}
final Loan loanToRecall = records.getLoan();
final LoanPolicy loanPolicy = loanToRecall.getLoanPolicy();
if (loanToRecall.wasDueDateChangedByRecall()) {
return completedFuture(succeeded(records));
}
return completedFuture(loanPolicy.recall(loanToRecall).map(records::withLoan)).thenCompose(r -> r.after(closedLibraryStrategyService::applyClosedLibraryDueDateManagement));
}
use of org.folio.circulation.domain.policy.LoanPolicy in project mod-circulation by folio-org.
the class UpdateLoan method recall.
private Result<LoanAndRelatedRecords> recall(LoanAndRelatedRecords loanAndRelatedRecords) {
final Loan loan = loanAndRelatedRecords.getLoan();
LoanPolicy loanPolicy = loan.getLoanPolicy();
// loan.wasDueDateChangedByRecall() condition found in the recall method of this class.
return loanPolicy.recall(loan).map(loanAndRelatedRecords::withLoan);
}
Aggregations