Skip to content

Commit

Permalink
PR-1910 Add item soft delete option
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisSaldabols committed Aug 27, 2024
1 parent a080ced commit 1999ed8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ NISO Circulation Interchange Protocol (NCIP) support in FOLIO
* (16) cancel.request.reason.name Reason for request cancellation when different item is checkout (Settings -> Circulation -> Request cancellation reasons)
* (17) cancel.request.reason.patron.name Reason for request cancellation when patron did not checkout item (Settings -> Circulation -> Request cancellation reasons)
* (18) request.note.name Request note name. Default value "ILL note"
* (19) request.note.enabled Request note enabled. Will add ILL request ID to loan and ILS request. Default value "false"
* (19) request.note.enabled Request note enabled. Will add ILL request ID to loan and ILS request. Default value `false`
* (20) item.soft.delete DeleteItem will use soft delete or delete entities. Default value `true`

Notes
* You can assign different values to these settings per Agency ID used in the NCIP requests. This approach lets you setup different values for different Agency IDs. For example, if Relais calls your NCIP server with the Agency ID of 'Relais' you can configure values for that agency. If ReShare calls your NCIP server using a different Agency ID, you can set up different configuration values to be used for ReShare requests. These settings have to exist for each Agency ID that will be used in the NCIP requests.
Expand Down Expand Up @@ -158,6 +159,7 @@ There are three types of settings that can exist in mod-configuration for the NC
| NCIP | Relais | cancel.request.reason.patron.name | Item Not Available |
| NCIP | Relais | request.note.name | ILL note |
| NCIP | Relais | request.note.enabled | false |
| NCIP | Relais | item.soft.delete | true |


You will need a set of these settings in mod-configuration for each individual Agency ID making NCIP requests. Example of an AgencyID in an NCIP request:
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/ncip/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ public class Constants {
public static final String NOTE_TITLE_TEMPLATE = "ILL Request id: %s";
public static final String NOTE_LINK_TYPE_REQUEST = "request";
public static final String STAFF_INFO_TYPE = "staffInfoAdded";
public static final String ITEM_STATUS_UNAVAILABLE = "Unavailable";

}
24 changes: 16 additions & 8 deletions src/main/java/org/folio/ncip/FolioRemoteServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1114,15 +1114,16 @@ public void deleteItem(String itemId, String agencyId) throws Exception {
String itemUuid = itemObject.getString(Constants.ID);
String holdingsRecordId = itemObject.getString("holdingsRecordId");

if (ncipProperties == null) {
throw new Exception("NCIP Properties have not been initialized.");
}
initProperties(agencyId, baseUrl);

// Search open requests
String requestResponseString = callApiGet(baseUrl + Constants.OPEN_REQUEST_BY_ITEM_ID_URL + itemUuid);
JsonObject requestResponse = new JsonObject(requestResponseString);
if (requestResponse.getInteger("totalRecords") > 0) {
// Need to close open requests
if (ncipProperties == null) {
throw new Exception("NCIP Properties have not been initialized.");
}
initProperties(agencyId, baseUrl);
String reasonId = ncipProperties.getProperty(agencyId + ".cancel.request.reason.patron.id");

JsonArray requests = requestResponse.getJsonArray("requests");
Expand All @@ -1141,11 +1142,18 @@ public void deleteItem(String itemId, String agencyId) throws Exception {
});
}

String holdingsUrl = baseUrl + Constants.HOLDINGS_URL + "/" + itemObject.getString("holdingsRecordId");
String holdingResponseString = callApiGet(holdingsUrl);
JsonObject holdingResponse = new JsonObject(holdingResponseString);
String softDeleteEnabled = ncipProperties.getProperty(agencyId + ".item.soft.delete");
if (Constants.BOOLEAN_TRUE.equalsIgnoreCase(softDeleteEnabled)) {
// Update item to Unavailable
itemObject.getJsonObject("status").put("name", Constants.ITEM_STATUS_UNAVAILABLE);
callApiPut(baseUrl + Constants.ITEM_URL + "/" + itemUuid, itemObject);
} else {
String holdingsUrl = baseUrl + Constants.HOLDINGS_URL + "/" + itemObject.getString("holdingsRecordId");
String holdingResponseString = callApiGet(holdingsUrl);
JsonObject holdingResponse = new JsonObject(holdingResponseString);

deleteItemAndRelatedRecords(baseUrl, holdingResponse.getString("instanceId"), holdingsRecordId, itemUuid);
deleteItemAndRelatedRecords(baseUrl, holdingResponse.getString("instanceId"), holdingsRecordId, itemUuid);
}
}
} catch (Exception exception) {
logger.error("Exception occurred during delete item");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/ncip.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ cancel.request.reason.name
cancel.request.reason.patron.name
request.note.name=ILL note
request.note.enabled=false
item.soft.delete=true
14 changes: 14 additions & 0 deletions src/test/resources/mockdata/ncip-configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@
"updatedDate": "2020-03-06T20:24:55.479+0000",
"updatedByUserId": "99999999-9999-1999-8999-999999999901"
}
},
{
"id": "a07bc5a3-7e26-485d-a09a-e72ea4dbdbe9",
"module": "NCIP",
"configName": "Relais",
"code": "item.soft.delete",
"enabled": true,
"value": "true",
"metadata": {
"createdDate": "2020-03-06T20:24:55.479+0000",
"createdByUserId": "99999999-9999-1999-8999-999999999901",
"updatedDate": "2020-03-06T20:24:55.479+0000",
"updatedByUserId": "99999999-9999-1999-8999-999999999901"
}
}
],
"totalRecords": 14,
Expand Down
10 changes: 10 additions & 0 deletions utils/setNcipProperties_diku.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,13 @@
response = requests.post(url + "/configurations/entries",the_data,headers=headers)
print(response)

configuration = {}
configuration['configName'] = "ReShare" #AGENCY ID
configuration['code'] = "item.soft.delete"
configuration['value'] = "true"
configuration['module'] = "NCIP"
the_data = json.dumps(configuration)
print(the_data)
response = requests.post(url + "/configurations/entries",the_data,headers=headers)
print(response)

0 comments on commit 1999ed8

Please sign in to comment.