Search in sources :

Example 1 with LoanAndRelatedRecords

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

the class PatronActionSessionService method saveCheckOutSessionRecord.

public CompletableFuture<Result<LoanAndRelatedRecords>> saveCheckOutSessionRecord(LoanAndRelatedRecords records) {
    UUID patronId = UUID.fromString(records.getUserId());
    UUID loanId = UUID.fromString(records.getLoan().getId());
    PatronSessionRecord patronSessionRecord = new PatronSessionRecord(UUID.randomUUID(), patronId, loanId, PatronActionType.CHECK_OUT);
    return patronActionSessionRepository.create(patronSessionRecord).thenApply(mapResult(v -> records));
}
Also used : Clients(org.folio.circulation.support.Clients) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) CompletableFuture(java.util.concurrent.CompletableFuture) TemplateContextUtil.createLoanNoticeContextWithoutUser(org.folio.circulation.domain.notice.TemplateContextUtil.createLoanNoticeContextWithoutUser) CheckInContext(org.folio.circulation.domain.CheckInContext) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) NoticeEventType(org.folio.circulation.domain.notice.NoticeEventType) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) PageLimit(org.folio.circulation.support.http.client.PageLimit) PatronNoticeEvent(org.folio.circulation.domain.notice.PatronNoticeEvent) EnumMap(java.util.EnumMap) Result.of(org.folio.circulation.support.results.Result.of) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) PageLimit.limit(org.folio.circulation.support.http.client.PageLimit.limit) UUID(java.util.UUID) ImmediatePatronNoticeService(org.folio.circulation.domain.notice.ImmediatePatronNoticeService) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) User(org.folio.circulation.domain.User) PatronNoticeEventBuilder(org.folio.circulation.domain.notice.PatronNoticeEventBuilder) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AsynchronousResultBindings.safelyInitialise(org.folio.circulation.support.results.AsynchronousResultBindings.safelyInitialise) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) AllArgsConstructor(lombok.AllArgsConstructor) LogManager(org.apache.logging.log4j.LogManager) LoanNoticeContextCombiner(org.folio.circulation.domain.notice.combiner.LoanNoticeContextCombiner) UUID(java.util.UUID)

Example 2 with LoanAndRelatedRecords

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

the class InactiveUserValidatorTests method refuseWhenUserIsNeitherActiveNorInactive.

@Test
void refuseWhenUserIsNeitherActiveNorInactive() {
    final User steve = new User(basedUponStevenJones().neitherActiveOrInactive().create());
    final InactiveUserValidator validator = forUser(steve.getBarcode());
    final Result<LoanAndRelatedRecords> result = validator.refuseWhenUserIsInactive(steve, null);
    assertThat(result.failed(), is(true));
}
Also used : User(org.folio.circulation.domain.User) InactiveUserValidator.forUser(org.folio.circulation.domain.validation.InactiveUserValidator.forUser) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) Test(org.junit.jupiter.api.Test)

Example 3 with LoanAndRelatedRecords

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

the class EventPublisher method publishItemCheckedOutEvent.

public CompletableFuture<Result<LoanAndRelatedRecords>> publishItemCheckedOutEvent(LoanAndRelatedRecords loanAndRelatedRecords, UserRepository userRepository) {
    if (loanAndRelatedRecords.getLoan() != null) {
        Loan loan = loanAndRelatedRecords.getLoan();
        JsonObject payloadJsonObject = new JsonObject();
        write(payloadJsonObject, USER_ID_FIELD, loan.getUserId());
        write(payloadJsonObject, LOAN_ID_FIELD, loan.getId());
        write(payloadJsonObject, DUE_DATE_FIELD, loan.getDueDate());
        ofNullable(loan.getLoanPolicy()).map(LoanPolicy::getGracePeriod).filter(Period::isValid).map(Period::asJson).ifPresent(json -> write(payloadJsonObject, GRACE_PERIOD_FIELD, json));
        runAsync(() -> userRepository.getUser(loanAndRelatedRecords.getLoggedInUserId()).thenApplyAsync(r -> r.after(loggedInUser -> CompletableFuture.completedFuture(Result.succeeded(pubSubPublishingService.publishEvent(LOG_RECORD.name(), mapToCheckOutLogEventContent(loanAndRelatedRecords, loggedInUser)))))));
        return pubSubPublishingService.publishEvent(ITEM_CHECKED_OUT.name(), payloadJsonObject.encode()).handle((result, error) -> handlePublishEventError(error, loanAndRelatedRecords));
    } else {
        logger.error(FAILED_TO_PUBLISH_LOG_TEMPLATE, ITEM_CHECKED_OUT.name());
    }
    return completedFuture(succeeded(loanAndRelatedRecords));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) RenewalContext(org.folio.circulation.resources.context.RenewalContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) LogContextActionResolver(org.folio.circulation.domain.representations.logs.LogContextActionResolver) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) RoutingContext(io.vertx.ext.web.RoutingContext) JsonPropertyWriter.write(org.folio.circulation.support.json.JsonPropertyWriter.write) CHECKED_IN(org.folio.circulation.domain.LoanAction.CHECKED_IN) DateFormatUtil.formatDateTimeOptional(org.folio.circulation.support.utils.DateFormatUtil.formatDateTimeOptional) LoanLogContext(org.folio.circulation.domain.representations.logs.LoanLogContext) LOAN_CLOSED(org.folio.circulation.domain.EventType.LOAN_CLOSED) LOG_EVENT_TYPE(org.folio.circulation.domain.representations.logs.LogEventPayloadField.LOG_EVENT_TYPE) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) Period(org.folio.circulation.domain.policy.Period) HttpFailure(org.folio.circulation.support.HttpFailure) CommonFailures.failedDueToServerError(org.folio.circulation.support.results.CommonFailures.failedDueToServerError) LoanAnonymizationRecords(org.folio.circulation.domain.anonymization.LoanAnonymizationRecords) JsonObject(io.vertx.core.json.JsonObject) DUE_DATE_CHANGED(org.folio.circulation.domain.LoanAction.DUE_DATE_CHANGED) LOAN(org.folio.circulation.domain.representations.logs.LogEventType.LOAN) CirculationCheckInCheckOutLogEventMapper.mapToCheckOutLogEventContent(org.folio.circulation.domain.representations.logs.CirculationCheckInCheckOutLogEventMapper.mapToCheckOutLogEventContent) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) PAYLOAD(org.folio.circulation.domain.representations.logs.LogEventPayloadField.PAYLOAD) Result(org.folio.circulation.support.results.Result) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) Logger(org.apache.logging.log4j.Logger) ITEM_CLAIMED_RETURNED(org.folio.circulation.domain.EventType.ITEM_CLAIMED_RETURNED) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) EventType(org.folio.circulation.domain.EventType) Request(org.folio.circulation.domain.Request) CompletableFuture(java.util.concurrent.CompletableFuture) ITEM_CHECKED_OUT(org.folio.circulation.domain.EventType.ITEM_CHECKED_OUT) CheckInContext(org.folio.circulation.domain.CheckInContext) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) RequestUpdateLogEventMapper.mapToRequestLogEventJson(org.folio.circulation.domain.representations.logs.RequestUpdateLogEventMapper.mapToRequestLogEventJson) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) LOAN_DUE_DATE_CHANGED(org.folio.circulation.domain.EventType.LOAN_DUE_DATE_CHANGED) LogEventType(org.folio.circulation.domain.representations.logs.LogEventType) CompletableFuture.runAsync(java.util.concurrent.CompletableFuture.runAsync) Optional.ofNullable(java.util.Optional.ofNullable) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) CirculationCheckInCheckOutLogEventMapper.mapToCheckInLogEventContent(org.folio.circulation.domain.representations.logs.CirculationCheckInCheckOutLogEventMapper.mapToCheckInLogEventContent) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) ITEM_AGED_TO_LOST(org.folio.circulation.domain.EventType.ITEM_AGED_TO_LOST) User(org.folio.circulation.domain.User) ITEM_CHECKED_IN(org.folio.circulation.domain.EventType.ITEM_CHECKED_IN) ITEM_DECLARED_LOST(org.folio.circulation.domain.EventType.ITEM_DECLARED_LOST) LOG_RECORD(org.folio.circulation.domain.EventType.LOG_RECORD) RECALLREQUESTED(org.folio.circulation.domain.LoanAction.RECALLREQUESTED) LogManager(org.apache.logging.log4j.LogManager) Loan(org.folio.circulation.domain.Loan) JsonObject(io.vertx.core.json.JsonObject) Period(org.folio.circulation.domain.policy.Period)

Example 4 with LoanAndRelatedRecords

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

the class CheckOutByBarcodeResource method checkOut.

private void checkOut(RoutingContext routingContext) {
    final WebContext context = new WebContext(routingContext);
    CheckOutByBarcodeRequest request = CheckOutByBarcodeRequest.fromJson(routingContext.getBodyAsJson());
    final 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);
    final var requestRepository = RequestRepository.using(clients, itemRepository, userRepository, loanRepository);
    final var requestQueueRepository = new RequestQueueRepository(requestRepository);
    final LoanService loanService = new LoanService(clients);
    final LoanPolicyRepository loanPolicyRepository = new LoanPolicyRepository(clients);
    final OverdueFinePolicyRepository overdueFinePolicyRepository = new OverdueFinePolicyRepository(clients);
    final LostItemPolicyRepository lostItemPolicyRepository = new LostItemPolicyRepository(clients);
    final PatronNoticePolicyRepository patronNoticePolicyRepository = new PatronNoticePolicyRepository(clients);
    final PatronGroupRepository patronGroupRepository = new PatronGroupRepository(clients);
    final ConfigurationRepository configurationRepository = new ConfigurationRepository(clients);
    final ScheduledNoticesRepository scheduledNoticesRepository = ScheduledNoticesRepository.using(clients);
    final LoanScheduledNoticeService scheduledNoticeService = new LoanScheduledNoticeService(scheduledNoticesRepository, patronNoticePolicyRepository);
    OkapiPermissions permissions = OkapiPermissions.from(new WebContext(routingContext).getHeaders());
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(permissions);
    CheckOutValidators validators = new CheckOutValidators(request, clients, errorHandler, permissions, loanRepository);
    final var requestQueueUpdate = UpdateRequestQueue.using(clients, requestRepository, requestQueueRepository);
    final LoanRepresentation loanRepresentation = new LoanRepresentation();
    final EventPublisher eventPublisher = new EventPublisher(routingContext);
    final PatronActionSessionService patronActionSessionService = PatronActionSessionService.using(clients, PatronActionSessionRepository.using(clients, loanRepository, userRepository));
    ofAsync(() -> new LoanAndRelatedRecords(request.toLoan())).thenApply(validators::refuseCheckOutWhenServicePointIsNotPresent).thenComposeAsync(r -> lookupUser(request.getUserBarcode(), userRepository, r, errorHandler)).thenComposeAsync(validators::refuseWhenCheckOutActionIsBlockedManuallyForPatron).thenComposeAsync(validators::refuseWhenCheckOutActionIsBlockedAutomaticallyForPatron).thenComposeAsync(r -> lookupProxyUser(request.getProxyUserBarcode(), userRepository, r, errorHandler)).thenApply(validators::refuseWhenUserIsInactive).thenApply(validators::refuseWhenProxyUserIsInactive).thenComposeAsync(validators::refuseWhenInvalidProxyRelationship).thenComposeAsync(r -> lookupItem(request.getItemBarcode(), itemRepository, r)).thenApply(validators::refuseWhenItemNotFound).thenApply(validators::refuseWhenItemIsAlreadyCheckedOut).thenApply(validators::refuseWhenItemIsNotAllowedForCheckOut).thenComposeAsync(validators::refuseWhenItemHasOpenLoans).thenComposeAsync(r -> r.combineAfter(configurationRepository::lookupTlrSettings, LoanAndRelatedRecords::withTlrSettings)).thenComposeAsync(r -> r.after(requestQueueRepository::get)).thenApply(validators::refuseWhenRequestedByAnotherPatron).thenComposeAsync(r -> r.after(l -> lookupLoanPolicy(l, loanPolicyRepository, errorHandler))).thenComposeAsync(validators::refuseWhenItemLimitIsReached).thenCompose(validators::refuseWhenItemIsNotLoanable).thenApply(r -> r.next(errorHandler::failWithValidationErrors)).thenCompose(r -> r.combineAfter(configurationRepository::findTimeZoneConfiguration, LoanAndRelatedRecords::withTimeZone)).thenComposeAsync(r -> r.after(overdueFinePolicyRepository::lookupOverdueFinePolicy)).thenComposeAsync(r -> r.after(lostItemPolicyRepository::lookupLostItemPolicy)).thenApply(r -> r.next(this::setItemLocationIdAtCheckout)).thenComposeAsync(r -> r.after(relatedRecords -> checkOut(relatedRecords, routingContext.getBodyAsJson(), clients))).thenApply(r -> r.map(this::checkOutItem)).thenComposeAsync(r -> r.after(requestQueueUpdate::onCheckOut)).thenComposeAsync(r -> r.after(loanService::truncateLoanWhenItemRecalled)).thenComposeAsync(r -> r.after(patronGroupRepository::findPatronGroupForLoanAndRelatedRecords)).thenComposeAsync(r -> r.after(l -> updateItem(l, itemRepository))).thenComposeAsync(r -> r.after(loanRepository::createLoan)).thenComposeAsync(r -> r.after(l -> saveCheckOutSessionRecord(l, patronActionSessionService, errorHandler))).thenApplyAsync(r -> r.map(records -> records.withLoggedInUserId(context.getUserId()))).thenComposeAsync(r -> r.after(l -> publishItemCheckedOutEvent(l, eventPublisher, userRepository, errorHandler))).thenApply(r -> r.next(scheduledNoticeService::scheduleNoticesForLoanDueDate)).thenApply(r -> r.map(LoanAndRelatedRecords::getLoan)).thenApply(r -> r.map(loanRepresentation::extendedLoan)).thenApply(r -> createdLoanFrom(r, errorHandler)).thenAccept(context::writeResultToHttpResponse);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ZonedDateTime(java.time.ZonedDateTime) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) ClosedLibraryStrategyService(org.folio.circulation.domain.policy.library.ClosedLibraryStrategyService) CheckOutByBarcodeRequest(org.folio.circulation.domain.representations.CheckOutByBarcodeRequest) FAILED_TO_FETCH_PROXY_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_PROXY_USER) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) PatronNoticePolicyRepository(org.folio.circulation.infrastructure.storage.notices.PatronNoticePolicyRepository) FAILED_TO_FETCH_ITEM(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_ITEM) JsonObject(io.vertx.core.json.JsonObject) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) FAILED_TO_PUBLISH_CHECKOUT_EVENT(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_PUBLISH_CHECKOUT_EVENT) Result(org.folio.circulation.support.results.Result) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) EventPublisher(org.folio.circulation.services.EventPublisher) RouteRegistration(org.folio.circulation.support.RouteRegistration) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) LoanService(org.folio.circulation.domain.LoanService) CirculationErrorType(org.folio.circulation.resources.handlers.error.CirculationErrorType) CHECKED_OUT_THROUGH_OVERRIDE(org.folio.circulation.domain.LoanAction.CHECKED_OUT_THROUGH_OVERRIDE) CheckOutValidators(org.folio.circulation.domain.validation.CheckOutValidators) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) WebContext(org.folio.circulation.support.http.server.WebContext) CompletableFuture(java.util.concurrent.CompletableFuture) FAILED_TO_SAVE_SESSION_RECORD(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_SAVE_SESSION_RECORD) HttpResponse(org.folio.circulation.support.http.server.HttpResponse) JsonHttpResponse.ok(org.folio.circulation.support.http.server.JsonHttpResponse.ok) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) RequestQueue(org.folio.circulation.domain.RequestQueue) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) FAILED_TO_FETCH_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_USER) PatronActionSessionRepository(org.folio.circulation.infrastructure.storage.sessions.PatronActionSessionRepository) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) JsonHttpResponse.created(org.folio.circulation.support.http.server.JsonHttpResponse.created) CHECKED_OUT(org.folio.circulation.domain.ItemStatus.CHECKED_OUT) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository) WebContext(org.folio.circulation.support.http.server.WebContext) CheckOutValidators(org.folio.circulation.domain.validation.CheckOutValidators) PatronNoticePolicyRepository(org.folio.circulation.infrastructure.storage.notices.PatronNoticePolicyRepository) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) PatronActionSessionService(org.folio.circulation.domain.notice.session.PatronActionSessionService) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) EventPublisher(org.folio.circulation.services.EventPublisher) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) Clients(org.folio.circulation.support.Clients) LoanService(org.folio.circulation.domain.LoanService) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LostItemPolicyRepository) CheckOutByBarcodeRequest(org.folio.circulation.domain.representations.CheckOutByBarcodeRequest) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) PatronGroupRepository(org.folio.circulation.infrastructure.storage.users.PatronGroupRepository)

Example 5 with LoanAndRelatedRecords

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

the class ChangeDueDateValidator method refuseChangeDueDateForItemInDisallowedStatus.

public CompletableFuture<Result<LoanAndRelatedRecords>> refuseChangeDueDateForItemInDisallowedStatus(Result<LoanAndRelatedRecords> loanAndRelatedRecordsResult) {
    return loanAndRelatedRecordsResult.after(relatedRecords -> {
        final Loan changedLoan = relatedRecords.getLoan();
        final Result<LoanAndRelatedRecords> statusValidation = itemStatusValidator.refuseWhenItemStatusDoesNotAllowDueDateChange(loanAndRelatedRecordsResult);
        // further logic
        if (statusValidation.succeeded()) {
            return ofAsync(() -> relatedRecords);
        }
        // all other changes are allowed
        return completedFuture(loanAndRelatedRecordsResult.map(LoanAndRelatedRecords::getExistingLoan)).thenApply(r -> r.failWhen(existingLoan -> dueDateHasChanged(existingLoan, changedLoan), existingLoan -> statusValidation.cause())).thenApply(r -> r.map(notUsed -> relatedRecords));
    });
}
Also used : LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) Result(org.folio.circulation.support.results.Result) Item(org.folio.circulation.domain.Item) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) DateTimeUtil.isSameMillis(org.folio.circulation.support.utils.DateTimeUtil.isSameMillis) Loan(org.folio.circulation.domain.Loan) LoanAndRelatedRecords(org.folio.circulation.domain.LoanAndRelatedRecords)

Aggregations

LoanAndRelatedRecords (org.folio.circulation.domain.LoanAndRelatedRecords)15 CompletableFuture (java.util.concurrent.CompletableFuture)10 Loan (org.folio.circulation.domain.Loan)10 Result (org.folio.circulation.support.results.Result)10 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)10 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)9 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)8 JsonObject (io.vertx.core.json.JsonObject)7 User (org.folio.circulation.domain.User)7 Result.ofAsync (org.folio.circulation.support.results.Result.ofAsync)7 RoutingContext (io.vertx.ext.web.RoutingContext)6 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)6 EventPublisher (org.folio.circulation.services.EventPublisher)6 Clients (org.folio.circulation.support.Clients)6 HttpClient (io.vertx.core.http.HttpClient)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 Item (org.folio.circulation.domain.Item)5 ValidationErrorFailure (org.folio.circulation.support.ValidationErrorFailure)5 ValidationErrorFailure.singleValidationError (org.folio.circulation.support.ValidationErrorFailure.singleValidationError)5