Search in sources :

Example 1 with ItemByIdInStorageFinder

use of org.folio.circulation.storage.ItemByIdInStorageFinder 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

HttpClient (io.vertx.core.http.HttpClient)1 JsonObject (io.vertx.core.json.JsonObject)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Item (org.folio.circulation.domain.Item)1 Loan (org.folio.circulation.domain.Loan)1 CommonFailures.noItemFoundForIdFailure (org.folio.circulation.domain.validation.CommonFailures.noItemFoundForIdFailure)1 UserNotFoundValidator (org.folio.circulation.domain.validation.UserNotFoundValidator)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)1 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)1 FAILED_TO_FETCH_USER (org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_USER)1 FAILED_TO_FIND_SINGLE_OPEN_LOAN (org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FIND_SINGLE_OPEN_LOAN)1 ITEM_DOES_NOT_EXIST (org.folio.circulation.resources.handlers.error.CirculationErrorType.ITEM_DOES_NOT_EXIST)1 USER_DOES_NOT_MATCH (org.folio.circulation.resources.handlers.error.CirculationErrorType.USER_DOES_NOT_MATCH)1 ItemByIdInStorageFinder (org.folio.circulation.storage.ItemByIdInStorageFinder)1 SingleOpenLoanForItemInStorageFinder (org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder)1 ValidationErrorFailure.failedValidation (org.folio.circulation.support.ValidationErrorFailure.failedValidation)1