From 1999ed8e583ecf98d05561f291802aaa96b01f38 Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Tue, 27 Aug 2024 09:16:20 +0300 Subject: [PATCH] PR-1910 Add item soft delete option --- README.md | 4 +++- src/main/java/org/folio/ncip/Constants.java | 1 + .../folio/ncip/FolioRemoteServiceManager.java | 24 ++++++++++++------- src/main/resources/ncip.properties | 1 + src/test/resources/mockdata/ncip-configs.json | 14 +++++++++++ utils/setNcipProperties_diku.py | 10 ++++++++ 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index eebc77d..f0210c9 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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: diff --git a/src/main/java/org/folio/ncip/Constants.java b/src/main/java/org/folio/ncip/Constants.java index 565682f..a7c4a97 100644 --- a/src/main/java/org/folio/ncip/Constants.java +++ b/src/main/java/org/folio/ncip/Constants.java @@ -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"; } diff --git a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java index e52dc29..58d3708 100644 --- a/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java +++ b/src/main/java/org/folio/ncip/FolioRemoteServiceManager.java @@ -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"); @@ -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"); diff --git a/src/main/resources/ncip.properties b/src/main/resources/ncip.properties index 8e510d5..e16ec95 100644 --- a/src/main/resources/ncip.properties +++ b/src/main/resources/ncip.properties @@ -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 diff --git a/src/test/resources/mockdata/ncip-configs.json b/src/test/resources/mockdata/ncip-configs.json index 8f59960..fc9b28d 100644 --- a/src/test/resources/mockdata/ncip-configs.json +++ b/src/test/resources/mockdata/ncip-configs.json @@ -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, diff --git a/utils/setNcipProperties_diku.py b/utils/setNcipProperties_diku.py index cc5e442..10c94fd 100644 --- a/utils/setNcipProperties_diku.py +++ b/utils/setNcipProperties_diku.py @@ -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) +