[open-ils-commits] r14802 - in trunk/Open-ILS: src/perlmods/OpenILS/Application src/perlmods/OpenILS/WWW web/js/dojo/openils (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Nov 6 00:20:43 EST 2009
Author: dbs
Date: 2009-11-06 00:20:39 -0500 (Fri, 06 Nov 2009)
New Revision: 14802
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
trunk/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
trunk/Open-ILS/web/js/dojo/openils/BibTemplate.js
Log:
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 <volumes> element.
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm 2009-11-06 04:16:22 UTC (rev 14801)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm 2009-11-06 05:20:39 UTC (rev 14802)
@@ -932,6 +932,7 @@
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 @@
$year += 1900;
$month += 1;
- $client->respond("<volumes xmlns='http://open-ils.org/spec/holdings/v1'>");
+ $client->respond("<volumes xmlns='http://open-ils.org/spec/holdings/v1'>\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 "</volumes>";
+ return "</volumes>\n";
}
__PACKAGE__->register_method(
method => 'new_record_holdings',
@@ -1010,8 +1019,14 @@
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 @@
my $self = shift;
my $args = shift;
- my $xml = '<uri xmlns="http://open-ils.org/spec/holdings/v1" ';
+ my $xml = ' <uri xmlns="http://open-ils.org/spec/holdings/v1" ';
$xml .= 'id="tag:open-ils.org:asset-uri/' . $self->obj->id . '" ';
$xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" ';
$xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
@@ -1695,21 +1710,21 @@
if (!$args->{no_volumes}) {
if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) {
- $xml .= '<volumes>' . join(
+ $xml .= " <volumes>\n" . join(
'',
map {
OpenILS::Application::SuperCat::unAPI
->new( $_->call_number )
->as_xml({ %$args, no_uris=>1, no_copies=>1 })
} @{ $self->obj->call_number_maps }
- ) . '</volumes>';
+ ) . " </volumes>\n";
} else {
- $xml .= '<volumes/>';
+ $xml .= " <volumes/>\n";
}
}
- $xml .= '</uri>';
+ $xml .= " </uri>\n";
return $xml;
}
@@ -1721,49 +1736,51 @@
my $self = shift;
my $args = shift;
- my $xml = '<volume xmlns="http://open-ils.org/spec/holdings/v1" ';
+ my $xml = ' <volume xmlns="http://open-ils.org/spec/holdings/v1" ';
$xml .= 'id="tag:open-ils.org:asset-call_number/' . $self->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 .= '<copies>' . join(
+ $xml .= " <copies>\n" . join(
'',
map {
OpenILS::Application::SuperCat::unAPI
->new( $_ )
->as_xml({ %$args, no_volume=>1 })
} @{ $self->obj->copies }
- ) . '</copies>';
+ ) . " </copies>\n";
} else {
- $xml .= '<copies/>';
+ $xml .= " <copies/>\n";
}
}
if (!$args->{no_uris}) {
if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) {
- $xml .= '<uris>' . join(
+ $xml .= " <uris>\n" . join(
'',
map {
OpenILS::Application::SuperCat::unAPI
->new( $_->uri )
->as_xml({ %$args, no_volumes=>1 })
} @{ $self->obj->uri_maps }
- ) . '</uris>';
+ ) . " </uris>\n";
} else {
- $xml .= '<uris/>';
+ $xml .= " <uris/>\n";
}
}
- $xml .= '<owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
+ $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
$xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->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 @@
$xml .= $U->entityize($r_doc->documentElement->toString);
}
- $xml .= '</volume>';
+ $xml .= " </volume>\n";
return $xml;
}
@@ -1785,7 +1802,7 @@
my $self = shift;
my $args = shift;
- my $xml = '<copy xmlns="http://open-ils.org/spec/holdings/v1" '.
+ my $xml = ' <copy xmlns="http://open-ils.org/spec/holdings/v1" '.
'id="tag:open-ils.org:asset-copy/' . $self->obj->id . '" ';
$xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
@@ -1793,34 +1810,38 @@
deposit_amount price barcode circ_modifier circ_as_type opac_visible
/);
- $xml .= '>';
+ $xml .= ">\n";
- $xml .= '<status ident="' . $self->obj->status->id . '">' . $self->escape( $self->obj->status->name ) . '</status>';
- $xml .= '<location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . '</location>';
- $xml .= '<circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . '</circlib>';
+ $xml .= ' <status ident="' . $self->obj->status->id . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
+ $xml .= ' <location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . "</location>\n";
+ $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
- $xml .= '<circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
+ $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
$xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->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 .= "<copy_notes>";
+ $xml .= " <copy_notes>\n";
if (ref($self->obj->notes) && $self->obj->notes) {
for my $note ( @{$self->obj->notes} ) {
next unless ( $note->pub eq 't' );
- $xml .= sprintf('<copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
+ $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
+ $xml .= "\n";
}
}
- $xml .= "</copy_notes><statcats>";
+ $xml .= " </copy_notes>\n";
+ $xml .= " <statcats>\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('<statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
+ $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
+ $xml .= "\n";
}
}
- $xml .= "</statcats>";
+ $xml .= " </statcats>\n";
unless ($args->{no_volume}) {
if (ref($self->obj->call_number)) {
@@ -1828,11 +1849,11 @@
->new( $self->obj->call_number )
->as_xml({ %$args, no_copies=>1 });
} else {
- $xml .= '<volume/>';
+ $xml .= " <volume/>\n";
}
}
- $xml .= '</copy>';
+ $xml .= " </copy>\n";
return $xml;
}
Modified: trunk/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm 2009-11-06 04:16:22 UTC (rev 14801)
+++ trunk/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm 2009-11-06 05:20:39 UTC (rev 14802)
@@ -42,7 +42,7 @@
my $year = (gmtime())[5] + 1900;
my $content = '';
- $content .= "<volumes xmlns='http://open-ils.org/spec/holdings/v1'>";
+ $content .= "<volumes xmlns='http://open-ils.org/spec/holdings/v1'>\n";
for my $cn (@$tree) {
(my $cn_class = $cn->class_name) =~ s/::/-/gso;
@@ -69,17 +69,17 @@
my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
- $content .= "<volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
- $content .= "<owning_lib xmlns='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
+ $content .= "<volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>\n";
+ $content .= "<owning_lib xmlns='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>\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 .= "</volume>";
+ $content .= "</volume>\n";
}
- $content .= '</volumes>';
+ $content .= "</volumes>\n";
return ("Content-type: application/xml\n\n",$content);
};
@@ -162,7 +162,8 @@
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 @@
}
}
+=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 = "<format><name>$type</name><type>application/xml</type>";
+
+ for my $part ( qw/namespace_uri docs schema_location/ ) {
+ $format .= "<$part>$$h{$base_type}{$part}</$part>"
+ if ($$h{$base_type}{$part});
+ }
+
+ $format .= '</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 = "<format name='$type' type='application/xml'";
+
+ for my $part ( qw/namespace_uri docs schema_location/ ) {
+ $format .= " $part='$$h{$base_type}{$part}'"
+ if ($$h{$base_type}{$part});
+ }
+
+ $format .= "/>\n";
+
+ return $format;
+}
+
+
sub oisbn {
my $apache = shift;
@@ -234,8 +324,8 @@
my $locale = $cgi->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 @@
for my $h (@$list) {
my ($type) = keys %$h;
- $body .= "\t<format name='$type' type='application/xml'";
+ $body .= unapi_format($h, $type);
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- $body .= " $part='$$h{$type}{$part}'"
- if ($$h{$type}{$part});
- }
-
- $body .= "/>\n";
-
if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
- $body .= "\t<format name='$type-full' type='application/xml'";
-
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- $body .= " $part='$$h{$type}{$part}'"
- if ($$h{$type}{$part});
- }
-
- $body .= "/>\n";
+ $body .= unapi_format($h, "$type-full");
+ $body .= unapi_format($h, "$type-uris");
}
}
@@ -322,24 +399,11 @@
for my $h (@$list) {
my ($type) = keys %$h;
- $body .= "\t<format name='$type' type='application/xml'";
+ $body .= "\t" . unapi_format($h, $type);
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- $body .= " $part='$$h{$type}{$part}'"
- if ($$h{$type}{$part});
- }
-
- $body .= "/>\n";
-
if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
- $body .= "\t<format name='$type-full' type='application/xml'";
-
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- $body .= " $part='$$h{$type}{$part}'"
- if ($$h{$type}{$part});
- }
-
- $body .= "/>\n";
+ $body .= "\t" . unapi_format($h, "$type-full");
+ $body .= "\t" . unapi_format($h, "$type-uris");
}
}
@@ -514,8 +578,8 @@
my $path = $cgi->path_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 @@
for my $h (@$list) {
my ($type) = keys %$h;
- print "<format><name>$type</name><type>application/xml</type>";
+ print supercat_format($h, $type);
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- print "<$part>$$h{$type}{$part}</$part>"
- if ($$h{$type}{$part});
- }
-
- print '</format>';
-
if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
- print "<format><name>$type-full</name><type>application/xml</type>";
-
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- print "<$part>$$h{$type}{$part}</$part>"
- if ($$h{$type}{$part});
- }
-
- print '</format>';
+ print supercat_format($h, "$type-full");
+ print supercat_format($h, "$type-uris");
}
}
@@ -636,24 +687,11 @@
for my $h (@$list) {
my ($type) = keys %$h;
- print "<format><name>$type</name><type>application/xml</type>";
+ print supercat_format($h, $type);
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- print "<$part>$$h{$type}{$part}</$part>"
- if ($$h{$type}{$part});
- }
-
- print '</format>';
-
if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
- print "<format><name>$type-full</name><type>application/xml</type>";
-
- for my $part ( qw/namespace_uri docs schema_location/ ) {
- print "<$part>$$h{$type}{$part}</$part>"
- if ($$h{$type}{$part});
- }
-
- print '</format>';
+ print supercat_format($h, "$type-full");
+ print supercat_format($h, "$type-uris");
}
}
@@ -790,7 +828,7 @@
#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 @@
$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 @@
} 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,8 +1274,10 @@
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);
$feed->unapi($unapi) if ($flesh);
@@ -1267,7 +1308,7 @@
$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 @@
$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 @@
$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;
Modified: trunk/Open-ILS/web/js/dojo/openils/BibTemplate.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/BibTemplate.js 2009-11-06 04:16:22 UTC (rev 14801)
+++ trunk/Open-ILS/web/js/dojo/openils/BibTemplate.js 2009-11-06 05:20:39 UTC (rev 14802)
@@ -32,7 +32,9 @@
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];
More information about the open-ils-commits
mailing list