Search in sources :

Example 16 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.

the class RequestsAPICreationTests method requestCreationDoesNotFailWhenCirculationRulesReferenceInvalidNoticePolicyId.

@Test
void requestCreationDoesNotFailWhenCirculationRulesReferenceInvalidNoticePolicyId() {
    UUID invalidNoticePolicyId = UUID.randomUUID();
    IndividualResource record = noticePoliciesFixture.create(new NoticePolicyBuilder().withId(invalidNoticePolicyId).withName("Example NoticePolicy"));
    setInvalidNoticePolicyReferenceInRules(invalidNoticePolicyId.toString());
    noticePoliciesFixture.delete(record);
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource createdRequest = requestsFixture.place(new RequestBuilder().open().page().forItem(smallAngryPlanet).by(steve).withRequestDate(ClockUtil.getZonedDateTime()).fulfilToHoldShelf().withPickupServicePointId(servicePointsFixture.cd1().getId()));
    assertThat(createdRequest.getResponse(), hasStatus(HTTP_CREATED));
}
Also used : MoveRequestBuilder(api.support.builders.MoveRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 17 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.

the class RequestsAPICreationTests method recallNoticeToLoanOwnerIsSentForMovedRecallIfDueDateIsNotChanged.

@Test
void recallNoticeToLoanOwnerIsSentForMovedRecallIfDueDateIsNotChanged() {
    UUID recallToLoanOwnerTemplateId = UUID.randomUUID();
    JsonObject recallToLoanOwnerNoticeConfiguration = new NoticeConfigurationBuilder().withTemplateId(recallToLoanOwnerTemplateId).withEventType(ITEM_RECALLED).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with recall notice").withLoanNotices(Collections.singletonList(recallToLoanOwnerNoticeConfiguration));
    LoanPolicyBuilder loanPolicy = new LoanPolicyBuilder().withName("Policy with recall notice").withDescription("Recall configuration has no effect on due date").rolling(Period.weeks(3)).withClosedLibraryDueDateManagement(DueDateManagement.KEEP_THE_CURRENT_DUE_DATE.getValue()).withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(3)).withRecallsRecallReturnInterval(Period.weeks(1));
    useFallbackPolicies(loanPoliciesFixture.create(loanPolicy).getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    UUID pickupServicePointId = servicePointsFixture.cd1().getId();
    List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
    IndividualResource itemToMoveTo = items.get(0);
    IndividualResource itemToMoveFrom = items.get(1);
    IndividualResource requester = usersFixture.rebecca();
    IndividualResource loanOwner = usersFixture.jessica();
    ZonedDateTime loanDate = ZonedDateTime.of(2020, 7, 22, 10, 22, 54, 0, UTC);
    checkOutFixture.checkOutByBarcode(itemToMoveTo, loanOwner, loanDate);
    checkOutFixture.checkOutByBarcode(itemToMoveFrom, loanOwner, loanDate);
    ZonedDateTime requestDate = loanDate.plusDays(1);
    mockClockManagerToReturnFixedDateTime(requestDate);
    IndividualResource recallRequest = requestsFixture.place(new RequestBuilder().withId(UUID.randomUUID()).open().recall().forItem(itemToMoveFrom).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(LocalDate.of(2020, 7, 30)).withHoldShelfExpiration(LocalDate.of(2020, 8, 31)).withPickupServicePointId(pickupServicePointId).withTags(new RequestBuilder.Tags(asList("new", "important"))));
    requestsFixture.move(new MoveRequestBuilder(recallRequest.getId(), itemToMoveTo.getId(), RECALL.getValue()));
    // Recall notice to loan owner should be sent twice without changing due date
    verifyNumberOfSentNotices(2);
    verifyNumberOfPublishedEvents(NOTICE, 2);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : MoveRequestBuilder(api.support.builders.MoveRequestBuilder) MoveRequestBuilder(api.support.builders.MoveRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 18 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.

the class RequestsAPICreationTests method holdRequestNoticeIsSentWhenPolicyDefinesHoldRequestNoticeConfiguration.

@Test
void holdRequestNoticeIsSentWhenPolicyDefinesHoldRequestNoticeConfiguration() {
    UUID holdConfirmationTemplateId = UUID.randomUUID();
    JsonObject holdConfirmationConfiguration = new NoticeConfigurationBuilder().withTemplateId(holdConfirmationTemplateId).withEventType(HOLD_REQUEST_EVENT).create();
    JsonObject recallConfirmationConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withEventType(RECALL_REQUEST_EVENT).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with hold notice").withLoanNotices(Arrays.asList(holdConfirmationConfiguration, recallConfirmationConfiguration));
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    UUID id = UUID.randomUUID();
    UUID pickupServicePointId = servicePointsFixture.cd1().getId();
    ItemBuilder itemBuilder = ItemExamples.basedUponSmallAngryPlanet(materialTypesFixture.book().getId(), loanTypesFixture.canCirculate().getId());
    HoldingBuilder holdingBuilder = itemsFixture.applyCallNumberHoldings("CN", "Prefix", "Suffix", Collections.singletonList("CopyNumbers"));
    ItemResource item = itemsFixture.basedUponSmallAngryPlanet(itemBuilder, holdingBuilder);
    IndividualResource requester = usersFixture.steve();
    ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
    checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
    IndividualResource request = requestsFixture.place(new RequestBuilder().withId(id).open().hold().forItem(item).by(requester).withRequestDate(requestDate).fulfilToHoldShelf().withRequestExpiration(LocalDate.of(2017, 7, 30)).withHoldShelfExpiration(LocalDate.of(2017, 8, 31)).withPickupServicePointId(pickupServicePointId).withTags(new RequestBuilder.Tags(asList("new", "important"))));
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    Map<String, Matcher<String>> noticeContextMatchers = new HashMap<>();
    noticeContextMatchers.putAll(TemplateContextMatchers.getUserContextMatchers(requester));
    noticeContextMatchers.putAll(TemplateContextMatchers.getItemContextMatchers(item, true));
    noticeContextMatchers.putAll(TemplateContextMatchers.getRequestContextMatchers(request));
    assertThat(FakeModNotify.getSentPatronNotices(), hasItems(hasEmailNoticeProperties(requester.getId(), holdConfirmationTemplateId, noticeContextMatchers)));
}
Also used : MoveRequestBuilder(api.support.builders.MoveRequestBuilder) RequestBuilder(api.support.builders.RequestBuilder) Matcher(org.hamcrest.Matcher) HashMap(java.util.HashMap) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.emptyString(org.hamcrest.Matchers.emptyString) HoldingBuilder(api.support.builders.HoldingBuilder) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ItemBuilder(api.support.builders.ItemBuilder) ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) UUID(java.util.UUID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 19 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.

the class RequestsAPICreationTests method itemCheckOutRecallRequestCreationShouldProduceNotice.

@Test
void itemCheckOutRecallRequestCreationShouldProduceNotice() {
    configurationsFixture.enableTlrFeature();
    JsonObject recallToLoaneeConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withEventType(NoticeEventType.ITEM_RECALLED.getRepresentation()).create();
    JsonObject recallRequestToRequesterConfiguration = new NoticeConfigurationBuilder().withTemplateId(UUID.randomUUID()).withEventType(NoticeEventType.RECALL_REQUEST.getRepresentation()).create();
    NoticePolicyBuilder noticePolicy = new NoticePolicyBuilder().withName("Policy with recall notice").withLoanNotices(List.of(recallToLoaneeConfiguration, recallRequestToRequesterConfiguration));
    useFallbackPolicies(loanPoliciesFixture.canCirculateRolling().getId(), requestPoliciesFixture.allowAllRequestPolicy().getId(), noticePoliciesFixture.create(noticePolicy).getId(), overdueFinePoliciesFixture.facultyStandard().getId(), lostItemFeePoliciesFixture.facultyStandard().getId());
    ItemResource item = itemsFixture.basedUponSmallAngryPlanet();
    IndividualResource requester = usersFixture.steve();
    ZonedDateTime requestDate = ZonedDateTime.of(2017, 7, 22, 10, 22, 54, 0, UTC);
    checkOutFixture.checkOutByBarcode(item, usersFixture.jessica());
    requestsFixture.placeItemLevelHoldShelfRequest(item, requester, requestDate, "Recall");
    // notice for the recall is expected
    verifyNumberOfSentNotices(2);
    verifyNumberOfPublishedEvents(NOTICE, 2);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    List<JsonObject> noticeLogContextItemLogs = FakePubSub.getPublishedEventsAsList(byLogEventType(NOTICE));
    // verify noticeLogContextItemLogs
    validateNoticeLogContextItem(noticeLogContextItemLogs.get(0), item);
    validateNoticeLogContextItem(noticeLogContextItemLogs.get(1), item);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 20 with NoticePolicyBuilder

use of api.support.builders.NoticePolicyBuilder in project mod-circulation by folio-org.

the class OverdueFineScheduledNoticesProcessingTests method generateOverdueFine.

private void generateOverdueFine(TriggeringEvent triggeringEvent, JsonObject... patronNoticeConfigs) {
    NoticePolicyBuilder noticePolicyBuilder = new NoticePolicyBuilder().withName("Patron notice policy with fee/fine notices").withFeeFineNotices(Arrays.asList(patronNoticeConfigs));
    use(noticePolicyBuilder);
    templateFixture.createDummyNoticeTemplate(TEMPLATE_IDS.get(UPON_AT));
    templateFixture.createDummyNoticeTemplate(TEMPLATE_IDS.get(AFTER));
    UUID checkInServicePointId = servicePointsFixture.cd1().getId();
    IndividualResource location = locationsFixture.basedUponExampleLocation(builder -> builder.withPrimaryServicePoint(checkInServicePointId));
    IndividualResource user = usersFixture.james();
    userId = user.getId();
    IndividualResource item = itemsFixture.basedUponNod(builder -> builder.withPermanentLocation(location.getId()));
    itemId = item.getId();
    JsonObject servicePointOwner = new JsonObject().put("value", checkInServicePointId.toString()).put("label", "Service Desk 1");
    feeFineOwnersClient.create(new FeeFineOwnerBuilder().withId(randomUUID()).withOwner("test owner").withServicePointOwner(Collections.singletonList(servicePointOwner)));
    feeFinesClient.create(new FeeFineBuilder().withId(randomUUID()).withFeeFineType(OVERDUE_FINE).withAutomatic(true));
    final ZonedDateTime checkOutDate = ClockUtil.getZonedDateTime().minusYears(1);
    final ZonedDateTime checkInDate = checkOutDate.plusMonths(1);
    IndividualResource checkOutResponse = checkOutFixture.checkOutByBarcode(item, user, checkOutDate);
    loanId = UUID.fromString(checkOutResponse.getJson().getString("id"));
    switch(triggeringEvent) {
        case OVERDUE_FINE_RETURNED:
            checkInFixture.checkInByBarcode(new CheckInByBarcodeRequestBuilder().forItem(item).on(checkInDate).at(checkInServicePointId));
            break;
        case OVERDUE_FINE_RENEWED:
            loansFixture.renewLoan(item, user);
            break;
        default:
            break;
    }
    List<JsonObject> accounts = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(accountsClient::getAll, hasSize(1));
    assertThat("Fee/fine record should have been created", accounts, hasSize(1));
    account = Account.from(accounts.get(0));
    accountId = UUID.fromString(account.getId());
    List<JsonObject> actions = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(feeFineActionsClient::getAll, hasSize(1));
    assertThat("Fee/fine action record should have been created", actions, hasSize(1));
    action = FeeFineAction.from(actions.get(0));
    actionId = UUID.fromString(action.getId());
    actionDateTime = action.getDateAction();
}
Also used : FeeFineOwnerBuilder(api.support.builders.FeeFineOwnerBuilder) ZonedDateTime(java.time.ZonedDateTime) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) JsonObject(io.vertx.core.json.JsonObject) FeeFineBuilder(api.support.builders.FeeFineBuilder) CheckInByBarcodeRequestBuilder(api.support.builders.CheckInByBarcodeRequestBuilder) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) IndividualResource(api.support.http.IndividualResource)

Aggregations

NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)73 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)64 Test (org.junit.jupiter.api.Test)63 JsonObject (io.vertx.core.json.JsonObject)58 ZonedDateTime (java.time.ZonedDateTime)53 IndividualResource (api.support.http.IndividualResource)51 UUID (java.util.UUID)47 ItemResource (api.support.http.ItemResource)37 RequestBuilder (api.support.builders.RequestBuilder)28 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)21 CheckInByBarcodeRequestBuilder (api.support.builders.CheckInByBarcodeRequestBuilder)18 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ItemBuilder (api.support.builders.ItemBuilder)11 Period (org.folio.circulation.domain.policy.Period)11 Matcher (org.hamcrest.Matcher)11 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)10 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)9 HashMap (java.util.HashMap)9 lombok.val (lombok.val)8