use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class ItemLevelRequestNoticeSender method sendNoticeOnRequestCreated.
@Override
public Result<RequestAndRelatedRecords> sendNoticeOnRequestCreated(RequestAndRelatedRecords relatedRecords) {
Request request = relatedRecords.getRequest();
Item item = request.getItem();
NoticeEventType eventType = requestTypeToEventMap.getOrDefault(request.getRequestType(), NoticeEventType.UNKNOWN);
PatronNoticeEvent requestCreatedEvent = createPatronNoticeEvent(request, eventType).withItem(item);
patronNoticeService.acceptNoticeEvent(requestCreatedEvent);
Loan loan = request.getLoan();
if (request.getRequestType() == RequestType.RECALL && loan != null) {
sendNoticeOnItemRecalledEvent(loan);
sendLogEvent(loan);
}
return Result.succeeded(relatedRecords);
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RenewByIdResource method findLoan.
@Override
protected CompletableFuture<Result<Loan>> findLoan(JsonObject request, LoanRepository loanRepository, ItemRepository itemRepository, UserRepository userRepository, CirculationErrorHandler errorHandler) {
final Result<RenewByIdRequest> requestResult = RenewByIdRequest.from(request);
final String itemId = requestResult.map(RenewByIdRequest::getItemId).orElse("unknown item ID");
final SingleOpenLoanForItemInStorageFinder singleOpenLoanFinder = new SingleOpenLoanForItemInStorageFinder(loanRepository, userRepository, false);
final ItemByIdInStorageFinder itemFinder = new ItemByIdInStorageFinder(itemRepository, noItemFoundForIdFailure(itemId));
return completedFuture(requestResult).thenCompose(r -> lookupItem(itemFinder, itemId, errorHandler)).thenCompose(r -> r.after(item -> lookupLoan(singleOpenLoanFinder, item, errorHandler))).thenApply(r -> r.next(loan -> refuseWhenUserNotFound(loan, errorHandler))).thenApply(r -> r.next(loan -> refuseWhenUserDoesNotMatch(loan, requestResult.value(), errorHandler)));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RenewalResource method validateIfRenewIsPossible.
private Result<RenewalContext> validateIfRenewIsPossible(RenewalContext context) {
Loan loan = context.getLoan();
if (ITEM_STATUSES_NOT_POSSIBLE_TO_RENEW.contains(loan.getItemStatus())) {
final List<ValidationError> errors = new ArrayList<>();
errors.add(itemByIdValidationError("item is " + loan.getItemStatusName(), loan.getItemId()));
return failedValidation(errors);
}
return succeeded(context);
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RenewalResource method unsetDueDateChangedByRecallIfNoOpenRecallsInQueue.
private RenewalContext unsetDueDateChangedByRecallIfNoOpenRecallsInQueue(RenewalContext renewalContext) {
Loan loan = renewalContext.getLoan();
RequestQueue queue = renewalContext.getRequestQueue();
if (loan.wasDueDateChangedByRecall() && !queue.hasOpenRecalls()) {
return renewalContext.withLoan(loan.unsetDueDateChangedByRecall());
} else {
return renewalContext;
}
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RenewalResource method renew.
private Result<RenewalContext> renew(RenewalContext context, ZonedDateTime renewDate) {
final var loan = context.getLoan();
final var requestQueue = context.getRequestQueue();
final var loanPolicy = loan.getLoanPolicy();
final Result<ZonedDateTime> proposedDueDateResult = calculateNewDueDate(loan, requestQueue, renewDate);
final List<ValidationError> errors = new ArrayList<>();
addErrorsIfDueDateResultFailed(loan, errors, proposedDueDateResult);
if (errors.isEmpty()) {
final BlockOverrides blockOverrides = BlockOverrides.from(getObjectProperty(context.getRenewalRequest(), "overrideBlocks"));
if (!blockOverrides.getPatronBlockOverride().isRequested() && !blockOverrides.getRenewalBlockOverride().isRequested()) {
return proposedDueDateResult.map(dueDate -> loan.renew(dueDate, loanPolicy.getId())).map(l -> context);
}
return proposedDueDateResult.map(dueDate -> loan.overrideRenewal(dueDate, loanPolicy.getId(), blockOverrides.getComment())).map(l -> context);
}
return failedValidation(errors);
}
Aggregations