Search in sources :

Example 26 with RequestQueue

use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.

the class RollingLoanPolicyRenewalDueDateCalculationTests method shouldFailWhenDurationIsInvalid.

@ParameterizedTest
@ValueSource(strings = { "0", "-1" })
void shouldFailWhenDurationIsInvalid(int duration) {
    final JsonObject representation = new LoanPolicyBuilder().rolling(Period.minutes(duration)).withName("Invalid Loan Policy").create();
    LoanPolicy loanPolicy = LoanPolicy.from(representation);
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = loanFor(loanDate, loanDate, loanPolicy);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
    assertTrue(matchErrorReason(errorHandler, String.format("the duration \"%s\" in the loan policy is invalid", duration)));
}
Also used : Loan(org.folio.circulation.domain.Loan) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) JsonObject(io.vertx.core.json.JsonObject) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with RequestQueue

use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.

the class UnknownLoanPolicyProfileTests method shouldFailRenewalCalculationForNonRollingProfile.

@Test
void shouldFailRenewalCalculationForNonRollingProfile() {
    LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().withName("Invalid Loan Policy").withLoansProfile("Unknown profile").create());
    ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 14, 11, 14, 54, 0, UTC);
    Loan loan = new LoanBuilder().open().withLoanDate(loanDate).asDomainObject().withLoanPolicy(loanPolicy);
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loan, ClockUtil.getZonedDateTime(), new RequestQueue(Collections.emptyList()), errorHandler);
    assertTrue(errorHandler.getErrors().keySet().stream().map(ValidationErrorFailure.class::cast).anyMatch(httpFailure -> httpFailure.hasErrorWithReason("profile \"Unknown profile\" in the loan policy is not recognised")));
}
Also used : FailureMatcher.hasValidationFailure(api.support.matchers.FailureMatcher.hasValidationFailure) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) RenewalContext(org.folio.circulation.resources.context.RenewalContext) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) ZonedDateTime(java.time.ZonedDateTime) Loan(org.folio.circulation.domain.Loan) LoanBuilder(api.support.builders.LoanBuilder) Result(org.folio.circulation.support.results.Result) Test(org.junit.jupiter.api.Test) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) ClockUtil(org.folio.circulation.support.utils.ClockUtil) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UTC(java.time.ZoneOffset.UTC) RenewByBarcodeResource(org.folio.circulation.resources.renewal.RenewByBarcodeResource) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RequestQueue(org.folio.circulation.domain.RequestQueue) Collections(java.util.Collections) LoanBuilder(api.support.builders.LoanBuilder) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) RequestQueue(org.folio.circulation.domain.RequestQueue) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) Test(org.junit.jupiter.api.Test)

Example 28 with RequestQueue

use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.

the class ChangeDueDateResource method unsetDueDateChangedByRecallIfNoOpenRecallsInQueue.

private LoanAndRelatedRecords unsetDueDateChangedByRecallIfNoOpenRecallsInQueue(LoanAndRelatedRecords loanAndRelatedRecords) {
    RequestQueue queue = loanAndRelatedRecords.getRequestQueue();
    Loan loan = loanAndRelatedRecords.getLoan();
    log.info("Loan {} prior to flag check: {}", loan.getId(), loan.asJson().toString());
    if (loan.wasDueDateChangedByRecall() && !queue.hasOpenRecalls()) {
        log.info("Loan {} registers as having due date change flag set to true and no open recalls in queue.", loan.getId());
        return loanAndRelatedRecords.withLoan(loan.unsetDueDateChangedByRecall());
    } else {
        log.info("Loan {} registers as either not having due date change flag set to true or as having open recalls in queue.", loan.getId());
        return loanAndRelatedRecords;
    }
}
Also used : Loan(org.folio.circulation.domain.Loan) RequestQueue(org.folio.circulation.domain.RequestQueue)

Example 29 with RequestQueue

use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.

the class CheckInProcessAdapter method updateRequestQueue.

CompletableFuture<Result<RequestQueue>> updateRequestQueue(CheckInContext context) {
    final RequestQueue requestQueue = context.getRequestQueue();
    final Item item = context.getItem();
    final String checkInServicePointId = context.getCheckInServicePointId().toString();
    return requestQueueUpdate.onCheckIn(requestQueue, item, checkInServicePointId);
}
Also used : UpdateItem(org.folio.circulation.domain.UpdateItem) Item(org.folio.circulation.domain.Item) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) RequestQueue(org.folio.circulation.domain.RequestQueue)

Example 30 with RequestQueue

use of org.folio.circulation.domain.RequestQueue in project mod-circulation by folio-org.

the class CheckOutByBarcodeResource method calculateDefaultInitialDueDate.

private Result<LoanAndRelatedRecords> calculateDefaultInitialDueDate(LoanAndRelatedRecords loanAndRelatedRecords) {
    Loan loan = loanAndRelatedRecords.getLoan();
    LoanPolicy loanPolicy = loan.getLoanPolicy();
    RequestQueue requestQueue = loanAndRelatedRecords.getRequestQueue();
    return loanPolicy.calculateInitialDueDate(loan, requestQueue).map(loan::changeDueDate).map(loanAndRelatedRecords::withLoan);
}
Also used : Loan(org.folio.circulation.domain.Loan) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) RequestQueue(org.folio.circulation.domain.RequestQueue) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy)

Aggregations

RequestQueue (org.folio.circulation.domain.RequestQueue)53 Loan (org.folio.circulation.domain.Loan)45 ZonedDateTime (java.time.ZonedDateTime)39 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)37 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)37 Test (org.junit.jupiter.api.Test)31 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)27 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)17 JsonObject (io.vertx.core.json.JsonObject)16 LoanBuilder (api.support.builders.LoanBuilder)11 Result (org.folio.circulation.support.results.Result)8 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)6 Item (org.folio.circulation.domain.Item)6 Request (org.folio.circulation.domain.Request)6 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 ValidationErrorFailure (org.folio.circulation.support.ValidationErrorFailure)5