Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new functionality to Usage chart requests (#716)
* Add new functionality to Usage chart requests Added the ability for Usage chart requests to provide non-numeric values for '_filter' parameters. The new feature will attempt to translate these non-numeric values into appropriate id values that can be used during chart generation. Specifically this new feature is to support integration w/ Coldfront. * Updates to support multiple string values * Style fix * Updating documentation * Simplification of the `translateValue` function per @jpwhite4 Per code review comments I've simplified this function. - Moved the `is_numeric` check to the top of the function and used it as a short circuit. - Removed the anonymous function and moved the code it contained to the bottom of the function, executed contingent on which `case`, if any, is hit. * New integration tests for the newly added Usage functionality This new test checks that the `_filter` variables accept non-id values (optionally, multiple comma delimited values). The test data includes the following: - Tests run as all users ( pub, cd, cs, pi, usr ) - Multiple Realms ( Jobs, Cloud ) - For the Jobs realm, all combinations of: ( including single, multiple, numeric & non-numeric values ) - 'resource', 'resource_filter' - 'pi', 'pi_filter' - For the Cloud realm: ( including single, multiple, numeric, and non-numeric values ) - 'project', 'project_filter' * Style Fix * Updates per @jpwhite4 comment As this function should only ever return one value the code has been updated so that this is the case. * Updates per convo w/ @smgallo - Updated `translateFilterValue` to return an array of values and the calling code to work with an array as opposed to a single value. This is to support the use case of a system account being associated with more than one person. - Updated `translateFilterValue` to only interpret `$usageFilterValue` as a string if it contains quotes ( single or double ). This allows us to identify when the calling code is passing us a value that is intended to be interpreted as a string not a number. - Updated Test Cases so that string values are quoted with both single / double quotes. - Added additional test cases that test what happens when a string value is provided that is not found in the db. * Refactor / Simplification of Usage Filter generation Refactored a portion of the `convertChartRequest` function and combined the two `for-each` loops that were populating the `$meFilters` variable. Now we have one loop that has the same functionality. Also a tiny comment update in the `translateFilterValue` function for the 'pi' filter type. Now that we always return an array the previous comment didn't really make sense anymore. * Simplified `translateFilterValue` Now that we have a reliable test for what constitutes a "string" ( i.e. must be quoted ) we can simplify the internals of `translateFilterValue` by removing the vast majority of the if/elseif block. Also added a few comments to help provide context. * Providing more informative exception info Added `$usageFilterType` to the message for the exception thrown in `translateFilterValue`. * Updating the translateFilterValue exception message Added the invalid `$usageFilterValue` to the exception message and updated the section in the tests that handled detecting when exceptions are thrown to handle this update. * Update classes/DataWarehouse/Access/Usage.php Co-Authored-By: ryanrath <ryanrath@buffalo.edu>
- Loading branch information