my $client = shift;
my $bib = shift;
my $ou = shift;
+ my $hide_copies = shift;
my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
$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',
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',
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 ) . '" ';
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;
}
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 ) ;
$xml .= $U->entityize($r_doc->documentElement->toString);
}
- $xml .= '</volume>';
+ $xml .= " </volume>\n";
return $xml;
}
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/
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)) {
->new( $self->obj->call_number )
->as_xml({ %$args, no_copies=>1 });
} else {
- $xml .= '<volume/>';
+ $xml .= " <volume/>\n";
}
}
- $xml .= '</copy>';
+ $xml .= " </copy>\n";
return $xml;
}
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;
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);
};
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 );
}
}
+=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;
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) {
for my $h (@$list) {
my ($type) = keys %$h;
- $body .= "\t<format name='$type' 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);
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");
}
}
for my $h (@$list) {
my ($type) = keys %$h;
- $body .= "\t<format name='$type' 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);
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");
}
}
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';
for my $h (@$list) {
my ($type) = keys %$h;
- print "<format><name>$type</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);
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");
}
}
for my $h (@$list) {
my ($type) = keys %$h;
- print "<format><name>$type</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);
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");
}
}
#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);
$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);
} 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');
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);
$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);
}
$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;
$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;