From 60ea1fc2b9f6f6f05cae812267c123ef277e577c Mon Sep 17 00:00:00 2001 From: Jaswinder Singh Date: Thu, 18 Oct 2018 17:17:25 -0400 Subject: [PATCH] LP#1772680: Fixed a bug with checkouts and holds API call Signed-off-by: Jaswinder Singh Signed-off-by: Galen Charlton --- .../src/perlmods/lib/OpenILS/Application/EbookAPI.pm | 20 +++++++++++--------- .../lib/OpenILS/Application/EbookAPI/RBDigital.pm | 17 +++++++++++------ .../lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm | 10 +++++----- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm index f2632ef09d..3876a31590 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm @@ -84,7 +84,7 @@ sub update_cache { $logger->info("EbookAPI: overlaying new values on existing cache object"); foreach my $k (%$cache_obj) { # Add/overwrite existing cached value if a new value is defined. - $orig_cache->{$k} = $cache_obj->{$k} if (defined $cache_obj->{$k}); + $orig_cache->{$k} = $cache_obj->{$k} if ($k && defined($cache_obj->{$k})); } # The cache object we want to save is the (updated) original one. $cache_obj = $orig_cache; @@ -865,14 +865,16 @@ sub _get_patron_xacts { return; } - # cache and return transaction details - $handler->{$xact_type} = $xacts; - # Overlay transactions onto existing cached handler. - if (update_cache($handler, 1)) { - return $handler->{$xact_type}; - } else { - $logger->error("EbookAPI: error caching transaction details ($xact_type)"); - return; + if (defined($xacts)) { + # cache and return transaction details + $handler->{$xact_type} = $xacts; + # Overlay transactions onto existing cached handler. + if (update_cache($handler, 1)) { + return $handler->{$xact_type}; + } else { + $logger->error("EbookAPI: error caching transaction details ($xact_type)"); + return; + } } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm index eeef80436d..2e1449ea9e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm @@ -846,13 +846,15 @@ sub get_patron_checkouts { }; $logger->info("EbookAPI: retrieved " . scalar(@$checkouts) . " RBDigital checkouts for patron $patron_id"); - $self->{checkouts} = $checkouts; - return $self->{checkouts}; } else { $logger->error("EbookAPI: failed to retrieve RBDigital checkouts for patron $patron_id"); - return; + return ; } + if (scalar(@$checkouts) > 0) { + return $checkouts; + } + return undef; } @@ -895,12 +897,15 @@ sub get_patron_holds { }; }; $logger->info("EbookAPI: retrieved " . scalar(@$holds) . " RBDigital holds for patron $patron_id"); - $self->{holds} = $holds; - return $self->{holds}; } else { $logger->error("EbookAPI: failed to retrieve RBDigital holds for patron $patron_id"); - return; } + + if (scalar(@$holds) > 0) { + return $holds; + } + + return undef; } # Call this method to return 1 - true or 0 - false if the patron is associated with rbdigital library diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm index f4f05c4bcd..b028f198e9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm @@ -336,10 +336,10 @@ sub _get_patron_holds { my %holds_ref; - if (defined($holds_req->content)) { + if (defined($holds_req) && $holds_req->content ne '') { $logger->info('EbookAPI: RBDigitalSearch Patron Holds API call was successful'); # Loop over the holds contents and build hash array for easier to use in the UI: { isbn => '1', ...} - $logger->info("Holds response: " . Dumper($holds_req->content)); + $logger->info("EbookAPI: Holds response: " . Dumper($holds_req->content)); foreach my $value (@{$holds_req->content}) { $holds_ref{$value->{title_id}} = "1"; } @@ -359,10 +359,10 @@ sub _get_patron_checkouts { my %checkouts_ref; - if (defined($checkouts_req->content)) { - $logger->info('EbookAPI: RBDigitalSearch Patron Checkouts API call was successful'); + if (defined($checkouts_req) && $checkouts_req->content ne '') { + $logger->info('EbookAPI: EbookAPI: RBDigitalSearch Patron Checkouts API call was successful'); # Loop over the checkout contents and build hash array for easier to use in the UI: { isbn => '1', ...} - $logger->debug("Checkout response: " . Dumper($checkouts_req->content)); + $logger->debug("EbookAPI: Checkout response: " . Dumper($checkouts_req->content)); foreach my $value (@{$checkouts_req->content}) { $checkouts_ref{$value->{title_id}} = $value->{download_url}; } -- 2.11.0