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;
}
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);
}
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);
}
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)));
}
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);
}
Aggregations