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

Issue 308: Create workflow to add a note to all New Bookshelf Items on a regular basis. #311

Merged
merged 5 commits into from
Oct 17, 2023
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
8 changes: 8 additions & 0 deletions nbs-items-note/nodes/buildItems.json
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 13 additions & 0 deletions nbs-items-note/nodes/connetToLDP.json
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions nbs-items-note/nodes/disconnectFromLDP.json
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions nbs-items-note/nodes/end.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "6509ec72-5065-4757-8f5c-4aec865725f0",
"name": "End",
"description": "End of the workflow.",
"deserializeAs": "EndEvent"
}
6 changes: 6 additions & 0 deletions nbs-items-note/nodes/endItemsSubprocess.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "ac4abb19-0cb8-482b-8cab-e1c385cd7b6b",
"name": "End Items Subprocess",
"description": "The Items sub-process is complete.",
"deserializeAs": "EndEvent"
}
25 changes: 25 additions & 0 deletions nbs-items-note/nodes/getItem.json
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions nbs-items-note/nodes/getItemsFromLDP.json
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions nbs-items-note/nodes/itemsSubprocess.json
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 9 additions & 0 deletions nbs-items-note/nodes/js/buildItems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var itemsArr = JSON.parse(itemsResponse);

print('\nitemsResponse = ' + itemsResponse + '\n');

if (!itemsArr) {
itemsArr = [];
}

execution.setVariable('items', S(JSON.stringify(itemsArr)));
36 changes: 36 additions & 0 deletions nbs-items-note/nodes/js/processItem.js
Original file line number Diff line number Diff line change
@@ -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 : '');
34 changes: 34 additions & 0 deletions nbs-items-note/nodes/okapiLogin.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions nbs-items-note/nodes/processItem.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 8 additions & 0 deletions nbs-items-note/nodes/start.json
Original file line number Diff line number Diff line change
@@ -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 * * ?"
}
8 changes: 8 additions & 0 deletions nbs-items-note/nodes/startItemsSubprocess.json
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions nbs-items-note/nodes/updateItem.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions nbs-items-note/setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
24 changes: 24 additions & 0 deletions nbs-items-note/workflow.json
Original file line number Diff line number Diff line change
@@ -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": {}
}