1 # We'll be working with XML, so...
4 use Unicode::Normalize;
6 # ... and this has some handy common methods
7 use OpenILS::Application::AppUtils;
9 my $parser = new XML::LibXML;
10 my $U = 'OpenILS::Application::AppUtils';
13 package OpenILS::Application::SuperCat;
17 use OpenILS::Utils::Normalize qw( naco_normalize );
19 # All OpenSRF applications must be based on OpenSRF::Application or
20 # a subclass thereof. Makes sense, eh?
21 use OpenILS::Application;
22 use base qw/OpenILS::Application/;
24 # This is the client class, used for connecting to open-ils.storage
25 use OpenSRF::AppSession;
27 # This is an extension of Error.pm that supplies some error types to throw
28 use OpenSRF::EX qw(:try);
30 # This is a helper class for querying the OpenSRF Settings application ...
31 use OpenSRF::Utils::SettingsClient;
33 # ... and here we have the built in logging helper ...
34 use OpenSRF::Utils::Logger qw($logger);
36 # ... and this is our OpenILS object (en|de)coder and psuedo-ORM package.
37 use OpenILS::Utils::Fieldmapper;
39 use OpenILS::Utils::CStoreEditor q/:funcs/;
48 %authority_browse_axis_cache,
52 # we need an XML parser
53 $_parser = new XML::LibXML;
56 $_xslt = new XML::LibXSLT;
58 # parse the MODS xslt ...
59 my $mods33_xslt = $_parser->parse_file(
60 OpenSRF::Utils::SettingsClient
62 ->config_value( dirs => 'xsl' ).
63 "/MARC21slim2MODS33.xsl"
65 # and stash a transformer
66 $record_xslt{mods33}{xslt} = $_xslt->parse_stylesheet( $mods33_xslt );
67 $record_xslt{mods33}{namespace_uri} = 'http://www.loc.gov/mods/v3';
68 $record_xslt{mods33}{docs} = 'http://www.loc.gov/mods/';
69 $record_xslt{mods33}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-3.xsd';
71 # parse the MODS xslt ...
72 my $mods32_xslt = $_parser->parse_file(
73 OpenSRF::Utils::SettingsClient
75 ->config_value( dirs => 'xsl' ).
76 "/MARC21slim2MODS32.xsl"
78 # and stash a transformer
79 $record_xslt{mods32}{xslt} = $_xslt->parse_stylesheet( $mods32_xslt );
80 $record_xslt{mods32}{namespace_uri} = 'http://www.loc.gov/mods/v3';
81 $record_xslt{mods32}{docs} = 'http://www.loc.gov/mods/';
82 $record_xslt{mods32}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-2.xsd';
84 # parse the MODS xslt ...
85 my $mods3_xslt = $_parser->parse_file(
86 OpenSRF::Utils::SettingsClient
88 ->config_value( dirs => 'xsl' ).
89 "/MARC21slim2MODS3.xsl"
91 # and stash a transformer
92 $record_xslt{mods3}{xslt} = $_xslt->parse_stylesheet( $mods3_xslt );
93 $record_xslt{mods3}{namespace_uri} = 'http://www.loc.gov/mods/v3';
94 $record_xslt{mods3}{docs} = 'http://www.loc.gov/mods/';
95 $record_xslt{mods3}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-1.xsd';
97 # parse the MODS xslt ...
98 my $mods_xslt = $_parser->parse_file(
99 OpenSRF::Utils::SettingsClient
101 ->config_value( dirs => 'xsl' ).
102 "/MARC21slim2MODS.xsl"
104 # and stash a transformer
105 $record_xslt{mods}{xslt} = $_xslt->parse_stylesheet( $mods_xslt );
106 $record_xslt{mods}{namespace_uri} = 'http://www.loc.gov/mods/';
107 $record_xslt{mods}{docs} = 'http://www.loc.gov/mods/';
108 $record_xslt{mods}{schema_location} = 'http://www.loc.gov/standards/mods/mods.xsd';
110 # parse the ATOM entry xslt ...
111 my $atom_xslt = $_parser->parse_file(
112 OpenSRF::Utils::SettingsClient
114 ->config_value( dirs => 'xsl' ).
115 "/MARC21slim2ATOM.xsl"
117 # and stash a transformer
118 $record_xslt{atom}{xslt} = $_xslt->parse_stylesheet( $atom_xslt );
119 $record_xslt{atom}{namespace_uri} = 'http://www.w3.org/2005/Atom';
120 $record_xslt{atom}{docs} = 'http://www.ietf.org/rfc/rfc4287.txt';
122 # parse the RDFDC xslt ...
123 my $rdf_dc_xslt = $_parser->parse_file(
124 OpenSRF::Utils::SettingsClient
126 ->config_value( dirs => 'xsl' ).
127 "/MARC21slim2RDFDC.xsl"
129 # and stash a transformer
130 $record_xslt{rdf_dc}{xslt} = $_xslt->parse_stylesheet( $rdf_dc_xslt );
131 $record_xslt{rdf_dc}{namespace_uri} = 'http://purl.org/dc/elements/1.1/';
132 $record_xslt{rdf_dc}{schema_location} = 'http://purl.org/dc/elements/1.1/';
134 # parse the SRWDC xslt ...
135 my $srw_dc_xslt = $_parser->parse_file(
136 OpenSRF::Utils::SettingsClient
138 ->config_value( dirs => 'xsl' ).
139 "/MARC21slim2SRWDC.xsl"
141 # and stash a transformer
142 $record_xslt{srw_dc}{xslt} = $_xslt->parse_stylesheet( $srw_dc_xslt );
143 $record_xslt{srw_dc}{namespace_uri} = 'info:srw/schema/1/dc-schema';
144 $record_xslt{srw_dc}{schema_location} = 'http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd';
146 # parse the OAIDC xslt ...
147 my $oai_dc_xslt = $_parser->parse_file(
148 OpenSRF::Utils::SettingsClient
150 ->config_value( dirs => 'xsl' ).
151 "/MARC21slim2OAIDC.xsl"
153 # and stash a transformer
154 $record_xslt{oai_dc}{xslt} = $_xslt->parse_stylesheet( $oai_dc_xslt );
155 $record_xslt{oai_dc}{namespace_uri} = 'http://www.openarchives.org/OAI/2.0/oai_dc/';
156 $record_xslt{oai_dc}{schema_location} = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd';
158 # parse the RSS xslt ...
159 my $rss_xslt = $_parser->parse_file(
160 OpenSRF::Utils::SettingsClient
162 ->config_value( dirs => 'xsl' ).
163 "/MARC21slim2RSS2.xsl"
165 # and stash a transformer
166 $record_xslt{rss2}{xslt} = $_xslt->parse_stylesheet( $rss_xslt );
168 # parse the FGDC xslt ...
169 my $fgdc_xslt = $_parser->parse_file(
170 OpenSRF::Utils::SettingsClient
172 ->config_value( dirs => 'xsl' ).
173 "/MARC21slim2FGDC.xsl"
175 # and stash a transformer
176 $record_xslt{fgdc}{xslt} = $_xslt->parse_stylesheet( $fgdc_xslt );
177 $record_xslt{fgdc}{docs} = 'http://www.fgdc.gov/metadata/csdgm/index_html';
178 $record_xslt{fgdc}{schema_location} = 'http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd';
180 register_record_transforms();
182 register_new_authorities_methods();
187 sub register_record_transforms {
188 for my $type ( keys %record_xslt ) {
189 __PACKAGE__->register_method(
190 method => 'retrieve_record_transform',
191 api_name => "open-ils.supercat.record.$type.retrieve",
195 { desc => "Returns the \U$type\E representation ".
196 "of the requested bibliographic record",
200 desc => 'An OpenILS biblio::record_entry id',
204 { desc => "The bib record in \U$type\E",
209 __PACKAGE__->register_method(
210 method => 'retrieve_isbn_transform',
211 api_name => "open-ils.supercat.isbn.$type.retrieve",
215 { desc => "Returns the \U$type\E representation ".
216 "of the requested bibliographic record",
224 { desc => "The bib record in \U$type\E",
231 sub register_new_authorities_methods {
232 my %register_args = (
233 method => "generic_new_authorities_method",
237 desc => q/Generated method/,
240 desc => "An axis, an authority tag number, or a bibliographic tag number, depending on invocation",
243 desc => "A search term",
246 desc => "zero-based page number of results",
248 {name => "page size",
249 desc => "number of results per page",
253 desc => "A list of authority record IDs", type => "array"
258 foreach my $how (qw/axis atag btag/) {
259 foreach my $action (qw/browse_center browse_top
260 search_rank search_heading/) {
262 $register_args{api_name} =
263 "open-ils.supercat.authority.$action.by_$how";
264 __PACKAGE__->register_method(%register_args);
266 $register_args{api_name} =
267 "open-ils.supercat.authority.$action.by_$how.refs";
268 __PACKAGE__->register_method(%register_args);
274 sub generic_new_authorities_method {
278 # We want to be extra careful with these arguments, since the next
279 # thing we're doing with them is passing them to a DB procedure.
282 my $page = int(shift || 0);
283 my $page_size = shift;
285 # undef ok, but other non numbers not ok
286 $page_size = int($page_size) if defined $page_size;
288 # Figure out how we were called and what DB procedure we'll call in turn.
289 $self->api_name =~ /\.by_(\w+)($|\.)/;
293 $self->api_name =~ /authority\.(\w+)\./;
296 my $method = "${metaaxis}_$action";
297 $method .= "_refs" if $refs;
299 # Match authority.full_rec normalization
300 # XXX don't know whether we need second arg 'subfield'?
301 $term = naco_normalize($term);
303 my $storage = create OpenSRF::AppSession("open-ils.storage");
304 my $list = $storage->request(
305 "open-ils.storage.authority.in_db.browse_or_search",
306 $method, $what, $term, $page, $page_size
320 return unless ($tree && ref($tree->$field));
322 my @things = $filter->($tree);
323 for my $v ( @{$tree->$field} ){
324 push @things, $filter->($v);
325 push @things, tree_walker($v, $field, $filter);
330 # find a label_sortkey for a call number with a label which is equal
331 # (or close to) a given label value
332 sub _label_sortkey_from_label {
333 my ($label, $_storage, $ou_ids, $cp_filter) = @_;
335 my $closest_cn = $_storage->request(
336 "open-ils.cstore.direct.asset.call_number.search.atomic",
337 { label => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } },
338 (scalar(@$ou_ids) ? (owning_lib => $ou_ids) : ()),
343 flesh_fields => { acn => [qw/label_class/] },
345 order_by => { acn => "oils_text_as_bytea(label), id" }
349 if ($closest_cn->[0]->label eq $label) {
350 # we found an exact match stop here
351 return $closest_cn->[0]->label_sortkey;
353 # we got as close as we could by label alone, let's try to
354 # normalize and get closer
355 $closest_cn = $_storage->request(
356 "open-ils.cstore.direct.asset.call_number.search.atomic",
358 => { ">=" => [$closest_cn->[0]->label_class->normalizer, $label] },
359 (scalar(@$ou_ids) ? (owning_lib => $ou_ids) : ()),
364 order_by => { acn => "label_sortkey, id" }
368 return $closest_cn->[0]->label_sortkey;
373 return '~~~'; #fallback to high ascii value, we are at the end of the range
382 my $page_size = shift || 9;
383 my $page = shift || 0;
384 my $statuses = shift || [];
385 my $copy_locations = shift || [];
387 my ($before_limit,$after_limit) = (0,0);
388 my ($before_offset,$after_offset) = (0,0);
391 $before_limit = $after_limit = int($page_size / 2);
392 $after_limit += 1 if ($page_size % 2);
394 $before_offset = $after_offset = int($page_size / 2);
395 $before_offset += 1 if ($page_size % 2);
396 $before_limit = $after_limit = $page_size;
399 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
402 # if OU is not specified, or if '-' is specified, do not enter the block
403 unless (!$ou || $ou eq '-') {
404 # check if the shortname of the top org_unit is specified
405 my $top_org = $_storage->request(
406 "open-ils.cstore.direct.actor.org_unit.search",
407 { parent_ou => undef }
410 if ($ou eq $top_org->shortname) {
411 $logger->debug("Searching for CNs at top org $ou");
413 my $o_search = { shortname => $ou };
415 my $orgs = $_storage->request(
416 "open-ils.cstore.direct.actor.org_unit.search",
419 flesh_fields => { aou => [qw/children/] }
423 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
425 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
432 if (@$statuses || @$copy_locations) {
438 call_number => { '=' => { '+acn' => 'id' } },
440 ((@$statuses) ? ( status => $statuses) : ()),
441 ((@$copy_locations) ? ( location => $copy_locations) : ())
447 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
450 my $before = $_storage->request(
451 "open-ils.cstore.direct.asset.call_number.search.atomic",
452 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
453 (scalar(@ou_ids) ? (owning_lib => \@ou_ids) : ()),
458 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
459 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
460 limit => $before_limit,
461 offset => abs($page) * $page_size - $before_offset,
464 push @list, reverse(@$before);
468 my $after = $_storage->request(
469 "open-ils.cstore.direct.asset.call_number.search.atomic",
470 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
471 (scalar(@ou_ids) ? (owning_lib => \@ou_ids) : ()),
476 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
477 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
478 limit => $after_limit,
479 offset => abs($page) * $page_size - $after_offset,
487 __PACKAGE__->register_method(
488 method => 'cn_browse',
489 api_name => 'open-ils.supercat.call_number.browse',
494 Returns the XML representation of the requested bibliographic record's holdings
499 desc => 'The target call number label',
501 { name => 'org_unit',
502 desc => 'The org unit shortname (or "-" or undef for global) to browse',
504 { name => 'page_size',
505 desc => 'Count of call numbers to retrieve, default is 9',
508 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
510 { name => 'statuses',
511 desc => 'Array of statuses to filter copies by, optional and can be undef.',
513 { name => 'locations',
514 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
518 { desc => 'Call numbers with owning_lib and record fleshed',
529 my $limit = shift || 10;
530 my $page = shift || 0;
531 my $statuses = shift || [];
532 my $copy_locations = shift || [];
535 my $offset = abs($page) * $limit;
536 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
538 my $o_search = { shortname => $ou };
539 if (!$ou || $ou eq '-') {
540 $o_search = { parent_ou => undef };
543 my $orgs = $_storage->request(
544 "open-ils.cstore.direct.actor.org_unit.search",
547 flesh_fields => { aou => [qw/children/] }
551 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
553 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
558 if (@$statuses || @$copy_locations) {
564 call_number => { '=' => { '+acn' => 'id' } },
566 ((@$statuses) ? ( status => $statuses) : ()),
567 ((@$copy_locations) ? ( location => $copy_locations) : ())
573 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
576 my $before = $_storage->request(
577 "open-ils.cstore.direct.asset.call_number.search.atomic",
578 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
579 owning_lib => \@ou_ids,
584 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
585 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
590 push @list, reverse(@$before);
594 my $after = $_storage->request(
595 "open-ils.cstore.direct.asset.call_number.search.atomic",
596 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
597 owning_lib => \@ou_ids,
602 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
603 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
613 __PACKAGE__->register_method(
614 method => 'cn_startwith',
615 api_name => 'open-ils.supercat.call_number.startwith',
620 Returns the XML representation of the requested bibliographic record's holdings
625 desc => 'The target call number label',
627 { name => 'org_unit',
628 desc => 'The org unit shortname (or "-" or undef for global) to browse',
630 { name => 'page_size',
631 desc => 'Count of call numbers to retrieve, default is 9',
634 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
636 { name => 'statuses',
637 desc => 'Array of statuses to filter copies by, optional and can be undef.',
639 { name => 'locations',
640 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
644 { desc => 'Call numbers with owning_lib and record fleshed',
650 sub new_books_by_item {
655 my $page_size = shift || 10;
656 my $page = shift || 1;
657 my $statuses = shift || [];
658 my $copy_locations = shift || [];
660 my $offset = $page_size * ($page - 1);
662 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
665 if ($ou && $ou ne '-') {
666 my $orgs = $_storage->request(
667 "open-ils.cstore.direct.actor.org_unit.search",
668 { shortname => $ou },
670 flesh_fields => { aou => [qw/children/] }
673 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
676 $logger->debug("Searching for records with new copies at orgs [".join(',',@ou_ids)."], based on $ou");
677 my $cns = $_storage->request(
678 "open-ils.cstore.json_query.atomic",
679 { select => { acn => ['record'],
680 acp => [{ aggregate => 1 => transform => max => column => create_date => alias => 'create_date'}]
682 from => { 'acn' => { 'acp' => { field => call_number => fkey => 'id' } } },
686 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
687 ((@$statuses) ? ( status => $statuses) : ()),
688 ((@$copy_locations) ? ( location => $copy_locations) : ())
690 '+acn' => { record => { '>' => 0 } },
692 order_by => { acp => { create_date => { transform => 'max', direction => 'desc' } } },
698 return [ map { $_->{record} } @$cns ];
700 __PACKAGE__->register_method(
701 method => 'new_books_by_item',
702 api_name => 'open-ils.supercat.new_book_list',
707 Returns the XML representation of the requested bibliographic record's holdings
711 { name => 'org_unit',
712 desc => 'The org unit shortname (or "-" or undef for global) to list',
714 { name => 'page_size',
715 desc => 'Count of records to retrieve, default is 10',
718 desc => 'The page of records to retrieve, calculated based on page_size. Starts at 1.',
720 { name => 'statuses',
721 desc => 'Array of statuses to filter copies by, optional and can be undef.',
723 { name => 'locations',
724 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
728 { desc => 'Record IDs',
737 return tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
739 __PACKAGE__->register_method(
740 method => 'general_browse',
741 api_name => 'open-ils.supercat.title.browse',
742 tag => 'tnf', subfield => 'a',
746 { desc => "Returns a list of the requested org-scoped record IDs held",
748 [ { name => 'value', desc => 'The target title', type => 'string' },
749 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
750 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
751 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
752 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
753 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
754 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
757 __PACKAGE__->register_method(
758 method => 'general_browse',
759 api_name => 'open-ils.supercat.author.browse',
760 tag => [qw/100 110 111/], subfield => 'a',
764 { desc => "Returns a list of the requested org-scoped record IDs held",
766 [ { name => 'value', desc => 'The target author', type => 'string' },
767 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
768 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
769 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
770 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
771 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
772 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
775 __PACKAGE__->register_method(
776 method => 'general_browse',
777 api_name => 'open-ils.supercat.subject.browse',
778 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
782 { desc => "Returns a list of the requested org-scoped record IDs held",
784 [ { name => 'value', desc => 'The target subject', type => 'string' },
785 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
786 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
787 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
788 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
789 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
790 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
793 __PACKAGE__->register_method(
794 method => 'general_browse',
795 api_name => 'open-ils.supercat.topic.browse',
796 tag => [qw/650 690/], subfield => 'a',
800 { desc => "Returns a list of the requested org-scoped record IDs held",
802 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
803 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
804 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
805 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
806 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
807 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
808 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
811 __PACKAGE__->register_method(
812 method => 'general_browse',
813 api_name => 'open-ils.supercat.series.browse',
814 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
818 { desc => "Returns a list of the requested org-scoped record IDs held",
820 [ { name => 'value', desc => 'The target series', type => 'string' },
821 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
822 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
823 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
824 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
825 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
826 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
836 my $subfield = shift;
839 my $page_size = shift || 9;
840 my $page = shift || 0;
841 my $statuses = shift || [];
842 my $copy_locations = shift || [];
844 my ($before_limit,$after_limit) = (0,0);
845 my ($before_offset,$after_offset) = (0,0);
848 $before_limit = $after_limit = int($page_size / 2);
849 $after_limit += 1 if ($page_size % 2);
851 $before_offset = $after_offset = int($page_size / 2);
852 $before_offset += 1 if ($page_size % 2);
853 $before_limit = $after_limit = $page_size;
856 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
859 if ($ou && $ou ne '-') {
860 my $orgs = $_storage->request(
861 "open-ils.cstore.direct.actor.org_unit.search",
862 { shortname => $ou },
864 flesh_fields => { aou => [qw/children/] }
867 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
870 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
875 my $before = $_storage->request(
876 "open-ils.cstore.json_query.atomic",
877 { select => { mfr => [qw/record value/] },
882 subfield => $subfield,
883 value => { '<' => lc($value) }
887 { select=> { acp => [ 'id' ] },
888 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
890 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
893 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
894 ((@$statuses) ? ( status => $statuses) : ()),
895 ((@$copy_locations) ? ( location => $copy_locations) : ())
902 { select=> { auri => [ 'id' ] },
903 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
905 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
906 '+auri' => { active => 't' }
913 order_by => { mfr => { value => 'desc' } },
914 limit => $before_limit,
915 offset => abs($page) * $page_size - $before_offset,
918 push @list, map { $_->{record} } reverse(@$before);
922 my $after = $_storage->request(
923 "open-ils.cstore.json_query.atomic",
924 { select => { mfr => [qw/record value/] },
929 subfield => $subfield,
930 value => { '>=' => lc($value) }
934 { select=> { acp => [ 'id' ] },
935 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
937 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
940 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
941 ((@$statuses) ? ( status => $statuses) : ()),
942 ((@$copy_locations) ? ( location => $copy_locations) : ())
949 { select=> { auri => [ 'id' ] },
950 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
952 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
953 '+auri' => { active => 't' }
960 order_by => { mfr => { value => 'asc' } },
961 limit => $after_limit,
962 offset => abs($page) * $page_size - $after_offset,
965 push @list, map { $_->{record} } @$after;
970 __PACKAGE__->register_method(
971 method => 'tag_sf_browse',
972 api_name => 'open-ils.supercat.tag.browse',
977 Returns a list of the requested org-scoped record IDs held
982 desc => 'The target MARC tag',
984 { name => 'subfield',
985 desc => 'The target MARC subfield',
988 desc => 'The target string',
990 { name => 'org_unit',
991 desc => 'The org unit shortname (or "-" or undef for global) to browse',
993 { name => 'page_size',
994 desc => 'Count of call numbers to retrieve, default is 9',
997 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
999 { name => 'statuses',
1000 desc => 'Array of statuses to filter copies by, optional and can be undef.',
1002 { name => 'locations',
1003 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
1007 { desc => 'Record IDs that have copies at the relevant org units',
1012 sub grab_authority_browse_axes {
1013 my ($self, $client, $full) = @_;
1015 unless(scalar(keys(%authority_browse_axis_cache))) {
1016 my $axes = new_editor->search_authority_browse_axis([
1017 { code => { '<>' => undef } },
1018 { flesh => 2, flesh_fields => { aba => ['fields'], acsaf => ['bib_fields','sub_entries'] } }
1020 $authority_browse_axis_cache{$_->code} = $_ for (@$axes);
1025 map { $authority_browse_axis_cache{$_} } sort keys %authority_browse_axis_cache
1028 return [keys %authority_browse_axis_cache];
1031 __PACKAGE__->register_method(
1032 method => 'grab_authority_browse_axes',
1033 api_name => 'open-ils.supercat.authority.browse_axis_list',
1037 { desc => "Returns a list of valid authority browse/startswith axes",
1039 { name => 'full', desc => 'Optional. If true, return array containing the full object for each axis, sorted by code. Otherwise just return an array of the codes.', type => 'number' }
1041 'return' => { desc => 'Axis codes or whole axes, see "full" param', type => 'array' }
1045 sub axis_authority_browse {
1050 $axis =~ s/^authority\.//;
1051 $axis =~ s/(\.refs)$//;
1054 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
1057 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
1058 push @tags, $f->tag;
1060 push @tags, $_->tag for @{$f->sub_entries};
1064 return authority_tag_sf_browse($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
1066 __PACKAGE__->register_method(
1067 method => 'axis_authority_browse',
1068 api_name => 'open-ils.supercat.authority.browse.by_axis',
1072 { desc => "Returns a list of the requested authority record IDs held",
1074 [ { name => 'axis', desc => 'The target axis', type => 'string' },
1075 { name => 'value', desc => 'The target value', type => 'string' },
1076 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1077 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1078 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1084 sub general_authority_browse {
1087 return authority_tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
1089 __PACKAGE__->register_method(
1090 method => 'general_authority_browse',
1091 api_name => 'open-ils.supercat.authority.title.browse',
1092 tag => ['130'], subfield => 'a',
1096 { desc => "Returns a list of the requested authority record IDs held",
1098 [ { name => 'value', desc => 'The target title', type => 'string' },
1099 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1100 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1101 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1104 __PACKAGE__->register_method(
1105 method => 'general_authority_browse',
1106 api_name => 'open-ils.supercat.authority.author.browse',
1107 tag => [qw/100 110 111/], subfield => 'a',
1111 { desc => "Returns a list of the requested authority record IDs held",
1113 [ { name => 'value', desc => 'The target author', type => 'string' },
1114 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1115 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1116 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1119 __PACKAGE__->register_method(
1120 method => 'general_authority_browse',
1121 api_name => 'open-ils.supercat.authority.subject.browse',
1122 tag => [qw/148 150 151 155/], subfield => 'a',
1126 { desc => "Returns a list of the requested authority record IDs held",
1128 [ { name => 'value', desc => 'The target subject', type => 'string' },
1129 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1130 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1131 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1134 __PACKAGE__->register_method(
1135 method => 'general_authority_browse',
1136 api_name => 'open-ils.supercat.authority.topic.browse',
1137 tag => ['150'], subfield => 'a',
1141 { desc => "Returns a list of the requested authority record IDs held",
1143 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1144 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1145 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1146 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1149 __PACKAGE__->register_method(
1150 method => 'general_authority_browse',
1151 api_name => 'open-ils.supercat.authority.title.refs.browse',
1152 tag => ['130'], subfield => 'a',
1156 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1158 [ { name => 'value', desc => 'The target title', type => 'string' },
1159 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1160 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1161 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1164 __PACKAGE__->register_method(
1165 method => 'general_authority_browse',
1166 api_name => 'open-ils.supercat.authority.author.refs.browse',
1167 tag => [qw/100 110 111/], subfield => 'a',
1171 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1173 [ { name => 'value', desc => 'The target author', type => 'string' },
1174 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1175 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1176 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1179 __PACKAGE__->register_method(
1180 method => 'general_authority_browse',
1181 api_name => 'open-ils.supercat.authority.subject.refs.browse',
1182 tag => [qw/148 150 151 155/], subfield => 'a',
1186 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1188 [ { name => 'value', desc => 'The target subject', type => 'string' },
1189 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1190 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1191 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1194 __PACKAGE__->register_method(
1195 method => 'general_authority_browse',
1196 api_name => 'open-ils.supercat.authority.topic.refs.browse',
1197 tag => ['150'], subfield => 'a',
1201 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1203 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1204 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1205 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1206 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1212 sub authority_tag_sf_browse {
1217 my $subfield = shift;
1219 my $page_size = shift || 9;
1220 my $page = shift || 0;
1222 # Match authority.full_rec normalization
1223 $value = naco_normalize($value, $subfield);
1225 my ($before_limit,$after_limit) = (0,0);
1226 my ($before_offset,$after_offset) = (0,0);
1229 $before_limit = $after_limit = int($page_size / 2);
1230 $after_limit += 1 if ($page_size % 2);
1232 $before_offset = $after_offset = int($page_size / 2);
1233 $before_offset += 1 if ($page_size % 2);
1234 $before_limit = $after_limit = $page_size;
1237 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1239 # .refs variant includes 4xx and 5xx variants for see / see also
1241 foreach my $tagname (@$tag) {
1242 push(@ref_tags, $tagname);
1243 if ($self->api_name =~ /\.refs\./) {
1244 push(@ref_tags, '4' . substr($tagname, 1, 2));
1245 push(@ref_tags, '5' . substr($tagname, 1, 2));
1251 my $before = $_storage->request(
1252 "open-ils.cstore.json_query.atomic",
1253 { select => { afr => [qw/record value/] },
1255 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1256 order_by => { afr => { value => 'desc' } },
1257 limit => $before_limit,
1258 offset => abs($page) * $page_size - $before_offset,
1261 push @list, map { $_->{record} } reverse(@$before);
1265 my $after = $_storage->request(
1266 "open-ils.cstore.json_query.atomic",
1267 { select => { afr => [qw/record value/] },
1269 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1270 order_by => { afr => { value => 'asc' } },
1271 limit => $after_limit,
1272 offset => abs($page) * $page_size - $after_offset,
1275 push @list, map { $_->{record} } @$after;
1278 # If we're not pulling in see/see also references, just return the raw list
1279 if ($self->api_name !~ /\.refs\./) {
1283 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1286 foreach my $record (@list) {
1287 next if exists $seen{$record};
1288 push @retlist, int($record);
1294 __PACKAGE__->register_method(
1295 method => 'authority_tag_sf_browse',
1296 api_name => 'open-ils.supercat.authority.tag.browse',
1300 { desc => <<" DESC",
1301 Returns a list of the requested authority record IDs held
1306 desc => 'The target Authority MARC tag',
1308 { name => 'subfield',
1309 desc => 'The target Authority MARC subfield',
1312 desc => 'The target string',
1314 { name => 'page_size',
1315 desc => 'Count of call numbers to retrieve, default is 9',
1318 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1322 { desc => 'Authority Record IDs that are near the target string',
1327 sub general_startwith {
1330 return tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1332 __PACKAGE__->register_method(
1333 method => 'general_startwith',
1334 api_name => 'open-ils.supercat.title.startwith',
1335 tag => 'tnf', subfield => 'a',
1339 { desc => "Returns a list of the requested org-scoped record IDs held",
1341 [ { name => 'value', desc => 'The target title', type => 'string' },
1342 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1343 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1344 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1345 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1346 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1347 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1350 __PACKAGE__->register_method(
1351 method => 'general_startwith',
1352 api_name => 'open-ils.supercat.author.startwith',
1353 tag => [qw/100 110 111/], subfield => 'a',
1357 { desc => "Returns a list of the requested org-scoped record IDs held",
1359 [ { name => 'value', desc => 'The target author', type => 'string' },
1360 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1361 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1362 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1363 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1364 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1365 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1368 __PACKAGE__->register_method(
1369 method => 'general_startwith',
1370 api_name => 'open-ils.supercat.subject.startwith',
1371 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
1375 { desc => "Returns a list of the requested org-scoped record IDs held",
1377 [ { name => 'value', desc => 'The target subject', type => 'string' },
1378 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1379 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1380 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1381 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1382 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1383 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1386 __PACKAGE__->register_method(
1387 method => 'general_startwith',
1388 api_name => 'open-ils.supercat.topic.startwith',
1389 tag => [qw/650 690/], subfield => 'a',
1393 { desc => "Returns a list of the requested org-scoped record IDs held",
1395 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1396 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1397 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1398 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1399 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1400 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1401 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1404 __PACKAGE__->register_method(
1405 method => 'general_startwith',
1406 api_name => 'open-ils.supercat.series.startwith',
1407 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
1411 { desc => "Returns a list of the requested org-scoped record IDs held",
1413 [ { name => 'value', desc => 'The target series', type => 'string' },
1414 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1415 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1416 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1417 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1418 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1419 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1424 sub tag_sf_startwith {
1429 my $subfield = shift;
1432 my $limit = shift || 10;
1433 my $page = shift || 0;
1434 my $statuses = shift || [];
1435 my $copy_locations = shift || [];
1437 my $offset = $limit * abs($page);
1438 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1441 if ($ou && $ou ne '-') {
1442 my $orgs = $_storage->request(
1443 "open-ils.cstore.direct.actor.org_unit.search",
1444 { shortname => $ou },
1446 flesh_fields => { aou => [qw/children/] }
1449 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1452 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
1457 my $before = $_storage->request(
1458 "open-ils.cstore.json_query.atomic",
1459 { select => { mfr => [qw/record value/] },
1464 subfield => $subfield,
1465 value => { '<' => lc($value) }
1469 { select=> { acp => [ 'id' ] },
1470 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1472 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1475 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1476 ((@$statuses) ? ( status => $statuses) : ()),
1477 ((@$copy_locations) ? ( location => $copy_locations) : ())
1484 { select=> { auri => [ 'id' ] },
1485 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1487 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1488 '+auri' => { active => 't' }
1495 order_by => { mfr => { value => 'desc' } },
1500 push @list, map { $_->{record} } reverse(@$before);
1504 my $after = $_storage->request(
1505 "open-ils.cstore.json_query.atomic",
1506 { select => { mfr => [qw/record value/] },
1511 subfield => $subfield,
1512 value => { '>=' => lc($value) }
1516 { select=> { acp => [ 'id' ] },
1517 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1519 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1522 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1523 ((@$statuses) ? ( status => $statuses) : ()),
1524 ((@$copy_locations) ? ( location => $copy_locations) : ())
1531 { select=> { auri => [ 'id' ] },
1532 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1534 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1535 '+auri' => { active => 't' }
1542 order_by => { mfr => { value => 'asc' } },
1547 push @list, map { $_->{record} } @$after;
1552 __PACKAGE__->register_method(
1553 method => 'tag_sf_startwith',
1554 api_name => 'open-ils.supercat.tag.startwith',
1558 { desc => <<" DESC",
1559 Returns a list of the requested org-scoped record IDs held
1564 desc => 'The target MARC tag',
1566 { name => 'subfield',
1567 desc => 'The target MARC subfield',
1570 desc => 'The target string',
1572 { name => 'org_unit',
1573 desc => 'The org unit shortname (or "-" or undef for global) to browse',
1575 { name => 'page_size',
1576 desc => 'Count of call numbers to retrieve, default is 9',
1579 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1581 { name => 'statuses',
1582 desc => 'Array of statuses to filter copies by, optional and can be undef.',
1584 { name => 'locations',
1585 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
1589 { desc => 'Record IDs that have copies at the relevant org units',
1594 sub axis_authority_startwith {
1599 $axis =~ s/^authority\.//;
1600 $axis =~ s/(\.refs)$//;
1603 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
1606 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
1607 push @tags, $f->tag;
1609 push @tags, $_->tag for @{$f->sub_entries};
1613 return authority_tag_sf_startwith($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
1615 __PACKAGE__->register_method(
1616 method => 'axis_authority_startwith',
1617 api_name => 'open-ils.supercat.authority.startwith.by_axis',
1621 { desc => "Returns a list of the requested authority record IDs held",
1623 [ { name => 'axis', desc => 'The target axis', type => 'string' },
1624 { name => 'value', desc => 'The target value', type => 'string' },
1625 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1626 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1627 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1633 sub general_authority_startwith {
1636 return authority_tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1638 __PACKAGE__->register_method(
1639 method => 'general_authority_startwith',
1640 api_name => 'open-ils.supercat.authority.title.startwith',
1641 tag => ['130'], subfield => 'a',
1645 { desc => "Returns a list of the requested authority record IDs held",
1647 [ { name => 'value', desc => 'The target title', type => 'string' },
1648 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1649 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1650 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1653 __PACKAGE__->register_method(
1654 method => 'general_authority_startwith',
1655 api_name => 'open-ils.supercat.authority.author.startwith',
1656 tag => [qw/100 110 111/], subfield => 'a',
1660 { desc => "Returns a list of the requested authority record IDs held",
1662 [ { name => 'value', desc => 'The target author', type => 'string' },
1663 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1664 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1665 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1668 __PACKAGE__->register_method(
1669 method => 'general_authority_startwith',
1670 api_name => 'open-ils.supercat.authority.subject.startwith',
1671 tag => [qw/148 150 151 155/], subfield => 'a',
1675 { desc => "Returns a list of the requested authority record IDs held",
1677 [ { name => 'value', desc => 'The target subject', type => 'string' },
1678 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1679 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1680 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1683 __PACKAGE__->register_method(
1684 method => 'general_authority_startwith',
1685 api_name => 'open-ils.supercat.authority.topic.startwith',
1686 tag => ['150'], subfield => 'a',
1690 { desc => "Returns a list of the requested authority record IDs held",
1692 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1693 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1694 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1695 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1698 __PACKAGE__->register_method(
1699 method => 'general_authority_startwith',
1700 api_name => 'open-ils.supercat.authority.title.refs.startwith',
1701 tag => ['130'], subfield => 'a',
1705 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1707 [ { name => 'value', desc => 'The target title', type => 'string' },
1708 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1709 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1710 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1713 __PACKAGE__->register_method(
1714 method => 'general_authority_startwith',
1715 api_name => 'open-ils.supercat.authority.author.refs.startwith',
1716 tag => [qw/100 110 111/], subfield => 'a',
1720 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1722 [ { name => 'value', desc => 'The target author', type => 'string' },
1723 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1724 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1725 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1728 __PACKAGE__->register_method(
1729 method => 'general_authority_startwith',
1730 api_name => 'open-ils.supercat.authority.subject.refs.startwith',
1731 tag => [qw/148 150 151 155/], subfield => 'a',
1735 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1737 [ { name => 'value', desc => 'The target subject', type => 'string' },
1738 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1739 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1740 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1743 __PACKAGE__->register_method(
1744 method => 'general_authority_startwith',
1745 api_name => 'open-ils.supercat.authority.topic.refs.startwith',
1746 tag => ['150'], subfield => 'a',
1750 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1752 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1753 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1754 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1755 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1761 sub authority_tag_sf_startwith {
1766 my $subfield = shift;
1769 my $limit = shift || 10;
1770 my $page = shift || 0;
1772 # Match authority.full_rec normalization
1773 $value = naco_normalize($value, $subfield);
1775 my $ref_limit = $limit;
1776 my $offset = $limit * abs($page);
1777 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1780 # .refs variant includes 4xx and 5xx variants for see / see also
1781 foreach my $tagname (@$tag) {
1782 push(@ref_tags, $tagname);
1783 if ($self->api_name =~ /\.refs\./) {
1784 push(@ref_tags, '4' . substr($tagname, 1, 2));
1785 push(@ref_tags, '5' . substr($tagname, 1, 2));
1792 # Don't skip the first actual page of results in descending order
1793 $offset = $offset - $limit;
1795 my $before = $_storage->request(
1796 "open-ils.cstore.json_query.atomic",
1797 { select => { afr => [qw/record value/] },
1799 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1800 order_by => { afr => { value => 'desc' } },
1801 limit => $ref_limit,
1805 push @list, map { $_->{record} } reverse(@$before);
1809 my $after = $_storage->request(
1810 "open-ils.cstore.json_query.atomic",
1811 { select => { afr => [qw/record value/] },
1813 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1814 order_by => { afr => { value => 'asc' } },
1815 limit => $ref_limit,
1819 push @list, map { $_->{record} } @$after;
1822 # If we're not pulling in see/see also references, just return the raw list
1823 if ($self->api_name !~ /\.refs\./) {
1827 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1830 foreach my $record (@list) {
1831 next if exists $seen{$record};
1832 push @retlist, int($record);
1838 __PACKAGE__->register_method(
1839 method => 'authority_tag_sf_startwith',
1840 api_name => 'open-ils.supercat.authority.tag.startwith',
1844 { desc => <<" DESC",
1845 Returns a list of the requested authority record IDs held
1850 desc => 'The target Authority MARC tag',
1852 { name => 'subfield',
1853 desc => 'The target Authority MARC subfield',
1856 desc => 'The target string',
1858 { name => 'page_size',
1859 desc => 'Count of call numbers to retrieve, default is 10',
1862 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1866 { desc => 'Authority Record IDs that are near the target string',
1872 sub holding_data_formats {
1875 namespace_uri => 'http://www.loc.gov/MARC21/slim',
1876 docs => 'http://www.loc.gov/marcxml/',
1877 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
1881 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acn.formats', api_level => 1 );
1882 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acp.formats', api_level => 1 );
1883 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.auri.formats', api_level => 1 );
1886 __PACKAGE__->register_method(
1887 method => 'retrieve_uri',
1888 api_name => 'open-ils.supercat.auri.marcxml.retrieve',
1892 { desc => <<" DESC",
1893 Returns a fleshed call number object
1898 desc => 'An OpenILS asset::uri id',
1902 { desc => 'fleshed uri',
1910 my $args = shift || {};
1912 return OpenILS::Application::SuperCat::unAPI
1913 ->new(OpenSRF::AppSession
1914 ->create( 'open-ils.cstore' )
1916 "open-ils.cstore.direct.asset.uri.retrieve",
1920 auri => [qw/call_number_maps/],
1921 auricnm => [qw/call_number/],
1922 acn => [qw/owning_lib record prefix suffix/],
1929 __PACKAGE__->register_method(
1930 method => 'retrieve_copy',
1931 api_name => 'open-ils.supercat.acp.marcxml.retrieve',
1935 { desc => <<" DESC",
1936 Returns a fleshed call number object
1941 desc => 'An OpenILS asset::copy id',
1945 { desc => 'fleshed copy',
1953 my $args = shift || {};
1955 return OpenILS::Application::SuperCat::unAPI
1956 ->new(OpenSRF::AppSession
1957 ->create( 'open-ils.cstore' )
1959 "open-ils.cstore.direct.asset.copy.retrieve",
1963 acn => [qw/owning_lib record prefix suffix/],
1964 acp => [qw/call_number location status circ_lib stat_cat_entries notes parts/],
1971 __PACKAGE__->register_method(
1972 method => 'retrieve_callnumber',
1973 api_name => 'open-ils.supercat.acn.marcxml.retrieve',
1978 { desc => <<" DESC",
1979 Returns a fleshed call number object
1984 desc => 'An OpenILS asset::call_number id',
1988 { desc => 'call number with copies',
1992 sub retrieve_callnumber {
1996 my $args = shift || {};
1998 return OpenILS::Application::SuperCat::unAPI
1999 ->new(OpenSRF::AppSession
2000 ->create( 'open-ils.cstore' )
2002 "open-ils.cstore.direct.asset.call_number.retrieve",
2006 acn => [qw/owning_lib record copies uri_maps prefix suffix/],
2007 auricnm => [qw/uri/],
2008 acp => [qw/location status circ_lib stat_cat_entries notes parts/],
2016 __PACKAGE__->register_method(
2017 method => 'basic_record_holdings',
2018 api_name => 'open-ils.supercat.record.basic_holdings.retrieve',
2023 { desc => <<" DESC",
2024 Returns a basic hash representation of the requested bibliographic record's holdings
2029 desc => 'An OpenILS biblio::record_entry id',
2033 { desc => 'Hash of bib record holdings hierarchy (call numbers and copies)',
2037 sub basic_record_holdings {
2043 # holdings hold an array of call numbers, which hold an array of copies
2044 # holdings => [ label: { library, [ copies: { barcode, location, status, circ_lib } ] } ]
2047 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2049 my $tree = $_storage->request(
2050 "open-ils.cstore.direct.biblio.record_entry.retrieve",
2054 bre => [qw/call_numbers/],
2055 acn => [qw/copies owning_lib prefix suffix/],
2056 acp => [qw/location status circ_lib parts/],
2061 my $o_search = { shortname => uc($ou) };
2062 if (!$ou || $ou eq '-') {
2063 $o_search = { parent_ou => undef };
2066 my $orgs = $_storage->request(
2067 "open-ils.cstore.direct.actor.org_unit.search",
2070 flesh_fields => { aou => [qw/children/] }
2074 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
2076 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2078 for my $cn (@{$tree->call_numbers}) {
2079 next unless ( $cn->deleted eq 'f' || !$cn->deleted );
2082 for my $c (@{$cn->copies}) {
2083 next unless grep {$c->circ_lib->id == $_} @ou_ids;
2084 next unless _cp_is_visible($cn, $c);
2090 $holdings{$cn->label}{'owning_lib'} = $cn->owning_lib->shortname;
2092 for my $cp (@{$cn->copies}) {
2094 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
2095 next unless _cp_is_visible($cn, $cp);
2097 push @{$holdings{$cn->label}{'copies'}}, {
2098 barcode => $cp->barcode,
2099 status => $cp->status->name,
2100 location => $cp->location->name,
2101 circlib => $cp->circ_lib->shortname
2110 sub _cp_is_visible {
2115 if ( ($cp->deleted eq 'f' || !$cp->deleted) &&
2116 $cp->location->opac_visible eq 't' &&
2117 $cp->status->opac_visible eq 't' &&
2118 $cp->opac_visible eq 't' &&
2119 $cp->circ_lib->opac_visible eq 't' &&
2120 $cn->owning_lib->opac_visible eq 't'
2128 #__PACKAGE__->register_method(
2129 # method => 'new_record_holdings',
2130 # api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
2135 # { desc => <<" DESC",
2136 #Returns the XML representation of the requested bibliographic record's holdings
2140 # { name => 'bibId',
2141 # desc => 'An OpenILS biblio::record_entry id',
2142 # type => 'number' },
2145 # { desc => 'Stream of bib record holdings hierarchy in XML',
2146 # type => 'string' }
2151 sub new_record_holdings {
2160 $paging = [-1,0] if (!$paging or !ref($paging) or @$paging == 0);
2161 my $limit = $$paging[0];
2162 my $offset = $$paging[1] || 0;
2164 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2165 my $_search = OpenSRF::AppSession->create( 'open-ils.search' );
2167 my $o_search = { shortname => uc($ou) };
2168 if (!$ou || $ou eq '-') {
2169 $o_search = { parent_ou => undef };
2172 my $one_org = $_storage->request(
2173 "open-ils.cstore.direct.actor.org_unit.search",
2177 my $count_req = $_search->request('open-ils.search.biblio.record.copy_count' => $one_org->id => $bib);
2178 my $staff_count_req = $_search->request('open-ils.search.biblio.record.copy_count.staff' => $one_org->id => $bib);
2180 my $orgs = $_storage->request(
2181 'open-ils.cstore.json_query.atomic',
2182 { from => [ 'actor.org_unit_descendants', defined($depth) ? ( $one_org->id, $depth ) : ( $one_org->id ) ] }
2186 my @ou_ids = map { $_->{id} } @$orgs;
2188 $logger->info("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2190 my %subselect = ( '-or' => [
2191 { owning_lib => \@ou_ids },
2195 call_number => { '=' => {'+acn'=>'id'} },
2197 circ_lib => \@ou_ids
2204 # we are dealing with -full or -uris, so we need to flesh things out
2207 # either way we're going to need uris
2208 # get all the uris up the tree (see also ba47ecc6196)
2210 my $uri_orgs = $_storage->request(
2211 'open-ils.cstore.json_query.atomic',
2212 { from => [ 'actor.org_unit_ancestors', $one_org->id ] }
2215 my @uri_ou_ids = map { $_->{id} } @$uri_orgs;
2217 # we have a -uris, just get the uris
2220 owning_lib => \@uri_ou_ids,
2223 from => { auricnm => 'auri' },
2225 call_number => { '=' => {'+acn'=>'id'} },
2226 '+auri' => { active => 't' }
2230 # we have a -full, get all the things
2231 } elsif ($flesh == 1) {
2232 %subselect = ( '-or' => [
2233 { owning_lib => \@ou_ids },
2237 call_number => { '=' => {'+acn'=>'id'} },
2239 circ_lib => \@ou_ids
2245 { owning_lib => \@uri_ou_ids },
2247 from => { auricnm => 'auri' },
2249 call_number => { '=' => {'+acn'=>'id'} },
2250 '+auri' => { active => 't' }
2259 my $cns = $_storage->request(
2260 "open-ils.cstore.direct.asset.call_number.search.atomic",
2267 acn => [qw/copies owning_lib uri_maps prefix suffix/],
2268 auricnm => [qw/uri/],
2269 acp => [qw/circ_lib location status stat_cat_entries notes parts/],
2270 asce => [qw/stat_cat/],
2272 ( $limit > -1 ? ( limit => $limit ) : () ),
2273 ( $offset ? ( offset => $offset ) : () ),
2274 order_by => { acn => { label_sortkey => {} } }
2278 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2282 $client->respond("<holdings xmlns='http://open-ils.org/spec/holdings/v1'><counts>\n");
2284 my $copy_counts = $count_req->gather(1);
2285 my $staff_copy_counts = $staff_count_req->gather(1);
2287 for my $c (@$copy_counts) {
2288 $$c{transcendant} ||= 0;
2289 my $out = "<count type='public'";
2290 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2291 $client->respond("$out/>\n")
2294 for my $c (@$staff_copy_counts) {
2295 $$c{transcendant} ||= 0;
2296 my $out = "<count type='staff'";
2297 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2298 $client->respond("$out/>\n")
2301 $client->respond("</counts><volumes>\n");
2303 for my $cn (@$cns) {
2304 next unless (@{$cn->copies} > 0 or (ref($cn->uri_maps) and @{$cn->uri_maps}));
2306 # We don't want O:A:S:unAPI::acn to return the record, we've got that already
2307 # In the context of BibTemplate, copies aren't necessary because we pull those
2308 # in a separate call
2310 OpenILS::Application::SuperCat::unAPI::acn
2312 ->as_xml( {no_record => 1, no_copies => ($flesh ? 0 : 1)} )
2316 $client->respond("</volumes><subscriptions>\n");
2318 $logger->info("Searching for serial holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2320 %subselect = ( '-or' => [
2321 { owning_lib => \@ou_ids },
2324 where => { holding_lib => \@ou_ids },
2330 my $ssubs = $_storage->request(
2331 "open-ils.cstore.direct.serial.subscription.search.atomic",
2332 { record_entry => $bib,
2337 ssub => [qw/distributions issuances scaps owning_lib/],
2338 sdist => [qw/basic_summary supplement_summary index_summary streams holding_lib/],
2339 sstr => [qw/items/],
2340 sitem => [qw/notes unit/],
2341 sunit => [qw/notes location status circ_lib stat_cat_entries call_number/],
2342 acn => [qw/owning_lib prefix suffix/],
2344 ( $limit > -1 ? ( limit => $limit ) : () ),
2345 ( $offset ? ( offset => $offset ) : () ),
2357 date_expected => {},
2364 for my $ssub (@$ssubs) {
2365 next unless (@{$ssub->distributions} or @{$ssub->issuances} or @{$ssub->scaps});
2367 # We don't want O:A:S:unAPI::ssub to return the record, we've got that already
2368 # In the context of BibTemplate, copies aren't necessary because we pull those
2369 # in a separate call
2371 OpenILS::Application::SuperCat::unAPI::ssub
2373 ->as_xml( {no_record => 1, no_items => ($flesh ? 0 : 1)} )
2378 return "</subscriptions></holdings>\n";
2380 __PACKAGE__->register_method(
2381 method => 'new_record_holdings',
2382 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
2387 { desc => <<" DESC",
2388 Returns the XML representation of the requested bibliographic record's holdings
2393 desc => 'An OpenILS biblio::record_entry ID',
2395 { name => 'orgUnit',
2396 desc => 'An OpenILS actor::org_unit short name that limits the scope of returned holdings',
2399 desc => 'An OpenILS actor::org_unit_type depththat limits the scope of returned holdings',
2401 { name => 'hideCopies',
2402 desc => 'Flag that prevents the inclusion of copies in the returned holdings',
2403 type => 'boolean' },
2405 desc => 'Arry of limit and offset for holdings paging',
2409 { desc => 'Stream of bib record holdings hierarchy in XML',
2419 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2421 my $recs = $_storage->request(
2422 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2423 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2426 return undef unless (@$recs);
2428 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
2430 __PACKAGE__->register_method(
2431 method => 'isbn_holdings',
2432 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
2436 { desc => <<" DESC",
2437 Returns the XML representation of the requested bibliographic record's holdings
2446 { desc => 'The bib record holdings hierarchy in XML',
2454 return '' unless $text;
2455 $text =~ s/&/&/gsom;
2456 $text =~ s/</</gsom;
2457 $text =~ s/>/>/gsom;
2458 $text =~ s/"/"/gsom;
2459 $text =~ s/'/'/gsom;
2463 sub recent_changes {
2466 my $when = shift || '1-01-01';
2469 my $type = 'biblio';
2472 if ($self->api_name =~ /authority/o) {
2473 $type = 'authority';
2477 my $axis = 'create_date';
2478 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
2480 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2482 return $_storage->request(
2483 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
2484 { $axis => { ">" => $when }, id => { '>' => 0 }, deleted => 'f', active => 't' },
2485 { order_by => { $hint => "$axis desc" }, limit => $limit }
2489 for my $t ( qw/biblio authority/ ) {
2490 for my $a ( qw/import edit/ ) {
2492 __PACKAGE__->register_method(
2493 method => 'recent_changes',
2494 api_name => "open-ils.supercat.$t.record.$a.recent",
2498 { desc => "Returns a list of recently ${a}ed $t records",
2502 desc => "Date to start looking for ${a}ed records",
2503 default => '1-01-01',
2507 desc => "Maximum count to retrieve",
2511 { desc => "An id list of $t records",
2519 sub retrieve_authority_marcxml {
2524 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2526 my $record = $_storage->request( 'open-ils.cstore.direct.authority.record_entry.retrieve' => $rid )->gather(1);
2527 return $U->entityize( $record->marc ) if ($record);
2531 __PACKAGE__->register_method(
2532 method => 'retrieve_authority_marcxml',
2533 api_name => 'open-ils.supercat.authority.marcxml.retrieve',
2537 { desc => <<" DESC",
2538 Returns the MARCXML representation of the requested authority record
2542 { name => 'authorityId',
2543 desc => 'An OpenILS authority::record_entry id',
2547 { desc => 'The authority record in MARCXML',
2552 sub retrieve_record_marcxml {
2557 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2559 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
2560 return $U->entityize( $record->marc ) if ($record);
2564 __PACKAGE__->register_method(
2565 method => 'retrieve_record_marcxml',
2566 api_name => 'open-ils.supercat.record.marcxml.retrieve',
2570 { desc => <<" DESC",
2571 Returns the MARCXML representation of the requested bibliographic record
2576 desc => 'An OpenILS biblio::record_entry id',
2580 { desc => 'The bib record in MARCXML',
2585 sub retrieve_isbn_marcxml {
2590 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2592 my $recs = $_storage->request(
2593 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2594 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2597 return undef unless (@$recs);
2599 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2600 return $U->entityize( $record->marc ) if ($record);
2604 __PACKAGE__->register_method(
2605 method => 'retrieve_isbn_marcxml',
2606 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
2610 { desc => <<" DESC",
2611 Returns the MARCXML representation of the requested ISBN
2616 desc => 'An ... um ... ISBN',
2620 { desc => 'The bib record in MARCXML',
2625 sub retrieve_record_transform {
2630 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
2632 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2633 #$_storage->connect;
2635 my $record = $_storage->request(
2636 'open-ils.cstore.direct.biblio.record_entry.retrieve',
2640 return undef unless ($record);
2642 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2645 sub retrieve_isbn_transform {
2650 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2652 my $recs = $_storage->request(
2653 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2654 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2657 return undef unless (@$recs);
2659 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
2661 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2663 return undef unless ($record);
2665 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2668 sub retrieve_record_objects {
2673 my $type = 'biblio';
2675 if ($self->api_name =~ /authority/) {
2676 $type = 'authority';
2679 $ids = [$ids] unless (ref $ids);
2680 $ids = [grep {$_} @$ids];
2682 return [] unless (@$ids);
2684 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2685 return $_storage->request("open-ils.cstore.direct.$type.record_entry.search.atomic" => { id => [grep {$_} @$ids] })->gather(1);
2687 __PACKAGE__->register_method(
2688 method => 'retrieve_record_objects',
2689 api_name => 'open-ils.supercat.record.object.retrieve',
2693 { desc => <<" DESC",
2694 Returns the Fieldmapper object representation of the requested bibliographic records
2699 desc => 'OpenILS biblio::record_entry ids',
2703 { desc => 'The bib records',
2708 __PACKAGE__->register_method(
2709 method => 'retrieve_record_objects',
2710 api_name => 'open-ils.supercat.authority.object.retrieve',
2714 { desc => <<" DESC",
2715 Returns the Fieldmapper object representation of the requested authority records
2719 { name => 'authIds',
2720 desc => 'OpenILS authority::record_entry ids',
2724 { desc => 'The authority records',
2729 sub retrieve_isbn_object {
2734 return undef unless ($isbn);
2736 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2737 my $recs = $_storage->request(
2738 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2739 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2742 return undef unless (@$recs);
2744 return $_storage->request(
2745 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
2746 { id => $recs->[0]->record }
2749 __PACKAGE__->register_method(
2750 method => 'retrieve_isbn_object',
2751 api_name => 'open-ils.supercat.isbn.object.retrieve',
2755 { desc => <<" DESC",
2756 Returns the Fieldmapper object representation of the requested bibliographic record
2765 { desc => 'The bib record',
2772 sub retrieve_metarecord_mods {
2777 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
2779 # Get the metarecord in question
2782 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
2785 # Now get the map of all bib records for the metarecord
2788 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2789 {metarecord => $rid}
2792 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
2794 # and retrieve the lead (master) record as MODS
2796 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2797 ->run($mr->master_record);
2798 my $master_mods = $_parser->parse_string($master)->documentElement;
2799 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods" );
2800 $master_mods->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2802 # ... and a MODS clone to populate, with guts removed.
2803 my $mods = $_parser->parse_string($master)->documentElement;
2804 $mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # modsCollection element
2805 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2806 ($mods) = $mods->findnodes('//mods:mods');
2807 #$mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # mods element
2808 $mods->removeChildNodes;
2809 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2811 # Add the metarecord ID as a (locally defined) info URI
2812 my $recordInfo = $mods
2814 ->createElement("recordInfo");
2816 my $recordIdentifier = $mods
2818 ->createElement("recordIdentifier");
2820 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2825 $recordIdentifier->appendTextNode(
2826 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
2829 $recordInfo->appendChild($recordIdentifier);
2830 $mods->appendChild($recordInfo);
2832 # Grab the title, author and ISBN for the master record and populate the metarecord
2833 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
2836 $title->setNamespace( "http://www.loc.gov/mods/", "mods" );
2837 $title->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2838 $title = $mods->ownerDocument->importNode($title);
2839 $mods->appendChild($title);
2842 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
2844 $author->setNamespace( "http://www.loc.gov/mods/", "mods" );
2845 $author->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2846 $author = $mods->ownerDocument->importNode($author);
2847 $mods->appendChild($author);
2850 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
2852 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2853 $isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2854 $isbn = $mods->ownerDocument->importNode($isbn);
2855 $mods->appendChild($isbn);
2858 # ... and loop over the constituent records
2859 for my $map ( @$recs ) {
2863 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2864 ->run($map->source);
2866 my $part_mods = $_parser->parse_string($rec);
2867 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods" );
2868 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2869 ($part_mods) = $part_mods->findnodes('//mods:mods');
2871 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
2872 $node->setNamespace( "http://www.loc.gov/mods/", "mods" );
2873 $node->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2874 $node = $mods->ownerDocument->importNode($node);
2875 $mods->appendChild( $node );
2878 my $relatedItem = $mods
2880 ->createElement("relatedItem");
2882 $relatedItem->setAttribute( type => 'constituent' );
2884 my $identifier = $mods
2886 ->createElement("identifier");
2888 $identifier->setAttribute( type => 'uri' );
2890 my $subRecordInfo = $mods
2892 ->createElement("recordInfo");
2894 my $subRecordIdentifier = $mods
2896 ->createElement("recordIdentifier");
2898 my $subid = $map->source;
2899 $subRecordIdentifier->appendTextNode(
2900 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
2905 $subRecordInfo->appendChild($subRecordIdentifier);
2907 $relatedItem->appendChild( $subRecordInfo );
2909 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
2910 $tor->setNamespace( "http://www.loc.gov/mods/", "mods" );
2911 $tor->setNamespace( "http://www.loc.gov/mods/", undef, 1 ) if ($tor);
2912 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
2913 $relatedItem->appendChild($tor) if ($tor);
2915 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
2916 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2917 $part_isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2918 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
2919 $relatedItem->appendChild( $part_isbn );
2922 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
2926 $mods->appendChild( $relatedItem );
2930 $_storage->disconnect;
2932 return $U->entityize($mods->toString);
2935 __PACKAGE__->register_method(
2936 method => 'retrieve_metarecord_mods',
2937 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
2941 { desc => <<" DESC",
2942 Returns the MODS representation of the requested metarecord
2946 { name => 'metarecordId',
2947 desc => 'An OpenILS metabib::metarecord id',
2951 { desc => 'The metarecord in MODS',
2956 sub list_metarecord_formats {
2959 { namespace_uri => 'http://www.loc.gov/mods/',
2960 docs => 'http://www.loc.gov/mods/',
2961 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
2966 for my $type ( keys %metarecord_xslt ) {
2969 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
2970 docs => $metarecord_xslt{$type}{docs},
2971 schema_location => $metarecord_xslt{$type}{schema_location},
2978 __PACKAGE__->register_method(
2979 method => 'list_metarecord_formats',
2980 api_name => 'open-ils.supercat.metarecord.formats',
2984 { desc => <<" DESC",
2985 Returns the list of valid metarecord formats that supercat understands.
2988 { desc => 'The format list',
2994 sub list_authority_formats {
2997 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2998 docs => 'http://www.loc.gov/marcxml/',
2999 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
3001 marc21 => { docs => 'http://www.loc.gov/marc/' }
3005 # for my $type ( keys %record_xslt ) {
3008 # { namespace_uri => $record_xslt{$type}{namespace_uri},
3009 # docs => $record_xslt{$type}{docs},
3010 # schema_location => $record_xslt{$type}{schema_location},
3017 __PACKAGE__->register_method(
3018 method => 'list_authority_formats',
3019 api_name => 'open-ils.supercat.authority.formats',
3023 { desc => <<" DESC",
3024 Returns the list of valid authority formats that supercat understands.
3027 { desc => 'The format list',
3032 sub list_record_formats {
3035 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
3036 docs => 'http://www.loc.gov/marcxml/',
3037 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
3040 { marc21 => { docs => 'http://www.loc.gov/marc/' } }
3043 for my $type ( keys %record_xslt ) {
3046 { namespace_uri => $record_xslt{$type}{namespace_uri},
3047 docs => $record_xslt{$type}{docs},
3048 schema_location => $record_xslt{$type}{schema_location},
3055 __PACKAGE__->register_method(
3056 method => 'list_record_formats',
3057 api_name => 'open-ils.supercat.record.formats',
3061 { desc => <<" DESC",
3062 Returns the list of valid record formats that supercat understands.
3065 { desc => 'The format list',
3069 __PACKAGE__->register_method(
3070 method => 'list_record_formats',
3071 api_name => 'open-ils.supercat.isbn.formats',
3075 { desc => <<" DESC",
3076 Returns the list of valid record formats that supercat understands.
3079 { desc => 'The format list',
3092 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
3093 unless (length($isbn) >= 10);
3095 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
3097 # Create a storage session, since we'll be making muliple requests.
3100 # Find the record that has that ISBN.
3101 my $bibrec = $_storage->request(
3102 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
3103 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
3106 # Go away if we don't have one.
3107 return {} unless (@$bibrec);
3109 # Find the metarecord for that bib record.
3110 my $mr = $_storage->request(
3111 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
3112 {source => $bibrec->[0]->record}
3115 # Find the other records for that metarecord.
3116 my $records = $_storage->request(
3117 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
3118 {metarecord => $mr->[0]->metarecord}
3121 # Just to be safe. There's currently no unique constraint on sources...
3122 my %unique_recs = map { ($_->source, 1) } @$records;
3123 my @rec_list = sort keys %unique_recs;
3125 # And now fetch the ISBNs for thos records.
3129 'open-ils.cstore.direct.metabib.full_rec.search',
3130 { tag => '020', subfield => 'a', record => $_ }
3131 )->gather(1) for (@rec_list);
3133 # We're done with the storage server session.
3134 $_storage->disconnect;
3136 # Return the oISBN data structure. This will be XMLized at a higher layer.
3138 { metarecord => $mr->[0]->metarecord,
3139 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
3142 __PACKAGE__->register_method(
3144 api_name => 'open-ils.supercat.oisbn',
3148 { desc => <<" DESC",
3149 Returns the ISBN list for the metarecord of the requested isbn
3154 desc => 'An ISBN. Duh.',
3158 { desc => 'record to isbn map',
3163 sub return_bib_search_aliases {
3166 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
3168 my $cmsa = $_storage->request(
3169 'open-ils.cstore.direct.config.metabib_search_alias.search.atomic',
3170 { alias => { '!=' => undef } }
3174 if ($_->alias =~ /\./) {
3175 my ($qualifier, $name) = $_->alias =~ m/^(.+?)\.(.+)$/;
3176 $aliases{$qualifier}{$name}{'index'} = $_->alias;
3177 # We will add a 'title' property in a subsequent schema
3178 $aliases{$qualifier}{$name}{'title'} = $name;
3180 # au/kw/se/su/ti go into the default 'eg' qualifier
3181 $aliases{'eg'}{$_->alias}{'index'} = $_->alias;
3182 $aliases{'eg'}{$_->alias}{'title'} = $_->alias;
3189 __PACKAGE__->register_method(
3190 method => 'return_bib_search_aliases',
3191 api_name => 'open-ils.supercat.biblio.search_aliases',
3195 { desc => <<" DESC",
3196 Returns the set of qualified search aliases in the system
3200 { desc => 'Hash of qualified search aliases',
3206 package OpenILS::Application::SuperCat::unAPI;
3207 use base qw/OpenILS::Application::SuperCat/;
3210 die "dummy superclass, use a real class";
3216 return unless ($obj);
3218 $class = ref($class) || $class;
3220 if ($class eq __PACKAGE__) {
3221 return unless (ref($obj));
3222 $class .= '::' . $obj->json_hint;
3225 return bless { obj => $obj } => $class;
3230 return $self->{obj};
3233 package OpenILS::Application::SuperCat::unAPI::auri;
3234 use base qw/OpenILS::Application::SuperCat::unAPI/;
3240 my $xml = ' <uri xmlns="http://open-ils.org/spec/holdings/v1" ';
3241 $xml .= 'id="tag:open-ils.org:asset-uri/' . $self->obj->id . '" ';
3242 $xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" ';
3243 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3244 $xml .= 'href="' . $self->escape( $self->obj->href ) . '">';
3246 if (!$args->{no_volumes}) {
3247 if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) {
3248 $xml .= " <volumes>\n" . join(
3251 OpenILS::Application::SuperCat::unAPI
3252 ->new( $_->call_number )
3253 ->as_xml({ %$args, no_uris=>1, no_copies=>1 })
3254 } @{ $self->obj->call_number_maps }
3255 ) . " </volumes>\n";
3258 $xml .= " <volumes/>\n";
3262 $xml .= " </uri>\n";
3267 package OpenILS::Application::SuperCat::unAPI::acn;
3268 use base qw/OpenILS::Application::SuperCat::unAPI/;
3274 my $xml = ' <volume xmlns="http://open-ils.org/spec/holdings/v1" ';
3276 $xml .= 'id="tag:open-ils.org:asset-call_number/' . $self->obj->id . '" ';
3277 $xml .= 'lib="' . $self->escape( $self->obj->owning_lib->shortname ) . '" ';
3278 $xml .= 'opac_visible="' . $self->obj->owning_lib->opac_visible . '" ';
3279 $xml .= 'deleted="' . $self->obj->deleted . '" ';
3280 $xml .= 'label="' . $self->escape( $self->obj->label ) . '">';
3283 if (!$args->{no_copies}) {
3284 if (ref($self->obj->copies) && @{ $self->obj->copies }) {
3285 $xml .= " <copies>\n" . join(
3288 OpenILS::Application::SuperCat::unAPI
3290 ->as_xml({ %$args, no_volume=>1 })
3291 } @{ $self->obj->copies }
3295 $xml .= " <copies/>\n";
3299 if (!$args->{no_uris}) {
3300 if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) {
3301 $xml .= " <uris>\n" . join(
3304 OpenILS::Application::SuperCat::unAPI
3306 ->as_xml({ %$args, no_volumes=>1 })
3307 } @{ $self->obj->uri_maps }
3311 $xml .= " <uris/>\n";
3316 $xml .= ' <prefix ';
3317 $xml .= 'ident="' . $self->obj->prefix->id . '" ';
3318 $xml .= 'id="tag:open-ils.org:asset-call_number_prefix/' . $self->obj->prefix->id . '" ';
3319 $xml .= 'label_sortkey="'.$self->escape( $self->obj->prefix->label_sortkey ) .'">';
3320 $xml .= $self->escape( $self->obj->prefix->label ) .'</prefix>';
3323 $xml .= ' <suffix ';
3324 $xml .= 'ident="' . $self->obj->suffix->id . '" ';
3325 $xml .= 'id="tag:open-ils.org:asset-call_number_suffix/' . $self->obj->suffix->id . '" ';
3326 $xml .= 'label_sortkey="'.$self->escape( $self->obj->suffix->label_sortkey ) .'">';
3327 $xml .= $self->escape( $self->obj->suffix->label ) .'</suffix>';
3330 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3331 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3332 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3333 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3336 unless ($args->{no_record}) {
3337 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3339 my $r_doc = $parser->parse_string($self->obj->record->marc);
3340 $r_doc->documentElement->setAttribute( id => $rec_tag );
3341 $xml .= $U->entityize($r_doc->documentElement->toString);
3344 $xml .= " </volume>\n";
3349 package OpenILS::Application::SuperCat::unAPI::ssub;
3350 use base qw/OpenILS::Application::SuperCat::unAPI/;
3356 my $xml = ' <subscription xmlns="http://open-ils.org/spec/holdings/v1" ';
3358 $xml .= 'id="tag:open-ils.org:serial-subscription/' . $self->obj->id . '" ';
3359 $xml .= 'start="' . $self->escape( $self->obj->start_date ) . '" ';
3360 $xml .= 'end="' . $self->escape( $self->obj->end_date ) . '" ';
3361 $xml .= 'expected_date_offset="' . $self->escape( $self->obj->expected_date_offset ) . '">';
3364 if (!$args->{no_distributions}) {
3365 if (ref($self->obj->distributions) && @{ $self->obj->distributions }) {
3366 $xml .= " <distributions>\n" . join(
3369 OpenILS::Application::SuperCat::unAPI
3371 ->as_xml({ %$args, no_subscription=>1, no_issuance=>1 })
3372 } @{ $self->obj->distributions }
3373 ) . " </distributions>\n";
3376 $xml .= " <distributions/>\n";
3380 if (!$args->{no_captions_and_patterns}) {
3381 if (ref($self->obj->scaps) && @{ $self->obj->scaps }) {
3382 $xml .= " <captions_and_patterns>\n" . join(
3385 OpenILS::Application::SuperCat::unAPI
3387 ->as_xml({ %$args, no_subscription=>1 })
3388 } @{ $self->obj->scaps }
3389 ) . " </captions_and_patterns>\n";
3392 $xml .= " <captions_and_patterns/>\n";
3396 if (!$args->{no_issuances}) {
3397 if (ref($self->obj->issuances) && @{ $self->obj->issuances }) {
3398 $xml .= " <issuances>\n" . join(
3401 OpenILS::Application::SuperCat::unAPI
3403 ->as_xml({ %$args, no_subscription=>1, no_items=>1 })
3404 } @{ $self->obj->issuances }
3405 ) . " </issuances>\n";
3408 $xml .= " <issuances/>\n";
3413 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3414 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3415 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3416 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3419 unless ($args->{no_record}) {
3420 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3422 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3423 $r_doc->documentElement->setAttribute( id => $rec_tag );
3424 $xml .= $U->entityize($r_doc->documentElement->toString);
3427 $xml .= " </subscription>\n";
3432 package OpenILS::Application::SuperCat::unAPI::ssum_base;
3433 use base qw/OpenILS::Application::SuperCat::unAPI/;
3439 (my $type = ref($self)) =~ s/^.+([^:]+)$/$1/;
3441 my $xml = " <serial_summary xmlns=\"http://open-ils.org/spec/holdings/v1\" type=\"$type\" ";
3443 $xml .= "id=\"tag:open-ils.org:serial-summary-$type/" . $self->obj->id . '" ';
3444 $xml .= 'generated_coverage="' . $self->escape( $self->obj->generated_coverage ) . '" ';
3445 $xml .= 'show_generated="' . $self->escape( $self->obj->show_generated ) . '" ';
3446 $xml .= 'textual_holdings="' . $self->escape( $self->obj->textual_holdings ) . '">';
3449 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_summaries=>1 }) if (!$args->{no_distribution});
3451 $xml .= " </serial_summary>\n";
3457 package OpenILS::Application::SuperCat::unAPI::sssum;
3458 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3460 package OpenILS::Application::SuperCat::unAPI::sbsum;
3461 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3463 package OpenILS::Application::SuperCat::unAPI::sisum;
3464 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3466 package OpenILS::Application::SuperCat::unAPI::sdist;
3467 use base qw/OpenILS::Application::SuperCat::unAPI/;
3473 my $xml = ' <distribution xmlns="http://open-ils.org/spec/holdings/v1" ';
3475 $xml .= 'id="tag:open-ils.org:serial-distribution/' . $self->obj->id . '" ';
3476 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3477 $xml .= 'unit_label_prefix="' . $self->escape( $self->obj->unit_label_prefix ) . '" ';
3478 $xml .= 'unit_label_suffix="' . $self->escape( $self->obj->unit_label_suffix ) . '">';
3481 if (!$args->{no_distributions}) {
3482 if (ref($self->obj->streams) && @{ $self->obj->streams }) {
3483 $xml .= " <streams>\n" . join(
3486 OpenILS::Application::SuperCat::unAPI
3488 ->as_xml({ %$args, no_distribution=>1 })
3489 } @{ $self->obj->streams }
3490 ) . " </streams>\n";
3493 $xml .= " <streams/>\n";
3497 if (!$args->{no_summaries}) {
3498 $xml .= " <summaries>\n";
3502 OpenILS::Application::SuperCat::unAPI
3504 ->as_xml({ %$args, no_distribution=>1 }) : ""
3505 } ($self->obj->basic_summary, $self->obj->supplement_summary, $self->obj->index_summary)
3508 $xml .= " </summaries>\n";
3512 $xml .= ' <holding_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3513 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->holding_lib->id . '" ';
3514 $xml .= 'shortname="'.$self->escape( $self->obj->holding_lib->shortname ) .'" ';
3515 $xml .= 'name="'.$self->escape( $self->obj->holding_lib->name ) .'"/>';
3518 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_distributions=>1 }) if (!$args->{no_subscription});
3520 if (!$args->{no_record} && $self->obj->record_entry) {
3521 my $rec_tag = "tag:open-ils.org:serial-record_entry/".$self->obj->record_entry->id ;
3523 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3524 $r_doc->documentElement->setAttribute( id => $rec_tag );
3525 $xml .= $U->entityize($r_doc->documentElement->toString);
3528 $xml .= " </distribution>\n";
3533 package OpenILS::Application::SuperCat::unAPI::sstr;
3534 use base qw/OpenILS::Application::SuperCat::unAPI/;
3540 my $xml = ' <stream xmlns="http://open-ils.org/spec/holdings/v1" ';
3542 $xml .= 'id="tag:open-ils.org:serial-stream/' . $self->obj->id . '" ';
3543 $xml .= 'routing_label="' . $self->escape( $self->obj->routing_label ) . '">';
3546 if (!$args->{no_items}) {
3547 if (ref($self->obj->items) && @{ $self->obj->items }) {
3548 $xml .= " <items>\n" . join(
3551 OpenILS::Application::SuperCat::unAPI
3553 ->as_xml({ %$args, no_stream=>1 })
3554 } @{ $self->obj->items }
3558 $xml .= " <items/>\n";
3562 #XXX routing_list_user's?
3564 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_streams=>1 }) if (!$args->{no_distribution});
3566 $xml .= " </stream>\n";
3571 package OpenILS::Application::SuperCat::unAPI::sitem;
3572 use base qw/OpenILS::Application::SuperCat::unAPI/;
3578 my $xml = ' <serial_item xmlns="http://open-ils.org/spec/holdings/v1" ';
3580 $xml .= 'id="tag:open-ils.org:serial-item/' . $self->obj->id . '" ';
3581 $xml .= 'date_expected="' . $self->escape( $self->obj->date_expected ) . '"';
3582 $xml .= ' date_received="' . $self->escape( $self->obj->date_received ) .'"'if ($self->obj->date_received);
3584 if ($args->{no_issuance}) {
3585 my $siss = ref($self->obj->issuance) ? $self->obj->issuance->id : $self->obj->issuance;
3586 $xml .= ' issuance="tag:open-ils.org:serial-issuance/' . $siss . '"';
3591 if (ref($self->obj->notes) && $self->obj->notes) {
3592 $xml .= " <notes>\n";
3593 for my $note ( @{$self->obj->notes} ) {
3594 next unless ( $note->pub eq 't' );
3595 $xml .= sprintf(' <note date="%s" title="%s">%s</note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3598 $xml .= " </notes>\n";
3600 $xml .= " <notes/>\n";
3603 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->issuance )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_issuance});
3604 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->stream )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_stream});
3605 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->unit )->as_xml({ %$args, no_items=>1, no_volumes=>1 }) if ($self->obj->unit && !$args->{no_unit});
3606 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->uri )->as_xml({ %$args, no_items=>1, no_volumes=>1 }) if ($self->obj->uri && !$args->{no_uri});
3608 $xml .= " </serial_item>\n";
3613 package OpenILS::Application::SuperCat::unAPI::sunit;
3614 use base qw/OpenILS::Application::SuperCat::unAPI/;
3620 my $xml = ' <serial_unit xmlns="http://open-ils.org/spec/holdings/v1" '.
3621 'id="tag:open-ils.org:serial-unit/' . $self->obj->id . '" ';
3623 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3624 create_date edit_date copy_number circulate deposit ref holdable deleted
3625 deposit_amount price barcode circ_modifier circ_as_type opac_visible cost
3626 status_changed_time floating mint_condition detailed_contents sort_key summary_contents
3631 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3632 $xml .= ' <location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3633 $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
3635 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3636 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3637 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3638 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'"/>';
3641 $xml .= " <copy_notes>\n";
3642 if (ref($self->obj->notes) && $self->obj->notes) {
3643 for my $note ( @{$self->obj->notes} ) {
3644 next unless ( $note->pub eq 't' );
3645 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3650 $xml .= " </copy_notes>\n";
3651 $xml .= " <statcats>\n";
3653 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3654 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3655 next unless ( $sce->stat_cat->opac_visible eq 't' );
3656 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3660 $xml .= " </statcats>\n";
3662 unless ($args->{no_volume}) {
3663 if (ref($self->obj->call_number)) {
3664 $xml .= OpenILS::Application::SuperCat::unAPI
3665 ->new( $self->obj->call_number )
3666 ->as_xml({ %$args, no_copies=>1 });
3668 $xml .= " <volume/>\n";
3672 $xml .= " </serial_unit>\n";
3677 package OpenILS::Application::SuperCat::unAPI::scap;
3678 use base qw/OpenILS::Application::SuperCat::unAPI/;
3684 my $xml = ' <caption_and_pattern xmlns="http://open-ils.org/spec/holdings/v1" '.
3685 'id="tag:open-ils.org:serial-caption_and_pattern/' . $self->obj->id . '" ';
3687 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3688 create_date type active pattern_code enum_1 enum_2 enum_3 enum_4
3689 enum_5 enum_6 chron_1 chron_2 chron_3 chron_4 chron_5 start_date end_date
3692 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_captions_and_patterns=>1 }) if (!$args->{no_subscription});
3693 $xml .= " </caption_and_pattern>\n";
3698 package OpenILS::Application::SuperCat::unAPI::siss;
3699 use base qw/OpenILS::Application::SuperCat::unAPI/;
3705 my $xml = ' <issuance xmlns="http://open-ils.org/spec/holdings/v1" '.
3706 'id="tag:open-ils.org:serial-issuance/' . $self->obj->id . '" ';
3708 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" '
3709 for (qw/create_date edit_date label date_published holding_code holding_type holding_link_id/);
3713 if (!$args->{no_items}) {
3714 if (ref($self->obj->items) && @{ $self->obj->items }) {
3715 $xml .= " <items>\n" . join(
3718 OpenILS::Application::SuperCat::unAPI
3720 ->as_xml({ %$args, no_stream=>1 })
3721 } @{ $self->obj->items }
3725 $xml .= " <items/>\n";
3729 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_issuances=>1 }) if (!$args->{no_subscription});
3730 $xml .= " </issuance>\n";
3735 package OpenILS::Application::SuperCat::unAPI::acp;
3736 use base qw/OpenILS::Application::SuperCat::unAPI/;
3742 my $xml = ' <copy xmlns="http://open-ils.org/spec/holdings/v1" '.
3743 'id="tag:open-ils.org:asset-copy/' . $self->obj->id . '" ';
3745 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3746 create_date edit_date copy_number circulate deposit ref holdable deleted
3747 deposit_amount price barcode circ_modifier circ_as_type opac_visible
3752 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3753 $xml .= ' <location ident="' . $self->obj->location->id . '" opac_visible="'.$self->obj->location->opac_visible.'">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3754 $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '" opac_visible="'.$self->obj->circ_lib->opac_visible.'">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
3756 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3757 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3758 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3759 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'" opac_visible="'.$self->obj->circ_lib->opac_visible.'"/>';
3762 $xml .= " <monograph_parts>\n";
3763 if (ref($self->obj->parts) && $self->obj->parts) {
3764 for my $part ( @{$self->obj->parts} ) {
3765 $xml .= sprintf(' <monograph_part record="%s" sortkey="%s">%s</monograph_part>',$part->record, $self->escape($part->label_sortkey), $self->escape($part->label));
3770 $xml .= " </monograph_parts>\n";
3771 $xml .= " <copy_notes>\n";
3772 if (ref($self->obj->notes) && $self->obj->notes) {
3773 for my $note ( @{$self->obj->notes} ) {
3774 next unless ( $note->pub eq 't' );
3775 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3780 $xml .= " </copy_notes>\n";
3781 $xml .= " <statcats>\n";
3783 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3784 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3785 next unless ( $sce->stat_cat->opac_visible eq 't' );
3786 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3790 $xml .= " </statcats>\n";
3792 unless ($args->{no_volume}) {
3793 if (ref($self->obj->call_number)) {
3794 $xml .= OpenILS::Application::SuperCat::unAPI
3795 ->new( $self->obj->call_number )
3796 ->as_xml({ %$args, no_copies=>1 });
3798 $xml .= " <volume/>\n";
3802 $xml .= " </copy>\n";