Search in sources :

Example 26 with Clients

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)));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) RoutingContext(io.vertx.ext.web.RoutingContext) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) ChangeItemStatusRequest(org.folio.circulation.domain.representations.ChangeItemStatusRequest) PubSubPublishingService(org.folio.circulation.services.PubSubPublishingService) JsonObject(io.vertx.core.json.JsonObject) ChangeItemStatusService(org.folio.circulation.services.ChangeItemStatusService) Result.failed(org.folio.circulation.support.results.Result.failed) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) 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) NotInItemStatusValidator(org.folio.circulation.domain.validation.NotInItemStatusValidator) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) 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) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) ChangeItemStatusService(org.folio.circulation.services.ChangeItemStatusService) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository)

Example 27 with Clients

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())));
}
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)

Example 28 with Clients

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());
        }
    }
}
Also used : ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) WebContext(org.folio.circulation.support.http.server.WebContext) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) EndPatronSessionRequest(org.folio.circulation.domain.representations.EndPatronSessionRequest) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) Result(org.folio.circulation.support.results.Result)

Example 29 with Clients

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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) ZonedDateTime(java.time.ZonedDateTime) WebContext(org.folio.circulation.support.http.server.WebContext) ALL(org.folio.circulation.domain.notice.session.PatronActionType.ALL) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) RoutingContext(io.vertx.ext.web.RoutingContext) StringUtils(org.apache.commons.lang3.StringUtils) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) CommonFailures(org.folio.circulation.support.results.CommonFailures) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) PatronExpiredSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronExpiredSessionRepository) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) ExpiredSession(org.folio.circulation.domain.notice.session.ExpiredSession) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) RouteRegistration(org.folio.circulation.support.RouteRegistration) List(java.util.List) ClockUtil(org.folio.circulation.support.utils.ClockUtil) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) PatronExpiredSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronExpiredSessionRepository) WebContext(org.folio.circulation.support.http.server.WebContext) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository)

Example 30 with Clients

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);
}
Also used : Clients(org.folio.circulation.support.Clients) RouteRegistration(org.folio.circulation.support.RouteRegistration) WebContext(org.folio.circulation.support.http.server.WebContext) Router(io.vertx.ext.web.Router) ItemsInTransitReportService(org.folio.circulation.services.ItemsInTransitReportService) RoutingContext(io.vertx.ext.web.RoutingContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) ItemsInTransitReportService(org.folio.circulation.services.ItemsInTransitReportService) Clients(org.folio.circulation.support.Clients)

Aggregations

Clients (org.folio.circulation.support.Clients)41 WebContext (org.folio.circulation.support.http.server.WebContext)38 HttpClient (io.vertx.core.http.HttpClient)36 RoutingContext (io.vertx.ext.web.RoutingContext)36 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)33 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)32 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)31 Result (org.folio.circulation.support.results.Result)31 Router (io.vertx.ext.web.Router)30 CompletableFuture (java.util.concurrent.CompletableFuture)29 JsonObject (io.vertx.core.json.JsonObject)26 EventPublisher (org.folio.circulation.services.EventPublisher)26 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)23 RouteRegistration (org.folio.circulation.support.RouteRegistration)21 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)21 Loan (org.folio.circulation.domain.Loan)19 RequestRepository (org.folio.circulation.infrastructure.storage.requests.RequestRepository)19 JsonHttpResponse (org.folio.circulation.support.http.server.JsonHttpResponse)19 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)19 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)19