use of org.folio.circulation.support.Clients 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.support.Clients 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.support.Clients in project mod-circulation by folio-org.
the class EndPatronActionSessionResource method process.
private void process(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
Clients clients = Clients.create(context, client);
final var userRepository = new UserRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
List<Result<EndPatronSessionRequest>> resultListOfEndSessionRequestResult = EndPatronSessionRequest.from(routingContext.getBodyAsJson());
for (Result<EndPatronSessionRequest> result : resultListOfEndSessionRequestResult) {
if (result.failed()) {
result.cause().writeTo(routingContext.response());
} else {
EndPatronSessionRequest endSessionRequest = result.value();
patronActionSessionService.endSessions(endSessionRequest.getPatronId(), endSessionRequest.getActionType());
noContent().writeTo(routingContext.response());
}
}
}
use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.
the class ExpiredSessionProcessingResource method process.
private void process(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
final var userRepository = new UserRepository(clients);
final var itemRepository = new ItemRepository(clients);
final var loanRepository = new LoanRepository(clients, itemRepository, userRepository);
final PatronActionSessionService patronSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
final PatronExpiredSessionRepository patronExpiredSessionRepository = PatronExpiredSessionRepository.using(clients);
safelyInitialise(configurationRepository::lookupSessionTimeout).thenCompose(r -> r.after(this::defineExpiredTime)).thenCompose(r -> r.after(inactivityTime -> patronExpiredSessionRepository.findPatronExpiredSessions(ALL, inactivityTime))).thenCompose(r -> r.after(expiredSessions -> attemptEndSessions(patronSessionService, expiredSessions))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).exceptionally(CommonFailures::failedDueToServerError).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.support.Clients in project mod-circulation by folio-org.
the class ItemsInTransitResource method buildReport.
private void buildReport(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
new ItemsInTransitReportService(clients).buildReport().thenApply(r -> r.map(JsonHttpResponse::ok)).thenAccept(context::writeResultToHttpResponse);
}
Aggregations