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