From 7d26505c6b7052770032816f1197cf5d45cf8471 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 27 Apr 2011 11:42:58 -0400 Subject: [PATCH] Start of AC by record ID from 2011 hackfest Rough, untested cut. use rec id as they added content key; fetch isbn/upc from full_rec; push full set of isbns and upcs down to handler code Signed-off-by: Jeff Godin Signed-off-by: Ben Shum --- .../perlmods/lib/OpenILS/WWW/AddedContent.pm | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent.pm index 9c0611f380..dcd5d1fa4f 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; @@ -82,45 +83,87 @@ 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; + my $key_data = get_rec_keys($id); + my @isbns = grep {$_->{tag} eq '020'} @$key_data; + my @upcs = grep {$_->{tag} eq '024'} @$key_data; + + my $keys = { + isbn => [map {$_->{value}} @isbns], + upc => [map {$_->{value}} @upcs] + }; + + # TODO clean isbn + + # XXX DEBUG + use OpenSRF::Utils::JSON; + $logger->info("Added Content Keys: " . OpenSRF::Utils::JSON->perl2JSON($keys)); + try { - $data = $handler->$method($key); - } catch Error with { - $err = shift; + $data = $handler->$method($keys); + } catch Error with { + $err = shift; decr_error_countdown(); - $logger->debug("added content handler failed: $method($key) => $err"); + $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.43.2