Search in sources :

Example 51 with RequestQueue

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

the class RequestNoticeSender method sendNoticeOnRequestAwaitingPickup.

public Result<CheckInContext> sendNoticeOnRequestAwaitingPickup(CheckInContext context) {
    final Item item = context.getItem();
    final RequestQueue requestQueue = context.getRequestQueue();
    if (item == null || item.isNotFound()) {
        log.warn("Request Awaiting Pickup notice processing is aborted: item is missing");
    } else if (requestQueue == null) {
        log.warn("Request Awaiting Pickup notice processing is aborted: request queue is null");
    } else if (item.isAwaitingPickup()) {
        requestQueue.getRequests().stream().filter(Request::hasTopPriority).filter(Request::isAwaitingPickup).filter(Request::hasChangedStatus).findFirst().map(request -> request.withItem(item)).ifPresent(this::fetchDataAndSendRequestAwaitingPickupNotice);
    }
    return succeeded(context);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) Request(org.folio.circulation.domain.Request) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CompletableFuture(java.util.concurrent.CompletableFuture) CheckInContext(org.folio.circulation.domain.CheckInContext) Item(org.folio.circulation.domain.Item) NoticeEventType(org.folio.circulation.domain.notice.NoticeEventType) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) HttpFailure(org.folio.circulation.support.HttpFailure) Map(java.util.Map) PatronNoticeEvent(org.folio.circulation.domain.notice.PatronNoticeEvent) TemplateContextUtil(org.folio.circulation.domain.notice.TemplateContextUtil) RequestQueue(org.folio.circulation.domain.RequestQueue) Result.failed(org.folio.circulation.support.results.Result.failed) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) CompletableFuture.runAsync(java.util.concurrent.CompletableFuture.runAsync) RequestType(org.folio.circulation.domain.RequestType) SingleImmediatePatronNoticeService(org.folio.circulation.domain.notice.SingleImmediatePatronNoticeService) EnumMap(java.util.EnumMap) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) ServicePoint(org.folio.circulation.domain.ServicePoint) ImmediatePatronNoticeService(org.folio.circulation.domain.notice.ImmediatePatronNoticeService) Result(org.folio.circulation.support.results.Result) 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) Logger(org.apache.logging.log4j.Logger) RequestStatus(org.folio.circulation.domain.RequestStatus) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) TemplateContextUtil.createRequestNoticeContext(org.folio.circulation.domain.notice.TemplateContextUtil.createRequestNoticeContext) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) RecordNotFoundFailure(org.folio.circulation.support.RecordNotFoundFailure) Item(org.folio.circulation.domain.Item) RequestQueue(org.folio.circulation.domain.RequestQueue) Request(org.folio.circulation.domain.Request)

Example 52 with RequestQueue

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

the class LoanCollectionResource method unsetDueDateChangedByRecallIfNoOpenRecallsInQueue.

private LoanAndRelatedRecords unsetDueDateChangedByRecallIfNoOpenRecallsInQueue(LoanAndRelatedRecords loanAndRelatedRecords) {
    if (dueDateHasNotChanged(loanAndRelatedRecords.getExistingLoan(), loanAndRelatedRecords.getLoan())) {
        return loanAndRelatedRecords;
    }
    RequestQueue queue = loanAndRelatedRecords.getRequestQueue();
    Loan loan = loanAndRelatedRecords.getLoan();
    log.info("Loan {} prior to flag check: {}", loan.getId(), loan.asJson());
    if (loan.wasDueDateChangedByRecall() && !queue.hasOpenRecalls()) {
        log.info("Loan {} registers as having due date change flag set to true and no open recalls in queue.", loan.getId());
        return loanAndRelatedRecords.withLoan(loan.unsetDueDateChangedByRecall());
    } else {
        log.info("Loan {} registers as either not having due date change flag set to true or as having open recalls in queue.", loan.getId());
        return loanAndRelatedRecords;
    }
}
Also used : Loan(org.folio.circulation.domain.Loan) UpdateRequestQueue(org.folio.circulation.domain.UpdateRequestQueue) RequestQueue(org.folio.circulation.domain.RequestQueue)

Example 53 with RequestQueue

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

the class RenewalResource method validateIfRenewIsAllowed.

private Result<RenewalContext> validateIfRenewIsAllowed(RenewalContext context, boolean isDueDateRequired) {
    Loan loan = context.getLoan();
    RequestQueue requestQueue = context.getRequestQueue();
    try {
        final var errors = isDueDateRequired ? validateIfRenewIsAllowedAndDueDateRequired(loan, requestQueue) : validateIfRenewIsAllowedAndDueDateNotRequired(loan, requestQueue);
        final var loanPolicy = loan.getLoanPolicy();
        if (loanPolicy.isNotLoanable() || loanPolicy.isNotRenewable()) {
            return failedValidation(errors);
        }
        if (errors.isEmpty()) {
            return succeeded(context);
        }
        return failedValidation(errors);
    } catch (Exception e) {
        return failedDueToServerError(e);
    }
}
Also used : Loan(org.folio.circulation.domain.Loan) RequestQueue(org.folio.circulation.domain.RequestQueue)

Aggregations

RequestQueue (org.folio.circulation.domain.RequestQueue)53 Loan (org.folio.circulation.domain.Loan)45 ZonedDateTime (java.time.ZonedDateTime)39 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)37 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)37 Test (org.junit.jupiter.api.Test)31 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)27 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)23 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)17 JsonObject (io.vertx.core.json.JsonObject)16 LoanBuilder (api.support.builders.LoanBuilder)11 Result (org.folio.circulation.support.results.Result)8 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)6 Item (org.folio.circulation.domain.Item)6 Request (org.folio.circulation.domain.Request)6 UpdateRequestQueue (org.folio.circulation.domain.UpdateRequestQueue)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 CompletableFuture (java.util.concurrent.CompletableFuture)5 ValidationErrorFailure (org.folio.circulation.support.ValidationErrorFailure)5