use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FeeFineScheduledNoticeHandler method buildNoticeLogContext.
@Override
protected NoticeLogContext buildNoticeLogContext(ScheduledNoticeContext context) {
Loan loan = context.getLoan();
ScheduledNotice notice = context.getNotice();
NoticeLogContextItem logContextItem = NoticeLogContextItem.from(loan).withTemplateId(notice.getConfiguration().getTemplateId()).withTriggeringEvent(notice.getTriggeringEvent().getRepresentation()).withNoticePolicyId(context.getPatronNoticePolicyId());
return new NoticeLogContext().withUser(loan.getUser()).withAccountId(context.getAccount().getId()).withItems(singletonList(logContextItem));
}
use of org.folio.circulation.domain.Loan 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));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class PatronActionSessionService method discardInvalidSessions.
private List<PatronSessionRecord> discardInvalidSessions(List<PatronSessionRecord> sessions) {
List<PatronSessionRecord> validSessions = new ArrayList<>();
for (PatronSessionRecord session : sessions) {
Loan loan = session.getLoan();
String errorMessage = null;
if (loan == null) {
errorMessage = "referenced loan was not found";
} else {
if (loan.getItem() == null || loan.getItem().isNotFound()) {
errorMessage = "referenced item was not found";
}
if (loan.getUser() == null) {
errorMessage = "referenced user was not found";
}
}
if (errorMessage != null) {
errorMessage += ". " + session;
log.error("Failed to send notice for patron action session: {}", errorMessage);
publishNoticeErrorEvent(singletonList(session), errorMessage);
} else {
validSessions.add(session);
}
}
if (validSessions.size() < sessions.size()) {
log.warn("{} session(s) are invalid in the group of {} session(s)", sessions.size() - validSessions.size(), sessions.size());
}
return validSessions;
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class PatronActionSessionService method saveCheckInSessionRecord.
public CompletableFuture<Result<CheckInContext>> saveCheckInSessionRecord(CheckInContext context) {
Loan loan = context.getLoan();
if (loan == null) {
log.info("CheckInSessionRecord is not saved, context doesn't have a valid loan.");
return completedFuture(of(() -> context));
}
UUID patronId = UUID.fromString(loan.getUserId());
UUID loanId = UUID.fromString(loan.getId());
PatronSessionRecord patronSessionRecord = new PatronSessionRecord(UUID.randomUUID(), patronId, loanId, PatronActionType.CHECK_IN);
return patronActionSessionRepository.create(patronSessionRecord).thenApply(mapResult(v -> context));
}
use of org.folio.circulation.domain.Loan in project mod-circulation by folio-org.
the class FixedLoanPolicyCheckOutDueDateCalculationTests method shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable.
@Test
void shouldFailWhenLoanDateIsAfterOnlyScheduleAvailable() {
LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().fixed(UUID.randomUUID()).withName("Example Fixed Schedule Loan Policy").create()).withDueDateSchedules(new FixedDueDateSchedulesBuilder().addSchedule(FixedDueDateSchedule.wholeYear(2018)).create());
ZonedDateTime loanDate = ZonedDateTime.of(2019, 1, 1, 8, 10, 45, 0, UTC);
Loan loan = loanFor(loanDate);
final Result<ZonedDateTime> result = loanPolicy.calculateInitialDueDate(loan, null);
assertThat(result, hasValidationFailure("loan date falls outside of the date ranges in the loan policy"));
}
Aggregations