Search in sources :

Example 1 with ChangeDueDateRequest

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

the class ChangeDueDateResource method createChangeDueDateRequest.

private Result<ChangeDueDateRequest> createChangeDueDateRequest(RoutingContext routingContext) {
    final String loanId = routingContext.pathParam("id");
    final JsonObject body = routingContext.getBodyAsJson();
    if (!body.containsKey(DUE_DATE)) {
        return failed(singleValidationError("A new due date is required in order to change the due date", DUE_DATE, null));
    }
    return Result.of(() -> new ChangeDueDateRequest(loanId, getDateTimeProperty(body, DUE_DATE)));
}
Also used : ChangeDueDateRequest(org.folio.circulation.domain.representations.ChangeDueDateRequest) JsonObject(io.vertx.core.json.JsonObject)

Example 2 with ChangeDueDateRequest

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

the class ChangeDueDateResource method processChangeDueDate.

private CompletableFuture<Result<LoanAndRelatedRecords>> processChangeDueDate(final ChangeDueDateRequest request, RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    final Clients clients = Clients.create(context, client);
    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 LoanScheduledNoticeService scheduledNoticeService = LoanScheduledNoticeService.using(clients);
    final ItemStatusValidator itemStatusValidator = new ItemStatusValidator(ChangeDueDateResource::errorWhenInIncorrectStatus);
    final EventPublisher eventPublisher = new EventPublisher(routingContext);
    final LoanNoticeSender loanNoticeSender = LoanNoticeSender.using(clients);
    final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
    log.info("starting change due date process for loan {}", request.getLoanId());
    return succeeded(request).after(r -> getExistingLoan(loanRepository, r)).thenApply(LoanValidator::refuseWhenLoanIsClosed).thenApply(this::toLoanAndRelatedRecords).thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings, LoanAndRelatedRecords::withTlrSettings)).thenComposeAsync(r -> r.after(requestQueueRepository::get)).thenApply(itemStatusValidator::refuseWhenItemStatusDoesNotAllowDueDateChange).thenApply(r -> changeDueDate(r, request)).thenApply(r -> r.map(this::unsetDueDateChangedByRecallIfNoOpenRecallsInQueue)).thenComposeAsync(r -> r.after(loanRepository::updateLoan)).thenComposeAsync(r -> r.after(eventPublisher::publishDueDateChangedEvent)).thenApply(r -> r.next(scheduledNoticeService::rescheduleDueDateNotices)).thenCompose(r -> r.after(loanNoticeSender::sendManualDueDateChangeNotice));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) JsonPropertyFetcher.getDateTimeProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getDateTimeProperty) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) ZonedDateTime(java.time.ZonedDateTime) WebContext(org.folio.circulation.support.http.server.WebContext) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) 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) Item(org.folio.circulation.domain.Item) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) JsonObject(io.vertx.core.json.JsonObject) RequestQueue(org.folio.circulation.domain.RequestQueue) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) Result.failed(org.folio.circulation.support.results.Result.failed) ChangeDueDateRequest(org.folio.circulation.domain.representations.ChangeDueDateRequest) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) ITEM_ID(org.folio.circulation.domain.representations.LoanProperties.ITEM_ID) Result(org.folio.circulation.support.results.Result) EventPublisher(org.folio.circulation.services.EventPublisher) DUE_DATE(org.folio.circulation.domain.representations.ChangeDueDateRequest.DUE_DATE) RouteRegistration(org.folio.circulation.support.RouteRegistration) Logger(org.apache.logging.log4j.Logger) ItemStatusValidator(org.folio.circulation.domain.validation.ItemStatusValidator) LogManager(org.apache.logging.log4j.LogManager) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) ItemStatusValidator(org.folio.circulation.domain.validation.ItemStatusValidator) Clients(org.folio.circulation.support.Clients) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)2 ChangeDueDateRequest (org.folio.circulation.domain.representations.ChangeDueDateRequest)2 HttpClient (io.vertx.core.http.HttpClient)1 Router (io.vertx.ext.web.Router)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 MethodHandles (java.lang.invoke.MethodHandles)1 ZonedDateTime (java.time.ZonedDateTime)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Item (org.folio.circulation.domain.Item)1 Loan (org.folio.circulation.domain.Loan)1 LoanAndRelatedRecords (org.folio.circulation.domain.LoanAndRelatedRecords)1 RequestQueue (org.folio.circulation.domain.RequestQueue)1 LoanScheduledNoticeService (org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService)1 DUE_DATE (org.folio.circulation.domain.representations.ChangeDueDateRequest.DUE_DATE)1 ITEM_ID (org.folio.circulation.domain.representations.LoanProperties.ITEM_ID)1 ItemStatusValidator (org.folio.circulation.domain.validation.ItemStatusValidator)1 LoanValidator (org.folio.circulation.domain.validation.LoanValidator)1 ConfigurationRepository (org.folio.circulation.infrastructure.storage.ConfigurationRepository)1