Search in sources :

Example 1 with SingleOpenLoanForItemInStorageFinder

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

Example 2 with SingleOpenLoanForItemInStorageFinder

use of org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder in project mod-circulation by folio-org.

the class CheckInProcessAdapter method newInstance.

public static CheckInProcessAdapter newInstance(Clients clients, ItemRepository itemRepository, UserRepository userRepository, LoanRepository loanRepository, RequestRepository requestRepository, RequestQueueRepository requestQueueRepository) {
    final var itemFinder = new ItemByBarcodeInStorageFinder(itemRepository);
    final SingleOpenLoanForItemInStorageFinder singleOpenLoanFinder = new SingleOpenLoanForItemInStorageFinder(loanRepository, userRepository, true);
    final var overdueFineService = new OverdueFineService(new OverdueFinePolicyRepository(clients), itemRepository, new FeeFineOwnerRepository(clients), new FeeFineRepository(clients), ScheduledNoticesRepository.using(clients), new OverduePeriodCalculatorService(new CalendarRepository(clients), new LoanPolicyRepository(clients)), new FeeFineFacade(clients));
    return new CheckInProcessAdapter(itemFinder, singleOpenLoanFinder, new LoanCheckInService(), requestQueueRepository, new UpdateItem(itemRepository), UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository), loanRepository, new ServicePointRepository(clients), userRepository, new AddressTypeRepository(clients), new LogCheckInService(clients), overdueFineService, FeeFineScheduledNoticeService.using(clients), new LostItemFeeRefundService(clients, itemRepository, userRepository, loanRepository), new EventPublisher(clients.pubSubPublishingService()));
}
Also used : FeeFineFacade(org.folio.circulation.services.FeeFineFacade) EventPublisher(org.folio.circulation.services.EventPublisher) FeeFineOwnerRepository(org.folio.circulation.infrastructure.storage.feesandfines.FeeFineOwnerRepository) CalendarRepository(org.folio.circulation.infrastructure.storage.CalendarRepository) OverdueFineService(org.folio.circulation.domain.OverdueFineService) ItemByBarcodeInStorageFinder(org.folio.circulation.storage.ItemByBarcodeInStorageFinder) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) FeeFineRepository(org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository) OverduePeriodCalculatorService(org.folio.circulation.domain.OverduePeriodCalculatorService) SingleOpenLoanForItemInStorageFinder(org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder) UpdateItem(org.folio.circulation.domain.UpdateItem) AddressTypeRepository(org.folio.circulation.infrastructure.storage.users.AddressTypeRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) LogCheckInService(org.folio.circulation.services.LogCheckInService) LoanCheckInService(org.folio.circulation.domain.LoanCheckInService) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository)

Aggregations

SingleOpenLoanForItemInStorageFinder (org.folio.circulation.storage.SingleOpenLoanForItemInStorageFinder)2 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 LoanCheckInService (org.folio.circulation.domain.LoanCheckInService)1 OverdueFineService (org.folio.circulation.domain.OverdueFineService)1 OverduePeriodCalculatorService (org.folio.circulation.domain.OverduePeriodCalculatorService)1 UpdateItem (org.folio.circulation.domain.UpdateItem)1 CommonFailures.noItemFoundForIdFailure (org.folio.circulation.domain.validation.CommonFailures.noItemFoundForIdFailure)1 UserNotFoundValidator (org.folio.circulation.domain.validation.UserNotFoundValidator)1 CalendarRepository (org.folio.circulation.infrastructure.storage.CalendarRepository)1 ServicePointRepository (org.folio.circulation.infrastructure.storage.ServicePointRepository)1 FeeFineOwnerRepository (org.folio.circulation.infrastructure.storage.feesandfines.FeeFineOwnerRepository)1 FeeFineRepository (org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 LoanPolicyRepository (org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository)1