Search in sources :

Example 6 with Loan

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());
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test)

Example 7 with Loan

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)));
}
Also used : Loan(org.folio.circulation.domain.Loan) Test(org.junit.jupiter.api.Test)

Example 8 with Loan

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);
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UpdateItem(org.folio.circulation.domain.UpdateItem) Item(org.folio.circulation.domain.Item) CompletableFuture(java.util.concurrent.CompletableFuture) Loan(org.folio.circulation.domain.Loan) UpdateLoan(org.folio.circulation.domain.UpdateLoan) ZonedDateTime(java.time.ZonedDateTime) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with Loan

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);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) DeclareItemLostRequest(org.folio.circulation.domain.representations.DeclareItemLostRequest) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) LostItemFeeChargingService(org.folio.circulation.services.LostItemFeeChargingService) RoutingContext(io.vertx.ext.web.RoutingContext) Function(java.util.function.Function) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) NoteCreator(org.folio.circulation.domain.notes.NoteCreator) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) StringUtils.defaultIfBlank(org.apache.commons.lang.StringUtils.defaultIfBlank) CompletionStage(java.util.concurrent.CompletionStage) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) WebContext(org.folio.circulation.support.http.server.WebContext) EventPublisher(org.folio.circulation.services.EventPublisher) Clients(org.folio.circulation.support.Clients)

Example 10 with Loan

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))));
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) Clients(org.folio.circulation.support.Clients) DeclareItemLostRequest(org.folio.circulation.domain.representations.DeclareItemLostRequest) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) WebContext(org.folio.circulation.support.http.server.WebContext) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) Router(io.vertx.ext.web.Router) CompletableFuture(java.util.concurrent.CompletableFuture) ValidationErrorFailure.singleValidationError(org.folio.circulation.support.ValidationErrorFailure.singleValidationError) LostItemFeeChargingService(org.folio.circulation.services.LostItemFeeChargingService) RoutingContext(io.vertx.ext.web.RoutingContext) Function(java.util.function.Function) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) LoanValidator(org.folio.circulation.domain.validation.LoanValidator) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) LostItemFeeRefundService(org.folio.circulation.services.LostItemFeeRefundService) NoteCreator(org.folio.circulation.domain.notes.NoteCreator) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Loan(org.folio.circulation.domain.Loan) MappingFunctions.toFixedValue(org.folio.circulation.support.results.MappingFunctions.toFixedValue) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) EventPublisher(org.folio.circulation.services.EventPublisher) StringUtils.defaultIfBlank(org.apache.commons.lang.StringUtils.defaultIfBlank) CompletionStage(java.util.concurrent.CompletionStage) StoreLoanAndItem(org.folio.circulation.StoreLoanAndItem) NoContentResponse(org.folio.circulation.support.http.server.NoContentResponse) HttpClient(io.vertx.core.http.HttpClient) NotesRepository(org.folio.circulation.infrastructure.storage.notes.NotesRepository) NoteCreator(org.folio.circulation.domain.notes.NoteCreator)

Aggregations

Loan (org.folio.circulation.domain.Loan)133 ZonedDateTime (java.time.ZonedDateTime)89 Test (org.junit.jupiter.api.Test)77 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)70 RequestQueue (org.folio.circulation.domain.RequestQueue)48 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)39 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)39 JsonObject (io.vertx.core.json.JsonObject)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)30 Result (org.folio.circulation.support.results.Result)26 CompletableFuture (java.util.concurrent.CompletableFuture)23 Result.succeeded (org.folio.circulation.support.results.Result.succeeded)21 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)20 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)19 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)19 UserRepository (org.folio.circulation.infrastructure.storage.users.UserRepository)17 RoutingContext (io.vertx.ext.web.RoutingContext)15 Clients (org.folio.circulation.support.Clients)15 HttpClient (io.vertx.core.http.HttpClient)14