Search in sources :

Example 1 with LostItemFeeChargingService

use of org.folio.circulation.services.LostItemFeeChargingService in project mod-circulation by folio-org.

the class DeclareLostResource method declareItemLost.

private CompletableFuture<Result<Loan>> declareItemLost(DeclareItemLostRequest request, Clients clients, WebContext context) {
    final var itemRepository = new ItemRepository(clients);
    final var userRepository = new UserRepository(clients);
    final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
    final var storeLoanAndItem = new StoreLoanAndItem(loanRepository, itemRepository);
    final var lostItemFeeService = new LostItemFeeChargingService(clients, storeLoanAndItem, new LostItemFeeRefundService(clients, itemRepository, userRepository, loanRepository));
    return loanRepository.getById(request.getLoanId()).thenApply(LoanValidator::refuseWhenLoanIsClosed).thenApply(this::refuseWhenItemIsAlreadyDeclaredLost).thenCompose(declareItemLost(request, clients)).thenCompose(r -> r.after(storeLoanAndItem::updateLoanAndItemInStorage)).thenCompose(r -> r.after(loan -> lostItemFeeService.chargeLostItemFees(loan, request, context.getUserId())));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) DeclareItemLostRequest(org.folio.circulation.domain.representations.DeclareItemLostRequest) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) LostItemFeeChargingService(org.folio.circulation.services.LostItemFeeChargingService) RoutingContext(io.vertx.ext.web.RoutingContext) Function(java.util.function.Function) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) NoteCreator(org.folio.circulation.domain.notes.NoteCreator) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) StringUtils.defaultIfBlank(org.apache.commons.lang.StringUtils.defaultIfBlank) CompletionStage(java.util.concurrent.CompletionStage) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) LostItemFeeChargingService(org.folio.circulation.services.LostItemFeeChargingService) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1 StringUtils.defaultIfBlank (org.apache.commons.lang.StringUtils.defaultIfBlank)1 StoreLoanAndItem (org.folio.circulation.StoreLoanAndItem)1 Loan (org.folio.circulation.domain.Loan)1 NoteCreator (org.folio.circulation.domain.notes.NoteCreator)1 DeclareItemLostRequest (org.folio.circulation.domain.representations.DeclareItemLostRequest)1 LoanValidator (org.folio.circulation.domain.validation.LoanValidator)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1 NotesRepository (org.folio.circulation.infrastructure.storage.notes.NotesRepository)1 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)1 EventPublisher (org.folio.circulation.services.EventPublisher)1 LostItemFeeChargingService (org.folio.circulation.services.LostItemFeeChargingService)1 LostItemFeeRefundService (org.folio.circulation.services.LostItemFeeRefundService)1