use of org.folio.circulation.domain.validation.LoanValidator 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())));
}
use of org.folio.circulation.domain.validation.LoanValidator in project mod-circulation by folio-org.
the class ChangeDueDateResource method processChangeDueDate.
private CompletableFuture<Result<LoanAndRelatedRecords>> processChangeDueDate(final ChangeDueDateRequest request, RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final var requestRepository = RequestRepository.using(clients, itemRepository, userRepository, loanRepository);
final var requestQueueRepository = new RequestQueueRepository(requestRepository);
final LoanScheduledNoticeService scheduledNoticeService = LoanScheduledNoticeService.using(clients);
final ItemStatusValidator itemStatusValidator = new ItemStatusValidator(ChangeDueDateResource::errorWhenInIncorrectStatus);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients);
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
log.info("starting change due date process for loan {}", request.getLoanId());
return succeeded(request).after(r -> getExistingLoan(loanRepository, r)).thenApply(LoanValidator::refuseWhenLoanIsClosed).thenApply(this::toLoanAndRelatedRecords).thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings, LoanAndRelatedRecords::withTlrSettings)).thenComposeAsync(r -> r.after(requestQueueRepository::get)).thenApply(itemStatusValidator::refuseWhenItemStatusDoesNotAllowDueDateChange).thenApply(r -> changeDueDate(r, request)).thenApply(r -> r.map(this::unsetDueDateChangedByRecallIfNoOpenRecallsInQueue)).thenComposeAsync(r -> r.after(loanRepository::updateLoan)).thenComposeAsync(r -> r.after(eventPublisher::publishDueDateChangedEvent)).thenApply(r -> r.next(scheduledNoticeService::rescheduleDueDateNotices)).thenCompose(r -> r.after(loanNoticeSender::sendManualDueDateChangeNotice));
}
Aggregations