Search in sources :

Example 1 with ScheduledNoticeContext

use of org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext in project mod-circulation by folio-org.

the class GroupedLoanScheduledNoticeHandler method handleDataCollectionFailure.

protected CompletableFuture<Result<ScheduledNoticeContext>> handleDataCollectionFailure(Result<ScheduledNoticeContext> result, ScheduledNotice notice) {
    if (result.failed()) {
        HttpFailure cause = result.cause();
        log.error("Failed to collect data for scheduled notice: {}.\n{}", cause, notice);
        return loanScheduledNoticeHandler.deleteNotice(notice, cause.toString()).thenApply(r -> r.next(n -> result));
    }
    return completedFuture(result);
}
Also used : Clients(org.folio.circulation.support.Clients) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) AsyncCoordinationUtil.allResultsOf(org.folio.circulation.support.AsyncCoordinationUtil.allResultsOf) HttpFailure(org.folio.circulation.support.HttpFailure) ScheduledPatronNoticeService(org.folio.circulation.domain.notice.ScheduledPatronNoticeService) Logger(org.slf4j.Logger) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) User(org.folio.circulation.domain.User) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) NoticeLogContextItem(org.folio.circulation.domain.representations.logs.NoticeLogContextItem) TemplateContextUtil.createMultiLoanNoticeContext(org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext) Predicate.not(java.util.function.Predicate.not) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) HttpFailure(org.folio.circulation.support.HttpFailure)

Example 2 with ScheduledNoticeContext

use of org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext in project mod-circulation by folio-org.

the class GroupedLoanScheduledNoticeHandler method sendGroupedNotice.

private CompletableFuture<Result<List<ScheduledNoticeContext>>> sendGroupedNotice(List<ScheduledNoticeContext> contexts) {
    if (contexts.isEmpty()) {
        log.warn("No notices left in the group to process, skipping the group");
        return completedFuture(succeeded(contexts));
    }
    List<ScheduledNoticeContext> relevantContexts = contexts.stream().filter(not(loanScheduledNoticeHandler::isNoticeIrrelevant)).collect(toList());
    if (relevantContexts.isEmpty()) {
        log.warn("No relevant notices in the group, skipping the group");
        return completedFuture(succeeded(contexts));
    }
    // All the notices have the same properties so we can get any of them
    ScheduledNoticeContext contextSample = relevantContexts.get(0);
    User user = contextSample.getLoan().getUser();
    List<Loan> loans = relevantContexts.stream().map(ScheduledNoticeContext::getLoan).collect(toList());
    log.info("Attempting to send a grouped notice for {} scheduled notices", relevantContexts.size());
    return patronNoticeService.sendNotice(contextSample.getNotice().getConfiguration(), user.getId(), createMultiLoanNoticeContext(user, loans), buildNoticeLogContext(relevantContexts, user)).thenApply(mapResult(v -> contexts));
}
Also used : Clients(org.folio.circulation.support.Clients) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) AsyncCoordinationUtil.allResultsOf(org.folio.circulation.support.AsyncCoordinationUtil.allResultsOf) HttpFailure(org.folio.circulation.support.HttpFailure) ScheduledPatronNoticeService(org.folio.circulation.domain.notice.ScheduledPatronNoticeService) Logger(org.slf4j.Logger) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) User(org.folio.circulation.domain.User) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) NoticeLogContextItem(org.folio.circulation.domain.representations.logs.NoticeLogContextItem) TemplateContextUtil.createMultiLoanNoticeContext(org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext) Predicate.not(java.util.function.Predicate.not) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) User(org.folio.circulation.domain.User) Loan(org.folio.circulation.domain.Loan) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext)

Aggregations

MethodHandles (java.lang.invoke.MethodHandles)2 ZonedDateTime (java.time.ZonedDateTime)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 Predicate.not (java.util.function.Predicate.not)2 Collectors.toList (java.util.stream.Collectors.toList)2 Loan (org.folio.circulation.domain.Loan)2 User (org.folio.circulation.domain.User)2 ScheduledPatronNoticeService (org.folio.circulation.domain.notice.ScheduledPatronNoticeService)2 TemplateContextUtil.createMultiLoanNoticeContext (org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext)2 ScheduledNoticeContext (org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext)2 NoticeLogContext (org.folio.circulation.domain.representations.logs.NoticeLogContext)2 NoticeLogContextItem (org.folio.circulation.domain.representations.logs.NoticeLogContextItem)2 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)2 AsyncCoordinationUtil.allOf (org.folio.circulation.support.AsyncCoordinationUtil.allOf)2 AsyncCoordinationUtil.allResultsOf (org.folio.circulation.support.AsyncCoordinationUtil.allResultsOf)2 Clients (org.folio.circulation.support.Clients)2 HttpFailure (org.folio.circulation.support.HttpFailure)2 Result (org.folio.circulation.support.results.Result)2