Search in sources :

Example 1 with CirculationErrorHandler

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CirculationErrorHandler

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CirculationErrorHandler

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));
}
Also used : CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CirculationErrorHandler

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));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CirculationErrorHandler

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)));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) FAILED_TO_FETCH_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_USER) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) ItemByIdInStorageFinder(org.folio.circulation.storage.ItemByIdInStorageFinder) Loan(org.folio.circulation.domain.Loan) FAILED_TO_FIND_SINGLE_OPEN_LOAN(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FIND_SINGLE_OPEN_LOAN) CompletableFuture(java.util.concurrent.CompletableFuture) Result(org.folio.circulation.support.results.Result) StringUtils(org.apache.commons.lang3.StringUtils) Item(org.folio.circulation.domain.Item) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) UserNotFoundValidator(org.folio.circulation.domain.validation.UserNotFoundValidator) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) CommonFailures.noItemFoundForIdFailure(org.folio.circulation.domain.validation.CommonFailures.noItemFoundForIdFailure) JsonObject(io.vertx.core.json.JsonObject) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) SingleOpenLoanForItemInStorageFinder(org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder) ITEM_DOES_NOT_EXIST(org.folio.circulation.resources.handlers.error.CirculationErrorType.ITEM_DOES_NOT_EXIST) USER_DOES_NOT_MATCH(org.folio.circulation.resources.handlers.error.CirculationErrorType.USER_DOES_NOT_MATCH) HttpClient(io.vertx.core.http.HttpClient) SingleOpenLoanForItemInStorageFinder(org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder) ItemByIdInStorageFinder(org.folio.circulation.storage.ItemByIdInStorageFinder)

Aggregations

CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)41 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)40 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)38 Test (org.junit.jupiter.api.Test)36 Loan (org.folio.circulation.domain.Loan)28 ZonedDateTime (java.time.ZonedDateTime)27 RequestQueue (org.folio.circulation.domain.RequestQueue)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)16 LoanBuilder (api.support.builders.LoanBuilder)11 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)11 JsonObject (io.vertx.core.json.JsonObject)10 RequestBuilder (api.support.builders.RequestBuilder)5 Result (org.folio.circulation.support.results.Result)5 HttpClient (io.vertx.core.http.HttpClient)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)3 FailureMatcher.hasValidationFailure (api.support.matchers.FailureMatcher.hasValidationFailure)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2