Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR-2062 - include additional request ID in the FOLIO loan note. #45

Merged
merged 15 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 1.15.4 2024-11-12
## 1.15.6 2024-11-21
* Fix missing permission issue
* Use item call number from AcceptItem request if it is provided

## 1.15.5 2024-11-12
* Add new configuration options
* Make sure default values are used

Expand Down
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"permissionsRequired": ["ncip.post"],
"modulePermissions": [
"users.collection.get",
"automated-patron-blocks.collection.get",
"patron-blocks.automated-patron-blocks.collection.get",
"addresstypes.collection.get",
"circulation.requests.item.post",
"circulation-storage.circulation-rules.get",
Expand Down
4 changes: 2 additions & 2 deletions 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>mod-ncip</artifactId>
<version>1.15.6-SNAPSHOT</version>
<version>1.15.7-SNAPSHOT</version>
<name>NCIP</name>
<description>NCIP responder for FOLIO (internal module)</description>

Expand All @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<org.extensiblecatalog.ncip.v2.version>4.1.0</org.extensiblecatalog.ncip.v2.version>
<org.extensiblecatalog.ncip.v2.version>4.1.1</org.extensiblecatalog.ncip.v2.version>
</properties>

<dependencyManagement>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/folio/ncip/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public class Constants {
public static final String DEFAULT_FEE_STATUS = "Open";
public static final String BOOLEAN_TRUE = "true";
public static final String NOTE_DOMAIN_REQUESTS = "requests";
public static final String NOTE_TITLE_TEMPLATE = "ILL Request id: %s";
public static final String NOTE_TITLE_TEMPLATE = "ILL Request ID: %s";
public static final String NOTE_TITLE_TEMPLATE_CUSTOM_EXTERNAL_REFERNECE = "ILL Request ID: %s, ILL %s: %s";
public static final String NOTE_LINK_TYPE_REQUEST = "request";
public static final String ITEM_STATUS_UNAVAILABLE = "Unavailable";

Expand Down
55 changes: 42 additions & 13 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public JsonObject checkOut(CheckOutItemInitiationData initData, String agencyId)
try {
String checkoutResponse = callApiPost(url, jsonObject);
JsonObject checkoutResponseAsJson = new JsonObject(checkoutResponse);
addStaffInfoIfNeeded(agencyId, initData.getRequestId(), checkoutResponseAsJson.getString(Constants.ID), baseUrl);
addStaffInfoIfNeeded(agencyId, initData.getRequestId(), checkoutResponseAsJson.getString(Constants.ID), baseUrl, initData.getExternalReference());
return checkoutResponseAsJson;
}
catch(Exception e) {
Expand All @@ -446,22 +446,45 @@ public JsonObject checkOut(CheckOutItemInitiationData initData, String agencyId)
}
}

private void addStaffInfoIfNeeded(String agencyId, RequestId requestId, String loanUuid, String baseUrl){
private void addStaffInfoIfNeeded(String agencyId, RequestId requestId, String loanUuid, String baseUrl, RequestId externalReference) {
String noteEnabled = getProperty(agencyId, "request.note.enabled");
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(noteEnabled) && requestId != null &&
requestId.getRequestIdentifierValue() != null) {
JsonObject staffInfo = new JsonObject();
staffInfo.put("action", getProperty(agencyId, "checkout.loan.info.type"));
staffInfo.put("actionComment", String.format(Constants.NOTE_TITLE_TEMPLATE, requestId.getRequestIdentifierValue()));
try {
callApiPost(baseUrl + String.format(Constants.ADD_STAFF_INFO_URL, loanUuid), staffInfo);
} catch (Exception e) {
logger.error("Unable to add staff info to loan: {}", loanUuid);
logger.error(e.getMessage());
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(noteEnabled) && requestId != null) {
String requestIdentifierValue = requestId.getRequestIdentifierValue();

if (requestIdentifierValue != null) {
JsonObject staffInfo = new JsonObject();
String actionComment = generateActionComment(requestIdentifierValue, externalReference);
staffInfo.put("action", getProperty(agencyId, "checkout.loan.info.type"));
staffInfo.put("actionComment", actionComment);

try {
callApiPost(baseUrl + String.format(Constants.ADD_STAFF_INFO_URL, loanUuid), staffInfo);
} catch (Exception e) {
logger.error("Unable to add staff info to loan: {}", loanUuid);
logger.error(e.getMessage());
}
}
}
}

private String generateActionComment(String requestIdentifierValue, RequestId externalReference) {
if (externalReference != null &&
externalReference.getRequestIdentifierValue() != null &&
externalReference.getRequestIdentifierType() != null) {
return String.format(
Constants.NOTE_TITLE_TEMPLATE_CUSTOM_EXTERNAL_REFERNECE,
requestIdentifierValue,
externalReference.getRequestIdentifierType().getValue(),
externalReference.getRequestIdentifierValue()
);
} else {
return String.format(
Constants.NOTE_TITLE_TEMPLATE,
requestIdentifierValue
);
}
}

/**
* The acceptItem method: 1) creates an instance (bib) 2) creates a holding
* record 3) creates an item 4) places the item on hold
Expand Down Expand Up @@ -497,6 +520,11 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
throw new FolioNcipException(Constants.REQUEST_ID_MISSING);
}

String callNumber = null;
if (initData.getItemOptionalFields() != null && initData.getItemOptionalFields().getItemDescription() != null) {
callNumber = initData.getItemOptionalFields().getItemDescription().getCallNumber();
}

// VALIDATE PICKUP LOCATION
String pickUpLocationCode = initData.getPickupLocation().getValue();
String sPointId = getServicePointId(pickUpLocationCode, baseUrl);
Expand Down Expand Up @@ -547,7 +575,8 @@ public JsonObject acceptItem(AcceptItemInitiationData initData, UserId userId, S
item.put(Constants.ID, itemUuid.toString());
item.put(Constants.HOLDINGS_RECORD_ID, holdingsUuid.toString());
item.put("discoverySuppress", true);
item.put("itemLevelCallNumber", itemId.getItemIdentifierValue());

item.put("itemLevelCallNumber", StringUtils.isNotBlank(callNumber) ? callNumber : itemId.getItemIdentifierValue());
// PLACE HOLD DOES NOT WORK UNLESS THE ITEM HAS A PERM LOCATION
JsonObject permLocation = new JsonObject();
permLocation.put(Constants.ID, itemLocation);
Expand Down
27 changes: 25 additions & 2 deletions src/test/java/org/folio/ncip/CheckOutItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import java.net.MalformedURLException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class CheckOutItem extends TestBase {

Expand All @@ -18,4 +17,28 @@ public void callCheckOutItem() throws MalformedURLException {
assertEquals(200, response.getStatusCode());
assertTrue(body.contains(ITEM_ID));
}

@Test
public void callCheckOutItemWithoutExternalReference() throws MalformedURLException {
Response response = postData("src/test/resources/mockdata/ncip-checkout-null-request-id-external-reference.xml");
String body = response.getBody().prettyPrint();
assertEquals(200, response.getStatusCode());
assertTrue(body.contains(ITEM_ID));
}

@Test
public void callCheckOutItemWithoutExternalReferenceType() throws MalformedURLException {
Response response = postData("src/test/resources/mockdata/ncip-checkout-null-external-reference-type.xml");
String body = response.getBody().prettyPrint();
assertEquals(200, response.getStatusCode());
assertTrue(body.contains(ITEM_ID));
}

@Test
public void callCheckOutItemEmptyExternalReferenceValue() throws MalformedURLException {
Response response = postData("src/test/resources/mockdata/ncip-checkout-null-external-reference-value.xml");
String body = response.getBody().prettyPrint();
assertEquals(200, response.getStatusCode());
assertTrue(body.contains(ITEM_ID));
}
}
7 changes: 7 additions & 0 deletions src/test/resources/mockdata/ncip-checkout-full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierValue>js-test-0015</ns1:RequestIdentifierValue>
</ns1:RequestId>
<ns1:Ext>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierType ns1:Scheme="Schema">ExternReferenz</ns1:RequestIdentifierType>
<ns1:RequestIdentifierValue>GDFG2343</ns1:RequestIdentifierValue>
</ns1:RequestId>
</ns1:Ext>
</ns1:CheckOutItem>
</ns1:NCIPMessage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd">
<ns1:CheckOutItem>
<ns1:InitiationHeader>
<ns1:FromAgencyId>
<ns1:AgencyId>relais</ns1:AgencyId>
</ns1:FromAgencyId>
<ns1:ToAgencyId>
<ns1:AgencyId>other</ns1:AgencyId>
</ns1:ToAgencyId>
<ns1:ApplicationProfileType>EZBORROW</ns1:ApplicationProfileType>
</ns1:InitiationHeader>
<ns1:UserId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:UserIdentifierValue>slnp_one_inst_user</ns1:UserIdentifierValue>
</ns1:UserId>
<ns1:ItemId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:ItemIdentifierValue>tl-a11</ns1:ItemIdentifierValue>
</ns1:ItemId>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierValue>js-test-0015</ns1:RequestIdentifierValue>
</ns1:RequestId>
<ns1:Ext>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierValue>GDFG2343</ns1:RequestIdentifierValue>
</ns1:RequestId>
</ns1:Ext>
</ns1:CheckOutItem>
</ns1:NCIPMessage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd">
<ns1:CheckOutItem>
<ns1:InitiationHeader>
<ns1:FromAgencyId>
<ns1:AgencyId>relais</ns1:AgencyId>
</ns1:FromAgencyId>
<ns1:ToAgencyId>
<ns1:AgencyId>other</ns1:AgencyId>
</ns1:ToAgencyId>
<ns1:ApplicationProfileType>EZBORROW</ns1:ApplicationProfileType>
</ns1:InitiationHeader>
<ns1:UserId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:UserIdentifierValue>slnp_one_inst_user</ns1:UserIdentifierValue>
</ns1:UserId>
<ns1:ItemId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:ItemIdentifierValue>tl-a11</ns1:ItemIdentifierValue>
</ns1:ItemId>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierValue>js-test-0015</ns1:RequestIdentifierValue>
</ns1:RequestId>
<ns1:Ext>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierType ns1:Scheme="Schema">ExternReferenz</ns1:RequestIdentifierType>
<ns1:RequestIdentifierValue></ns1:RequestIdentifierValue>
</ns1:RequestId>
</ns1:Ext>
</ns1:CheckOutItem>
</ns1:NCIPMessage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_0/imp1/xsd/ncip_v2_0.xsd">
<ns1:CheckOutItem>
<ns1:InitiationHeader>
<ns1:FromAgencyId>
<ns1:AgencyId>relais</ns1:AgencyId>
</ns1:FromAgencyId>
<ns1:ToAgencyId>
<ns1:AgencyId>other</ns1:AgencyId>
</ns1:ToAgencyId>
<ns1:ApplicationProfileType>EZBORROW</ns1:ApplicationProfileType>
</ns1:InitiationHeader>
<ns1:UserId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:UserIdentifierValue>slnp_one_inst_user</ns1:UserIdentifierValue>
</ns1:UserId>
<ns1:ItemId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:ItemIdentifierValue>tl-a11</ns1:ItemIdentifierValue>
</ns1:ItemId>
<ns1:RequestId>
<ns1:AgencyId>relais</ns1:AgencyId>
<ns1:RequestIdentifierValue>js-test-0015</ns1:RequestIdentifierValue>
</ns1:RequestId>
</ns1:CheckOutItem>
</ns1:NCIPMessage>
Loading