diff --git a/nbs-items-note/nodes/buildItems.json b/nbs-items-note/nodes/buildItems.json new file mode 100644 index 00000000..ac75fa24 --- /dev/null +++ b/nbs-items-note/nodes/buildItems.json @@ -0,0 +1,8 @@ +{ + "id": "0df78f23-252f-448c-8bf0-0145cb22a728", + "name": "Build Items", + "description": "Build Items array from the LDP response.", + "deserializeAs": "ScriptTask", + "scriptFormat": "javascript", + "code": "buildItems.js" +} diff --git a/nbs-items-note/nodes/connetToLDP.json b/nbs-items-note/nodes/connetToLDP.json new file mode 100644 index 00000000..5481f074 --- /dev/null +++ b/nbs-items-note/nodes/connetToLDP.json @@ -0,0 +1,13 @@ +{ + "id": "7f7b1d38-a006-4dca-a9b2-d2fbb17c5dda", + "name": "Connect to LDP", + "description": "Connect to the LDP.", + "deserializeAs": "DatabaseConnectionTask", + "inputVariables": [], + "outputVariable": {}, + "designation": "ldp", + "url": "{{{ldp-url}}}", + "username": "{{{ldp-user}}}", + "password": "{{{ldp-password}}}", + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/disconnectFromLDP.json b/nbs-items-note/nodes/disconnectFromLDP.json new file mode 100644 index 00000000..d91036b2 --- /dev/null +++ b/nbs-items-note/nodes/disconnectFromLDP.json @@ -0,0 +1,10 @@ +{ + "id": "b8aef7d8-9d8a-4c6d-b66e-eb942b1e8626", + "name": "Disconnect from LDP", + "description": "Disconnect from the LDP.", + "deserializeAs": "DatabaseDisconnectTask", + "inputVariables": [], + "outputVariable": {}, + "designation": "ldp", + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/end.json b/nbs-items-note/nodes/end.json new file mode 100644 index 00000000..792bccb6 --- /dev/null +++ b/nbs-items-note/nodes/end.json @@ -0,0 +1,6 @@ +{ + "id": "6509ec72-5065-4757-8f5c-4aec865725f0", + "name": "End", + "description": "End of the workflow.", + "deserializeAs": "EndEvent" +} diff --git a/nbs-items-note/nodes/endItemsSubprocess.json b/nbs-items-note/nodes/endItemsSubprocess.json new file mode 100644 index 00000000..72e8731e --- /dev/null +++ b/nbs-items-note/nodes/endItemsSubprocess.json @@ -0,0 +1,6 @@ +{ + "id": "ac4abb19-0cb8-482b-8cab-e1c385cd7b6b", + "name": "End Items Subprocess", + "description": "The Items sub-process is complete.", + "deserializeAs": "EndEvent" +} diff --git a/nbs-items-note/nodes/getItem.json b/nbs-items-note/nodes/getItem.json new file mode 100644 index 00000000..8a6f9094 --- /dev/null +++ b/nbs-items-note/nodes/getItem.json @@ -0,0 +1,25 @@ +{ + "id": "225fbb68-b311-4623-b397-856357be1c90", + "name": "Request Item", + "description": "Request the Item by its given Item ID.", + "deserializeAs": "RequestTask", + "request": { + "url": "{{okapi-internal}}/inventory/items/${item.id}", + "method": "GET", + "accept": "application/json" + }, + "inputVariables": [ + { + "key": "item", + "type": "PROCESS", + "spin": true + } + ], + "headerOutputVariables": [], + "outputVariable": { + "key": "itemResponse", + "type": "LOCAL", + "spin": true + }, + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/getItemsFromLDP.json b/nbs-items-note/nodes/getItemsFromLDP.json new file mode 100644 index 00000000..9cbb346e --- /dev/null +++ b/nbs-items-note/nodes/getItemsFromLDP.json @@ -0,0 +1,14 @@ +{ + "id": "badb402c-916d-4e0d-a525-fcaa8f490974", + "name": "Get Items from LDP", + "description": "Load all Items from the LDP using an SQL query.", + "deserializeAs": "DatabaseQueryTask", + "inputVariables": [], + "outputVariable": { + "key": "itemsResponse", + "type": "PROCESS" + }, + "designation": "ldp", + "query": "(select id from inventory_items where effective_location_id = '07a4e97e-9941-4f60-ad25-577bb6672c08' and status__name = 'Checked out' and json_array_length(data->'circulationNotes') = 0 ) union ( select s.id from ( select id, to_jsonb(data->'circulationNotes') as notes from inventory_items where effective_location_id = '07a4e97e-9941-4f60-ad25-577bb6672c08' and status__name = 'Checked out' ) s where not s.notes @> '[{\"note\":\"Place on New Bookshelf\"}]'::jsonb)", + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/itemsSubprocess.json b/nbs-items-note/nodes/itemsSubprocess.json new file mode 100644 index 00000000..33405589 --- /dev/null +++ b/nbs-items-note/nodes/itemsSubprocess.json @@ -0,0 +1,19 @@ +{ + "id": "5a24ffbc-468d-4eca-90c7-21e9158f208e", + "name": "Items Subprocess", + "description": "Subprocess for processing all of the loaded Items.", + "type": "EMBEDDED", + "deserializeAs": "Subprocess", + "nodes": [ + "{{mod-workflow}}/startEvent/fa28c94a-7f55-4b60-85f0-fb1a3fe03c1b", + "{{mod-workflow}}/requestTask/225fbb68-b311-4623-b397-856357be1c90", + "{{mod-workflow}}/scriptTask/1d0b24bd-fe24-4158-9e23-f12874e5798c", + "{{mod-workflow}}/requestTask/0d236b3c-e571-4b37-8114-7570c9d496a4", + "{{mod-workflow}}/endEvent/ac4abb19-0cb8-482b-8cab-e1c385cd7b6b" + ], + "loopRef": { + "dataInputRefExpression": "${items.elements()}", + "inputDataName": "item", + "parallel": false + } +} diff --git a/nbs-items-note/nodes/js/buildItems.js b/nbs-items-note/nodes/js/buildItems.js new file mode 100644 index 00000000..9a9d26fe --- /dev/null +++ b/nbs-items-note/nodes/js/buildItems.js @@ -0,0 +1,9 @@ +var itemsArr = JSON.parse(itemsResponse); + +print('\nitemsResponse = ' + itemsResponse + '\n'); + +if (!itemsArr) { + itemsArr = []; +} + +execution.setVariable('items', S(JSON.stringify(itemsArr))); diff --git a/nbs-items-note/nodes/js/processItem.js b/nbs-items-note/nodes/js/processItem.js new file mode 100644 index 00000000..1eda75d8 --- /dev/null +++ b/nbs-items-note/nodes/js/processItem.js @@ -0,0 +1,36 @@ +var itemObj = JSON.parse(itemResponse); + +print('\nitemResponse = ' + itemResponse + '\n'); + +var extractResponseArray = function (response, key) { + return (!response || !response[key]) ? [] : response[key]; +}; + +if (!!itemObj && !!itemObj.status && !!itemObj.status.name && itemObj.status.name == 'Checked out') { + var circulationNotes = extractResponseArray(itemObj, 'circulationNotes'); + var addNote = true; + + if (circulationNotes.length > 0) { + for (var i = 0; i < circulationNotes.length; i++) { + if (!!circulationNotes[i].noteType && !!circulationNotes[i].note) { + if (circulationNotes[i].noteType == 'Check in' && circulationNotes[i].note == 'Place on New Bookshelf') { + addNote = false; + break; + } + } + } + } + + if (addNote) { + circulationNotes.push({ + 'noteType': 'Check in', + 'note': 'Place on New Bookshelf', + 'staffOnly': true + }); + + itemObj.circulationNotes = circulationNotes; + } +} + +execution.setVariable('updatedItem', S(JSON.stringify(itemObj))); +execution.setVariable('itemId', (!!itemObj && !!itemObj.id) ? itemObj.id : ''); diff --git a/nbs-items-note/nodes/okapiLogin.json b/nbs-items-note/nodes/okapiLogin.json new file mode 100644 index 00000000..56616502 --- /dev/null +++ b/nbs-items-note/nodes/okapiLogin.json @@ -0,0 +1,34 @@ +{ + "id": "a94cd209-e301-4f48-b8fa-c53e766279c9", + "name": "Okapi Login", + "description": "Login to Okapi.", + "deserializeAs": "RequestTask", + "request": { + "url": "{{okapi-internal}}/authn/login", + "method": "POST", + "contentType": "application/json", + "accept": "application/json", + "bodyTemplate": "{\"username\": \"{{{username}}}\", \"password\": \"{{{password}}}\"}" + }, + "inputVariables": [ + { + "key": "username", + "type": "PROCESS" + }, + { + "key": "password", + "type": "PROCESS" + } + ], + "headerOutputVariables": [ + { + "key": "X-Okapi-Token", + "type": "PROCESS" + } + ], + "outputVariable": { + "key": "loginResponse", + "type": "PROCESS" + }, + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/processItem.json b/nbs-items-note/nodes/processItem.json new file mode 100644 index 00000000..23411995 --- /dev/null +++ b/nbs-items-note/nodes/processItem.json @@ -0,0 +1,8 @@ +{ + "id": "1d0b24bd-fe24-4158-9e23-f12874e5798c", + "name": "Process Item", + "description": "Process an Item, determining if it still needs to be updated and if so then populate the Item accordingly.", + "deserializeAs": "ScriptTask", + "scriptFormat": "javascript", + "code": "processItem.js" +} diff --git a/nbs-items-note/nodes/start.json b/nbs-items-note/nodes/start.json new file mode 100644 index 00000000..ec2a46c3 --- /dev/null +++ b/nbs-items-note/nodes/start.json @@ -0,0 +1,8 @@ +{ + "id": "cdd600ba-e209-429c-a60f-f42632bfe5c3", + "name": "Start", + "description": "Execute workflow as a cronjob, where start time is in UTC.", + "type": "SCHEDULED", + "deserializeAs": "StartEvent", + "expression": "0 0 12 * * ?" +} diff --git a/nbs-items-note/nodes/startItemsSubprocess.json b/nbs-items-note/nodes/startItemsSubprocess.json new file mode 100644 index 00000000..afe7d77a --- /dev/null +++ b/nbs-items-note/nodes/startItemsSubprocess.json @@ -0,0 +1,8 @@ +{ + "id": "fa28c94a-7f55-4b60-85f0-fb1a3fe03c1b", + "name": "Start Items Subprocess", + "description": "Start processing the Items array.", + "type": "NONE", + "deserializeAs": "StartEvent", + "asyncBefore": true +} diff --git a/nbs-items-note/nodes/updateItem.json b/nbs-items-note/nodes/updateItem.json new file mode 100644 index 00000000..9c9699e1 --- /dev/null +++ b/nbs-items-note/nodes/updateItem.json @@ -0,0 +1,28 @@ +{ + "id": "0d236b3c-e571-4b37-8114-7570c9d496a4", + "name": "Update Item", + "description": "Update the Item using the appropriate REST request.", + "deserializeAs": "RequestTask", + "request": { + "url": "{{okapi-internal}}/inventory/items/${itemId}", + "method": "PUT", + "contentType": "application/json", + "accept": "text/plain", + "bodyTemplate": "${updatedItem}" + }, + "inputVariables": [ + { + "key": "updatedItem", + "type": "PROCESS", + "spin": true, + "asJson": true + }, + { + "key": "itemId", + "type": "PROCESS" + } + ], + "headerOutputVariables": [], + "outputVariable": {}, + "asyncBefore": true +} diff --git a/nbs-items-note/setup.json b/nbs-items-note/setup.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/nbs-items-note/setup.json @@ -0,0 +1 @@ +{} diff --git a/nbs-items-note/workflow.json b/nbs-items-note/workflow.json new file mode 100644 index 00000000..77a99497 --- /dev/null +++ b/nbs-items-note/workflow.json @@ -0,0 +1,24 @@ +{ + "id": "6122f375-c6cf-450d-92b0-59ae13a4408e", + "name": "New Bookshelf Items Note", + "description": "Navigate through each Item in 'Evans nbs', adding an 'Inventory Item Circulation Note' on 'Check in'.", + "versionTag": "1.0", + "historyTimeToLive": 90, + "deploymentId": null, + "active": false, + "setup": { + "asyncBefore": false, + "asyncAfter": false + }, + "nodes": [ + "{{mod-workflow}}/startEvent/cdd600ba-e209-429c-a60f-f42632bfe5c3", + "{{mod-workflow}}/requestTask/a94cd209-e301-4f48-b8fa-c53e766279c9", + "{{mod-workflow}}/databaseConnectionTask/7f7b1d38-a006-4dca-a9b2-d2fbb17c5dda", + "{{mod-workflow}}/databaseQueryTask/badb402c-916d-4e0d-a525-fcaa8f490974", + "{{mod-workflow}}/scriptTask/0df78f23-252f-448c-8bf0-0145cb22a728", + "{{mod-workflow}}/databaseDisconnectTask/b8aef7d8-9d8a-4c6d-b66e-eb942b1e8626", + "{{mod-workflow}}/subprocess/5a24ffbc-468d-4eca-90c7-21e9158f208e", + "{{mod-workflow}}/endEvent/6509ec72-5065-4757-8f5c-4aec865725f0" + ], + "initialContext": {} +}