Search in sources :

Example 1 with Period

use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.

the class LostItemFeePoliciesFixture method facultyStandardPolicy.

public LostItemFeePolicyBuilder facultyStandardPolicy() {
    final Period itemAgedLostOverdue = Period.months(12);
    final Period patronBilledAfterAgedLost = Period.months(12);
    return new LostItemFeePolicyBuilder().withName("Undergrad standard").withDescription("This is description for undergrad standard").withItemAgedToLostAfterOverdue(itemAgedLostOverdue).withPatronBilledAfterItemAgedToLost(patronBilledAfterAgedLost).withNoChargeAmountItem().doNotChargeProcessingFeeWhenDeclaredLost().withChargeAmountItemSystem(true).refundProcessingFeeWhenReturned().withReplacedLostItemProcessingFee(true).withReplacementAllowed(true).chargeOverdueFineWhenReturned();
}
Also used : LostItemFeePolicyBuilder(api.support.builders.LostItemFeePolicyBuilder) Period(org.folio.circulation.domain.policy.Period)

Example 2 with Period

use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.

the class FeeFineScheduledNoticeHandler method getNextRecurringNotice.

private static ScheduledNotice getNextRecurringNotice(ScheduledNotice notice) {
    Period recurringPeriod = notice.getConfiguration().getRecurringPeriod();
    ZonedDateTime nextRunTime = recurringPeriod.plusDate(notice.getNextRunTime());
    ZonedDateTime now = getZonedDateTime();
    if (isBeforeMillis(nextRunTime, now)) {
        nextRunTime = recurringPeriod.plusDate(now);
    }
    return notice.withNextRunTime(nextRunTime);
}
Also used : ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Period(org.folio.circulation.domain.policy.Period)

Example 3 with Period

use of org.folio.circulation.domain.policy.Period 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);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) JsonObjectMatcher.toStringMatcher(api.support.matchers.JsonObjectMatcher.toStringMatcher) Arrays(java.util.Arrays) ZonedDateTime(java.time.ZonedDateTime) APITests(api.support.APITests) FakePubSub(api.support.fakes.FakePubSub) PatronNoticeTestHelper.verifyNumberOfScheduledNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfScheduledNotices) DateFormatUtil.parseDateTime(org.folio.circulation.support.utils.DateFormatUtil.parseDateTime) Pair(org.apache.commons.lang3.tuple.Pair) IndividualResource(api.support.http.IndividualResource) Period(org.folio.circulation.domain.policy.Period) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ZoneOffset(java.time.ZoneOffset) DateTimeUtil.isSameMillis(org.folio.circulation.support.utils.DateTimeUtil.isSameMillis) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) DateFormatUtil(org.folio.circulation.support.utils.DateFormatUtil) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) DateTimeUtil.atStartOfDay(org.folio.circulation.support.utils.DateTimeUtil.atStartOfDay) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals(api.support.fixtures.TemplateContextMatchers.getLoanPolicyContextMatchersForUnlimitedRenewals) TemplateContextMatchers.getMultipleLoansContextMatcher(api.support.fixtures.TemplateContextMatchers.getMultipleLoansContextMatcher) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) UUID(java.util.UUID) UserBuilder(api.support.builders.UserBuilder) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) ConfigurationExample(api.support.fixtures.ConfigurationExample) ZoneId(java.time.ZoneId) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) Test(org.junit.jupiter.api.Test) MatcherAssert(org.hamcrest.MatcherAssert) ClockUtil(org.folio.circulation.support.utils.ClockUtil) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matcher(org.hamcrest.Matcher) Collections(java.util.Collections) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) Period(org.folio.circulation.domain.policy.Period) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 4 with Period

use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.

the class DueDateScheduledNoticesTests method checkOutSchedulesDifferentBeforeDueDateNotices.

@Test
void checkOutSchedulesDifferentBeforeDueDateNotices() {
    UUID firstBeforeTemplateId = UUID.randomUUID();
    Period firstBeforePeriod = Period.weeks(1);
    UUID secondBeforeTemplateId = UUID.randomUUID();
    Period secondBeforePeriod = Period.hours(12);
    JsonObject firstBeforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(firstBeforeTemplateId).withDueDateEvent().withBeforeTiming(firstBeforePeriod).sendInRealTime(false).create();
    JsonObject secondBeforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(secondBeforeTemplateId).withDueDateEvent().withBeforeTiming(secondBeforePeriod).sendInRealTime(true).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with before due date notices").withLoanNotices(Arrays.asList(firstBeforeDueDateNoticeConfiguration, secondBeforeDueDateNoticeConfiguration));
    use(noticePolicy);
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource steve = usersFixture.steve();
    final ZonedDateTime loanDate = ZonedDateTime.of(2018, 3, 18, 11, 43, 54, 0, UTC);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(new CheckOutByBarcodeRequestBuilder().forItem(smallAngryPlanet).to(steve).on(loanDate).at(UUID.randomUUID()));
    ZonedDateTime dueDate = getDateTimeProperty(loan.getJson(), "dueDate");
    verifyNumberOfScheduledNotices(2);
    List<JsonObject> scheduledNotices = scheduledNoticesClient.getAll();
    assertThat(scheduledNotices, hasItems(hasScheduledLoanNotice(loan.getId(), firstBeforePeriod.minusDate(dueDate), BEFORE_TIMING, firstBeforeTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), secondBeforePeriod.minusDate(dueDate), BEFORE_TIMING, secondBeforeTemplateId, null, true)));
}
Also used : CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) Period(org.folio.circulation.domain.policy.Period) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 5 with Period

use of org.folio.circulation.domain.policy.Period in project mod-circulation by folio-org.

the class DueDateScheduledNoticesTests method noticesShouldBeRescheduledAfterRecall.

@Test
void noticesShouldBeRescheduledAfterRecall() {
    UUID beforeTemplateId = UUID.randomUUID();
    Period beforePeriod = Period.days(2);
    Period beforeRecurringPeriod = Period.hours(6);
    UUID uponAtTemplateId = UUID.randomUUID();
    UUID afterTemplateId = UUID.randomUUID();
    Period afterPeriod = Period.days(3);
    Period afterRecurringPeriod = Period.hours(4);
    JsonObject beforeDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(beforeTemplateId).withDueDateEvent().withBeforeTiming(beforePeriod).recurring(beforeRecurringPeriod).sendInRealTime(true).create();
    JsonObject uponAtDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(uponAtTemplateId).withDueDateEvent().withUponAtTiming().sendInRealTime(false).create();
    JsonObject afterDueDateNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(afterTemplateId).withDueDateEvent().withAfterTiming(afterPeriod).recurring(afterRecurringPeriod).sendInRealTime(true).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with due date notices").withLoanNotices(Arrays.asList(beforeDueDateNoticeConfiguration, uponAtDueDateNoticeConfiguration, afterDueDateNoticeConfiguration));
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling for recall").rolling(Period.weeks(3)).withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2));
    use(loanPolicy, noticePolicy);
    IndividualResource item = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource borrower = usersFixture.steve();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(item, borrower);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), usersFixture.jessica());
    verifyNumberOfScheduledNotices(6);
    requestsFixture.place(new RequestBuilder().open().recall().forItem(item).by(usersFixture.james()).withPickupServicePointId(servicePointsFixture.cd1().getId()));
    IndividualResource loanAfterRecall = loansClient.get(loan.getId());
    ZonedDateTime dueDateAfterRecall = getDateTimeProperty(loanAfterRecall.getJson(), "dueDate");
    Matcher<Iterable<JsonObject>> scheduledNoticesAfterRecallMatcher = hasItems(hasScheduledLoanNotice(loan.getId(), beforePeriod.minusDate(dueDateAfterRecall), BEFORE_TIMING, beforeTemplateId, beforeRecurringPeriod, true), hasScheduledLoanNotice(loan.getId(), dueDateAfterRecall, UPON_AT_TIMING, uponAtTemplateId, null, false), hasScheduledLoanNotice(loan.getId(), afterPeriod.plusDate(dueDateAfterRecall), AFTER_TIMING, afterTemplateId, afterRecurringPeriod, true));
    Awaitility.await().atMost(1, TimeUnit.SECONDS).until(scheduledNoticesClient::getAll, scheduledNoticesAfterRecallMatcher);
    verifyNumberOfScheduledNotices(6);
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CheckOutByBarcodeRequestBuilder(api.support.builders.CheckOutByBarcodeRequestBuilder) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) Period(org.folio.circulation.domain.policy.Period) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Aggregations

Period (org.folio.circulation.domain.policy.Period)33 ZonedDateTime (java.time.ZonedDateTime)25 Test (org.junit.jupiter.api.Test)17 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)16 IndividualResource (api.support.http.IndividualResource)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 JsonObject (io.vertx.core.json.JsonObject)14 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)10 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)10 LostItemFeePolicyBuilder (api.support.builders.LostItemFeePolicyBuilder)9 UUID (java.util.UUID)9 CsvSource (org.junit.jupiter.params.provider.CsvSource)8 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)7 RequestBuilder (api.support.builders.RequestBuilder)5 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)4 ItemResource (api.support.http.ItemResource)3 NOTICE (org.folio.circulation.domain.representations.logs.LogEventType.NOTICE)3 NOTICE_ERROR (org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR)3 APITests (api.support.APITests)2 UserBuilder (api.support.builders.UserBuilder)2