Search in sources :

Example 1 with ACTION_TYPE

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE in project mod-circulation by folio-org.

the class EndPatronSessionRequest method from.

public static List<Result<EndPatronSessionRequest>> from(JsonObject jsonObject) {
    final String END_SESSIONS = "endSessions";
    List<Result<EndPatronSessionRequest>> resultListOfEndPatronSessionRequests = new ArrayList<>();
    JsonArray endSessions = jsonObject.getJsonArray(END_SESSIONS);
    for (int i = 0; i < endSessions.size(); i++) {
        JsonObject endSession = endSessions.getJsonObject(i);
        final String patronIdFromJson = getProperty(endSession, PATRON_ID);
        if (isBlank(patronIdFromJson)) {
            return singletonList(failedValidation("End patron session request must have patron id", PATRON_ID, null));
        }
        String actionTypeRepresentation = getProperty(endSession, ACTION_TYPE);
        if (isBlank(actionTypeRepresentation)) {
            return singletonList(failedValidation("End patron session request must have action type", ACTION_TYPE, null));
        }
        resultListOfEndPatronSessionRequests.add(PatronActionType.from(actionTypeRepresentation).map(patronActionType -> new EndPatronSessionRequest(patronIdFromJson, patronActionType)).map(Result::succeeded).orElse(failedValidation("Invalid patron action type value", ACTION_TYPE, actionTypeRepresentation)));
    }
    return resultListOfEndPatronSessionRequests;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) Getter(lombok.Getter) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) Result(org.folio.circulation.support.results.Result) Collections.singletonList(java.util.Collections.singletonList) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) ArrayList(java.util.ArrayList) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) JsonObject(io.vertx.core.json.JsonObject) AllArgsConstructor(lombok.AllArgsConstructor) JsonPropertyFetcher.getProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getProperty) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Result(org.folio.circulation.support.results.Result)

Example 2 with ACTION_TYPE

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method patronHasSomeSessionsAndOnlySessionsWithSameActionTypeShouldBeExpiredByTimeout.

@Test
void patronHasSomeSessionsAndOnlySessionsWithSameActionTypeShouldBeExpiredByTimeout() {
    IndividualResource james = usersFixture.james();
    ItemResource nod = itemsFixture.basedUponNod();
    ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
    checkOutFixture.checkOutByBarcode(nod, james);
    checkOutFixture.checkOutByBarcode(interestingTimes, james);
    checkInFixture.checkInByBarcode(nod);
    checkInFixture.checkInByBarcode(interestingTimes);
    expiredEndSessionClient.deleteAll();
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(4));
    String patronId = sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_IN.getRepresentation())).findFirst().map(session -> session.getString(PATRON_ID)).orElse("");
    createExpiredEndSession(patronId, CHECK_IN);
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, hasSize(2));
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : IntStream(java.util.stream.IntStream) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) APITests(api.support.APITests) Awaitility.waitAtMost(org.awaitility.Awaitility.waitAtMost) IndividualResource(api.support.http.IndividualResource) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) Wait.waitAtLeast(api.support.Wait.waitAtLeast) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) EndSessionBuilder(api.support.builders.EndSessionBuilder) Matchers.empty(org.hamcrest.Matchers.empty) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) LOAN_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.LOAN_ID) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ID) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemplateContextMatchers(api.support.fixtures.TemplateContextMatchers) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 3 with ACTION_TYPE

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method patronHasSeveralSessionsAndOnlyOneShouldBeExpiredByTimeout.

@Test
void patronHasSeveralSessionsAndOnlyOneShouldBeExpiredByTimeout() {
    IndividualResource james = usersFixture.james();
    ItemResource nod = itemsFixture.basedUponNod();
    ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
    checkOutFixture.checkOutByBarcode(nod, james);
    checkOutFixture.checkOutByBarcode(interestingTimes, james);
    checkInFixture.checkInByBarcode(nod);
    expiredEndSessionClient.deleteAll();
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(3));
    String patronId = sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_IN.getRepresentation())).findFirst().map(session -> session.getString(PATRON_ID)).orElse("");
    createExpiredEndSession(patronId, CHECK_IN);
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, hasSize(2));
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : IntStream(java.util.stream.IntStream) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) APITests(api.support.APITests) Awaitility.waitAtMost(org.awaitility.Awaitility.waitAtMost) IndividualResource(api.support.http.IndividualResource) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) Wait.waitAtLeast(api.support.Wait.waitAtLeast) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) EndSessionBuilder(api.support.builders.EndSessionBuilder) Matchers.empty(org.hamcrest.Matchers.empty) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) LOAN_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.LOAN_ID) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ID) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemplateContextMatchers(api.support.fixtures.TemplateContextMatchers) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 4 with ACTION_TYPE

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method patronNoticeContextContainsUserTokensWhenNoticeIsTriggeredByExpiredSession.

@Test
void patronNoticeContextContainsUserTokensWhenNoticeIsTriggeredByExpiredSession() {
    IndividualResource james = usersFixture.james();
    ItemResource nod = itemsFixture.basedUponNod();
    checkOutFixture.checkOutByBarcode(nod, james);
    patronSessionRecordsClient.getAll().stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_OUT.getRepresentation())).map(session -> session.getString(PATRON_ID)).forEach(patronId -> createExpiredEndSession(patronId, CHECK_OUT));
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, empty());
    verifyNumberOfSentNotices(1);
    verifyNumberOfPublishedEvents(NOTICE, 1);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
    assertThat(FakeModNotify.getFirstSentPatronNotice(), hasEmailNoticeProperties(james.getId(), CHECK_OUT_TEMPLATE_ID, TemplateContextMatchers.getUserContextMatchers(james)));
}
Also used : IntStream(java.util.stream.IntStream) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) APITests(api.support.APITests) Awaitility.waitAtMost(org.awaitility.Awaitility.waitAtMost) IndividualResource(api.support.http.IndividualResource) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) Wait.waitAtLeast(api.support.Wait.waitAtLeast) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) EndSessionBuilder(api.support.builders.EndSessionBuilder) Matchers.empty(org.hamcrest.Matchers.empty) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) LOAN_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.LOAN_ID) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ID) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemplateContextMatchers(api.support.fixtures.TemplateContextMatchers) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Example 5 with ACTION_TYPE

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE in project mod-circulation by folio-org.

the class EndExpiredPatronActionSessionTests method patronsHaveSessionsAndAllShouldBeExpiredByTimeout.

@Test
void patronsHaveSessionsAndAllShouldBeExpiredByTimeout() {
    IndividualResource james = usersFixture.james();
    IndividualResource jessica = usersFixture.jessica();
    IndividualResource steve = usersFixture.steve();
    ItemResource nod = itemsFixture.basedUponNod();
    ItemResource interestingTimes = itemsFixture.basedUponInterestingTimes();
    ItemResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    checkOutFixture.checkOutByBarcode(nod, james);
    checkOutFixture.checkOutByBarcode(interestingTimes, jessica);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve);
    checkInFixture.checkInByBarcode(nod);
    checkInFixture.checkInByBarcode(interestingTimes);
    checkInFixture.checkInByBarcode(smallAngryPlanet);
    expiredEndSessionClient.deleteAll();
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(6));
    sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_IN.getRepresentation())).map(session -> session.getString(PATRON_ID)).forEach(patronId -> createExpiredEndSession(patronId, CHECK_IN));
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtMost(1, SECONDS).until(patronSessionRecordsClient::getAll, hasSize(3));
    expiredEndSessionClient.deleteAll();
    sessions.stream().filter(session -> session.getMap().get(ACTION_TYPE).equals(PatronActionType.CHECK_OUT.getRepresentation())).map(session -> session.getString(PATRON_ID)).forEach(patronId -> createExpiredEndSession(patronId, CHECK_OUT));
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtLeast(1, SECONDS).until(patronSessionRecordsClient::getAll, empty());
    Stream.of(CHECK_OUT_TEMPLATE_ID, CHECK_IN_TEMPLATE_ID).forEach(templateId -> Stream.of(james, jessica, steve).forEach(patron -> FakeModNotify.getSentPatronNotices().stream().filter(pn -> pn.getString("templateId").equals(templateId.toString())).filter(pn -> pn.getString("recipientId").equals(patron.getId().toString())).forEach(patronNotice -> assertThat(patronNotice, hasEmailNoticeProperties(patron.getId(), templateId, TemplateContextMatchers.getUserContextMatchers(patron))))));
    verifyNumberOfSentNotices(6);
    verifyNumberOfPublishedEvents(NOTICE, 6);
    verifyNumberOfPublishedEvents(NOTICE_ERROR, 0);
}
Also used : IntStream(java.util.stream.IntStream) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) APITests(api.support.APITests) Awaitility.waitAtMost(org.awaitility.Awaitility.waitAtMost) IndividualResource(api.support.http.IndividualResource) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) Wait.waitAtLeast(api.support.Wait.waitAtLeast) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) Matchers.hasSize(org.hamcrest.Matchers.hasSize) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) EndSessionBuilder(api.support.builders.EndSessionBuilder) Matchers.empty(org.hamcrest.Matchers.empty) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) FakeModNotify(api.support.fakes.FakeModNotify) lombok.val(lombok.val) LOAN_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.LOAN_ID) UUID(java.util.UUID) ItemResource(api.support.http.ItemResource) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ID) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemplateContextMatchers(api.support.fixtures.TemplateContextMatchers) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)6 ACTION_TYPE (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE)6 PATRON_ID (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID)6 List (java.util.List)5 UUID (java.util.UUID)5 ID (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ID)5 LOAN_ID (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.LOAN_ID)5 PatronActionType (org.folio.circulation.domain.notice.session.PatronActionType)5 APITests (api.support.APITests)4 Wait.waitAtLeast (api.support.Wait.waitAtLeast)4 EndSessionBuilder (api.support.builders.EndSessionBuilder)4 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)4 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)4 FakeModNotify (api.support.fakes.FakeModNotify)4 TemplateContextMatchers (api.support.fixtures.TemplateContextMatchers)4 IndividualResource (api.support.http.IndividualResource)4 ItemResource (api.support.http.ItemResource)4 PatronNoticeMatcher.hasEmailNoticeProperties (api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties)4 PatronNoticeTestHelper.verifyNumberOfPublishedEvents (api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents)4 PatronNoticeTestHelper.verifyNumberOfSentNotices (api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices)4