use of api.support.builders.NoticeConfigurationBuilder in project mod-circulation by folio-org.
the class PatronActionSessionTests method beforeEach.
@BeforeEach
public void beforeEach() {
JsonObject checkOutNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(CHECK_OUT_NOTICE_TEMPLATE_ID).withCheckOutEvent().create();
JsonObject checkInNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(CHECK_IN_NOTICE_TEMPLATE_ID).withCheckInEvent().create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with check-out notice").withLoanNotices(Arrays.asList(checkOutNoticeConfig, checkInNoticeConfig));
useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
}
use of api.support.builders.NoticeConfigurationBuilder in project mod-circulation by folio-org.
the class RenewalAPITests method renewalNoticeIsNotSentWhenPatronNoticeRequestFails.
@Test
void renewalNoticeIsNotSentWhenPatronNoticeRequestFails() {
UUID renewalTemplateId = UUID.randomUUID();
JsonObject renewalNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(renewalTemplateId).withRenewalEvent().create();
JsonObject checkInNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withCheckInEvent().create();
NoticePolicyBuilder policyWithRenewalNotice = new NoticePolicyBuilder().withName("Policy with renewal notice").withLoanNotices(Arrays.asList(renewalNoticeConfiguration, checkInNoticeConfiguration));
LoanPolicyBuilder limitedRenewalsLoanPolicy = new LoanPolicyBuilder().withName("Limited renewals loan policy").rolling(Period.months(1)).limitedRenewals(3);
use(limitedRenewalsLoanPolicy, policyWithRenewalNotice);
ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId(), StringUtils.EMPTY, "ItemPrefix", "ItemSuffix", "");
ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, itemsFixture.thirdFloorHoldings());
final IndividualResource steve = usersFixture.steve();
final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
loansFixture.renewLoan(smallAngryPlanet, steve);
verifyNumberOfSentNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
use of api.support.builders.NoticeConfigurationBuilder in project mod-circulation by folio-org.
the class DueDateNotRealTimeScheduledNoticesProcessingTests method processingTakesNoticesLimitedByConfiguration.
@Test
void processingTakesNoticesLimitedByConfiguration() {
Period beforePeriod = Period.weeks(1);
JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withBeforeTiming(beforePeriod).sendInRealTime(false).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Collections.singletonList(uponAtDueDateNoticeConfig));
use(noticePolicy);
IndividualResource james = usersFixture.james();
IndividualResource steve = usersFixture.steve();
IndividualResource rebecca = usersFixture.rebecca();
// Generate several loans
for (int i = 0; i < 4; i++) {
String baseBarcode = Integer.toString(i);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(b -> b.withBarcode(baseBarcode + "1")), james);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod((b -> b.withBarcode(baseBarcode + "2"))), steve);
checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod((b -> b.withBarcode(baseBarcode + "3"))), rebecca);
}
verifyNumberOfScheduledNotices(12);
int noticesLimitConfig = 10;
configClient.create(ConfigurationExample.schedulerNoticesLimitConfiguration(Integer.toString(noticesLimitConfig)));
// Should fetch 10 notices, when total records is 12
// So that notices for one of the users should not be processed
final ZonedDateTime runTime = ClockUtil.getZonedDateTime().plusDays(15);
mockClockManagerToReturnFixedDateTime(runTime);
scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(runTime);
long numberOfUniqueUserIds = scheduledNoticesClient.getAll().stream().map(notice -> notice.getString("recipientUserId")).distinct().count();
assertThat(numberOfUniqueUserIds, is(1L));
verifyNumberOfSentNotices(2);
verifyNumberOfScheduledNotices(4);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
use of api.support.builders.NoticeConfigurationBuilder in project mod-circulation by folio-org.
the class DueDateNotRealTimeScheduledNoticesProcessingTests method noticeIsNotSentOrDeletedWhenPatronNoticeRequestFails.
@Test
void noticeIsNotSentOrDeletedWhenPatronNoticeRequestFails() {
JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().sendInRealTime(false).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Collections.singletonList(uponAtDueDateNoticeConfig));
use(noticePolicy);
ZonedDateTime loanDate = ZonedDateTime.of(2019, 8, 23, 10, 30, 0, 0, ZoneOffset.UTC);
IndividualResource james = usersFixture.james();
ItemResource nod = itemsFixture.basedUponNod();
IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(nod, james, loanDate);
verifyNumberOfScheduledNotices(1);
ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
ZonedDateTime afterLoanDueDateTime = dueDate.plusDays(1);
FakeModNotify.setFailPatronNoticesWithBadRequest(true);
scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(afterLoanDueDateTime);
verifyNumberOfSentNotices(0);
verifyNumberOfScheduledNotices(1);
verifyNumberOfPublishedEvents(NOTICE, 0);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 1);
}
use of api.support.builders.NoticeConfigurationBuilder in project mod-circulation by folio-org.
the class DueDateNotRealTimeScheduledNoticesProcessingTests method uponAtDueDateNoticesShouldBeSentInGroups.
@Test
void uponAtDueDateNoticesShouldBeSentInGroups() {
JsonObject uponAtDueDateNoticeConfig = new NoticeConfigurationBuilder().withTemplateId(TEMPLATE_ID).withDueDateEvent().withUponAtTiming().sendInRealTime(false).create();
NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Collections.singletonList(uponAtDueDateNoticeConfig));
use(noticePolicy);
ZonedDateTime loanDate = ZonedDateTime.of(2019, 8, 23, 10, 30, 0, 0, ZoneOffset.UTC);
IndividualResource james = usersFixture.james();
ItemResource nod = itemsFixture.basedUponNod();
ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
IndividualResource nodToJamesLoan = checkOutFixture.checkOutByBarcode(nod, james, loanDate);
IndividualResource interestingTimesToJamesLoan = checkOutFixture.checkOutByBarcode(interestingTimes, james, loanDate);
IndividualResource rebecca = usersFixture.rebecca();
ItemResource temeraire = itemsFixture.basedUponTemeraire();
ItemResource dunkirk = itemsFixture.basedUponDunkirk();
IndividualResource temeraireToRebeccaLoan = checkOutFixture.checkOutByBarcode(temeraire, rebecca, loanDate);
IndividualResource dunkirkToRebeccaLoan = checkOutFixture.checkOutByBarcode(dunkirk, rebecca, loanDate);
verifyNumberOfScheduledNotices(4);
ZonedDateTime dueDate = parseDateTime(nodToJamesLoan.getJson().getString("dueDate"));
ZonedDateTime afterLoanDueDateTime = dueDate.plusDays(1);
scheduledNoticeProcessingClient.runDueDateNotRealTimeNoticesProcessing(afterLoanDueDateTime);
final var loanPolicyMatcher = toStringMatcher(getLoanPolicyContextMatchersForUnlimitedRenewals());
final var noticeToJamesContextMatcher = getMultipleLoansContextMatcher(james, Arrays.asList(Pair.of(nodToJamesLoan, nod), Pair.of(interestingTimesToJamesLoan, interestingTimes)), loanPolicyMatcher);
final var noticeToRebeccaContextMatcher = getMultipleLoansContextMatcher(rebecca, Arrays.asList(Pair.of(temeraireToRebeccaLoan, temeraire), Pair.of(dunkirkToRebeccaLoan, dunkirk)), loanPolicyMatcher);
assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(james.getId(), TEMPLATE_ID, noticeToJamesContextMatcher), hasEmailNoticeProperties(rebecca.getId(), TEMPLATE_ID, noticeToRebeccaContextMatcher)));
verifyNumberOfSentNotices(2);
verifyNumberOfScheduledNotices(0);
verifyNumberOfPublishedEvents(NOTICE, 2);
verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Aggregations