Search in sources :

Example 1 with PATRON_ID

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID 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 PATRON_ID

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID 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 PATRON_ID

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID 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 PATRON_ID

use of org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID 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 PATRON_ID

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

the class EndExpiredPatronActionSessionTests method expiredEndSessionAfterCheckOut.

@Test
void expiredEndSessionAfterCheckOut() {
    IndividualResource james = usersFixture.james();
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponNod(), james);
    checkOutFixture.checkOutByBarcode(itemsFixture.basedUponInterestingTimes(), james);
    expiredEndSessionClient.deleteAll();
    List<JsonObject> sessions = patronSessionRecordsClient.getAll();
    assertThat(sessions, hasSize(2));
    String patronId = sessions.stream().findFirst().map(session -> session.getString(PATRON_ID)).orElse("");
    createExpiredEndSession(patronId, CHECK_OUT);
    expiredSessionProcessingClient.runRequestExpiredSessionsProcessing(204);
    waitAtLeast(1, SECONDS).until(patronSessionRecordsClient::getAll, empty());
    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) Test(org.junit.jupiter.api.Test)

Aggregations

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