Search in sources :

Example 31 with Request

use of org.folio.circulation.domain.Request 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 32 with Request

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

the class RequestNoticeSender method sendNoticeOnRequestMoved.

public Result<RequestAndRelatedRecords> sendNoticeOnRequestMoved(RequestAndRelatedRecords relatedRecords) {
    Request request = relatedRecords.getRequest();
    Loan loan = request.getLoan();
    if (request.getRequestType() == RequestType.RECALL && loan != null) {
        sendNoticeOnItemRecalledEvent(loan);
        sendLogEvent(loan);
    }
    return Result.succeeded(relatedRecords);
}
Also used : Loan(org.folio.circulation.domain.Loan) Request(org.folio.circulation.domain.Request)

Example 33 with Request

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

the class RenewalResource method renewThroughOverride.

public CompletableFuture<Result<RenewalContext>> renewThroughOverride(RenewalContext context) {
    final JsonObject overrideBlocks = context.getRenewalRequest().getJsonObject(OVERRIDE_BLOCKS);
    final String comment = getProperty(overrideBlocks, COMMENT);
    if (StringUtils.isBlank(comment)) {
        return completedFuture(failedValidation("Override renewal request must have a comment", COMMENT, null));
    }
    final ZonedDateTime overrideDueDate = getDateTimeProperty(overrideBlocks.getJsonObject(RENEWAL_DUE_DATE_REQUIRED_OVERRIDE_BLOCK), DUE_DATE);
    Loan loan = context.getLoan();
    boolean hasRecallRequest = context.getRequestQueue().getRequests().stream().findFirst().map(r -> r.getRequestType() == RequestType.RECALL).orElse(false);
    return completedFuture(overrideRenewal(loan, ClockUtil.getZonedDateTime(), overrideDueDate, comment, hasRecallRequest)).thenApply(mapResult(context::withLoan));
}
Also used : RenewalContext(org.folio.circulation.resources.context.RenewalContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) JsonPropertyFetcher.getDateTimeProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getDateTimeProperty) ZonedDateTime(java.time.ZonedDateTime) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) StringUtils(org.apache.commons.lang3.StringUtils) RENEWAL_IS_NOT_POSSIBLE(org.folio.circulation.resources.handlers.error.CirculationErrorType.RENEWAL_IS_NOT_POSSIBLE) CommonFailures.failedDueToServerError(org.folio.circulation.support.results.CommonFailures.failedDueToServerError) FeeFineOwnerRepository(org.folio.circulation.infrastructure.storage.feesandfines.FeeFineOwnerRepository) JsonObject(io.vertx.core.json.JsonObject) RenewalValidator.loanPolicyValidationError(org.folio.circulation.resources.RenewalValidator.loanPolicyValidationError) CLAIMED_RETURNED(org.folio.circulation.domain.ItemStatus.CLAIMED_RETURNED) EnumSet(java.util.EnumSet) Loan(org.folio.circulation.domain.Loan) ValidationError(org.folio.circulation.support.http.server.ValidationError) Result(org.folio.circulation.support.results.Result) RenewalValidator.errorForDueDate(org.folio.circulation.resources.RenewalValidator.errorForDueDate) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) InactiveUserRenewalValidator(org.folio.circulation.domain.validation.InactiveUserRenewalValidator) FeeFineScheduledNoticeService(org.folio.circulation.domain.notice.schedule.FeeFineScheduledNoticeService) RouteRegistration(org.folio.circulation.support.RouteRegistration) LoanRepresentation(org.folio.circulation.domain.LoanRepresentation) PATRON_BLOCK(org.folio.circulation.domain.override.OverridableBlockType.PATRON_BLOCK) OverduePeriodCalculatorService(org.folio.circulation.domain.OverduePeriodCalculatorService) JsonPropertyFetcher.getObjectProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getObjectProperty) ITEM_DOES_NOT_EXIST(org.folio.circulation.resources.handlers.error.CirculationErrorType.ITEM_DOES_NOT_EXIST) RequestRepository(org.folio.circulation.infrastructure.storage.requests.RequestRepository) INSUFFICIENT_OVERRIDE_PERMISSIONS(org.folio.circulation.resources.handlers.error.CirculationErrorType.INSUFFICIENT_OVERRIDE_PERMISSIONS) FeeFineRepository(org.folio.circulation.infrastructure.storage.feesandfines.FeeFineRepository) BlockValidator(org.folio.circulation.domain.validation.overriding.BlockValidator) OverdueFinePolicyRepository(org.folio.circulation.infrastructure.storage.loans.OverdueFinePolicyRepository) FeeFineFacade(org.folio.circulation.services.FeeFineFacade) WebContext(org.folio.circulation.support.http.server.WebContext) RenewalValidator.errorForNotMatchingOverrideCases(org.folio.circulation.resources.RenewalValidator.errorForNotMatchingOverrideCases) Resource(org.folio.circulation.resources.Resource) FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD_FOR_HOLDS(org.folio.circulation.resources.RenewalValidator.FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD_FOR_HOLDS) ArrayList(java.util.ArrayList) Validator(org.folio.circulation.domain.validation.Validator) RENEWAL_IS_BLOCKED(org.folio.circulation.resources.handlers.error.CirculationErrorType.RENEWAL_IS_BLOCKED) RenewalValidator.itemByIdValidationError(org.folio.circulation.resources.RenewalValidator.itemByIdValidationError) DECLARED_LOST(org.folio.circulation.domain.ItemStatus.DECLARED_LOST) USER_IS_BLOCKED_MANUALLY(org.folio.circulation.resources.handlers.error.CirculationErrorType.USER_IS_BLOCKED_MANUALLY) ScheduledNoticesRepository(org.folio.circulation.infrastructure.storage.notices.ScheduledNoticesRepository) RenewalValidator.errorForRecallRequest(org.folio.circulation.resources.RenewalValidator.errorForRecallRequest) RequestType(org.folio.circulation.domain.RequestType) AutomatedPatronBlocksRepository(org.folio.circulation.infrastructure.storage.AutomatedPatronBlocksRepository) OverdueFineService(org.folio.circulation.domain.OverdueFineService) UserManualBlocksValidator(org.folio.circulation.domain.validation.UserManualBlocksValidator) RENEWAL_VALIDATION_ERROR(org.folio.circulation.resources.handlers.error.CirculationErrorType.RENEWAL_VALIDATION_ERROR) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) CHECKED_OUT(org.folio.circulation.domain.ItemStatus.CHECKED_OUT) HOLD(org.folio.circulation.domain.RequestType.HOLD) RENEWAL_BLOCK(org.folio.circulation.domain.override.OverridableBlockType.RENEWAL_BLOCK) UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoanPolicyRepository(org.folio.circulation.infrastructure.storage.loans.LoanPolicyRepository) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) ItemStatus(org.folio.circulation.domain.ItemStatus) ClosedLibraryStrategyService(org.folio.circulation.domain.policy.library.ClosedLibraryStrategyService) CalendarRepository(org.folio.circulation.infrastructure.storage.CalendarRepository) LoanScheduledNoticeService(org.folio.circulation.domain.notice.schedule.LoanScheduledNoticeService) DateTimeUtil.isAfterMillis(org.folio.circulation.support.utils.DateTimeUtil.isAfterMillis) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) LoanNoticeSender(org.folio.circulation.resources.LoanNoticeSender) BlockOverrides(org.folio.circulation.domain.override.BlockOverrides) EventPublisher(org.folio.circulation.services.EventPublisher) FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD(org.folio.circulation.resources.RenewalValidator.FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD) List(java.util.List) RECALL(org.folio.circulation.domain.RequestType.RECALL) CAN_NOT_RENEW_ITEM_ERROR(org.folio.circulation.resources.RenewalValidator.CAN_NOT_RENEW_ITEM_ERROR) ClockUtil(org.folio.circulation.support.utils.ClockUtil) CirculationErrorType(org.folio.circulation.resources.handlers.error.CirculationErrorType) HttpClient(io.vertx.core.http.HttpClient) Clients(org.folio.circulation.support.Clients) Request(org.folio.circulation.domain.Request) CompletableFuture(java.util.concurrent.CompletableFuture) RenewalValidator.errorWhenEarlierOrSameDueDate(org.folio.circulation.resources.RenewalValidator.errorWhenEarlierOrSameDueDate) HttpResponse(org.folio.circulation.support.http.server.HttpResponse) Function(java.util.function.Function) JsonHttpResponse(org.folio.circulation.support.http.server.JsonHttpResponse) USER_IS_INACTIVE(org.folio.circulation.resources.handlers.error.CirculationErrorType.USER_IS_INACTIVE) AutomatedPatronBlocksValidator(org.folio.circulation.domain.validation.AutomatedPatronBlocksValidator) OkapiPermissions(org.folio.circulation.support.http.OkapiPermissions) AGED_TO_LOST(org.folio.circulation.domain.ItemStatus.AGED_TO_LOST) RequestQueue(org.folio.circulation.domain.RequestQueue) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) ValidationErrorFailure(org.folio.circulation.support.ValidationErrorFailure) FAILED_TO_FETCH_USER(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FETCH_USER) RENEWAL_DUE_DATE_REQUIRED_IS_BLOCKED(org.folio.circulation.resources.handlers.error.CirculationErrorType.RENEWAL_DUE_DATE_REQUIRED_IS_BLOCKED) FAILED_TO_FIND_SINGLE_OPEN_LOAN(org.folio.circulation.resources.handlers.error.CirculationErrorType.FAILED_TO_FIND_SINGLE_OPEN_LOAN) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) RenewalValidator.overrideDueDateIsRequiredError(org.folio.circulation.resources.RenewalValidator.overrideDueDateIsRequiredError) OverridingBlockValidator(org.folio.circulation.domain.validation.overriding.OverridingBlockValidator) USER_IS_BLOCKED_AUTOMATICALLY(org.folio.circulation.resources.handlers.error.CirculationErrorType.USER_IS_BLOCKED_AUTOMATICALLY) JsonPropertyFetcher.getProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getProperty) Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject)

Example 34 with Request

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

the class TitleLevelRequestNoticeSender method sendNoticeOnRequestCancelled.

@Override
protected Result<Void> sendNoticeOnRequestCancelled(RequestAndRelatedRecords relatedRecords) {
    Request request = relatedRecords.getRequest();
    if (request.getTlrSettingsConfiguration().isTitleLevelRequestsFeatureEnabled() && request.getTlrSettingsConfiguration().getCancellationPatronNoticeTemplateId() != null) {
        PatronNoticeEvent requestCancelledEvent = createPatronNoticeEvent(request, NoticeEventType.REQUEST_CANCELLATION);
        applyTlrCancellationNotice(request.getTlrSettingsConfiguration(), requestCancelledEvent);
    }
    return Result.succeeded(null);
}
Also used : Request(org.folio.circulation.domain.Request) PatronNoticeEvent(org.folio.circulation.domain.notice.PatronNoticeEvent)

Example 35 with Request

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

the class RenewalResource method validateIfRenewIsAllowedAndDueDateRequired.

private List<ValidationError> validateIfRenewIsAllowedAndDueDateRequired(Loan loan, RequestQueue requestQueue) {
    final List<ValidationError> errors = new ArrayList<>();
    final LoanPolicy loanPolicy = loan.getLoanPolicy();
    final Request firstRequest = getFirstRequestInQueue(requestQueue);
    if (loanPolicy.isNotLoanable()) {
        errors.add(loanPolicyValidationError(loanPolicy, "item is not loanable"));
    } else if (loanPolicy.isNotRenewable()) {
        errors.add(loanPolicyValidationError(loanPolicy, "loan is not renewable"));
    }
    if (isHold(firstRequest)) {
        if (!loanPolicy.isHoldRequestRenewable()) {
            errors.add(loanPolicyValidationError(loanPolicy, CAN_NOT_RENEW_ITEM_ERROR));
        }
        if (loanPolicy.isFixed()) {
            if (loanPolicy.hasAlternateRenewalLoanPeriodForHolds()) {
                errors.add(loanPolicyValidationError(loanPolicy, FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD_FOR_HOLDS));
            }
            if (loanPolicy.hasRenewalPeriod()) {
                errors.add(loanPolicyValidationError(loanPolicy, FIXED_POLICY_HAS_ALTERNATE_RENEWAL_PERIOD));
            }
        }
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) RenewalValidator.errorForRecallRequest(org.folio.circulation.resources.RenewalValidator.errorForRecallRequest) Request(org.folio.circulation.domain.Request) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) RenewalValidator.loanPolicyValidationError(org.folio.circulation.resources.RenewalValidator.loanPolicyValidationError) ValidationError(org.folio.circulation.support.http.server.ValidationError) RenewalValidator.itemByIdValidationError(org.folio.circulation.resources.RenewalValidator.itemByIdValidationError)

Aggregations

Request (org.folio.circulation.domain.Request)35 JsonObject (io.vertx.core.json.JsonObject)17 Loan (org.folio.circulation.domain.Loan)12 Result (org.folio.circulation.support.results.Result)11 Item (org.folio.circulation.domain.Item)10 ZonedDateTime (java.time.ZonedDateTime)9 List (java.util.List)9 Map (java.util.Map)9 ValidationError (org.folio.circulation.support.http.server.ValidationError)9 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)9 HashMap (java.util.HashMap)8 UUID (java.util.UUID)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 RequestAndRelatedRecords (org.folio.circulation.domain.RequestAndRelatedRecords)8 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)8 Clients (org.folio.circulation.support.Clients)8 Collection (java.util.Collection)7 Collectors (java.util.stream.Collectors)7 ItemRepository (org.folio.circulation.infrastructure.storage.inventory.ItemRepository)7 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)7