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);
}
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));
}
Aggregations