From f1e9be7a669127fde7cd21b85e8281bb246e03ec Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Fri, 21 Jun 2024 15:20:11 -0500 Subject: [PATCH 01/22] wip issue 378 --- books-call-number/nodes/js/buildQuery.js | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 5b73f851..26212760 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -6,6 +6,53 @@ if (logLevel === 'DEBUG') { var where = 'TRUE'; +// wip top + +var libraryNameArray = JSON.parse(libraryName); + +var normalizeArray = function (array) { + var index = array.indexOf('All'); + if (index >= 0) { + array.splice(index, 1); + } +}; + +if (libraryNameArray) { + normalizeArray(libraryNameArray); + if (libraryNameArray.length > 0) { + from += '\n\tLEFT JOIN public.inventory_locations publoc ON item_ext.effective_location_id = publoc.id' + + '\n\tLEFT JOIN public.inventory_libraries publib ON publoc.library_id = publib.id'; + + where += '\n\tAND publib.name IN (\'' + libraryNameArray.join('\',\'') + '\')'; + } +} + + +var locationDiscoveryDisplayNameArray = JSON.parse(locationDiscoveryDisplayName); + +if (locationDiscoveryDisplayNameArray) { + normalizeArray(locationDiscoveryDisplayNameArray); + + if (locationDiscoveryDisplayNameArray.length > 0) { + from += '\n\tLEFT JOIN public.inventory_locations publoc ON item_ext.effective_location_name = publoc.name'; + + where += '\n\tAND publoc.discovery_display_name IN (\'' + locationDiscoveryDisplayNameArray.join('\',\'') + '\')'; + } +} + +var locationNameArray = JSON.parse(locationName); + +if (locationNameArray) { + normalizeArray(locationNameArray); + + if (locationNameArray.length > 0) { + where += '\n\tAND item_ext.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; + } +} + + +// wip bottom + if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } @@ -24,6 +71,7 @@ var cte = 'WITH MaxLength AS (' + var booksCallNumberQuery = '\n\n' + cte + '\nSELECT ie.effective_call_number' + + '\n\tie.effective_location_name AS item_effective_location,' + // wip '\n\tFROM folio_reporting.item_ext ie' + '\n\tCROSS JOIN MaxLength' + '\nWHERE ' + where + From 1eeb5e9a645e876d5cd433c6a98e7d9c16d0b3a7 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 24 Jun 2024 07:53:35 -0500 Subject: [PATCH 02/22] added print statements, untested --- books-call-number/nodes/js/buildQuery.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 26212760..bf548dfa 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -2,12 +2,14 @@ if (logLevel === 'DEBUG') { print('\nlogLevel = ' + logLevel + '\n'); print('\ncall number start range = ' + startRange + '\n'); print('\ncall number end range = ' + endRange + '\n'); + + print('libraryName = ' + libraryName + '\n'); + print('locationDiscoveryDisplayName = ' + locationDiscoveryDisplayName + '\n'); + print('locationName = ' + locationName + '\n'); } var where = 'TRUE'; -// wip top - var libraryNameArray = JSON.parse(libraryName); var normalizeArray = function (array) { @@ -27,7 +29,6 @@ if (libraryNameArray) { } } - var locationDiscoveryDisplayNameArray = JSON.parse(locationDiscoveryDisplayName); if (locationDiscoveryDisplayNameArray) { @@ -50,9 +51,6 @@ if (locationNameArray) { } } - -// wip bottom - if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } @@ -71,11 +69,15 @@ var cte = 'WITH MaxLength AS (' + var booksCallNumberQuery = '\n\n' + cte + '\nSELECT ie.effective_call_number' + - '\n\tie.effective_location_name AS item_effective_location,' + // wip + '\n\tie.effective_location_name AS item_effective_location,' + '\n\tFROM folio_reporting.item_ext ie' + '\n\tCROSS JOIN MaxLength' + '\nWHERE ' + where + - '\nORDER BY ie.effective_call_number'; + '\nORDER BY ie.effective_call_number, item_effective_location'; + +if (logLevel === 'DEBUG') { + print('\nbooksCallNumberQuery = ' + booksCallNumberQuery); +} if (logLevel === 'DEBUG') { print('\nbooksCallNumberQuery = ' + booksCallNumberQuery); From 361a5281b979a95f797591dfc548efda075b4b23 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 24 Jun 2024 13:44:02 -0500 Subject: [PATCH 03/22] fixed query and cleaned up variables --- books-call-number/nodes/js/buildQuery.js | 55 +++++------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index bf548dfa..b614ab53 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -1,17 +1,11 @@ -if (logLevel === 'DEBUG') { print('\nlogLevel = ' + logLevel + '\n'); print('\ncall number start range = ' + startRange + '\n'); print('\ncall number end range = ' + endRange + '\n'); - print('libraryName = ' + libraryName + '\n'); - print('locationDiscoveryDisplayName = ' + locationDiscoveryDisplayName + '\n'); print('locationName = ' + locationName + '\n'); -} var where = 'TRUE'; -var libraryNameArray = JSON.parse(libraryName); - var normalizeArray = function (array) { var index = array.indexOf('All'); if (index >= 0) { @@ -19,38 +13,8 @@ var normalizeArray = function (array) { } }; -if (libraryNameArray) { - normalizeArray(libraryNameArray); - if (libraryNameArray.length > 0) { - from += '\n\tLEFT JOIN public.inventory_locations publoc ON item_ext.effective_location_id = publoc.id' - + '\n\tLEFT JOIN public.inventory_libraries publib ON publoc.library_id = publib.id'; - - where += '\n\tAND publib.name IN (\'' + libraryNameArray.join('\',\'') + '\')'; - } -} - -var locationDiscoveryDisplayNameArray = JSON.parse(locationDiscoveryDisplayName); - -if (locationDiscoveryDisplayNameArray) { - normalizeArray(locationDiscoveryDisplayNameArray); - - if (locationDiscoveryDisplayNameArray.length > 0) { - from += '\n\tLEFT JOIN public.inventory_locations publoc ON item_ext.effective_location_name = publoc.name'; - - where += '\n\tAND publoc.discovery_display_name IN (\'' + locationDiscoveryDisplayNameArray.join('\',\'') + '\')'; - } -} - var locationNameArray = JSON.parse(locationName); -if (locationNameArray) { - normalizeArray(locationNameArray); - - if (locationNameArray.length > 0) { - where += '\n\tAND item_ext.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; - } -} - if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } @@ -61,6 +25,13 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; +if (locationNameArray.length > 0) { + normalizeArray(locationNameArray); + print(locationNameArray); + + where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; +} + var cte = 'WITH MaxLength AS (' + '\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + '\n\tFROM folio_reporting.item_ext ie' + @@ -68,20 +39,14 @@ var cte = 'WITH MaxLength AS (' + var booksCallNumberQuery = '\n\n' + cte + - '\nSELECT ie.effective_call_number' + - '\n\tie.effective_location_name AS item_effective_location,' + + '\nSELECT ie.effective_call_number,' + + '\n\tie.effective_location_name AS item_effective_location' + '\n\tFROM folio_reporting.item_ext ie' + '\n\tCROSS JOIN MaxLength' + '\nWHERE ' + where + '\nORDER BY ie.effective_call_number, item_effective_location'; -if (logLevel === 'DEBUG') { - print('\nbooksCallNumberQuery = ' + booksCallNumberQuery); -} - -if (logLevel === 'DEBUG') { - print('\nbooksCallNumberQuery = ' + booksCallNumberQuery); -} +print(booksCallNumberQuery); var queryWrapper = { sql: booksCallNumberQuery, From 7d4f24b43184f21efaef9753f0f83751cb546df4 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 24 Jun 2024 15:53:05 -0500 Subject: [PATCH 04/22] wip selecting all values in dropdown and sending to query --- books-call-number/nodes/js/buildQuery.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index b614ab53..6e5a9399 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -13,6 +13,9 @@ var normalizeArray = function (array) { } }; +if(locationName == ["All"]){ + +} var locationNameArray = JSON.parse(locationName); if (startRange) { @@ -25,12 +28,9 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; -if (locationNameArray.length > 0) { - normalizeArray(locationNameArray); - print(locationNameArray); - - where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; -} + normalizeArray(locationNameArray); + print(locationNameArray); + where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; var cte = 'WITH MaxLength AS (' + '\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + From 78d85c7e2861bb99789d7b105a39057a8d42a24c Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 24 Jun 2024 15:54:50 -0500 Subject: [PATCH 05/22] removed unwanted code --- books-call-number/nodes/js/buildQuery.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 6e5a9399..07e8ee22 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -13,9 +13,6 @@ var normalizeArray = function (array) { } }; -if(locationName == ["All"]){ - -} var locationNameArray = JSON.parse(locationName); if (startRange) { From 0baaa5870f486cdf85d1478808168ff359784dd5 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Tue, 25 Jun 2024 14:59:59 -0500 Subject: [PATCH 06/22] wip --- books-call-number/nodes/js/buildQuery.js | 55 +++++++++++++----------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 07e8ee22..3e3ccc50 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -1,52 +1,59 @@ - print('\nlogLevel = ' + logLevel + '\n'); - print('\ncall number start range = ' + startRange + '\n'); - print('\ncall number end range = ' + endRange + '\n'); +print('\nlogLevel = ' + logLevel + '\n'); +print('\ncall number start range = ' + startRange + '\n'); +print('\ncall number end range = ' + endRange + '\n'); - print('locationName = ' + locationName + '\n'); +print('locationName = ' + locationName + '\n'); -var where = 'TRUE'; +var where; +var batchSize = 10; var normalizeArray = function (array) { - var index = array.indexOf('All'); - if (index >= 0) { - array.splice(index, 1); - } +var index = array.indexOf('All'); +if (index >= 0) { + array.splice(index, 1); +} }; var locationNameArray = JSON.parse(locationName); if (startRange) { - where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; +where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } if (endRange) { - where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange + '\'), max_len, \'ÿ\')'; +where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange + '\'), max_len, \'ÿ\')'; } where += '\n\t\tAND ie.status_name = \'Checked out\''; - normalizeArray(locationNameArray); - print(locationNameArray); - where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; - var cte = 'WITH MaxLength AS (' + '\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + '\n\tFROM folio_reporting.item_ext ie' + ')'; +if (locationNameArray.length) { +normalizeArray(locationNameArray); +print(locationNameArray); +where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; +} + var booksCallNumberQuery = - '\n\n' + cte + - '\nSELECT ie.effective_call_number,' + - '\n\tie.effective_location_name AS item_effective_location' + - '\n\tFROM folio_reporting.item_ext ie' + - '\n\tCROSS JOIN MaxLength' + - '\nWHERE ' + where + - '\nORDER BY ie.effective_call_number, item_effective_location'; +'\n\n' + cte + +'\nSELECT ie.effective_call_number,' + +'\n\tie.effective_location_name AS item_effective_location' + +'\n\tFROM folio_reporting.item_ext ie' + +'\n\tCROSS JOIN MaxLength'; + +if(!!where){ +booksCallNumberQuery += '\nWHERE ' + where; +} + +booksCallNumberQuery+= '\nORDER BY ie.effective_call_number, item_effective_location'; print(booksCallNumberQuery); var queryWrapper = { - sql: booksCallNumberQuery, +sql: booksCallNumberQuery, }; -execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); +execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); \ No newline at end of file From 67c72f3412bc59ed7ca94933cd2466edd151db08 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Thu, 27 Jun 2024 08:15:18 -0500 Subject: [PATCH 07/22] fix commas for query --- books-call-number/nodes/js/buildQuery.js | 29 ++++++++++-------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 3e3ccc50..a6c3c474 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -1,11 +1,9 @@ print('\nlogLevel = ' + logLevel + '\n'); print('\ncall number start range = ' + startRange + '\n'); print('\ncall number end range = ' + endRange + '\n'); - print('locationName = ' + locationName + '\n'); -var where; -var batchSize = 10; +var where = 'TRUE'; var normalizeArray = function (array) { var index = array.indexOf('All'); @@ -26,29 +24,26 @@ where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange where += '\n\t\tAND ie.status_name = \'Checked out\''; +if (locationNameArray.length > 0) { + print(locationNameArray); + +where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; +print("less than 20"); +} + var cte = 'WITH MaxLength AS (' + '\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + '\n\tFROM folio_reporting.item_ext ie' + ')'; -if (locationNameArray.length) { -normalizeArray(locationNameArray); -print(locationNameArray); -where += '\n\tAND ie.effective_location_name IN (\'' + locationNameArray.join('\',\'') + '\')'; -} - var booksCallNumberQuery = '\n\n' + cte + '\nSELECT ie.effective_call_number,' + '\n\tie.effective_location_name AS item_effective_location' + '\n\tFROM folio_reporting.item_ext ie' + -'\n\tCROSS JOIN MaxLength'; - -if(!!where){ -booksCallNumberQuery += '\nWHERE ' + where; -} - -booksCallNumberQuery+= '\nORDER BY ie.effective_call_number, item_effective_location'; +'\n\tCROSS JOIN MaxLength' + +'\nWHERE ' + where + +'\nORDER BY ie.effective_call_number, item_effective_location'; print(booksCallNumberQuery); @@ -56,4 +51,4 @@ var queryWrapper = { sql: booksCallNumberQuery, }; -execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); \ No newline at end of file +execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); From 2c70f323ea316f4ff932ddf1a7ca331bb321a448 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Fri, 28 Jun 2024 12:10:43 -0500 Subject: [PATCH 08/22] added code to cleanup locationName array --- books-call-number/nodes/js/buildQuery.js | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index a6c3c474..844b28f9 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -5,15 +5,24 @@ print('locationName = ' + locationName + '\n'); var where = 'TRUE'; -var normalizeArray = function (array) { -var index = array.indexOf('All'); -if (index >= 0) { - array.splice(index, 1); -} -}; +const locationNames = execution.getVariable('locationName') || []; +const maxAllowedCharacters = 3000; +let totalCharacterCount = 0; var locationNameArray = JSON.parse(locationName); + +for (var i = 0; i < locationNames.length; i++) { + var locationName = locationNames[i]; + totalCharacterCount += locationName.length; +} + + +if (totalCharacterCount > maxAllowedCharacters) { + throw new Error("Selection exceeds the maximum allowed character count."); +} +execution.setVariable('validatedLocationNames', locationNames); + if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } @@ -26,9 +35,7 @@ where += '\n\t\tAND ie.status_name = \'Checked out\''; if (locationNameArray.length > 0) { print(locationNameArray); - -where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; -print("less than 20"); + where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } var cte = 'WITH MaxLength AS (' + @@ -51,4 +58,4 @@ var queryWrapper = { sql: booksCallNumberQuery, }; -execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); +execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); \ No newline at end of file From 2e40897a7f557038d258c91146bf1fecbd208861 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Fri, 28 Jun 2024 12:19:34 -0500 Subject: [PATCH 09/22] cleaned up variable names --- books-call-number/nodes/js/buildQuery.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 844b28f9..649760b4 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -13,8 +13,8 @@ var locationNameArray = JSON.parse(locationName); for (var i = 0; i < locationNames.length; i++) { - var locationName = locationNames[i]; - totalCharacterCount += locationName.length; + var locationNameVar = locationNames[i]; + totalCharacterCount += locationNameVar.length; } @@ -33,7 +33,7 @@ where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange where += '\n\t\tAND ie.status_name = \'Checked out\''; -if (locationNameArray.length > 0) { +if (locationNameArray.length > 0 && locationNameArray.length < totalCharacterCount) { print(locationNameArray); where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } From 4e767c6716b861d9a2d12bbb6ea09c6d8fc36098 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 1 Jul 2024 13:12:53 -0500 Subject: [PATCH 10/22] removed unused code --- books-call-number/nodes/js/buildQuery.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 649760b4..e7e4eb8d 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -1,8 +1,9 @@ -print('\nlogLevel = ' + logLevel + '\n'); -print('\ncall number start range = ' + startRange + '\n'); -print('\ncall number end range = ' + endRange + '\n'); -print('locationName = ' + locationName + '\n'); - +if (logLevel === 'DEBUG') { + print('\nlogLevel = ' + logLevel + '\n'); + print('\ncall number start range = ' + startRange + '\n'); + print('\ncall number end range = ' + endRange + '\n'); + print('locationName = ' + locationName + '\n'); +} var where = 'TRUE'; const locationNames = execution.getVariable('locationName') || []; @@ -11,30 +12,24 @@ let totalCharacterCount = 0; var locationNameArray = JSON.parse(locationName); - for (var i = 0; i < locationNames.length; i++) { var locationNameVar = locationNames[i]; totalCharacterCount += locationNameVar.length; } -if (totalCharacterCount > maxAllowedCharacters) { - throw new Error("Selection exceeds the maximum allowed character count."); -} -execution.setVariable('validatedLocationNames', locationNames); - if (startRange) { -where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; + where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } if (endRange) { -where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange + '\'), max_len, \'ÿ\')'; + where += '\n\t\tAND UPPER(ie.effective_call_number) <= RPAD(UPPER(\'' + endRange + '\'), max_len, \'ÿ\')'; } where += '\n\t\tAND ie.status_name = \'Checked out\''; if (locationNameArray.length > 0 && locationNameArray.length < totalCharacterCount) { - print(locationNameArray); + print(locationNameArray); where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } From e9914d628c28c1aad09e4d38785a0a2eb00094bf Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 1 Jul 2024 13:31:11 -0500 Subject: [PATCH 11/22] fix indentation --- books-call-number/nodes/js/buildQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index e7e4eb8d..f9bd117f 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -50,7 +50,7 @@ var booksCallNumberQuery = print(booksCallNumberQuery); var queryWrapper = { -sql: booksCallNumberQuery, + sql: booksCallNumberQuery, }; execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); \ No newline at end of file From f9aafc2c92371c2b811f8905eb150374d7541486 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 1 Jul 2024 13:33:38 -0500 Subject: [PATCH 12/22] add eof line --- books-call-number/nodes/js/buildQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index f9bd117f..8c8baa99 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -53,4 +53,4 @@ var queryWrapper = { sql: booksCallNumberQuery, }; -execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); \ No newline at end of file +execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper))); From 79ca836c4ee36fe2a21a2cd6e8eb6aaf5aced77c Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Mon, 1 Jul 2024 19:47:30 -0500 Subject: [PATCH 13/22] removed unnecessary and repetitive code --- books-call-number/nodes/js/buildQuery.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 8c8baa99..313d28b2 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -6,18 +6,11 @@ if (logLevel === 'DEBUG') { } var where = 'TRUE'; -const locationNames = execution.getVariable('locationName') || []; +const locationNames = execution.getVariable('locationName'); + const maxAllowedCharacters = 3000; let totalCharacterCount = 0; -var locationNameArray = JSON.parse(locationName); - -for (var i = 0; i < locationNames.length; i++) { - var locationNameVar = locationNames[i]; - totalCharacterCount += locationNameVar.length; -} - - if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } @@ -28,9 +21,9 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; -if (locationNameArray.length > 0 && locationNameArray.length < totalCharacterCount) { - print(locationNameArray); - where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; +if(locationNames.length > 0) +{ + where += "\n\tAND ie.effective_location_name IN ('"+locationNames+"')"; } var cte = 'WITH MaxLength AS (' + From c4c132320f6be5d8a45f897025d9486e9fed109e Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Tue, 2 Jul 2024 09:54:48 -0500 Subject: [PATCH 14/22] use join function for array --- books-call-number/nodes/js/buildQuery.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 313d28b2..d14143ba 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -6,10 +6,7 @@ if (logLevel === 'DEBUG') { } var where = 'TRUE'; -const locationNames = execution.getVariable('locationName'); - -const maxAllowedCharacters = 3000; -let totalCharacterCount = 0; +var locationNameArray = JSON.parse(locationName); if (startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; @@ -21,9 +18,9 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; -if(locationNames.length > 0) +if(locationNameArray.length > 0) { - where += "\n\tAND ie.effective_location_name IN ('"+locationNames+"')"; + where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } var cte = 'WITH MaxLength AS (' + From 37cf1fdec614c93d91f4c19264a856a74f95c7ab Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Tue, 2 Jul 2024 10:05:00 -0500 Subject: [PATCH 15/22] fix spacing --- books-call-number/nodes/js/buildQuery.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index d14143ba..864e917c 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -18,9 +18,8 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; -if(locationNameArray.length > 0) -{ - where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; +if(locationNameArray.length > 0) { + where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } var cte = 'WITH MaxLength AS (' + From de446eed2ed4af47126bcf610a42edab1e53aca0 Mon Sep 17 00:00:00 2001 From: Rajdeep Date: Tue, 2 Jul 2024 10:06:35 -0500 Subject: [PATCH 16/22] added newline Co-authored-by: William Welling <144841721+wwelling@users.noreply.github.com> --- books-call-number/nodes/js/buildQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 864e917c..feaa95a2 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -2,7 +2,7 @@ if (logLevel === 'DEBUG') { print('\nlogLevel = ' + logLevel + '\n'); print('\ncall number start range = ' + startRange + '\n'); print('\ncall number end range = ' + endRange + '\n'); - print('locationName = ' + locationName + '\n'); + print('\nlocationName = ' + locationName + '\n'); } var where = 'TRUE'; From 15142f49d6ae73a18d16660b75e6cbe0341a3255 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Tue, 2 Jul 2024 10:08:02 -0500 Subject: [PATCH 17/22] fix indentation --- books-call-number/nodes/js/buildQuery.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 864e917c..90e339f5 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -18,7 +18,7 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; -if(locationNameArray.length > 0) { +if (locationNameArray.length > 0) { where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; } @@ -36,8 +36,6 @@ var booksCallNumberQuery = '\nWHERE ' + where + '\nORDER BY ie.effective_call_number, item_effective_location'; -print(booksCallNumberQuery); - var queryWrapper = { sql: booksCallNumberQuery, }; From 1469cbaa8705781e7d3760e1a5677a383a663d65 Mon Sep 17 00:00:00 2001 From: Rajdeep Hundal Date: Tue, 2 Jul 2024 10:20:27 -0500 Subject: [PATCH 18/22] fix indentation and added query printing line --- books-call-number/nodes/js/buildQuery.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index fb45d395..34ea0806 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -28,13 +28,17 @@ var cte = 'WITH MaxLength AS (' + ')'; var booksCallNumberQuery = -'\n\n' + cte + -'\nSELECT ie.effective_call_number,' + -'\n\tie.effective_location_name AS item_effective_location' + -'\n\tFROM folio_reporting.item_ext ie' + -'\n\tCROSS JOIN MaxLength' + -'\nWHERE ' + where + -'\nORDER BY ie.effective_call_number, item_effective_location'; + '\n\n' + cte + + '\nSELECT ie.effective_call_number,' + + '\n\tie.effective_location_name AS item_effective_location' + + '\n\tFROM folio_reporting.item_ext ie' + + '\n\tCROSS JOIN MaxLength' + + '\nWHERE ' + where + + '\nORDER BY ie.effective_call_number, item_effective_location'; + +if (logLevel === 'DEBUG') { + print('\nbooksCallNumberQuery = ' + booksCallNumberQuery); +} var queryWrapper = { sql: booksCallNumberQuery, From b710e9537ef34d13d28ce232871f316a58e3c0fb Mon Sep 17 00:00:00 2001 From: Rajdeep Date: Tue, 2 Jul 2024 10:47:47 -0500 Subject: [PATCH 19/22] add back missing line Co-authored-by: Kevin Day <35114839+kaladay@users.noreply.github.com> --- books-call-number/nodes/js/buildQuery.js | 1 + 1 file changed, 1 insertion(+) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 34ea0806..3a97542b 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -4,6 +4,7 @@ if (logLevel === 'DEBUG') { print('\ncall number end range = ' + endRange + '\n'); print('\nlocationName = ' + locationName + '\n'); } + var where = 'TRUE'; var locationNameArray = JSON.parse(locationName); From ebeedd5ecaa8ca490d1bd62e3abce202e6a916ff Mon Sep 17 00:00:00 2001 From: Rajdeep Date: Tue, 2 Jul 2024 10:48:07 -0500 Subject: [PATCH 20/22] use double not operator Co-authored-by: Kevin Day <35114839+kaladay@users.noreply.github.com> --- books-call-number/nodes/js/buildQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 3a97542b..05e6ef91 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -9,7 +9,7 @@ var where = 'TRUE'; var locationNameArray = JSON.parse(locationName); -if (startRange) { +if (!!startRange) { where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')'; } From 477a432fb546d6e04612b55b7bef0701779c943c Mon Sep 17 00:00:00 2001 From: Rajdeep Date: Tue, 2 Jul 2024 10:48:22 -0500 Subject: [PATCH 21/22] fix spacing Co-authored-by: Kevin Day <35114839+kaladay@users.noreply.github.com> --- books-call-number/nodes/js/buildQuery.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index 05e6ef91..ee3f3a07 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -24,9 +24,9 @@ if (locationNameArray.length > 0) { } var cte = 'WITH MaxLength AS (' + -'\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + -'\n\tFROM folio_reporting.item_ext ie' + -')'; + '\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' + + '\n\tFROM folio_reporting.item_ext ie' + + ')'; var booksCallNumberQuery = '\n\n' + cte + From 801d81af9dc54da0248d559f07851efef48269d8 Mon Sep 17 00:00:00 2001 From: Rajdeep Date: Tue, 2 Jul 2024 10:48:36 -0500 Subject: [PATCH 22/22] fix spacing Co-authored-by: Kevin Day <35114839+kaladay@users.noreply.github.com> --- books-call-number/nodes/js/buildQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/books-call-number/nodes/js/buildQuery.js b/books-call-number/nodes/js/buildQuery.js index ee3f3a07..3f709a2a 100644 --- a/books-call-number/nodes/js/buildQuery.js +++ b/books-call-number/nodes/js/buildQuery.js @@ -20,7 +20,7 @@ if (endRange) { where += '\n\t\tAND ie.status_name = \'Checked out\''; if (locationNameArray.length > 0) { - where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')"; + where += "\n\tAND ie.effective_location_name IN ('" + locationNameArray.join("', '") + "')"; } var cte = 'WITH MaxLength AS (' +