use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class OverrideRenewalTest method shouldUseCalculatedDateWhenItemLostAndNewDateIsAfterCurrent.
@Test
void shouldUseCalculatedDateWhenItemLostAndNewDateIsAfterCurrent() {
final ZonedDateTime estimatedDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
final Loan loan = createLoanWithDefaultPolicy().withItem(createDeclaredLostItem());
final Result<Loan> renewedLoan = renew(loan, null);
assertDueDateWithinOneSecondAfter(estimatedDueDate, renewedLoan);
assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class OverrideRenewalTest method overrideDateIsRequiredWhenCurrentDueDateIsAfterCalculated.
@Test
void overrideDateIsRequiredWhenCurrentDueDateIsAfterCalculated() {
final Loan loan = createLoanWithDueDateAfterCalculated();
final Result<Loan> renewedLoan = renew(loan, null);
assertThat(renewedLoan, hasValidationError(hasMessage(NEW_DUE_DATE_IS_REQUIRED_ERROR)));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method getLoanItems.
private CompletableFuture<Result<Map<Item, ZonedDateTime>>> getLoanItems(InstanceRequestRelatedRecords instanceRequestPackage, LoanRepository loanRepository) {
final List<Item> unsortedUnavailableItems = instanceRequestPackage.getUnsortedUnavailableItems();
if (unsortedUnavailableItems == null || unsortedUnavailableItems.isEmpty()) {
return CompletableFuture.completedFuture(succeeded(null));
}
Map<Item, CompletableFuture<Result<Loan>>> itemLoanFuturesMap = new HashMap<>();
// Find request queues and loan items for each item
for (Item item : unsortedUnavailableItems) {
itemLoanFuturesMap.put(item, loanRepository.findOpenLoanForItem(item));
}
final Collection<CompletableFuture<Result<Loan>>> loanFutures = itemLoanFuturesMap.values();
return CompletableFuture.allOf(loanFutures.toArray(new CompletableFuture[0])).thenApply(dd -> {
Map<Item, ZonedDateTime> itemDueDateMap = new HashMap<>();
List<Item> itemsWithoutLoansList = new ArrayList<>();
for (Map.Entry<Item, CompletableFuture<Result<Loan>>> entry : itemLoanFuturesMap.entrySet()) {
Result<Loan> aLoanResult = entry.getValue().join();
if (aLoanResult.succeeded() && aLoanResult.value() != null) {
itemDueDateMap.put(aLoanResult.value().getItem(), aLoanResult.value().getDueDate());
} else {
itemsWithoutLoansList.add(entry.getKey());
}
}
instanceRequestPackage.setItemsWithoutLoans(itemsWithoutLoansList);
return succeeded(itemDueDateMap);
});
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class DeclareLostResource method declareLost.
private void declareLost(RoutingContext routingContext) {
final WebContext context = new WebContext(routingContext);
final Clients clients = Clients.create(context, client);
final EventPublisher eventPublisher = new EventPublisher(routingContext);
validateDeclaredLostRequest(routingContext).after(request -> declareItemLost(request, clients, context)).thenComposeAsync(r -> r.after(loan -> publishEvent(loan, eventPublisher))).thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))).thenAccept(context::writeResultToHttpResponse);
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class DeclareLostResource method declareItemLostWhenClaimedReturned.
private CompletableFuture<Result<Loan>> declareItemLostWhenClaimedReturned(Loan loan, DeclareItemLostRequest request, Clients clients) {
final NotesRepository notesRepository = NotesRepository.createUsing(clients);
final NoteCreator creator = new NoteCreator(notesRepository);
return ofAsync(() -> declareItemLost(loan, request)).thenCompose(r -> r.after(l -> creator.createGeneralUserNote(loan.getUserId(), "Claimed returned item marked declared lost"))).thenCompose(r -> r.after(note -> completedFuture(succeeded(loan))));
}
Aggregations