From: dbs Date: Fri, 6 Nov 2009 05:20:39 +0000 (+0000) Subject: Add a new set of unapi/supercat holding-enriched formats, -uris X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=96f4dd1700a99efe0dd2772fdbbf885a23df53db;p=evergreen%2Fmasslnc.git Add a new set of unapi/supercat holding-enriched formats, -uris These formats focus on returning just URIs, rather than the bulky copy information returned by -full. Accordingly, the default data type requested by BibTemplate.js has been changed to 'marcxml-uris', as out of the box no functionality in the default or craftsman skins require copy information. Some of the duplicate code in OpenILS::WWW::SuperCat.pm has been refactored into subroutines. To aid the human reader of the -uris and -full output, line breaks and indentation has been introduced to the contents of the element. git-svn-id: svn://svn.open-ils.org/ILS/trunk@14802 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 6f7f5531b3..13f4e59e45 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -932,6 +932,7 @@ sub new_record_holdings { my $client = shift; my $bib = shift; my $ou = shift; + my $hide_copies = shift; my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' ); @@ -970,32 +971,40 @@ sub new_record_holdings { $year += 1900; $month += 1; - $client->respond(""); + $client->respond("\n"); for my $cn (@{$tree->call_numbers}) { - next unless ( $cn->deleted eq 'f' || $cn->deleted == 0 ); + next unless ( $cn->deleted eq 'f' || $cn->deleted == 0 ); my $found = 0; for my $c (@{$cn->copies}) { next unless grep {$c->circ_lib->id == $_} @ou_ids; - next unless ( $c->deleted eq 'f' || $c->deleted == 0 ); + next unless ( $c->deleted eq 'f' || $c->deleted == 0 ); $found = 1; last; } - if (!$found && ref($cn->uri_maps) && @{$cn->uri_maps}) { - $found = 1 if (grep {$cn->owning_lib->id == $_} @ou_ids); - } + if (!$found && ref($cn->uri_maps) && @{$cn->uri_maps}) { + $found = 1 if (grep {$cn->owning_lib->id == $_} @ou_ids); + } next unless $found; + # We don't want O:A:S:unAPI::acn to return the record, we've got that already + my $holdings_args = { no_record => 1 }; + # In the context of BibTemplate, copies aren't necessary because we pull those + # in a separate call + if ($hide_copies) { + $holdings_args->{no_copies} = 1; + } + $client->respond( OpenILS::Application::SuperCat::unAPI::acn ->new( $cn ) - ->as_xml({ no_record => 1 }) + ->as_xml( $holdings_args ) ); } - return ""; + return "\n"; } __PACKAGE__->register_method( method => 'new_record_holdings', @@ -1010,8 +1019,14 @@ Returns the XML representation of the requested bibliographic record's holdings params => [ { name => 'bibId', - desc => 'An OpenILS biblio::record_entry id', + desc => 'An OpenILS biblio::record_entry ID', type => 'number' }, + { name => 'orgUnit', + desc => 'An OpenILS actor::org_unit short name that limits the scope of returned holdings', + type => 'text' }, + { name => 'hideCopies', + desc => 'Flag that prevents the inclusion of copies in the returned holdings', + type => 'boolean' }, ], 'return' => { desc => 'Stream of bib record holdings hierarchy in XML', @@ -1687,7 +1702,7 @@ sub as_xml { my $self = shift; my $args = shift; - my $xml = 'obj->id . '" '; $xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" '; $xml .= 'label="' . $self->escape( $self->obj->label ) . '" '; @@ -1695,21 +1710,21 @@ sub as_xml { if (!$args->{no_volumes}) { if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) { - $xml .= '' . join( + $xml .= " \n" . join( '', map { OpenILS::Application::SuperCat::unAPI ->new( $_->call_number ) ->as_xml({ %$args, no_uris=>1, no_copies=>1 }) } @{ $self->obj->call_number_maps } - ) . ''; + ) . " \n"; } else { - $xml .= ''; + $xml .= " \n"; } } - $xml .= ''; + $xml .= " \n"; return $xml; } @@ -1721,49 +1736,51 @@ sub as_xml { my $self = shift; my $args = shift; - my $xml = 'obj->id . '" '; $xml .= 'lib="' . $self->escape( $self->obj->owning_lib->shortname ) . '" '; $xml .= 'label="' . $self->escape( $self->obj->label ) . '">'; + $xml .= "\n"; if (!$args->{no_copies}) { if (ref($self->obj->copies) && @{ $self->obj->copies }) { - $xml .= '' . join( + $xml .= " \n" . join( '', map { OpenILS::Application::SuperCat::unAPI ->new( $_ ) ->as_xml({ %$args, no_volume=>1 }) } @{ $self->obj->copies } - ) . ''; + ) . " \n"; } else { - $xml .= ''; + $xml .= " \n"; } } if (!$args->{no_uris}) { if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) { - $xml .= '' . join( + $xml .= " \n" . join( '', map { OpenILS::Application::SuperCat::unAPI ->new( $_->uri ) ->as_xml({ %$args, no_volumes=>1 }) } @{ $self->obj->uri_maps } - ) . ''; + ) . " \n"; } else { - $xml .= ''; + $xml .= " \n"; } } - $xml .= 'obj->owning_lib->id . '" '; $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" '; $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>'; + $xml .= "\n"; unless ($args->{no_record}) { my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ; @@ -1773,7 +1790,7 @@ sub as_xml { $xml .= $U->entityize($r_doc->documentElement->toString); } - $xml .= ''; + $xml .= " \n"; return $xml; } @@ -1785,7 +1802,7 @@ sub as_xml { my $self = shift; my $args = shift; - my $xml = 'obj->status->id . '">' . $self->escape( $self->obj->status->name ) . ''; - $xml .= '' . $self->escape( $self->obj->location->name ) . ''; - $xml .= '' . $self->escape( $self->obj->circ_lib->name ) . ''; + $xml .= ' ' . $self->escape( $self->obj->status->name ) . "\n"; + $xml .= ' ' . $self->escape( $self->obj->location->name ) . "\n"; + $xml .= ' ' . $self->escape( $self->obj->circ_lib->name ) . "\n"; - $xml .= 'obj->circ_lib->id . '" '; $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" '; $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'"/>'; + $xml .= "\n"; - $xml .= ""; + $xml .= " \n"; if (ref($self->obj->notes) && $self->obj->notes) { for my $note ( @{$self->obj->notes} ) { next unless ( $note->pub eq 't' ); - $xml .= sprintf('%s',$note->create_date, $self->escape($note->title), $self->escape($note->value)); + $xml .= sprintf(' %s',$note->create_date, $self->escape($note->title), $self->escape($note->value)); + $xml .= "\n"; } } - $xml .= ""; + $xml .= " \n"; + $xml .= " \n"; if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) { for my $sce ( @{$self->obj->stat_cat_entries} ) { next unless ( $sce->stat_cat->opac_visible eq 't' ); - $xml .= sprintf('%s',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value)); + $xml .= sprintf(' %s',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value)); + $xml .= "\n"; } } - $xml .= ""; + $xml .= " \n"; unless ($args->{no_volume}) { if (ref($self->obj->call_number)) { @@ -1828,11 +1849,11 @@ sub as_xml { ->new( $self->obj->call_number ) ->as_xml({ %$args, no_copies=>1 }); } else { - $xml .= ''; + $xml .= " \n"; } } - $xml .= ''; + $xml .= " \n"; return $xml; } diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index 62a3a824f9..379320dc6d 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -42,7 +42,7 @@ $browse_types{call_number}{xml} = sub { my $year = (gmtime())[5] + 1900; my $content = ''; - $content .= ""; + $content .= "\n"; for my $cn (@$tree) { (my $cn_class = $cn->class_name) =~ s/::/-/gso; @@ -69,17 +69,17 @@ $browse_types{call_number}{xml} = sub { my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname; - $content .= ""; - $content .= ""; + $content .= "\n"; + $content .= "\n"; my $r_doc = $parser->parse_string($cn->record->marc); $r_doc->documentElement->setAttribute( id => $rec_tag ); $content .= $U->entityize($r_doc->documentElement->toString); - $content .= ""; + $content .= "\n"; } - $content .= ''; + $content .= "\n"; return ("Content-type: application/xml\n\n",$content); }; @@ -162,7 +162,8 @@ sub child_init { my $base = shift; my $site = shift; - my $feed = create_record_feed( 'record', $real_format, $record_list, $unapi, $site, $real_format =~ /-full$/o ? 1 : 0 ); + $log->info("Creating record feed with params [$real_format, $record_list, $unapi, $site]"); + my $feed = create_record_feed( 'record', $real_format, $record_list, $unapi, $site, $real_format =~ /(-full|-uris)$/o ? 1 : 0 ); $feed->root( "$base/../" ); $feed->lib( $site ); $feed->link( next => $next => $feed->type ); @@ -178,6 +179,95 @@ sub child_init { } } +=head2 parse_feed_type($type) + +Determines whether and how a given feed type needs to be "fleshed out" +with holdings information. + +The feed type could end with the string "-full", in which case we want +to return call numbers, copies, and URIS. + +Or the feed type could be "-uris", in which case we want to return +call numbers and URIS. + +Otherwise, we won't return any holdings. + +=cut + +sub parse_feed_type { + my $type = shift; + + if ($type =~ /-full$/o) { + return 1; + } + + if ($type =~ /-uris$/o) { + return "uris"; + } + + # Otherwise, we'll return just the facts, ma'am + return 0; +} + +=head2 supercat_format($format_hashref, $format_type) + +Given a reference to a hash containing the namespace_uri, +docs, and schema location attributes for a set of formats, +generate the XML description required by the supercat service. + +We derive the base type from the format type so that we do not +have to populate the hash with redundant information. + +=cut + +sub supercat_format { + my $h = shift; + my $type = shift; + + (my $base_type = $type) =~ s/(-full|-uris)$//o; + + my $format = "$typeapplication/xml"; + + for my $part ( qw/namespace_uri docs schema_location/ ) { + $format .= "<$part>$$h{$base_type}{$part}" + if ($$h{$base_type}{$part}); + } + + $format .= ''; + + return $format; +} + +=head2 unapi_format($format_hashref, $format_type) + +Given a reference to a hash containing the namespace_uri, +docs, and schema location attributes for a set of formats, +generate the XML description required by the supercat service. + +We derive the base type from the format type so that we do not +have to populate the hash with redundant information. + +=cut + +sub unapi_format { + my $h = shift; + my $type = shift; + + (my $base_type = $type) =~ s/(-full|-uris)$//o; + + my $format = "param('locale') || 'en-US'; my $format = $cgi->param('format'); - my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0; - (my $base_format = $format) =~ s/-full$//o; + my $flesh_feed = parse_feed_type($format); + (my $base_format = $format) =~ s/(-full|-uris)$//o; my ($id,$type,$command,$lib) = ('','',''); if (!$format) { @@ -271,24 +361,11 @@ sub unapi { for my $h (@$list) { my ($type) = keys %$h; - $body .= "\texists($type)) { - $body .= "\texists($type)) { - $body .= "\tpath_info; my ($id,$type,$format,$command) = reverse split '/', $path; - my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0; - (my $base_format = $format) =~ s/-full$//o; + my $flesh_feed = parse_feed_type($type); + (my $base_format = $format) =~ s/(-full|-uris)$//o; my $skin = $cgi->param('skin') || 'default'; my $locale = $cgi->param('locale') || 'en-US'; @@ -564,24 +628,11 @@ sub supercat { for my $h (@$list) { my ($type) = keys %$h; - print "$typeapplication/xml"; - - for my $part ( qw/namespace_uri docs schema_location/ ) { - print "<$part>$$h{$type}{$part}" - if ($$h{$type}{$part}); - } - - print ''; + print supercat_format($h, $type); if (OpenILS::WWW::SuperCat::Feed->exists($type)) { - print "$type-fullapplication/xml"; - - for my $part ( qw/namespace_uri docs schema_location/ ) { - print "<$part>$$h{$type}{$part}" - if ($$h{$type}{$part}); - } - - print ''; + print supercat_format($h, "$type-full"); + print supercat_format($h, "$type-uris"); } } @@ -636,24 +687,11 @@ sub supercat { for my $h (@$list) { my ($type) = keys %$h; - print "$typeapplication/xml"; - - for my $part ( qw/namespace_uri docs schema_location/ ) { - print "<$part>$$h{$type}{$part}" - if ($$h{$type}{$part}); - } - - print ''; + print supercat_format($h, $type); if (OpenILS::WWW::SuperCat::Feed->exists($type)) { - print "$type-fullapplication/xml"; - - for my $part ( qw/namespace_uri docs schema_location/ ) { - print "<$part>$$h{$type}{$part}" - if ($$h{$type}{$part}); - } - - print ''; + print supercat_format($h, "$type-full"); + print supercat_format($h, "$type-uris"); } } @@ -790,7 +828,7 @@ sub bookbag_feed { #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi"; my ($id,$type) = reverse split '/', $path; - my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0; + my $flesh_feed = parse_feed_type($type); my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1); return Apache2::Const::NOT_FOUND unless($bucket); @@ -866,7 +904,8 @@ sub changes_feed { $path =~ s/^\/(?:feed\/)?freshmeat\///og; my ($type,$rtype,$axis,$limit,$date) = split '/', $path; - my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0; + my $flesh_feed = parse_feed_type($type); + $limit ||= 10; my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1); @@ -1074,7 +1113,7 @@ sub opensearch_feed { } elsif ($type eq '-') { $type = 'atom'; } - my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0; + my $flesh_feed = parse_feed_type($type); $terms = decode_utf8($terms); $lang = 'eng' if ($lang eq 'en-US'); @@ -1235,7 +1274,9 @@ sub create_record_feed { my $year = (gmtime())[5] + 1900; - my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0; + my $flesh_feed = parse_feed_type($type); + + $type =~ s/(-full|-uris)$//o; my $feed = new OpenILS::WWW::SuperCat::Feed ($type); $feed->base($base) if ($flesh); @@ -1267,7 +1308,7 @@ sub create_record_feed { $xml = ''; if ($lib && ($type eq 'marcxml' || $type eq 'atom') && $flesh) { - my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib ); + my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib, ($flesh_feed eq "uris") ? 1 : 0 ); while ( !$r->complete ) { $xml .= join('', map {$_->content} $r->recv); } @@ -1341,7 +1382,7 @@ sub string_browse { $page )->gather(1); - (my $norm_format = $format) =~ s/-full$//o; + (my $norm_format = $format) =~ s/(-full|-uris)$//o; my ($header,$content) = $browse_types{$axis}{$norm_format}->($tree,$prev,$next,$format,$unapi,$base,$site); print $header.$content; @@ -1396,7 +1437,7 @@ sub item_age_browse { $page )->gather(1); - (my $norm_format = $format) =~ s/-full$//o; + (my $norm_format = $format) =~ s/(-full|-uris)$//o; my ($header,$content) = $browse_types{$axis}{$norm_format}->($recs,$prev,$next,$format,$unapi,$base,$site); print $header.$content; diff --git a/Open-ILS/web/js/dojo/openils/BibTemplate.js b/Open-ILS/web/js/dojo/openils/BibTemplate.js index 03f1948114..71f5ef1d34 100644 --- a/Open-ILS/web/js/dojo/openils/BibTemplate.js +++ b/Open-ILS/web/js/dojo/openils/BibTemplate.js @@ -32,7 +32,9 @@ if(!dojo._hasResource["openils.BibTemplate"]) { var slots = {}; dojo.forEach(all_slots, function(s){ - var datatype = 'marcxml-full'; + // marcxml-uris does not include copies, which avoids timeouts + // with bib records that have hundreds or thousands of copies + var datatype = 'marcxml-uris'; if (s.getAttribute('type').indexOf('+') > -1) datatype = s.getAttribute('type').split('+').reverse()[0];