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