Search in sources :

Example 1 with ChangeItemStatusService

use of org.folio.circulation.services.ChangeItemStatusService 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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) WebContext(org.folio.circulation.support.http.server.WebContext) Loan(org.folio.circulation.domain.Loan) Router(io.vertx.ext.web.Router) ITEM_CLAIMED_RETURNED_DATE(org.folio.circulation.domain.ClaimItemReturnedRequest.ITEM_CLAIMED_RETURNED_DATE) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) RoutingContext(io.vertx.ext.web.RoutingContext) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) ClaimItemReturnedRequest(org.folio.circulation.domain.ClaimItemReturnedRequest) 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) 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 2 with ChangeItemStatusService

use of org.folio.circulation.services.ChangeItemStatusService 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)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)2 JsonObject (io.vertx.core.json.JsonObject)2 Router (io.vertx.ext.web.Router)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 StoreLoanAndItem (org.folio.circulation.StoreLoanAndItem)2 Loan (org.folio.circulation.domain.Loan)2 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)2 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)2 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)2 ChangeItemStatusService (org.folio.circulation.services.ChangeItemStatusService)2 EventPublisher (org.folio.circulation.services.EventPublisher)2 Clients (org.folio.circulation.support.Clients)2 RouteRegistration (org.folio.circulation.support.RouteRegistration)2 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)2 NoContentResponse (org.folio.circulation.support.http.server.NoContentResponse)2 WebContext (org.folio.circulation.support.http.server.WebContext)2 MappingFunctions.toFixedValue (org.folio.circulation.support.results.MappingFunctions.toFixedValue)2 Result (org.folio.circulation.support.results.Result)2 Result.failed (org.folio.circulation.support.results.Result.failed)2