Search in sources :

Example 6 with Request

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

the class ReorderRequestContext method getReorderRequestToRequestMap.

/**
 * Returns Map of pairs where key is ReorderedRequest and value is Request from the queue.
 *
 * @return Map of pairs ReorderRequest - Request.
 */
public Map<ReorderRequest, Request> getReorderRequestToRequestMap() {
    final Map<ReorderRequest, Request> reorderRequestToRequestMap = new HashMap<>();
    reorderQueueRequest.getReorderedQueue().forEach(reorderRequest -> {
        Request relatedRequest = requestQueue.getRequests().stream().filter(request -> request.getId().equals(reorderRequest.getId())).findAny().orElse(null);
        reorderRequestToRequestMap.put(reorderRequest, relatedRequest);
    });
    return reorderRequestToRequestMap;
}
Also used : ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest) HashMap(java.util.HashMap) ReorderQueueRequest(org.folio.circulation.domain.reorder.ReorderQueueRequest) Request(org.folio.circulation.domain.Request) ReorderRequest(org.folio.circulation.domain.reorder.ReorderRequest)

Example 7 with Request

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

the class RenewalResource method validateIfRenewIsAllowedAndDueDateNotRequired.

private List<ValidationError> validateIfRenewIsAllowedAndDueDateNotRequired(Loan loan, RequestQueue requestQueue) {
    final List<ValidationError> errors = new ArrayList<>();
    final LoanPolicy loanPolicy = loan.getLoanPolicy();
    final Request firstRequest = getFirstRequestInQueue(requestQueue);
    if (hasRecallRequest(firstRequest)) {
        errors.add(errorForRecallRequest("items cannot be renewed when there is an active recall request", firstRequest.getId()));
    }
    if (ITEM_STATUSES_DISALLOWED_FOR_RENEW.contains(loan.getItemStatus())) {
        errors.add(itemByIdValidationError("item is " + loan.getItemStatusName(), loan.getItemId()));
    }
    if (loanPolicy.hasReachedRenewalLimit(loan)) {
        errors.add(loanPolicyValidationError(loanPolicy, "loan at maximum renewal number"));
    }
    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)

Example 8 with Request

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

the class RequestScheduledNoticeHandler method isNoticeNotRelevantYet.

private static boolean isNoticeNotRelevantYet(ScheduledNoticeContext context) {
    Request request = context.getRequest();
    ScheduledNotice notice = context.getNotice();
    return notice.getConfiguration().getTiming() == UPON_AT && request.isOpen() && !(notice.getTriggeringEvent() == HOLD_EXPIRATION && request.isNotYetFilled());
}
Also used : Request(org.folio.circulation.domain.Request)

Example 9 with Request

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

the class RequestScheduledNoticeHandler method updateNotice.

@Override
protected CompletableFuture<Result<ScheduledNotice>> updateNotice(ScheduledNoticeContext context) {
    Request request = context.getRequest();
    ScheduledNotice notice = context.getNotice();
    boolean isNoticeNonRecurring = !notice.getConfiguration().isRecurring();
    if (isNoticeNotRelevantYet(context)) {
        return ofAsync(() -> notice);
    }
    if (request.isClosed() || isNoticeNonRecurring || isNoticeNoLongerRelevant(context)) {
        return deleteNoticeAsIrrelevant(notice);
    }
    ScheduledNotice nextRecurringNotice = updateNoticeNextRunTime(notice);
    return nextRecurringNoticeIsNotRelevant(nextRecurringNotice, request) ? deleteNoticeAsIrrelevant(notice) : scheduledNoticesRepository.update(nextRecurringNotice);
}
Also used : Request(org.folio.circulation.domain.Request)

Example 10 with Request

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

the class RequestScheduledNoticeService method scheduleRequestNotices.

public Result<RequestAndRelatedRecords> scheduleRequestNotices(RequestAndRelatedRecords relatedRecords) {
    Request request = relatedRecords.getRequest();
    if (request.isClosed()) {
        return succeeded(relatedRecords);
    }
    RequestLevel requestLevel = relatedRecords.getRequest().getRequestLevel();
    if (requestLevel == TITLE) {
        scheduleTlrRequestNotices(relatedRecords.getRequest());
    } else if (requestLevel == ITEM) {
        scheduleRequestNotices(relatedRecords.getRequest());
    }
    return succeeded(relatedRecords);
}
Also used : RequestLevel(org.folio.circulation.domain.RequestLevel) Request(org.folio.circulation.domain.Request)

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