LP#1772680: Fixed a bug with checkouts and holds API call
authorJaswinder Singh <Jaswinder.Singh0011@gmail.com>
Thu, 18 Oct 2018 21:17:25 +0000 (17:17 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 16 Mar 2020 19:09:45 +0000 (15:09 -0400)
Signed-off-by: Jaswinder Singh <jaswinder.singh0011@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/EbookAPI/RBDigital.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/RBDigitalSearch.pm

index f2632ef..3876a31 100644 (file)
@@ -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;
+        }
     }
 }
 
index eeef804..2e1449e 100644 (file)
@@ -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
index f4f05c4..b028f19 100644 (file)
@@ -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}; 
         }