Search in sources :

Example 1 with LoanPolicy

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());
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 2 with LoanPolicy

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)));
}
Also used : Loan(org.folio.circulation.domain.Loan) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 3 with LoanPolicy

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")));
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with LoanPolicy

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));
}
Also used : LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy)

Example 5 with LoanPolicy

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);
}
Also used : LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy)

Aggregations

LoanPolicy (org.folio.circulation.domain.policy.LoanPolicy)15 JsonObject (io.vertx.core.json.JsonObject)8 Loan (org.folio.circulation.domain.Loan)7 ZonedDateTime (java.time.ZonedDateTime)6 Request (org.folio.circulation.domain.Request)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 RenewalValidator.errorForRecallRequest (org.folio.circulation.resources.RenewalValidator.errorForRecallRequest)3 RenewalValidator.itemByIdValidationError (org.folio.circulation.resources.RenewalValidator.itemByIdValidationError)3 RenewalValidator.loanPolicyValidationError (org.folio.circulation.resources.RenewalValidator.loanPolicyValidationError)3 ValidationError (org.folio.circulation.support.http.server.ValidationError)3 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)2 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)2 RenewalContext (org.folio.circulation.resources.context.RenewalContext)2 CommonFailures.failedDueToServerError (org.folio.circulation.support.results.CommonFailures.failedDueToServerError)2 Result (org.folio.circulation.support.results.Result)2