Search in sources :

Example 1 with ChangeItemStatusRequest

use of org.folio.circulation.domain.representations.ChangeItemStatusRequest in project mod-circulation by folio-org.

the class DeclareClaimedReturnedItemAsMissingResource method createRequest.

private Result<ChangeItemStatusRequest> createRequest(RoutingContext routingContext) {
    final String loanId = routingContext.pathParam("id");
    final JsonObject body = routingContext.getBodyAsJson();
    final ChangeItemStatusRequest request = ChangeItemStatusRequest.from(loanId, body);
    if (request.getComment() == null) {
        return failed(singleValidationError("Comment is a required field", "comment", null));
    }
    return succeeded(request);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) ChangeItemStatusRequest(org.folio.circulation.domain.representations.ChangeItemStatusRequest)

Example 2 with ChangeItemStatusRequest

use of org.folio.circulation.domain.representations.ChangeItemStatusRequest 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 3 with ChangeItemStatusRequest

use of org.folio.circulation.domain.representations.ChangeItemStatusRequest in project mod-circulation by folio-org.

the class ClaimItemReturnedRequest method from.

public static ClaimItemReturnedRequest from(String loanId, JsonObject body) {
    final ChangeItemStatusRequest changeStatusRequest = ChangeItemStatusRequest.from(loanId, body);
    final ZonedDateTime itemClaimedReturnedDate = JsonPropertyFetcher.getDateTimeProperty(body, ITEM_CLAIMED_RETURNED_DATE);
    return new ClaimItemReturnedRequest(loanId, itemClaimedReturnedDate, changeStatusRequest.getComment());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ChangeItemStatusRequest(org.folio.circulation.domain.representations.ChangeItemStatusRequest)

Aggregations

ChangeItemStatusRequest (org.folio.circulation.domain.representations.ChangeItemStatusRequest)3 JsonObject (io.vertx.core.json.JsonObject)2 HttpClient (io.vertx.core.http.HttpClient)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 ZonedDateTime (java.time.ZonedDateTime)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 StoreLoanAndItem (org.folio.circulation.StoreLoanAndItem)1 Loan (org.folio.circulation.domain.Loan)1 NoteCreator (org.folio.circulation.domain.notes.NoteCreator)1 NotInItemStatusValidator (org.folio.circulation.domain.validation.NotInItemStatusValidator)1 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1 NotesRepository (org.folio.circulation.infrastructure.storage.notes.NotesRepository)1 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)1 ChangeItemStatusService (org.folio.circulation.services.ChangeItemStatusService)1 EventPublisher (org.folio.circulation.services.EventPublisher)1 PubSubPublishingService (org.folio.circulation.services.PubSubPublishingService)1 Clients (org.folio.circulation.support.Clients)1