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 owning_lib => $ou_ids,
343 order_by => { acn => "oils_text_as_bytea(label), id" }
347 return $closest_cn->[0]->label_sortkey;
349 return '~~~'; #fallback to high ascii value, we are at the end
359 my $page_size = shift || 9;
360 my $page = shift || 0;
361 my $statuses = shift || [];
362 my $copy_locations = shift || [];
364 my ($before_limit,$after_limit) = (0,0);
365 my ($before_offset,$after_offset) = (0,0);
368 $before_limit = $after_limit = int($page_size / 2);
369 $after_limit += 1 if ($page_size % 2);
371 $before_offset = $after_offset = int($page_size / 2);
372 $before_offset += 1 if ($page_size % 2);
373 $before_limit = $after_limit = $page_size;
376 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
378 my $o_search = { shortname => $ou };
379 if (!$ou || $ou eq '-') {
380 $o_search = { parent_ou => undef };
383 my $orgs = $_storage->request(
384 "open-ils.cstore.direct.actor.org_unit.search",
387 flesh_fields => { aou => [qw/children/] }
391 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
393 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
398 if (@$statuses || @$copy_locations) {
403 call_number => { '=' => { '+acn' => 'id' } },
405 ((@$statuses) ? ( status => $statuses) : ()),
406 ((@$copy_locations) ? ( location => $copy_locations) : ())
412 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
415 my $before = $_storage->request(
416 "open-ils.cstore.direct.asset.call_number.search.atomic",
417 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
418 owning_lib => \@ou_ids,
423 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
424 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
425 limit => $before_limit,
426 offset => abs($page) * $page_size - $before_offset,
429 push @list, reverse(@$before);
433 my $after = $_storage->request(
434 "open-ils.cstore.direct.asset.call_number.search.atomic",
435 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
436 owning_lib => \@ou_ids,
441 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
442 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
443 limit => $after_limit,
444 offset => abs($page) * $page_size - $after_offset,
452 __PACKAGE__->register_method(
453 method => 'cn_browse',
454 api_name => 'open-ils.supercat.call_number.browse',
459 Returns the XML representation of the requested bibliographic record's holdings
464 desc => 'The target call number label',
466 { name => 'org_unit',
467 desc => 'The org unit shortname (or "-" or undef for global) to browse',
469 { name => 'page_size',
470 desc => 'Count of call numbers to retrieve, default is 9',
473 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
475 { name => 'statuses',
476 desc => 'Array of statuses to filter copies by, optional and can be undef.',
478 { name => 'locations',
479 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
483 { desc => 'Call numbers with owning_lib and record fleshed',
494 my $limit = shift || 10;
495 my $page = shift || 0;
496 my $statuses = shift || [];
497 my $copy_locations = shift || [];
500 my $offset = abs($page) * $limit;
501 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
503 my $o_search = { shortname => $ou };
504 if (!$ou || $ou eq '-') {
505 $o_search = { parent_ou => undef };
508 my $orgs = $_storage->request(
509 "open-ils.cstore.direct.actor.org_unit.search",
512 flesh_fields => { aou => [qw/children/] }
516 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
518 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
523 if (@$statuses || @$copy_locations) {
528 call_number => { '=' => { '+acn' => 'id' } },
530 ((@$statuses) ? ( status => $statuses) : ()),
531 ((@$copy_locations) ? ( location => $copy_locations) : ())
537 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
540 my $before = $_storage->request(
541 "open-ils.cstore.direct.asset.call_number.search.atomic",
542 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
543 owning_lib => \@ou_ids,
548 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
549 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
554 push @list, reverse(@$before);
558 my $after = $_storage->request(
559 "open-ils.cstore.direct.asset.call_number.search.atomic",
560 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
561 owning_lib => \@ou_ids,
566 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
567 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
577 __PACKAGE__->register_method(
578 method => 'cn_startwith',
579 api_name => 'open-ils.supercat.call_number.startwith',
584 Returns the XML representation of the requested bibliographic record's holdings
589 desc => 'The target call number label',
591 { name => 'org_unit',
592 desc => 'The org unit shortname (or "-" or undef for global) to browse',
594 { name => 'page_size',
595 desc => 'Count of call numbers to retrieve, default is 9',
598 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
600 { name => 'statuses',
601 desc => 'Array of statuses to filter copies by, optional and can be undef.',
603 { name => 'locations',
604 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
608 { desc => 'Call numbers with owning_lib and record fleshed',
614 sub new_books_by_item {
619 my $page_size = shift || 10;
620 my $page = shift || 1;
621 my $statuses = shift || [];
622 my $copy_locations = shift || [];
624 my $offset = $page_size * ($page - 1);
626 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
629 if ($ou && $ou ne '-') {
630 my $orgs = $_storage->request(
631 "open-ils.cstore.direct.actor.org_unit.search",
632 { shortname => $ou },
634 flesh_fields => { aou => [qw/children/] }
637 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
640 $logger->debug("Searching for records with new copies at orgs [".join(',',@ou_ids)."], based on $ou");
641 my $cns = $_storage->request(
642 "open-ils.cstore.json_query.atomic",
643 { select => { acn => ['record'],
644 acp => [{ aggregate => 1 => transform => max => column => create_date => alias => 'create_date'}]
646 from => { 'acn' => { 'acp' => { field => call_number => fkey => 'id' } } },
650 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
651 ((@$statuses) ? ( status => $statuses) : ()),
652 ((@$copy_locations) ? ( location => $copy_locations) : ())
654 '+acn' => { record => { '>' => 0 } },
656 order_by => { acp => { create_date => { transform => 'max', direction => 'desc' } } },
662 return [ map { $_->{record} } @$cns ];
664 __PACKAGE__->register_method(
665 method => 'new_books_by_item',
666 api_name => 'open-ils.supercat.new_book_list',
671 Returns the XML representation of the requested bibliographic record's holdings
675 { name => 'org_unit',
676 desc => 'The org unit shortname (or "-" or undef for global) to list',
678 { name => 'page_size',
679 desc => 'Count of records to retrieve, default is 10',
682 desc => 'The page of records to retrieve, calculated based on page_size. Starts at 1.',
684 { name => 'statuses',
685 desc => 'Array of statuses to filter copies by, optional and can be undef.',
687 { name => 'locations',
688 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
692 { desc => 'Record IDs',
701 return tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
703 __PACKAGE__->register_method(
704 method => 'general_browse',
705 api_name => 'open-ils.supercat.title.browse',
706 tag => 'tnf', subfield => 'a',
710 { desc => "Returns a list of the requested org-scoped record IDs held",
712 [ { name => 'value', desc => 'The target title', type => 'string' },
713 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
714 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
715 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
716 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
717 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
718 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
721 __PACKAGE__->register_method(
722 method => 'general_browse',
723 api_name => 'open-ils.supercat.author.browse',
724 tag => [qw/100 110 111/], subfield => 'a',
728 { desc => "Returns a list of the requested org-scoped record IDs held",
730 [ { name => 'value', desc => 'The target author', type => 'string' },
731 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
732 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
733 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
734 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
735 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
736 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
739 __PACKAGE__->register_method(
740 method => 'general_browse',
741 api_name => 'open-ils.supercat.subject.browse',
742 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
746 { desc => "Returns a list of the requested org-scoped record IDs held",
748 [ { name => 'value', desc => 'The target subject', 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.topic.browse',
760 tag => [qw/650 690/], subfield => 'a',
764 { desc => "Returns a list of the requested org-scoped record IDs held",
766 [ { name => 'value', desc => 'The target topical subject', 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.series.browse',
778 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
782 { desc => "Returns a list of the requested org-scoped record IDs held",
784 [ { name => 'value', desc => 'The target series', 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' }
800 my $subfield = shift;
803 my $page_size = shift || 9;
804 my $page = shift || 0;
805 my $statuses = shift || [];
806 my $copy_locations = shift || [];
808 my ($before_limit,$after_limit) = (0,0);
809 my ($before_offset,$after_offset) = (0,0);
812 $before_limit = $after_limit = int($page_size / 2);
813 $after_limit += 1 if ($page_size % 2);
815 $before_offset = $after_offset = int($page_size / 2);
816 $before_offset += 1 if ($page_size % 2);
817 $before_limit = $after_limit = $page_size;
820 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
823 if ($ou && $ou ne '-') {
824 my $orgs = $_storage->request(
825 "open-ils.cstore.direct.actor.org_unit.search",
826 { shortname => $ou },
828 flesh_fields => { aou => [qw/children/] }
831 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
834 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
839 my $before = $_storage->request(
840 "open-ils.cstore.json_query.atomic",
841 { select => { mfr => [qw/record value/] },
846 subfield => $subfield,
847 value => { '<' => lc($value) }
851 { select=> { acp => [ 'id' ] },
852 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
854 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
857 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
858 ((@$statuses) ? ( status => $statuses) : ()),
859 ((@$copy_locations) ? ( location => $copy_locations) : ())
866 { select=> { auri => [ 'id' ] },
867 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
869 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
870 '+auri' => { active => 't' }
877 order_by => { mfr => { value => 'desc' } },
878 limit => $before_limit,
879 offset => abs($page) * $page_size - $before_offset,
882 push @list, map { $_->{record} } reverse(@$before);
886 my $after = $_storage->request(
887 "open-ils.cstore.json_query.atomic",
888 { select => { mfr => [qw/record value/] },
893 subfield => $subfield,
894 value => { '>=' => lc($value) }
898 { select=> { acp => [ 'id' ] },
899 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
901 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
904 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
905 ((@$statuses) ? ( status => $statuses) : ()),
906 ((@$copy_locations) ? ( location => $copy_locations) : ())
913 { select=> { auri => [ 'id' ] },
914 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
916 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
917 '+auri' => { active => 't' }
924 order_by => { mfr => { value => 'asc' } },
925 limit => $after_limit,
926 offset => abs($page) * $page_size - $after_offset,
929 push @list, map { $_->{record} } @$after;
934 __PACKAGE__->register_method(
935 method => 'tag_sf_browse',
936 api_name => 'open-ils.supercat.tag.browse',
941 Returns a list of the requested org-scoped record IDs held
946 desc => 'The target MARC tag',
948 { name => 'subfield',
949 desc => 'The target MARC subfield',
952 desc => 'The target string',
954 { name => 'org_unit',
955 desc => 'The org unit shortname (or "-" or undef for global) to browse',
957 { name => 'page_size',
958 desc => 'Count of call numbers to retrieve, default is 9',
961 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
963 { name => 'statuses',
964 desc => 'Array of statuses to filter copies by, optional and can be undef.',
966 { name => 'locations',
967 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
971 { desc => 'Record IDs that have copies at the relevant org units',
976 sub grab_authority_browse_axes {
977 my ($self, $client, $full) = @_;
979 unless(scalar(keys(%authority_browse_axis_cache))) {
980 my $axes = new_editor->search_authority_browse_axis([
981 { code => { '<>' => undef } },
982 { flesh => 2, flesh_fields => { aba => ['fields'], acsaf => ['bib_fields','sub_entries'] } }
984 $authority_browse_axis_cache{$_->code} = $_ for (@$axes);
989 map { $authority_browse_axis_cache{$_} } sort keys %authority_browse_axis_cache
992 return [keys %authority_browse_axis_cache];
995 __PACKAGE__->register_method(
996 method => 'grab_authority_browse_axes',
997 api_name => 'open-ils.supercat.authority.browse_axis_list',
1001 { desc => "Returns a list of valid authority browse/startswith axes",
1003 { 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' }
1005 'return' => { desc => 'Axis codes or whole axes, see "full" param', type => 'array' }
1009 sub axis_authority_browse {
1014 $axis =~ s/^authority\.//;
1015 $axis =~ s/(\.refs)$//;
1018 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
1021 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
1022 push @tags, $f->tag;
1024 push @tags, $_->tag for @{$f->sub_entries};
1028 return authority_tag_sf_browse($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
1030 __PACKAGE__->register_method(
1031 method => 'axis_authority_browse',
1032 api_name => 'open-ils.supercat.authority.browse.by_axis',
1036 { desc => "Returns a list of the requested authority record IDs held",
1038 [ { name => 'axis', desc => 'The target axis', type => 'string' },
1039 { name => 'value', desc => 'The target value', type => 'string' },
1040 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1041 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1042 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1048 sub general_authority_browse {
1051 return authority_tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
1053 __PACKAGE__->register_method(
1054 method => 'general_authority_browse',
1055 api_name => 'open-ils.supercat.authority.title.browse',
1056 tag => ['130'], subfield => 'a',
1060 { desc => "Returns a list of the requested authority record IDs held",
1062 [ { name => 'value', desc => 'The target title', type => 'string' },
1063 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1064 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1065 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1068 __PACKAGE__->register_method(
1069 method => 'general_authority_browse',
1070 api_name => 'open-ils.supercat.authority.author.browse',
1071 tag => [qw/100 110 111/], subfield => 'a',
1075 { desc => "Returns a list of the requested authority record IDs held",
1077 [ { name => 'value', desc => 'The target author', type => 'string' },
1078 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1079 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1080 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1083 __PACKAGE__->register_method(
1084 method => 'general_authority_browse',
1085 api_name => 'open-ils.supercat.authority.subject.browse',
1086 tag => [qw/148 150 151 155/], subfield => 'a',
1090 { desc => "Returns a list of the requested authority record IDs held",
1092 [ { name => 'value', desc => 'The target subject', type => 'string' },
1093 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1094 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1095 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1098 __PACKAGE__->register_method(
1099 method => 'general_authority_browse',
1100 api_name => 'open-ils.supercat.authority.topic.browse',
1101 tag => ['150'], subfield => 'a',
1105 { desc => "Returns a list of the requested authority record IDs held",
1107 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1108 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1109 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1110 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1113 __PACKAGE__->register_method(
1114 method => 'general_authority_browse',
1115 api_name => 'open-ils.supercat.authority.title.refs.browse',
1116 tag => ['130'], subfield => 'a',
1120 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1122 [ { name => 'value', desc => 'The target title', type => 'string' },
1123 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1124 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1125 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1128 __PACKAGE__->register_method(
1129 method => 'general_authority_browse',
1130 api_name => 'open-ils.supercat.authority.author.refs.browse',
1131 tag => [qw/100 110 111/], subfield => 'a',
1135 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1137 [ { name => 'value', desc => 'The target author', type => 'string' },
1138 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1139 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1140 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1143 __PACKAGE__->register_method(
1144 method => 'general_authority_browse',
1145 api_name => 'open-ils.supercat.authority.subject.refs.browse',
1146 tag => [qw/148 150 151 155/], subfield => 'a',
1150 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1152 [ { name => 'value', desc => 'The target subject', type => 'string' },
1153 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1154 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1155 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1158 __PACKAGE__->register_method(
1159 method => 'general_authority_browse',
1160 api_name => 'open-ils.supercat.authority.topic.refs.browse',
1161 tag => ['150'], subfield => 'a',
1165 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1167 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1168 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1169 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1170 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1176 sub authority_tag_sf_browse {
1181 my $subfield = shift;
1183 my $page_size = shift || 9;
1184 my $page = shift || 0;
1186 # Match authority.full_rec normalization
1187 $value = naco_normalize($value, $subfield);
1189 my ($before_limit,$after_limit) = (0,0);
1190 my ($before_offset,$after_offset) = (0,0);
1193 $before_limit = $after_limit = int($page_size / 2);
1194 $after_limit += 1 if ($page_size % 2);
1196 $before_offset = $after_offset = int($page_size / 2);
1197 $before_offset += 1 if ($page_size % 2);
1198 $before_limit = $after_limit = $page_size;
1201 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1203 # .refs variant includes 4xx and 5xx variants for see / see also
1205 foreach my $tagname (@$tag) {
1206 push(@ref_tags, $tagname);
1207 if ($self->api_name =~ /\.refs\./) {
1208 push(@ref_tags, '4' . substr($tagname, 1, 2));
1209 push(@ref_tags, '5' . substr($tagname, 1, 2));
1215 my $before = $_storage->request(
1216 "open-ils.cstore.json_query.atomic",
1217 { select => { afr => [qw/record value/] },
1219 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1220 order_by => { afr => { value => 'desc' } },
1221 limit => $before_limit,
1222 offset => abs($page) * $page_size - $before_offset,
1225 push @list, map { $_->{record} } reverse(@$before);
1229 my $after = $_storage->request(
1230 "open-ils.cstore.json_query.atomic",
1231 { select => { afr => [qw/record value/] },
1233 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1234 order_by => { afr => { value => 'asc' } },
1235 limit => $after_limit,
1236 offset => abs($page) * $page_size - $after_offset,
1239 push @list, map { $_->{record} } @$after;
1242 # If we're not pulling in see/see also references, just return the raw list
1243 if ($self->api_name !~ /\.refs\./) {
1247 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1250 foreach my $record (@list) {
1251 next if exists $seen{$record};
1252 push @retlist, int($record);
1258 __PACKAGE__->register_method(
1259 method => 'authority_tag_sf_browse',
1260 api_name => 'open-ils.supercat.authority.tag.browse',
1264 { desc => <<" DESC",
1265 Returns a list of the requested authority record IDs held
1270 desc => 'The target Authority MARC tag',
1272 { name => 'subfield',
1273 desc => 'The target Authority MARC subfield',
1276 desc => 'The target string',
1278 { name => 'page_size',
1279 desc => 'Count of call numbers to retrieve, default is 9',
1282 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1286 { desc => 'Authority Record IDs that are near the target string',
1291 sub general_startwith {
1294 return tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1296 __PACKAGE__->register_method(
1297 method => 'general_startwith',
1298 api_name => 'open-ils.supercat.title.startwith',
1299 tag => 'tnf', subfield => 'a',
1303 { desc => "Returns a list of the requested org-scoped record IDs held",
1305 [ { name => 'value', desc => 'The target title', type => 'string' },
1306 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1307 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1308 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1309 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1310 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1311 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1314 __PACKAGE__->register_method(
1315 method => 'general_startwith',
1316 api_name => 'open-ils.supercat.author.startwith',
1317 tag => [qw/100 110 111/], subfield => 'a',
1321 { desc => "Returns a list of the requested org-scoped record IDs held",
1323 [ { name => 'value', desc => 'The target author', type => 'string' },
1324 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1325 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1326 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1327 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1328 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1329 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1332 __PACKAGE__->register_method(
1333 method => 'general_startwith',
1334 api_name => 'open-ils.supercat.subject.startwith',
1335 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
1339 { desc => "Returns a list of the requested org-scoped record IDs held",
1341 [ { name => 'value', desc => 'The target subject', 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.topic.startwith',
1353 tag => [qw/650 690/], subfield => 'a',
1357 { desc => "Returns a list of the requested org-scoped record IDs held",
1359 [ { name => 'value', desc => 'The target topical subject', 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.series.startwith',
1371 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
1375 { desc => "Returns a list of the requested org-scoped record IDs held",
1377 [ { name => 'value', desc => 'The target series', 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' }
1388 sub tag_sf_startwith {
1393 my $subfield = shift;
1396 my $limit = shift || 10;
1397 my $page = shift || 0;
1398 my $statuses = shift || [];
1399 my $copy_locations = shift || [];
1401 my $offset = $limit * abs($page);
1402 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1405 if ($ou && $ou ne '-') {
1406 my $orgs = $_storage->request(
1407 "open-ils.cstore.direct.actor.org_unit.search",
1408 { shortname => $ou },
1410 flesh_fields => { aou => [qw/children/] }
1413 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1416 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
1421 my $before = $_storage->request(
1422 "open-ils.cstore.json_query.atomic",
1423 { select => { mfr => [qw/record value/] },
1428 subfield => $subfield,
1429 value => { '<' => lc($value) }
1433 { select=> { acp => [ 'id' ] },
1434 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1436 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1439 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1440 ((@$statuses) ? ( status => $statuses) : ()),
1441 ((@$copy_locations) ? ( location => $copy_locations) : ())
1448 { select=> { auri => [ 'id' ] },
1449 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1451 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1452 '+auri' => { active => 't' }
1459 order_by => { mfr => { value => 'desc' } },
1464 push @list, map { $_->{record} } reverse(@$before);
1468 my $after = $_storage->request(
1469 "open-ils.cstore.json_query.atomic",
1470 { select => { mfr => [qw/record value/] },
1475 subfield => $subfield,
1476 value => { '>=' => lc($value) }
1480 { select=> { acp => [ 'id' ] },
1481 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1483 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1486 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1487 ((@$statuses) ? ( status => $statuses) : ()),
1488 ((@$copy_locations) ? ( location => $copy_locations) : ())
1495 { select=> { auri => [ 'id' ] },
1496 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1498 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1499 '+auri' => { active => 't' }
1506 order_by => { mfr => { value => 'asc' } },
1511 push @list, map { $_->{record} } @$after;
1516 __PACKAGE__->register_method(
1517 method => 'tag_sf_startwith',
1518 api_name => 'open-ils.supercat.tag.startwith',
1522 { desc => <<" DESC",
1523 Returns a list of the requested org-scoped record IDs held
1528 desc => 'The target MARC tag',
1530 { name => 'subfield',
1531 desc => 'The target MARC subfield',
1534 desc => 'The target string',
1536 { name => 'org_unit',
1537 desc => 'The org unit shortname (or "-" or undef for global) to browse',
1539 { name => 'page_size',
1540 desc => 'Count of call numbers to retrieve, default is 9',
1543 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1545 { name => 'statuses',
1546 desc => 'Array of statuses to filter copies by, optional and can be undef.',
1548 { name => 'locations',
1549 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
1553 { desc => 'Record IDs that have copies at the relevant org units',
1558 sub axis_authority_startwith {
1563 $axis =~ s/^authority\.//;
1564 $axis =~ s/(\.refs)$//;
1567 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
1570 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
1571 push @tags, $f->tag;
1573 push @tags, $_->tag for @{$f->sub_entries};
1577 return authority_tag_sf_startwith($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
1579 __PACKAGE__->register_method(
1580 method => 'axis_authority_startwith',
1581 api_name => 'open-ils.supercat.authority.startwith.by_axis',
1585 { desc => "Returns a list of the requested authority record IDs held",
1587 [ { name => 'axis', desc => 'The target axis', type => 'string' },
1588 { name => 'value', desc => 'The target value', type => 'string' },
1589 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1590 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1591 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1597 sub general_authority_startwith {
1600 return authority_tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1602 __PACKAGE__->register_method(
1603 method => 'general_authority_startwith',
1604 api_name => 'open-ils.supercat.authority.title.startwith',
1605 tag => ['130'], subfield => 'a',
1609 { desc => "Returns a list of the requested authority record IDs held",
1611 [ { name => 'value', desc => 'The target title', type => 'string' },
1612 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1613 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1614 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1617 __PACKAGE__->register_method(
1618 method => 'general_authority_startwith',
1619 api_name => 'open-ils.supercat.authority.author.startwith',
1620 tag => [qw/100 110 111/], subfield => 'a',
1624 { desc => "Returns a list of the requested authority record IDs held",
1626 [ { name => 'value', desc => 'The target author', type => 'string' },
1627 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1628 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1629 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1632 __PACKAGE__->register_method(
1633 method => 'general_authority_startwith',
1634 api_name => 'open-ils.supercat.authority.subject.startwith',
1635 tag => [qw/148 150 151 155/], subfield => 'a',
1639 { desc => "Returns a list of the requested authority record IDs held",
1641 [ { name => 'value', desc => 'The target subject', type => 'string' },
1642 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1643 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1644 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1647 __PACKAGE__->register_method(
1648 method => 'general_authority_startwith',
1649 api_name => 'open-ils.supercat.authority.topic.startwith',
1650 tag => ['150'], subfield => 'a',
1654 { desc => "Returns a list of the requested authority record IDs held",
1656 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1657 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1658 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1659 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1662 __PACKAGE__->register_method(
1663 method => 'general_authority_startwith',
1664 api_name => 'open-ils.supercat.authority.title.refs.startwith',
1665 tag => ['130'], subfield => 'a',
1669 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1671 [ { name => 'value', desc => 'The target title', type => 'string' },
1672 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1673 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1674 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1677 __PACKAGE__->register_method(
1678 method => 'general_authority_startwith',
1679 api_name => 'open-ils.supercat.authority.author.refs.startwith',
1680 tag => [qw/100 110 111/], subfield => 'a',
1684 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1686 [ { name => 'value', desc => 'The target author', type => 'string' },
1687 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1688 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1689 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1692 __PACKAGE__->register_method(
1693 method => 'general_authority_startwith',
1694 api_name => 'open-ils.supercat.authority.subject.refs.startwith',
1695 tag => [qw/148 150 151 155/], subfield => 'a',
1699 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1701 [ { name => 'value', desc => 'The target subject', type => 'string' },
1702 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1703 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1704 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1707 __PACKAGE__->register_method(
1708 method => 'general_authority_startwith',
1709 api_name => 'open-ils.supercat.authority.topic.refs.startwith',
1710 tag => ['150'], subfield => 'a',
1714 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1716 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1717 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1718 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1719 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1725 sub authority_tag_sf_startwith {
1730 my $subfield = shift;
1733 my $limit = shift || 10;
1734 my $page = shift || 0;
1736 # Match authority.full_rec normalization
1737 $value = naco_normalize($value, $subfield);
1739 my $ref_limit = $limit;
1740 my $offset = $limit * abs($page);
1741 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1744 # .refs variant includes 4xx and 5xx variants for see / see also
1745 foreach my $tagname (@$tag) {
1746 push(@ref_tags, $tagname);
1747 if ($self->api_name =~ /\.refs\./) {
1748 push(@ref_tags, '4' . substr($tagname, 1, 2));
1749 push(@ref_tags, '5' . substr($tagname, 1, 2));
1756 # Don't skip the first actual page of results in descending order
1757 $offset = $offset - $limit;
1759 my $before = $_storage->request(
1760 "open-ils.cstore.json_query.atomic",
1761 { select => { afr => [qw/record value/] },
1763 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1764 order_by => { afr => { value => 'desc' } },
1765 limit => $ref_limit,
1769 push @list, map { $_->{record} } reverse(@$before);
1773 my $after = $_storage->request(
1774 "open-ils.cstore.json_query.atomic",
1775 { select => { afr => [qw/record value/] },
1777 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1778 order_by => { afr => { value => 'asc' } },
1779 limit => $ref_limit,
1783 push @list, map { $_->{record} } @$after;
1786 # If we're not pulling in see/see also references, just return the raw list
1787 if ($self->api_name !~ /\.refs\./) {
1791 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1794 foreach my $record (@list) {
1795 next if exists $seen{$record};
1796 push @retlist, int($record);
1802 __PACKAGE__->register_method(
1803 method => 'authority_tag_sf_startwith',
1804 api_name => 'open-ils.supercat.authority.tag.startwith',
1808 { desc => <<" DESC",
1809 Returns a list of the requested authority record IDs held
1814 desc => 'The target Authority MARC tag',
1816 { name => 'subfield',
1817 desc => 'The target Authority MARC subfield',
1820 desc => 'The target string',
1822 { name => 'page_size',
1823 desc => 'Count of call numbers to retrieve, default is 10',
1826 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1830 { desc => 'Authority Record IDs that are near the target string',
1836 sub holding_data_formats {
1839 namespace_uri => 'http://www.loc.gov/MARC21/slim',
1840 docs => 'http://www.loc.gov/marcxml/',
1841 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
1845 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acn.formats', api_level => 1 );
1846 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acp.formats', api_level => 1 );
1847 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.auri.formats', api_level => 1 );
1850 __PACKAGE__->register_method(
1851 method => 'retrieve_uri',
1852 api_name => 'open-ils.supercat.auri.marcxml.retrieve',
1856 { desc => <<" DESC",
1857 Returns a fleshed call number object
1862 desc => 'An OpenILS asset::uri id',
1866 { desc => 'fleshed uri',
1874 my $args = shift || {};
1876 return OpenILS::Application::SuperCat::unAPI
1877 ->new(OpenSRF::AppSession
1878 ->create( 'open-ils.cstore' )
1880 "open-ils.cstore.direct.asset.uri.retrieve",
1884 auri => [qw/call_number_maps/],
1885 auricnm => [qw/call_number/],
1886 acn => [qw/owning_lib record prefix suffix/],
1893 __PACKAGE__->register_method(
1894 method => 'retrieve_copy',
1895 api_name => 'open-ils.supercat.acp.marcxml.retrieve',
1899 { desc => <<" DESC",
1900 Returns a fleshed call number object
1905 desc => 'An OpenILS asset::copy id',
1909 { desc => 'fleshed copy',
1917 my $args = shift || {};
1919 return OpenILS::Application::SuperCat::unAPI
1920 ->new(OpenSRF::AppSession
1921 ->create( 'open-ils.cstore' )
1923 "open-ils.cstore.direct.asset.copy.retrieve",
1927 acn => [qw/owning_lib record prefix suffix/],
1928 acp => [qw/call_number location status circ_lib stat_cat_entries notes parts/],
1935 __PACKAGE__->register_method(
1936 method => 'retrieve_callnumber',
1937 api_name => 'open-ils.supercat.acn.marcxml.retrieve',
1942 { desc => <<" DESC",
1943 Returns a fleshed call number object
1948 desc => 'An OpenILS asset::call_number id',
1952 { desc => 'call number with copies',
1956 sub retrieve_callnumber {
1960 my $args = shift || {};
1962 return OpenILS::Application::SuperCat::unAPI
1963 ->new(OpenSRF::AppSession
1964 ->create( 'open-ils.cstore' )
1966 "open-ils.cstore.direct.asset.call_number.retrieve",
1970 acn => [qw/owning_lib record copies uri_maps prefix suffix/],
1971 auricnm => [qw/uri/],
1972 acp => [qw/location status circ_lib stat_cat_entries notes parts/],
1980 __PACKAGE__->register_method(
1981 method => 'basic_record_holdings',
1982 api_name => 'open-ils.supercat.record.basic_holdings.retrieve',
1987 { desc => <<" DESC",
1988 Returns a basic hash representation of the requested bibliographic record's holdings
1993 desc => 'An OpenILS biblio::record_entry id',
1997 { desc => 'Hash of bib record holdings hierarchy (call numbers and copies)',
2001 sub basic_record_holdings {
2007 # holdings hold an array of call numbers, which hold an array of copies
2008 # holdings => [ label: { library, [ copies: { barcode, location, status, circ_lib } ] } ]
2011 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2013 my $tree = $_storage->request(
2014 "open-ils.cstore.direct.biblio.record_entry.retrieve",
2018 bre => [qw/call_numbers/],
2019 acn => [qw/copies owning_lib prefix suffix/],
2020 acp => [qw/location status circ_lib parts/],
2025 my $o_search = { shortname => uc($ou) };
2026 if (!$ou || $ou eq '-') {
2027 $o_search = { parent_ou => undef };
2030 my $orgs = $_storage->request(
2031 "open-ils.cstore.direct.actor.org_unit.search",
2034 flesh_fields => { aou => [qw/children/] }
2038 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
2040 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2042 for my $cn (@{$tree->call_numbers}) {
2043 next unless ( $cn->deleted eq 'f' || $cn->deleted == 0 );
2046 for my $c (@{$cn->copies}) {
2047 next unless grep {$c->circ_lib->id == $_} @ou_ids;
2048 next unless _cp_is_visible($cn, $c);
2054 $holdings{$cn->label}{'owning_lib'} = $cn->owning_lib->shortname;
2056 for my $cp (@{$cn->copies}) {
2058 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
2059 next unless _cp_is_visible($cn, $cp);
2061 push @{$holdings{$cn->label}{'copies'}}, {
2062 barcode => $cp->barcode,
2063 status => $cp->status->name,
2064 location => $cp->location->name,
2065 circlib => $cp->circ_lib->shortname
2074 sub _cp_is_visible {
2079 if ( ($cp->deleted eq 'f' || $cp->deleted == 0) &&
2080 $cp->location->opac_visible eq 't' &&
2081 $cp->status->opac_visible eq 't' &&
2082 $cp->opac_visible eq 't' &&
2083 $cp->circ_lib->opac_visible eq 't' &&
2084 $cn->owning_lib->opac_visible eq 't'
2092 #__PACKAGE__->register_method(
2093 # method => 'new_record_holdings',
2094 # api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
2099 # { desc => <<" DESC",
2100 #Returns the XML representation of the requested bibliographic record's holdings
2104 # { name => 'bibId',
2105 # desc => 'An OpenILS biblio::record_entry id',
2106 # type => 'number' },
2109 # { desc => 'Stream of bib record holdings hierarchy in XML',
2110 # type => 'string' }
2115 sub new_record_holdings {
2124 $paging = [-1,0] if (!$paging or !ref($paging) or @$paging == 0);
2125 my $limit = $$paging[0];
2126 my $offset = $$paging[1] || 0;
2128 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2129 my $_search = OpenSRF::AppSession->create( 'open-ils.search' );
2131 my $o_search = { shortname => uc($ou) };
2132 if (!$ou || $ou eq '-') {
2133 $o_search = { parent_ou => undef };
2136 my $one_org = $_storage->request(
2137 "open-ils.cstore.direct.actor.org_unit.search",
2141 my $count_req = $_search->request('open-ils.search.biblio.record.copy_count' => $one_org->id => $bib);
2142 my $staff_count_req = $_search->request('open-ils.search.biblio.record.copy_count.staff' => $one_org->id => $bib);
2144 my $orgs = $_storage->request(
2145 'open-ils.cstore.json_query.atomic',
2146 { from => [ 'actor.org_unit_descendants', defined($depth) ? ( $one_org->id, $depth ) : ( $one_org->id ) ] }
2150 my @ou_ids = map { $_->{id} } @$orgs;
2152 $logger->info("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2154 my %subselect = ( '-or' => [
2155 { owning_lib => \@ou_ids },
2159 call_number => { '=' => {'+acn'=>'id'} },
2161 circ_lib => \@ou_ids
2167 # we are dealing with -full or -uris, so we need to flesh things out
2170 # either way we're going to need uris
2171 # get all the uris up the tree (see also ba47ecc6196)
2173 my $uri_orgs = $_storage->request(
2174 'open-ils.cstore.json_query.atomic',
2175 { from => [ 'actor.org_unit_ancestors', $one_org->id ] }
2178 my @uri_ou_ids = map { $_->{id} } @$uri_orgs;
2180 # we have a -uris, just get the uris
2183 owning_lib => \@uri_ou_ids,
2185 from => { auricnm => 'auri' },
2187 call_number => { '=' => {'+acn'=>'id'} },
2188 '+auri' => { active => 't' }
2192 # we have a -full, get all the things
2193 } elsif ($flesh == 1) {
2194 %subselect = ( '-or' => [
2195 { owning_lib => \@ou_ids },
2199 call_number => { '=' => {'+acn'=>'id'} },
2201 circ_lib => \@ou_ids
2206 { owning_lib => \@uri_ou_ids },
2208 from => { auricnm => 'auri' },
2210 call_number => { '=' => {'+acn'=>'id'} },
2211 '+auri' => { active => 't' }
2219 my $cns = $_storage->request(
2220 "open-ils.cstore.direct.asset.call_number.search.atomic",
2227 acn => [qw/copies owning_lib uri_maps prefix suffix/],
2228 auricnm => [qw/uri/],
2229 acp => [qw/circ_lib location status stat_cat_entries notes parts/],
2230 asce => [qw/stat_cat/],
2232 ( $limit > -1 ? ( limit => $limit ) : () ),
2233 ( $offset ? ( offset => $offset ) : () ),
2234 order_by => { acn => { label_sortkey => {} } }
2238 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2242 $client->respond("<holdings xmlns='http://open-ils.org/spec/holdings/v1'><counts>\n");
2244 my $copy_counts = $count_req->gather(1);
2245 my $staff_copy_counts = $staff_count_req->gather(1);
2247 for my $c (@$copy_counts) {
2248 $$c{transcendant} ||= 0;
2249 my $out = "<count type='public'";
2250 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2251 $client->respond("$out/>\n")
2254 for my $c (@$staff_copy_counts) {
2255 $$c{transcendant} ||= 0;
2256 my $out = "<count type='staff'";
2257 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2258 $client->respond("$out/>\n")
2261 $client->respond("</counts><volumes>\n");
2263 for my $cn (@$cns) {
2264 next unless (@{$cn->copies} > 0 or (ref($cn->uri_maps) and @{$cn->uri_maps}));
2266 # We don't want O:A:S:unAPI::acn to return the record, we've got that already
2267 # In the context of BibTemplate, copies aren't necessary because we pull those
2268 # in a separate call
2270 OpenILS::Application::SuperCat::unAPI::acn
2272 ->as_xml( {no_record => 1, no_copies => ($flesh ? 0 : 1)} )
2276 $client->respond("</volumes><subscriptions>\n");
2278 $logger->info("Searching for serial holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2280 %subselect = ( '-or' => [
2281 { owning_lib => \@ou_ids },
2284 where => { holding_lib => \@ou_ids }
2289 my $ssubs = $_storage->request(
2290 "open-ils.cstore.direct.serial.subscription.search.atomic",
2291 { record_entry => $bib,
2296 ssub => [qw/distributions issuances scaps owning_lib/],
2297 sdist => [qw/basic_summary supplement_summary index_summary streams holding_lib/],
2298 sstr => [qw/items/],
2299 sitem => [qw/notes unit/],
2300 sunit => [qw/notes location status circ_lib stat_cat_entries call_number/],
2301 acn => [qw/owning_lib prefix suffix/],
2303 ( $limit > -1 ? ( limit => $limit ) : () ),
2304 ( $offset ? ( offset => $offset ) : () ),
2316 date_expected => {},
2323 for my $ssub (@$ssubs) {
2324 next unless (@{$ssub->distributions} or @{$ssub->issuances} or @{$ssub->scaps});
2326 # We don't want O:A:S:unAPI::ssub to return the record, we've got that already
2327 # In the context of BibTemplate, copies aren't necessary because we pull those
2328 # in a separate call
2330 OpenILS::Application::SuperCat::unAPI::ssub
2332 ->as_xml( {no_record => 1, no_items => ($flesh ? 0 : 1)} )
2337 return "</subscriptions></holdings>\n";
2339 __PACKAGE__->register_method(
2340 method => 'new_record_holdings',
2341 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
2346 { desc => <<" DESC",
2347 Returns the XML representation of the requested bibliographic record's holdings
2352 desc => 'An OpenILS biblio::record_entry ID',
2354 { name => 'orgUnit',
2355 desc => 'An OpenILS actor::org_unit short name that limits the scope of returned holdings',
2358 desc => 'An OpenILS actor::org_unit_type depththat limits the scope of returned holdings',
2360 { name => 'hideCopies',
2361 desc => 'Flag that prevents the inclusion of copies in the returned holdings',
2362 type => 'boolean' },
2364 desc => 'Arry of limit and offset for holdings paging',
2368 { desc => 'Stream of bib record holdings hierarchy in XML',
2378 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2380 my $recs = $_storage->request(
2381 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2382 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2385 return undef unless (@$recs);
2387 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
2389 __PACKAGE__->register_method(
2390 method => 'isbn_holdings',
2391 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
2395 { desc => <<" DESC",
2396 Returns the XML representation of the requested bibliographic record's holdings
2405 { desc => 'The bib record holdings hierarchy in XML',
2413 return '' unless $text;
2414 $text =~ s/&/&/gsom;
2415 $text =~ s/</</gsom;
2416 $text =~ s/>/>/gsom;
2417 $text =~ s/"/"/gsom;
2418 $text =~ s/'/'/gsom;
2422 sub recent_changes {
2425 my $when = shift || '1-01-01';
2428 my $type = 'biblio';
2431 if ($self->api_name =~ /authority/o) {
2432 $type = 'authority';
2436 my $axis = 'create_date';
2437 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
2439 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2441 return $_storage->request(
2442 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
2443 { $axis => { ">" => $when }, id => { '>' => 0 }, deleted => 'f', active => 't' },
2444 { order_by => { $hint => "$axis desc" }, limit => $limit }
2448 for my $t ( qw/biblio authority/ ) {
2449 for my $a ( qw/import edit/ ) {
2451 __PACKAGE__->register_method(
2452 method => 'recent_changes',
2453 api_name => "open-ils.supercat.$t.record.$a.recent",
2457 { desc => "Returns a list of recently ${a}ed $t records",
2461 desc => "Date to start looking for ${a}ed records",
2462 default => '1-01-01',
2466 desc => "Maximum count to retrieve",
2470 { desc => "An id list of $t records",
2478 sub retrieve_authority_marcxml {
2483 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2485 my $record = $_storage->request( 'open-ils.cstore.direct.authority.record_entry.retrieve' => $rid )->gather(1);
2486 return $U->entityize( $record->marc ) if ($record);
2490 __PACKAGE__->register_method(
2491 method => 'retrieve_authority_marcxml',
2492 api_name => 'open-ils.supercat.authority.marcxml.retrieve',
2496 { desc => <<" DESC",
2497 Returns the MARCXML representation of the requested authority record
2501 { name => 'authorityId',
2502 desc => 'An OpenILS authority::record_entry id',
2506 { desc => 'The authority record in MARCXML',
2511 sub retrieve_record_marcxml {
2516 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2518 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
2519 return $U->entityize( $record->marc ) if ($record);
2523 __PACKAGE__->register_method(
2524 method => 'retrieve_record_marcxml',
2525 api_name => 'open-ils.supercat.record.marcxml.retrieve',
2529 { desc => <<" DESC",
2530 Returns the MARCXML representation of the requested bibliographic record
2535 desc => 'An OpenILS biblio::record_entry id',
2539 { desc => 'The bib record in MARCXML',
2544 sub retrieve_isbn_marcxml {
2549 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2551 my $recs = $_storage->request(
2552 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2553 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2556 return undef unless (@$recs);
2558 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2559 return $U->entityize( $record->marc ) if ($record);
2563 __PACKAGE__->register_method(
2564 method => 'retrieve_isbn_marcxml',
2565 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
2569 { desc => <<" DESC",
2570 Returns the MARCXML representation of the requested ISBN
2575 desc => 'An ... um ... ISBN',
2579 { desc => 'The bib record in MARCXML',
2584 sub retrieve_record_transform {
2589 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
2591 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2592 #$_storage->connect;
2594 my $record = $_storage->request(
2595 'open-ils.cstore.direct.biblio.record_entry.retrieve',
2599 return undef unless ($record);
2601 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2604 sub retrieve_isbn_transform {
2609 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2611 my $recs = $_storage->request(
2612 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2613 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2616 return undef unless (@$recs);
2618 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
2620 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2622 return undef unless ($record);
2624 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2627 sub retrieve_record_objects {
2632 my $type = 'biblio';
2634 if ($self->api_name =~ /authority/) {
2635 $type = 'authority';
2638 $ids = [$ids] unless (ref $ids);
2639 $ids = [grep {$_} @$ids];
2641 return [] unless (@$ids);
2643 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2644 return $_storage->request("open-ils.cstore.direct.$type.record_entry.search.atomic" => { id => [grep {$_} @$ids] })->gather(1);
2646 __PACKAGE__->register_method(
2647 method => 'retrieve_record_objects',
2648 api_name => 'open-ils.supercat.record.object.retrieve',
2652 { desc => <<" DESC",
2653 Returns the Fieldmapper object representation of the requested bibliographic records
2658 desc => 'OpenILS biblio::record_entry ids',
2662 { desc => 'The bib records',
2667 __PACKAGE__->register_method(
2668 method => 'retrieve_record_objects',
2669 api_name => 'open-ils.supercat.authority.object.retrieve',
2673 { desc => <<" DESC",
2674 Returns the Fieldmapper object representation of the requested authority records
2678 { name => 'authIds',
2679 desc => 'OpenILS authority::record_entry ids',
2683 { desc => 'The authority records',
2688 sub retrieve_isbn_object {
2693 return undef unless ($isbn);
2695 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2696 my $recs = $_storage->request(
2697 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2698 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2701 return undef unless (@$recs);
2703 return $_storage->request(
2704 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
2705 { id => $recs->[0]->record }
2708 __PACKAGE__->register_method(
2709 method => 'retrieve_isbn_object',
2710 api_name => 'open-ils.supercat.isbn.object.retrieve',
2714 { desc => <<" DESC",
2715 Returns the Fieldmapper object representation of the requested bibliographic record
2724 { desc => 'The bib record',
2731 sub retrieve_metarecord_mods {
2736 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
2738 # Get the metarecord in question
2741 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
2744 # Now get the map of all bib records for the metarecord
2747 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2748 {metarecord => $rid}
2751 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
2753 # and retrieve the lead (master) record as MODS
2755 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2756 ->run($mr->master_record);
2757 my $master_mods = $_parser->parse_string($master)->documentElement;
2758 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods" );
2759 $master_mods->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2761 # ... and a MODS clone to populate, with guts removed.
2762 my $mods = $_parser->parse_string($master)->documentElement;
2763 $mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # modsCollection element
2764 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2765 ($mods) = $mods->findnodes('//mods:mods');
2766 #$mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # mods element
2767 $mods->removeChildNodes;
2768 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2770 # Add the metarecord ID as a (locally defined) info URI
2771 my $recordInfo = $mods
2773 ->createElement("recordInfo");
2775 my $recordIdentifier = $mods
2777 ->createElement("recordIdentifier");
2779 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2784 $recordIdentifier->appendTextNode(
2785 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
2788 $recordInfo->appendChild($recordIdentifier);
2789 $mods->appendChild($recordInfo);
2791 # Grab the title, author and ISBN for the master record and populate the metarecord
2792 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
2795 $title->setNamespace( "http://www.loc.gov/mods/", "mods" );
2796 $title->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2797 $title = $mods->ownerDocument->importNode($title);
2798 $mods->appendChild($title);
2801 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
2803 $author->setNamespace( "http://www.loc.gov/mods/", "mods" );
2804 $author->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2805 $author = $mods->ownerDocument->importNode($author);
2806 $mods->appendChild($author);
2809 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
2811 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2812 $isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2813 $isbn = $mods->ownerDocument->importNode($isbn);
2814 $mods->appendChild($isbn);
2817 # ... and loop over the constituent records
2818 for my $map ( @$recs ) {
2822 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2823 ->run($map->source);
2825 my $part_mods = $_parser->parse_string($rec);
2826 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods" );
2827 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2828 ($part_mods) = $part_mods->findnodes('//mods:mods');
2830 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
2831 $node->setNamespace( "http://www.loc.gov/mods/", "mods" );
2832 $node->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2833 $node = $mods->ownerDocument->importNode($node);
2834 $mods->appendChild( $node );
2837 my $relatedItem = $mods
2839 ->createElement("relatedItem");
2841 $relatedItem->setAttribute( type => 'constituent' );
2843 my $identifier = $mods
2845 ->createElement("identifier");
2847 $identifier->setAttribute( type => 'uri' );
2849 my $subRecordInfo = $mods
2851 ->createElement("recordInfo");
2853 my $subRecordIdentifier = $mods
2855 ->createElement("recordIdentifier");
2857 my $subid = $map->source;
2858 $subRecordIdentifier->appendTextNode(
2859 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
2864 $subRecordInfo->appendChild($subRecordIdentifier);
2866 $relatedItem->appendChild( $subRecordInfo );
2868 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
2869 $tor->setNamespace( "http://www.loc.gov/mods/", "mods" );
2870 $tor->setNamespace( "http://www.loc.gov/mods/", undef, 1 ) if ($tor);
2871 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
2872 $relatedItem->appendChild($tor) if ($tor);
2874 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
2875 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2876 $part_isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2877 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
2878 $relatedItem->appendChild( $part_isbn );
2881 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
2885 $mods->appendChild( $relatedItem );
2889 $_storage->disconnect;
2891 return $U->entityize($mods->toString);
2894 __PACKAGE__->register_method(
2895 method => 'retrieve_metarecord_mods',
2896 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
2900 { desc => <<" DESC",
2901 Returns the MODS representation of the requested metarecord
2905 { name => 'metarecordId',
2906 desc => 'An OpenILS metabib::metarecord id',
2910 { desc => 'The metarecord in MODS',
2915 sub list_metarecord_formats {
2918 { namespace_uri => 'http://www.loc.gov/mods/',
2919 docs => 'http://www.loc.gov/mods/',
2920 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
2925 for my $type ( keys %metarecord_xslt ) {
2928 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
2929 docs => $metarecord_xslt{$type}{docs},
2930 schema_location => $metarecord_xslt{$type}{schema_location},
2937 __PACKAGE__->register_method(
2938 method => 'list_metarecord_formats',
2939 api_name => 'open-ils.supercat.metarecord.formats',
2943 { desc => <<" DESC",
2944 Returns the list of valid metarecord formats that supercat understands.
2947 { desc => 'The format list',
2953 sub list_authority_formats {
2956 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2957 docs => 'http://www.loc.gov/marcxml/',
2958 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
2963 # for my $type ( keys %record_xslt ) {
2966 # { namespace_uri => $record_xslt{$type}{namespace_uri},
2967 # docs => $record_xslt{$type}{docs},
2968 # schema_location => $record_xslt{$type}{schema_location},
2975 __PACKAGE__->register_method(
2976 method => 'list_authority_formats',
2977 api_name => 'open-ils.supercat.authority.formats',
2981 { desc => <<" DESC",
2982 Returns the list of valid authority formats that supercat understands.
2985 { desc => 'The format list',
2990 sub list_record_formats {
2993 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2994 docs => 'http://www.loc.gov/marcxml/',
2995 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
3000 for my $type ( keys %record_xslt ) {
3003 { namespace_uri => $record_xslt{$type}{namespace_uri},
3004 docs => $record_xslt{$type}{docs},
3005 schema_location => $record_xslt{$type}{schema_location},
3012 __PACKAGE__->register_method(
3013 method => 'list_record_formats',
3014 api_name => 'open-ils.supercat.record.formats',
3018 { desc => <<" DESC",
3019 Returns the list of valid record formats that supercat understands.
3022 { desc => 'The format list',
3026 __PACKAGE__->register_method(
3027 method => 'list_record_formats',
3028 api_name => 'open-ils.supercat.isbn.formats',
3032 { desc => <<" DESC",
3033 Returns the list of valid record formats that supercat understands.
3036 { desc => 'The format list',
3049 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
3050 unless (length($isbn) >= 10);
3052 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
3054 # Create a storage session, since we'll be making muliple requests.
3057 # Find the record that has that ISBN.
3058 my $bibrec = $_storage->request(
3059 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
3060 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
3063 # Go away if we don't have one.
3064 return {} unless (@$bibrec);
3066 # Find the metarecord for that bib record.
3067 my $mr = $_storage->request(
3068 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
3069 {source => $bibrec->[0]->record}
3072 # Find the other records for that metarecord.
3073 my $records = $_storage->request(
3074 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
3075 {metarecord => $mr->[0]->metarecord}
3078 # Just to be safe. There's currently no unique constraint on sources...
3079 my %unique_recs = map { ($_->source, 1) } @$records;
3080 my @rec_list = sort keys %unique_recs;
3082 # And now fetch the ISBNs for thos records.
3086 'open-ils.cstore.direct.metabib.full_rec.search',
3087 { tag => '020', subfield => 'a', record => $_ }
3088 )->gather(1) for (@rec_list);
3090 # We're done with the storage server session.
3091 $_storage->disconnect;
3093 # Return the oISBN data structure. This will be XMLized at a higher layer.
3095 { metarecord => $mr->[0]->metarecord,
3096 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
3099 __PACKAGE__->register_method(
3101 api_name => 'open-ils.supercat.oisbn',
3105 { desc => <<" DESC",
3106 Returns the ISBN list for the metarecord of the requested isbn
3111 desc => 'An ISBN. Duh.',
3115 { desc => 'record to isbn map',
3120 sub return_bib_search_aliases {
3123 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
3125 my $cmsa = $_storage->request(
3126 'open-ils.cstore.direct.config.metabib_search_alias.search.atomic',
3127 { alias => { '!=' => undef } }
3131 if ($_->alias =~ /\./) {
3132 my ($qualifier, $name) = $_->alias =~ m/^(.+?)\.(.+)$/;
3133 $aliases{$qualifier}{$name}{'index'} = $_->alias;
3134 # We will add a 'title' property in a subsequent schema
3135 $aliases{$qualifier}{$name}{'title'} = $name;
3137 # au/kw/se/su/ti go into the default 'eg' qualifier
3138 $aliases{'eg'}{$_->alias}{'index'} = $_->alias;
3139 $aliases{'eg'}{$_->alias}{'title'} = $_->alias;
3146 __PACKAGE__->register_method(
3147 method => 'return_bib_search_aliases',
3148 api_name => 'open-ils.supercat.biblio.search_aliases',
3152 { desc => <<" DESC",
3153 Returns the set of qualified search aliases in the system
3157 { desc => 'Hash of qualified search aliases',
3163 package OpenILS::Application::SuperCat::unAPI;
3164 use base qw/OpenILS::Application::SuperCat/;
3167 die "dummy superclass, use a real class";
3173 return unless ($obj);
3175 $class = ref($class) || $class;
3177 if ($class eq __PACKAGE__) {
3178 return unless (ref($obj));
3179 $class .= '::' . $obj->json_hint;
3182 return bless { obj => $obj } => $class;
3187 return $self->{obj};
3190 package OpenILS::Application::SuperCat::unAPI::auri;
3191 use base qw/OpenILS::Application::SuperCat::unAPI/;
3197 my $xml = ' <uri xmlns="http://open-ils.org/spec/holdings/v1" ';
3198 $xml .= 'id="tag:open-ils.org:asset-uri/' . $self->obj->id . '" ';
3199 $xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" ';
3200 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3201 $xml .= 'href="' . $self->escape( $self->obj->href ) . '">';
3203 if (!$args->{no_volumes}) {
3204 if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) {
3205 $xml .= " <volumes>\n" . join(
3208 OpenILS::Application::SuperCat::unAPI
3209 ->new( $_->call_number )
3210 ->as_xml({ %$args, no_uris=>1, no_copies=>1 })
3211 } @{ $self->obj->call_number_maps }
3212 ) . " </volumes>\n";
3215 $xml .= " <volumes/>\n";
3219 $xml .= " </uri>\n";
3224 package OpenILS::Application::SuperCat::unAPI::acn;
3225 use base qw/OpenILS::Application::SuperCat::unAPI/;
3231 my $xml = ' <volume xmlns="http://open-ils.org/spec/holdings/v1" ';
3233 $xml .= 'id="tag:open-ils.org:asset-call_number/' . $self->obj->id . '" ';
3234 $xml .= 'lib="' . $self->escape( $self->obj->owning_lib->shortname ) . '" ';
3235 $xml .= 'opac_visible="' . $self->obj->owning_lib->opac_visible . '" ';
3236 $xml .= 'deleted="' . $self->obj->deleted . '" ';
3237 $xml .= 'label="' . $self->escape( $self->obj->label ) . '">';
3240 if (!$args->{no_copies}) {
3241 if (ref($self->obj->copies) && @{ $self->obj->copies }) {
3242 $xml .= " <copies>\n" . join(
3245 OpenILS::Application::SuperCat::unAPI
3247 ->as_xml({ %$args, no_volume=>1 })
3248 } @{ $self->obj->copies }
3252 $xml .= " <copies/>\n";
3256 if (!$args->{no_uris}) {
3257 if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) {
3258 $xml .= " <uris>\n" . join(
3261 OpenILS::Application::SuperCat::unAPI
3263 ->as_xml({ %$args, no_volumes=>1 })
3264 } @{ $self->obj->uri_maps }
3268 $xml .= " <uris/>\n";
3273 $xml .= ' <prefix ';
3274 $xml .= 'ident="' . $self->obj->prefix->id . '" ';
3275 $xml .= 'id="tag:open-ils.org:asset-call_number_prefix/' . $self->obj->prefix->id . '" ';
3276 $xml .= 'label_sortkey="'.$self->escape( $self->obj->prefix->label_sortkey ) .'">';
3277 $xml .= $self->escape( $self->obj->prefix->label ) .'</prefix>';
3280 $xml .= ' <suffix ';
3281 $xml .= 'ident="' . $self->obj->suffix->id . '" ';
3282 $xml .= 'id="tag:open-ils.org:asset-call_number_suffix/' . $self->obj->suffix->id . '" ';
3283 $xml .= 'label_sortkey="'.$self->escape( $self->obj->suffix->label_sortkey ) .'">';
3284 $xml .= $self->escape( $self->obj->suffix->label ) .'</suffix>';
3287 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3288 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3289 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3290 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3293 unless ($args->{no_record}) {
3294 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3296 my $r_doc = $parser->parse_string($self->obj->record->marc);
3297 $r_doc->documentElement->setAttribute( id => $rec_tag );
3298 $xml .= $U->entityize($r_doc->documentElement->toString);
3301 $xml .= " </volume>\n";
3306 package OpenILS::Application::SuperCat::unAPI::ssub;
3307 use base qw/OpenILS::Application::SuperCat::unAPI/;
3313 my $xml = ' <subscription xmlns="http://open-ils.org/spec/holdings/v1" ';
3315 $xml .= 'id="tag:open-ils.org:serial-subscription/' . $self->obj->id . '" ';
3316 $xml .= 'start="' . $self->escape( $self->obj->start_date ) . '" ';
3317 $xml .= 'end="' . $self->escape( $self->obj->end_date ) . '" ';
3318 $xml .= 'expected_date_offset="' . $self->escape( $self->obj->expected_date_offset ) . '">';
3321 if (!$args->{no_distributions}) {
3322 if (ref($self->obj->distributions) && @{ $self->obj->distributions }) {
3323 $xml .= " <distributions>\n" . join(
3326 OpenILS::Application::SuperCat::unAPI
3328 ->as_xml({ %$args, no_subscription=>1, no_issuance=>1 })
3329 } @{ $self->obj->distributions }
3330 ) . " </distributions>\n";
3333 $xml .= " <distributions/>\n";
3337 if (!$args->{no_captions_and_patterns}) {
3338 if (ref($self->obj->scaps) && @{ $self->obj->scaps }) {
3339 $xml .= " <captions_and_patterns>\n" . join(
3342 OpenILS::Application::SuperCat::unAPI
3344 ->as_xml({ %$args, no_subscription=>1 })
3345 } @{ $self->obj->scaps }
3346 ) . " </captions_and_patterns>\n";
3349 $xml .= " <captions_and_patterns/>\n";
3353 if (!$args->{no_issuances}) {
3354 if (ref($self->obj->issuances) && @{ $self->obj->issuances }) {
3355 $xml .= " <issuances>\n" . join(
3358 OpenILS::Application::SuperCat::unAPI
3360 ->as_xml({ %$args, no_subscription=>1, no_items=>1 })
3361 } @{ $self->obj->issuances }
3362 ) . " </issuances>\n";
3365 $xml .= " <issuances/>\n";
3370 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3371 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3372 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3373 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3376 unless ($args->{no_record}) {
3377 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3379 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3380 $r_doc->documentElement->setAttribute( id => $rec_tag );
3381 $xml .= $U->entityize($r_doc->documentElement->toString);
3384 $xml .= " </subscription>\n";
3389 package OpenILS::Application::SuperCat::unAPI::ssum_base;
3390 use base qw/OpenILS::Application::SuperCat::unAPI/;
3396 (my $type = ref($self)) =~ s/^.+([^:]+)$/$1/;
3398 my $xml = " <serial_summary xmlns=\"http://open-ils.org/spec/holdings/v1\" type=\"$type\" ";
3400 $xml .= "id=\"tag:open-ils.org:serial-summary-$type/" . $self->obj->id . '" ';
3401 $xml .= 'generated_coverage="' . $self->escape( $self->obj->generated_coverage ) . '" ';
3402 $xml .= 'show_generated="' . $self->escape( $self->obj->show_generated ) . '" ';
3403 $xml .= 'textual_holdings="' . $self->escape( $self->obj->textual_holdings ) . '">';
3406 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_summaries=>1 }) if (!$args->{no_distribution});
3408 $xml .= " </serial_summary>\n";
3414 package OpenILS::Application::SuperCat::unAPI::sssum;
3415 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3417 package OpenILS::Application::SuperCat::unAPI::sbsum;
3418 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3420 package OpenILS::Application::SuperCat::unAPI::sisum;
3421 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3423 package OpenILS::Application::SuperCat::unAPI::sdist;
3424 use base qw/OpenILS::Application::SuperCat::unAPI/;
3430 my $xml = ' <distribution xmlns="http://open-ils.org/spec/holdings/v1" ';
3432 $xml .= 'id="tag:open-ils.org:serial-distribution/' . $self->obj->id . '" ';
3433 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3434 $xml .= 'unit_label_prefix="' . $self->escape( $self->obj->unit_label_prefix ) . '" ';
3435 $xml .= 'unit_label_suffix="' . $self->escape( $self->obj->unit_label_suffix ) . '">';
3438 if (!$args->{no_distributions}) {
3439 if (ref($self->obj->streams) && @{ $self->obj->streams }) {
3440 $xml .= " <streams>\n" . join(
3443 OpenILS::Application::SuperCat::unAPI
3445 ->as_xml({ %$args, no_distribution=>1 })
3446 } @{ $self->obj->streams }
3447 ) . " </streams>\n";
3450 $xml .= " <streams/>\n";
3454 if (!$args->{no_summaries}) {
3455 $xml .= " <summaries>\n";
3459 OpenILS::Application::SuperCat::unAPI
3461 ->as_xml({ %$args, no_distribution=>1 }) : ""
3462 } ($self->obj->basic_summary, $self->obj->supplement_summary, $self->obj->index_summary)
3465 $xml .= " </summaries>\n";
3469 $xml .= ' <holding_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3470 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->holding_lib->id . '" ';
3471 $xml .= 'shortname="'.$self->escape( $self->obj->holding_lib->shortname ) .'" ';
3472 $xml .= 'name="'.$self->escape( $self->obj->holding_lib->name ) .'"/>';
3475 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_distributions=>1 }) if (!$args->{no_subscription});
3477 if (!$args->{no_record} && $self->obj->record_entry) {
3478 my $rec_tag = "tag:open-ils.org:serial-record_entry/".$self->obj->record_entry->id ;
3480 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3481 $r_doc->documentElement->setAttribute( id => $rec_tag );
3482 $xml .= $U->entityize($r_doc->documentElement->toString);
3485 $xml .= " </distribution>\n";
3490 package OpenILS::Application::SuperCat::unAPI::sstr;
3491 use base qw/OpenILS::Application::SuperCat::unAPI/;
3497 my $xml = ' <stream xmlns="http://open-ils.org/spec/holdings/v1" ';
3499 $xml .= 'id="tag:open-ils.org:serial-stream/' . $self->obj->id . '" ';
3500 $xml .= 'routing_label="' . $self->escape( $self->obj->routing_label ) . '">';
3503 if (!$args->{no_items}) {
3504 if (ref($self->obj->items) && @{ $self->obj->items }) {
3505 $xml .= " <items>\n" . join(
3508 OpenILS::Application::SuperCat::unAPI
3510 ->as_xml({ %$args, no_stream=>1 })
3511 } @{ $self->obj->items }
3515 $xml .= " <items/>\n";
3519 #XXX routing_list_user's?
3521 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_streams=>1 }) if (!$args->{no_distribution});
3523 $xml .= " </stream>\n";
3528 package OpenILS::Application::SuperCat::unAPI::sitem;
3529 use base qw/OpenILS::Application::SuperCat::unAPI/;
3535 my $xml = ' <serial_item xmlns="http://open-ils.org/spec/holdings/v1" ';
3537 $xml .= 'id="tag:open-ils.org:serial-item/' . $self->obj->id . '" ';
3538 $xml .= 'date_expected="' . $self->escape( $self->obj->date_expected ) . '"';
3539 $xml .= ' date_received="' . $self->escape( $self->obj->date_received ) .'"'if ($self->obj->date_received);
3541 if ($args->{no_issuance}) {
3542 my $siss = ref($self->obj->issuance) ? $self->obj->issuance->id : $self->obj->issuance;
3543 $xml .= ' issuance="tag:open-ils.org:serial-issuance/' . $siss . '"';
3548 if (ref($self->obj->notes) && $self->obj->notes) {
3549 $xml .= " <notes>\n";
3550 for my $note ( @{$self->obj->notes} ) {
3551 next unless ( $note->pub eq 't' );
3552 $xml .= sprintf(' <note date="%s" title="%s">%s</note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3555 $xml .= " </notes>\n";
3557 $xml .= " <notes/>\n";
3560 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->issuance )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_issuance});
3561 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->stream )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_stream});
3562 $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});
3563 $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});
3565 $xml .= " </serial_item>\n";
3570 package OpenILS::Application::SuperCat::unAPI::sunit;
3571 use base qw/OpenILS::Application::SuperCat::unAPI/;
3577 my $xml = ' <serial_unit xmlns="http://open-ils.org/spec/holdings/v1" '.
3578 'id="tag:open-ils.org:serial-unit/' . $self->obj->id . '" ';
3580 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3581 create_date edit_date copy_number circulate deposit ref holdable deleted
3582 deposit_amount price barcode circ_modifier circ_as_type opac_visible cost
3583 status_changed_time floating mint_condition detailed_contents sort_key summary_contents
3588 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3589 $xml .= ' <location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3590 $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
3592 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3593 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3594 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3595 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'"/>';
3598 $xml .= " <copy_notes>\n";
3599 if (ref($self->obj->notes) && $self->obj->notes) {
3600 for my $note ( @{$self->obj->notes} ) {
3601 next unless ( $note->pub eq 't' );
3602 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3607 $xml .= " </copy_notes>\n";
3608 $xml .= " <statcats>\n";
3610 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3611 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3612 next unless ( $sce->stat_cat->opac_visible eq 't' );
3613 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3617 $xml .= " </statcats>\n";
3619 unless ($args->{no_volume}) {
3620 if (ref($self->obj->call_number)) {
3621 $xml .= OpenILS::Application::SuperCat::unAPI
3622 ->new( $self->obj->call_number )
3623 ->as_xml({ %$args, no_copies=>1 });
3625 $xml .= " <volume/>\n";
3629 $xml .= " </serial_unit>\n";
3634 package OpenILS::Application::SuperCat::unAPI::scap;
3635 use base qw/OpenILS::Application::SuperCat::unAPI/;
3641 my $xml = ' <caption_and_pattern xmlns="http://open-ils.org/spec/holdings/v1" '.
3642 'id="tag:open-ils.org:serial-caption_and_pattern/' . $self->obj->id . '" ';
3644 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3645 create_date type active pattern_code enum_1 enum_2 enum_3 enum_4
3646 enum_5 enum_6 chron_1 chron_2 chron_3 chron_4 chron_5 start_date end_date
3649 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_captions_and_patterns=>1 }) if (!$args->{no_subscription});
3650 $xml .= " </caption_and_pattern>\n";
3655 package OpenILS::Application::SuperCat::unAPI::siss;
3656 use base qw/OpenILS::Application::SuperCat::unAPI/;
3662 my $xml = ' <issuance xmlns="http://open-ils.org/spec/holdings/v1" '.
3663 'id="tag:open-ils.org:serial-issuance/' . $self->obj->id . '" ';
3665 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" '
3666 for (qw/create_date edit_date label date_published holding_code holding_type holding_link_id/);
3670 if (!$args->{no_items}) {
3671 if (ref($self->obj->items) && @{ $self->obj->items }) {
3672 $xml .= " <items>\n" . join(
3675 OpenILS::Application::SuperCat::unAPI
3677 ->as_xml({ %$args, no_stream=>1 })
3678 } @{ $self->obj->items }
3682 $xml .= " <items/>\n";
3686 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_issuances=>1 }) if (!$args->{no_subscription});
3687 $xml .= " </issuance>\n";
3692 package OpenILS::Application::SuperCat::unAPI::acp;
3693 use base qw/OpenILS::Application::SuperCat::unAPI/;
3699 my $xml = ' <copy xmlns="http://open-ils.org/spec/holdings/v1" '.
3700 'id="tag:open-ils.org:asset-copy/' . $self->obj->id . '" ';
3702 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3703 create_date edit_date copy_number circulate deposit ref holdable deleted
3704 deposit_amount price barcode circ_modifier circ_as_type opac_visible
3709 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3710 $xml .= ' <location ident="' . $self->obj->location->id . '" opac_visible="'.$self->obj->location->opac_visible.'">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3711 $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";
3713 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3714 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3715 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3716 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'" opac_visible="'.$self->obj->circ_lib->opac_visible.'"/>';
3719 $xml .= " <monograph_parts>\n";
3720 if (ref($self->obj->parts) && $self->obj->parts) {
3721 for my $part ( @{$self->obj->parts} ) {
3722 $xml .= sprintf(' <monograph_part record="%s" sortkey="%s">%s</monograph_part>',$part->record, $self->escape($part->label_sortkey), $self->escape($part->label));
3727 $xml .= " </monograph_parts>\n";
3728 $xml .= " <copy_notes>\n";
3729 if (ref($self->obj->notes) && $self->obj->notes) {
3730 for my $note ( @{$self->obj->notes} ) {
3731 next unless ( $note->pub eq 't' );
3732 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3737 $xml .= " </copy_notes>\n";
3738 $xml .= " <statcats>\n";
3740 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3741 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3742 next unless ( $sce->stat_cat->opac_visible eq 't' );
3743 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3747 $xml .= " </statcats>\n";
3749 unless ($args->{no_volume}) {
3750 if (ref($self->obj->call_number)) {
3751 $xml .= OpenILS::Application::SuperCat::unAPI
3752 ->new( $self->obj->call_number )
3753 ->as_xml({ %$args, no_copies=>1 });
3755 $xml .= " <volume/>\n";
3759 $xml .= " </copy>\n";