From 85f89a260eb70d64c79fa3ce1f57996be28fc83a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 27 Apr 2011 11:42:58 -0400 Subject: [PATCH] Rough, untested cut. use rec id as they added content key; fetch isbn/upc from full_rec; loop and look up content, stop when we find something --- .../src/perlmods/lib/OpenILS/WWW/AddedContent.pm | 67 +++++++++++++++++----- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm index 0e85a54a34..5e9c2bf352 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm @@ -15,6 +15,7 @@ use OpenSRF::EX qw(:try); use OpenSRF::Utils::Cache; use OpenSRF::System; use OpenSRF::Utils::Logger qw/$logger/; +use OpenILS::Utils::CStoreEditor; use LWP::UserAgent; use MIME::Base64; @@ -81,45 +82,83 @@ sub handler { my @path_parts = split( /\//, $r->unparsed_uri ); my $type = $path_parts[-3]; my $format = $path_parts[-2]; - my $key = $path_parts[-1]; + my $id = $path_parts[-1]; my $res; child_init() unless $handler; - return Apache2::Const::NOT_FOUND unless $handler and $type and $format and $key; + return Apache2::Const::NOT_FOUND unless $handler and $type and $format and $id; my $err; my $data; my $method = "${type}_${format}"; return Apache2::Const::NOT_FOUND unless $handler->can($method); - return $res if defined($res = $AC->serve_from_cache($type, $format, $key)); + return $res if defined($res = $AC->serve_from_cache($type, $format, $id)); return Apache2::Const::NOT_FOUND unless $AC->lookups_enabled; - try { - $data = $handler->$method($key); - } catch Error with { - $err = shift; - decr_error_countdown(); - $logger->debug("added content handler failed: $method($key) => $err"); - }; + my $keys = get_rec_keys($id); + my @isbns = grep { $_->{tag} eq '020' } @$keys; + my @upcs = grep { $_->{tag} eq '024' } @$keys; - return Apache2::Const::NOT_FOUND if $err; + for my $key (@isbns, @upcs) { + + my $key_type = $key->{tag}; + my $key_value = $key->{value}; + $logger->info("AC: trying key $key_value : $key_type"); + + try { + $data = $handler->$method($key_value, $key_type); + } catch Error with { + $err = shift; + decr_error_countdown(); + $logger->debug("added content handler failed: $method($id) => $err"); + }; + + return Apache2::Const::NOT_FOUND if $err; + next unless $data; + } if(!$data) { # if the AC lookup found no corresponding data, cache that information - $logger->debug("added content handler returned no results $method($key)") unless $data; - $AC->cache_result($type, $format, $key, {nocontent=>1}); + $logger->debug("added content handler returned no results $method($id)") unless $data; + $AC->cache_result($type, $format, $id, {nocontent=>1}); return Apache2::Const::NOT_FOUND; } $AC->print_content($data); - $AC->cache_result($type, $format, $key, $data); + $AC->cache_result($type, $format, $id, $data); reset_error_countdown(); return Apache2::Const::OK; } +# returns [{tag => $tag, value => $value}, {tag => $tag2, value => $value2}] +sub get_rec_keys { + my $id = shift; + return OpenILS::Utils::CStoreEditor->new->json_query({ + select => {mfr => ['tag', 'value']}, + from => 'mfr', + where => { + record => $id, + '-or' => [ + { + '-and' => [ + {tag => '020'}, + {subfield => 'a'} + ] + }, { + '-and' => [ + {tag => '024'}, + {subfield => 'a'}, + {ind1 => 1} + ] + } + ] + } + }); +} + sub print_content { my($class, $data, $from_cache) = @_; return Apache2::Const::NOT_FOUND if $data->{nocontent}; -- 2.11.0