use of org.folio.circulation.StoreLoanAndItem in project mod-circulation by folio-org.
the class ClaimItemReturnedResource method processClaimItemReturned.
private CompletableFuture<Result<Loan>> processClaimItemReturned(RoutingContext routingContext, ClaimItemReturnedRequest request) {
final Clients clients = Clients.create(new WebContext(routingContext), client);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final ChangeItemStatusService changeItemStatusService = new ChangeItemStatusService(loanRepository, new StoreLoanAndItem(loanRepository, itemRepository));
return changeItemStatusService.getOpenLoan(request).thenApply(loan -> declareLoanClaimedReturned(loan, request)).thenCompose(changeItemStatusService::updateLoanAndItem);
}
use of org.folio.circulation.StoreLoanAndItem in project mod-circulation by folio-org.
the class DeclareClaimedReturnedItemAsMissingResource method processDeclareClaimedReturnedItemAsMissing.
private CompletableFuture<Result<Loan>> processDeclareClaimedReturnedItemAsMissing(RoutingContext routingContext, ChangeItemStatusRequest request) {
final Clients clients = Clients.create(new WebContext(routingContext), client);
final var itemRepository = new ItemRepository(clients);
final var userRepository = new UserRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final ChangeItemStatusService changeItemStatusService = new ChangeItemStatusService(loanRepository, new StoreLoanAndItem(loanRepository, itemRepository));
return changeItemStatusService.getOpenLoan(request).thenApply(NotInItemStatusValidator::refuseWhenItemIsNotClaimedReturned).thenApply(r -> declareLoanMissing(r, request)).thenCompose(changeItemStatusService::updateLoanAndItem).thenCompose(r -> r.after(loan -> createNote(clients, loan)));
}
use of org.folio.circulation.StoreLoanAndItem 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.StoreLoanAndItem in project mod-circulation by folio-org.
the class RenewalResource method renew.
private void renew(RoutingContext routingContext) {
final WebContext webContext = new WebContext(routingContext);
final Clients clients = Clients.create(webContext, client);
final OkapiPermissions okapiPermissions = OkapiPermissions.from(webContext.getHeaders());
final CirculationErrorHandler errorHandler = new OverridingErrorHandler(okapiPermissions);
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 LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
final StoreLoanAndItem storeLoanAndItem = new StoreLoanAndItem(loanRepository, itemRepository);
final LoanRepresentation loanRepresentation = new LoanRepresentation();
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
final LoanScheduledNoticeService scheduledNoticeService = LoanScheduledNoticeService.using(clients);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients);
final AutomatedPatronBlocksRepository automatedPatronBlocksRepository = new AutomatedPatronBlocksRepository(clients);
final FeeFineScheduledNoticeService feeFineNoticesService = FeeFineScheduledNoticeService.using(clients);
// TODO: Validation check for same user should be in the domain service
JsonObject bodyAsJson = routingContext.getBodyAsJson();
BlockOverrides overrideBlocks = getOverrideBlocks(bodyAsJson);
OkapiPermissions permissions = OkapiPermissions.from(new WebContext(routingContext).getHeaders());
final Validator<RenewalContext> automatedPatronBlocksValidator = createAutomatedPatronBlocksValidator(bodyAsJson, permissions, automatedPatronBlocksRepository);
final Validator<RenewalContext> manualPatronBlocksValidator = createManualPatronBlocksValidator(bodyAsJson, permissions, clients);
final Validator<RenewalContext> overrideRenewValidator = new OverridingBlockValidator<>(RENEWAL_BLOCK, overrideBlocks, permissions);
isRenewalBlockOverrideRequested = overrideBlocks.getRenewalBlockOverride().isRequested() || overrideBlocks.getRenewalDueDateRequiredBlockOverride().isRequested();
findLoan(bodyAsJson, loanRepository, itemRepository, userRepository, errorHandler).thenApply(r -> r.map(loan -> RenewalContext.create(loan, bodyAsJson, webContext.getUserId()))).thenComposeAsync(r -> refuseWhenPatronIsInactive(r, errorHandler, USER_IS_INACTIVE)).thenComposeAsync(r -> refuseWhenRenewalActionIsBlockedForPatron(manualPatronBlocksValidator, r, errorHandler, USER_IS_BLOCKED_MANUALLY)).thenComposeAsync(r -> refuseWhenRenewalActionIsBlockedForPatron(automatedPatronBlocksValidator, r, errorHandler, USER_IS_BLOCKED_AUTOMATICALLY)).thenComposeAsync(r -> refuseIfNoPermissionsForRenewalOverride(overrideRenewValidator, r, errorHandler)).thenCompose(r -> r.after(ctx -> lookupLoanPolicy(ctx, loanPolicyRepository, errorHandler))).thenComposeAsync(r -> r.after(ctx -> lookupRequestQueue(ctx, requestQueueRepository, errorHandler))).thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, RenewalContext::withTimeZone)).thenComposeAsync(r -> r.after(context -> renew(context, clients, errorHandler))).thenApply(r -> r.next(errorHandler::failWithValidationErrors)).thenApply(r -> r.map(this::unsetDueDateChangedByRecallIfNoOpenRecallsInQueue)).thenComposeAsync(r -> r.after(storeLoanAndItem::updateLoanAndItemInStorage)).thenComposeAsync(r -> r.after(context -> processFeesFines(context, clients, itemRepository, userRepository, loanRepository))).thenApplyAsync(r -> r.next(feeFineNoticesService::scheduleOverdueFineNotices)).thenComposeAsync(r -> r.after(eventPublisher::publishDueDateChangedEvent)).thenApply(r -> r.next(scheduledNoticeService::rescheduleDueDateNotices)).thenApply(r -> r.next(loanNoticeSender::sendRenewalPatronNotice)).thenApply(r -> r.map(loanRepresentation::extendedLoan)).thenApply(r -> r.map(this::toResponse)).thenAccept(webContext::writeResultToHttpResponse);
}
Aggregations