Skip to content

Commit

Permalink
Merge pull request #157 from folio-org/tmp-release-3.1.2
Browse files Browse the repository at this point in the history
Merge fix for 3.1.2
  • Loading branch information
kurtnordstrom authored Apr 24, 2024
2 parents dd6aad6 + 6c02f4d commit 8843515
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.1.2 2024-04-22
* [SIP2-169](https://issues.folio.org/browse/SIP2-169) Correct issue with incorrect values for items in transit from checkin response (backport)

## 3.1.1 2023-11-06
* [SIP2-178](https://issues.folio.org/browse/SIP2-178) Vert.x 4.4.6 fixing Netty HTTP/2 DoS (CVE-2023-44487)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.folio</groupId>
<artifactId>edge-sip2</artifactId>
<version>3.1.2-SNAPSHOT</version>
<version>3.1.3-SNAPSHOT</version>
<name>Standard Interchange Protocol v2 (SIP2)</name>
<url>https://github.com/folio-org/edge-sip2</url>
<description>Support for SIP2 in FOLIO. This allow self service circulation and patron services stations to perform supported operations in FOLIO.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class CirculationRepository {
public static final String TITLE = "title";
public static final String ITEM_BARCODE = "itemBarcode";
public static final String SERVICE_POINT_ID = "servicePointId";
public static final String ITEM_ID = "itemId";
private final IResourceProvider<IRequestData> resourceProvider;
private final PasswordVerifier passwordVerifier;
private final Clock clock;
Expand Down Expand Up @@ -102,20 +103,21 @@ public Future<CheckinResponse> performCheckinCommand(Checkin checkin, SessionDat
.compose(resource -> {
log.info("performCheckinCommand resource:{}", resource);
JsonObject resourceJson = resource.getResource();

log.debug("performCheckinCommand resource json is {}",
() -> resourceJson != null ? resourceJson.encode() : "null");
JsonObject valuesJson = extractCheckinValues(resourceJson);
log.debug("valuesJson is {}", valuesJson.encode());
final Future<JsonObject> getRequestsResult = resourceJson != null
? getRequestsByItemId(itemIdentifier, null, null,
? getRequestsByItemId(valuesJson.getString(ITEM_ID), null, null,
null, sessionData) : Future.succeededFuture(null);
return getRequestsResult
.compose(requestsJson -> {
JsonObject valuesJson = extractCheckinValues(resourceJson);
log.debug("JSON from getRequestsByItemId is {}",
() -> requestsJson != null ? requestsJson.encode() : "null");
MediaType mediaType = getMediaType(valuesJson.getJsonObject("itemMaterialTypeJson"));
JsonArray requestArray =
requestsJson != null ? requestsJson.getJsonArray("requests") : null;
JsonObject request = requestArray != null && !requestArray.isEmpty()
? requestArray.getJsonObject(0) : null;
final String requestState =
request != null ? request.getString("requestType") : null;
final String requestState = getRequestState(requestArray);
final boolean inTransit = valuesJson.getString("itemStatus") != null
&& valuesJson.getString("itemStatus").equals("In transit");
final boolean holdItem = requestState != null && requestState.equals("Hold");
Expand Down Expand Up @@ -357,7 +359,7 @@ public Future<JsonObject> getRequestsByItemId(String itemId, String requestType,
SessionData sessionData) {
final Map<String, String> headers = getBaseHeaders();

final RequestsRequestData requestsRequestData = new RequestsRequestData("itemId", itemId,
final RequestsRequestData requestsRequestData = new RequestsRequestData(ITEM_ID, itemId,
requestType, startItem, endItem, headers, sessionData);
final Future<IResource> result = resourceProvider.retrieveResource(requestsRequestData);

Expand Down Expand Up @@ -886,7 +888,7 @@ private MediaType getMediaType(JsonObject materialTypeJson) {
return mediaType;
}

private String getAlertType(boolean inTransit, boolean holdItem, boolean recallItem) {
protected static String getAlertType(boolean inTransit, boolean holdItem, boolean recallItem) {
String alertType;
if (inTransit || holdItem || recallItem) {
if (!inTransit) {
Expand All @@ -906,6 +908,7 @@ private JsonObject extractCheckinValues(JsonObject resourceJson) {
JsonObject valuesJson = new JsonObject();
JsonObject itemJson = resourceJson != null ? resourceJson.getJsonObject("item")
: null;
valuesJson.put(ITEM_ID, itemJson != null ? itemJson.getString("id") : null);
valuesJson.put("callNumber", itemJson != null ? itemJson.getString("callNumber")
: null);
JsonObject itemStatusJson = itemJson != null ? itemJson.getJsonObject("status")
Expand All @@ -922,4 +925,15 @@ private JsonObject extractCheckinValues(JsonObject resourceJson) {

return valuesJson;
}

private String getRequestState(JsonArray requestArray) {
if (requestArray == null || requestArray.isEmpty()) {
return null;
}
JsonObject request = requestArray.getJsonObject(0);
if (request == null) {
return null;
}
return request.getString("requestType");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ private ACSStatusBuilder setACSConfig(LinkedHashMap<String, JsonObject> sets,
}

private void addLocaleConfig(JsonObject config, SessionData sessionData) {
log.debug("Adding locale config with config {}",
() -> config != null ? config.encode() : "(null)");
if (config != null) {
sessionData.setTimeZone(config.getString("timezone"));
String currencyConfig = config.getString("currency") != null
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/CheckinResponse.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
<@lib.callNumber value=checkinResponse.callNumber!""/>
<#-- alert type: fixed-length optional field (extension) -->
<@lib.alertType value=checkinResponse.alertType!""/>
<#-- pickup service point: variable-length optional field (extension) -->
<@lib.pickupServicePoint value=checkinResponse.pickupServicePoint!""/>
4 changes: 4 additions & 0 deletions src/main/resources/templates/lib.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,8 @@
<@variableLengthField id="FF" value=value/>
</#macro>

<#macro pickupServicePoint value>
<@variableLengthField id="CT" value=value/>
</#macro>


Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void canExecuteASampleCheckinUsingHandler(
final String institutionId = "diku";
final String itemIdentifier = "1234567890";
final String currentLocation = UUID.randomUUID().toString();
final String servicePoint = "Circ Desk 1";
final Checkin checkin = Checkin.builder()
.noBlock(FALSE)
.transactionDate(OffsetDateTime.now())
Expand All @@ -61,6 +62,7 @@ public void canExecuteASampleCheckinUsingHandler(
.itemIdentifier(itemIdentifier)
.permanentLocation("Main Library")
.callNumber("23457799")
.pickupServicePoint(servicePoint)
.build()));

final CheckinHandler handler = new CheckinHandler(mockCirculationRepository,
Expand All @@ -72,7 +74,8 @@ public void canExecuteASampleCheckinUsingHandler(
testContext.succeeding(sipMessage -> testContext.verify(() -> {
final String expectedString = "101YUN"
+ TestUtils.getFormattedLocalDateTime(OffsetDateTime.now(clock))
+ "AO" + institutionId + "|AB" + itemIdentifier + "|AQMain Library|CS23457799|CV|";
+ "AO" + institutionId + "|AB" + itemIdentifier + "|AQMain Library|CS23457799|CV|"
+ "CT" + servicePoint + "|";

assertEquals(expectedString, sipMessage);

Expand Down Expand Up @@ -123,7 +126,7 @@ public void canExecuteASampleFailedCheckinUsingHandler(
testContext.succeeding(sipMessage -> testContext.verify(() -> {
final String expectedString = "100YUN"
+ TestUtils.getFormattedLocalDateTime(OffsetDateTime.now(clock))
+ "AO" + institutionId + "|AB" + itemIdentifier + "|AQ|CS|CV|";
+ "AO" + institutionId + "|AB" + itemIdentifier + "|AQ|CS|CV|CT|";

assertEquals(expectedString, sipMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ void canCheckin(Vertx vertx,
.put("location", new JsonObject()
.put("name", "Main Library"))
.put("materialType", new JsonObject()
.put("name", "book")))
.put("name", "book"))
.put("inTransitDestinationServicePoint", new JsonObject()
.put("name", "Annex"));
.put("name", "Annex"))
);


final JsonObject getRequestsResponseJson = new JsonObject()
Expand Down Expand Up @@ -150,6 +151,7 @@ void canCheckin(Vertx vertx,
assertNull(checkinResponse.getScreenMessage());
assertNull(checkinResponse.getPrintLine());
assertEquals(callNumber, checkinResponse.getCallNumber());
assertEquals("Annex", checkinResponse.getPickupServicePoint());

testContext.completeNow();
})));
Expand Down Expand Up @@ -1507,4 +1509,20 @@ void cannotGetRequestsByUserId(Vertx vertx,
testContext.completeNow();
})));
}

@Test
void testGetAlertType() {
assertEquals("01", CirculationRepository.getAlertType(
false, true, false));
assertEquals("01", CirculationRepository.getAlertType(
false, false, true));
assertEquals("02", CirculationRepository.getAlertType(
true, false, true));
assertEquals("02", CirculationRepository.getAlertType(
true, true, false));
assertEquals("04", CirculationRepository.getAlertType(
true, false, false));
assertNull(CirculationRepository.getAlertType(
false, false, false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,35 @@ public void canRetrieveTenantConfiguration(
testContext.completeNow();
})));
}

@Test
public void canRetrieveLocaleConfigurationWithAlternateCurrency(
Vertx vertx,
VertxTestContext testContext, @Mock Clock clock) {

List<LinkedHashMap<String, String>> configParamsList = new ArrayList<>();
LinkedHashMap<String, String> configParamsSet = new LinkedHashMap<>();
configParamsSet.put("module", "edge-sip2");
configParamsSet.put("configName", "acsTenantConfig");
String configKey = String.format("%s.%s.%s", "ORG", "localeSettings", "null");

configParamsList.add(configParamsSet);

IResourceProvider<IRequestData> resourceProvider =
new DefaultResourceProvider("json/DefaultACSConfigurationNonDefaultedCurrency.json");
ConfigurationRepository configRepo = new ConfigurationRepository(resourceProvider, clock);

configRepo.retrieveConfigurations(TestUtils.getMockedSessionData(),
configParamsList).onComplete(
testContext.succeeding(testTenantConfig -> testContext.verify(() -> {
assertNotNull(testTenantConfig);

JsonObject config = testTenantConfig.get(configKey);

assertEquals("EUR", config.getString("currency"));

testContext.completeNow();
})));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"configs": [
{
"id": "acd6dae1-b1ae-4780-8e06-993fbed00061",
"module": "edge-sip2",
"configName": "selfCheckoutConfig.TL01",
"enabled": true,
"value": "{\"timeoutPeriod\": 5,\"retriesAllowed\": 3,\"terminalDelimeter\" : \"\\r\",\"fieldDelimeter\" : \"|\",\"errorDetectionEnabled\" : true,\"charset\" : \"IBM850\",\"SCtimeZone\" : \"CEST\",\"checkinOk\": true,\"checkoutOk\": false,\"acsRenewalPolicy\": true,\"maxPrintWidth\" : 200,\"libraryName\": \"diku\",\"terminalLocation\": \"TL01\"}"
},
{
"id": "fb0ba4d3-6591-4a2c-99a7-d4009d711b4a",
"module": "edge-sip2",
"configName": "acsTenantConfig",
"enabled": true,
"value":"{\"tenantId\": \"dikutest\",\"supportedMessages\": [{\"messageName\": \"PATRON_STATUS_REQUEST\",\"isSupported\": \"Y\"},{\"messageName\": \"CHECKOUT\",\"isSupported\": \"N\"},{\"messageName\": \"CHECKIN\",\"isSupported\": \"N\"},{\"messageName\": \"BLOCK_PATRON\",\"isSupported\": \"N\"},{\"messageName\": \"SC_ACS_STATUS\",\"isSupported\": \"Y\"},{\"messageName\": \"LOGIN\",\"isSupported\": \"Y\"},{\"messageName\": \"PATRON_INFORMATION\",\"isSupported\": \"N\"},{\"messageName\": \"END_PATRON_SESSION\",\"isSupported\": \"N\"},{\"messageName\": \"FEE_PAID\",\"isSupported\": \"N\"},{\"messageName\": \"ITEM_INFORMATION\",\"isSupported\": \"N\"},{\"messageName\": \"ITEM_STATUS_UPDATE\",\"isSupported\": \"N\"},{\"messageName\": \"PATRON_ENABLE\",\"isSupported\": \"N\"},{\"messageName\": \"HOLD\",\"isSupported\": \"N\"},{\"messageName\": \"RENEW\",\"isSupported\": \"Y\"},{\"messageName\": \"RENEW_ALL\",\"isSupported\": \"N\"}],\"onlineStatus\": true,\"statusUpdateOk\": false,\"offlineOk\": false,\"protocolVersion\": \"1.23\",\"screenMessage\": \"screenMessages\",\"printLine\": \"line\",\"localTimeZone\" : \"CEST\",\"holdItemsLimit\" : 25,\"overdueItemsLimit\" : 5,\"feeLimit\" : 100,\"currencyType\" : \"Krona\",\"language\" : \"en\"}"
},
{
"id": "4e9b45dd-ed0b-4426-b75e-248e39e5b5d2",
"module": "ORG",
"configName": "localeSettings",
"enabled": true,
"value": "{\"locale\":\"en-SE\",\"timezone\":\"Etc/UTC\",\"currency\":\"EUR\"}"
}
],
"totalRecords": 3,
"resultInfo": {
"totalRecords": 3,
"facets": [],
"diagnostics": []
}
}

0 comments on commit 8843515

Please sign in to comment.