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

fix query to filter on effective location #381

Merged
merged 23 commits into from
Jul 8, 2024
Merged
Changes from 9 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
59 changes: 40 additions & 19 deletions books-call-number/nodes/js/buildQuery.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
if (logLevel === 'DEBUG') {
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
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');

var where = 'TRUE';
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved

const locationNames = execution.getVariable('locationName') || [];
wwtamu marked this conversation as resolved.
Show resolved Hide resolved
const maxAllowedCharacters = 3000;
wwtamu marked this conversation as resolved.
Show resolved Hide resolved
let totalCharacterCount = 0;
wwtamu marked this conversation as resolved.
Show resolved Hide resolved

var locationNameArray = JSON.parse(locationName);


for (var i = 0; i < locationNames.length; i++) {
wwtamu marked this conversation as resolved.
Show resolved Hide resolved
var locationNameVar = locationNames[i];
totalCharacterCount += locationNameVar.length;
}


if (totalCharacterCount > maxAllowedCharacters) {
throw new Error("Selection exceeds the maximum allowed character count.");
}
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved
execution.setVariable('validatedLocationNames', locationNames);

if (startRange) {
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved
where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')';
where = '\n\t\tUPPER(ie.effective_call_number) >= UPPER(\'' + startRange + '\')';
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
}

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, \'ÿ\')';
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
}

where += '\n\t\tAND ie.status_name = \'Checked out\'';

if (locationNameArray.length > 0 && locationNameArray.length < totalCharacterCount) {
wwtamu marked this conversation as resolved.
Show resolved Hide resolved
print(locationNameArray);
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
where += "\n\tAND ie.effective_location_name IN ('"+locationNameArray.join("', '")+"')";
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved
}

var cte = 'WITH MaxLength AS (' +
'\n\tSELECT MAX(LENGTH(ie.effective_call_number)) AS max_len' +
'\n\tFROM folio_reporting.item_ext ie' +
')';
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved

var booksCallNumberQuery =
'\n\n' + cte +
'\nSELECT ie.effective_call_number' +
'\n\tFROM folio_reporting.item_ext ie' +
'\n\tCROSS JOIN MaxLength' +
'\nWHERE ' + where +
'\nORDER BY ie.effective_call_number';

if (logLevel === 'DEBUG') {
print('\nbooksCallNumberQuery = ' + booksCallNumberQuery);
}
'\n\n' + cte +
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
'\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';

print(booksCallNumberQuery);

var queryWrapper = {
sql: booksCallNumberQuery,
rmathew1011 marked this conversation as resolved.
Show resolved Hide resolved
sql: booksCallNumberQuery,
};

execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper)));
execution.setVariableLocal('booksCallNumberQuery', S(JSON.stringify(queryWrapper)));
rhundal7 marked this conversation as resolved.
Show resolved Hide resolved