From: Lebbeous Fogle-Weekley Date: Fri, 30 Sep 2011 20:20:04 +0000 (-0400) Subject: SuperCat using new in DB authority browsing with NFI X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eba1bcdceb3afcd4d9771ef6a90e12dbb2f8db8f;p=evergreen%2Fequinox.git SuperCat using new in DB authority browsing with NFI There are still no external (WWW) supercat API entry points AFAICT for by axis browse top, search by rank, or search by heading. There are no entry points for doing anything by bib tag or by authority tag. There are, however, (ML) supercat API entry points for all of these. The new storage method was to support the only efficient way available to us of mapping the results of the in-DB authority browse/search functions (which are simple heading IDs, I think?) to authority record IDs. To do so in the middle layer would have been much, much slower, and would either involve lots of request or passing potentially huge arrays of IDs as arguments to a function. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm index af0dff69b7..e510439e4f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/authority.pm @@ -259,6 +259,30 @@ for my $class ( qw/title author subject keyword series identifier/ ) { cachable => 1, ); } +__PACKAGE__->register_method( + api_name => "open-ils.storage.authority.in_db.browse", + method => "authority_in_db_browse", + api_level => 1, + argc => 5 +); + +sub authority_in_db_browse { + my ($self, $shift, $method, @args) = @_; + return unless $method =~ /^\w+$/; + + my $db = authority::full_rec->db_Main; + my $list = $db->selectcol_arrayref( + qq/ + SELECT ash.record + FROM (SELECT * FROM authority.$method(?,?,?,?)) func + JOIN authority.simple_heading ash ON + (ash.id = func.$method); + /, + {}, @args + ); + + return $list; +} 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm index a43abc5fb8..7b8913bde4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm @@ -179,6 +179,8 @@ sub child_init { register_record_transforms(); + register_new_authorities_methods(); + return 1; } @@ -226,6 +228,73 @@ sub register_record_transforms { } } +sub register_new_authorities_methods { + my %register_args = ( + method => "generic_new_authorities_method", + api_level => 1, + argc => 1, + signature => { + desc => q/Generated method/, + } + ); + + foreach my $how (qw/axis atag btag/) { + foreach my $action (qw/browse_center browse_top + search_rank search_heading/) { + + $register_args{api_name} = + "open-ils.supercat.authority.$action.by_$how"; + __PACKAGE__->register_method(%register_args); + + $register_args{api_name} = + "open-ils.supercat.authority.$action.by_$how.refs"; + __PACKAGE__->register_method(%register_args); + + } + } +} + +sub generic_new_authorities_method { + my $self = shift; + my $client = shift; + + # We want to be extra careful with these arguments, since the next + # thing we're doing with them is passing them to a DB procedure. + my $term = ''.shift; + my $value = ''.shift; + my $page = int(shift || 0); + my $page_size = shift; + + # undef ok, but other non numbers not ok + $page_size = int($page_size) if defined $page_size; + + # Figure out how we were called and what DB procedure we'll call in turn. + $self->api_name =~ /\.by_(\w+)($|\.)/; + my $metaaxis = $1; + my $refs = $2; + + $self->api_name =~ /authority\.(\w+)\./; + my $action = $1; + + my $method = "${metaaxis}_$action"; + $method .= "_refs" if $refs; + + # Match authority.full_rec normalization + # XXX don't know whether we need second arg 'subfield'? + $value = naco_normalize($value); + + my $storage = create OpenSRF::AppSession("open-ils.storage"); + my $list = $storage->request( + "open-ils.storage.authority.in_db.browse", + $method, $term, $value, $page, $page_size + )->gather(1); + + $storage->kill_me; + + return $list; +} + + sub tree_walker { my $tree = shift; my $field = shift; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm index 4ca4b9d24d..1ae1dd0f1f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm @@ -1561,12 +1561,21 @@ sub string_browse { my $tree; if ($axis =~ /^authority/) { + # Formerly, this was always browse by axis, so for right this moment + # I'm still not implementing a front door API for atag and btag + # browsing, but I might do it in a moment. + + my ($realaxis, $refs) = ($axis =~ /^authority\.(\w+)(\.refs)?$/); + + my $method = "open-ils.supercat.authority.browse_center.by_axis"; + $method .= ".refs" if $refs; + $tree = $supercat->request( - "open-ils.supercat.authority.browse.by_axis", - $axis, + $method, + $realaxis, $string, - $page_size, - $page + $page, + $page_size )->gather(1); } else { $tree = $supercat->request(