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();
185 sub register_record_transforms {
186 for my $type ( keys %record_xslt ) {
187 __PACKAGE__->register_method(
188 method => 'retrieve_record_transform',
189 api_name => "open-ils.supercat.record.$type.retrieve",
193 { desc => "Returns the \U$type\E representation ".
194 "of the requested bibliographic record",
198 desc => 'An OpenILS biblio::record_entry id',
202 { desc => "The bib record in \U$type\E",
207 __PACKAGE__->register_method(
208 method => 'retrieve_isbn_transform',
209 api_name => "open-ils.supercat.isbn.$type.retrieve",
213 { desc => "Returns the \U$type\E representation ".
214 "of the requested bibliographic record",
222 { desc => "The bib record in \U$type\E",
234 return unless ($tree && ref($tree->$field));
236 my @things = $filter->($tree);
237 for my $v ( @{$tree->$field} ){
238 push @things, $filter->($v);
239 push @things, tree_walker($v, $field, $filter);
244 # find a label_sortkey for a call number with a label which is equal
245 # (or close to) a given label value
246 sub _label_sortkey_from_label {
247 my ($label, $_storage, $ou_ids, $cp_filter) = @_;
249 my $closest_cn = $_storage->request(
250 "open-ils.cstore.direct.asset.call_number.search.atomic",
251 { label => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } },
252 owning_lib => $ou_ids,
257 order_by => { acn => "oils_text_as_bytea(label), id" }
261 return $closest_cn->[0]->label_sortkey;
263 return '~~~'; #fallback to high ascii value, we are at the end
273 my $page_size = shift || 9;
274 my $page = shift || 0;
275 my $statuses = shift || [];
276 my $copy_locations = shift || [];
278 my ($before_limit,$after_limit) = (0,0);
279 my ($before_offset,$after_offset) = (0,0);
282 $before_limit = $after_limit = int($page_size / 2);
283 $after_limit += 1 if ($page_size % 2);
285 $before_offset = $after_offset = int($page_size / 2);
286 $before_offset += 1 if ($page_size % 2);
287 $before_limit = $after_limit = $page_size;
290 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
292 my $o_search = { shortname => $ou };
293 if (!$ou || $ou eq '-') {
294 $o_search = { parent_ou => undef };
297 my $orgs = $_storage->request(
298 "open-ils.cstore.direct.actor.org_unit.search",
301 flesh_fields => { aou => [qw/children/] }
305 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
307 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
312 if (@$statuses || @$copy_locations) {
317 call_number => { '=' => { '+acn' => 'id' } },
319 ((@$statuses) ? ( status => $statuses) : ()),
320 ((@$copy_locations) ? ( location => $copy_locations) : ())
326 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
329 my $before = $_storage->request(
330 "open-ils.cstore.direct.asset.call_number.search.atomic",
331 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
332 owning_lib => \@ou_ids,
337 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
338 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
339 limit => $before_limit,
340 offset => abs($page) * $page_size - $before_offset,
343 push @list, reverse(@$before);
347 my $after = $_storage->request(
348 "open-ils.cstore.direct.asset.call_number.search.atomic",
349 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
350 owning_lib => \@ou_ids,
355 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
356 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
357 limit => $after_limit,
358 offset => abs($page) * $page_size - $after_offset,
366 __PACKAGE__->register_method(
367 method => 'cn_browse',
368 api_name => 'open-ils.supercat.call_number.browse',
373 Returns the XML representation of the requested bibliographic record's holdings
378 desc => 'The target call number label',
380 { name => 'org_unit',
381 desc => 'The org unit shortname (or "-" or undef for global) to browse',
383 { name => 'page_size',
384 desc => 'Count of call numbers to retrieve, default is 9',
387 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
389 { name => 'statuses',
390 desc => 'Array of statuses to filter copies by, optional and can be undef.',
392 { name => 'locations',
393 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
397 { desc => 'Call numbers with owning_lib and record fleshed',
408 my $limit = shift || 10;
409 my $page = shift || 0;
410 my $statuses = shift || [];
411 my $copy_locations = shift || [];
414 my $offset = abs($page) * $limit;
415 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
417 my $o_search = { shortname => $ou };
418 if (!$ou || $ou eq '-') {
419 $o_search = { parent_ou => undef };
422 my $orgs = $_storage->request(
423 "open-ils.cstore.direct.actor.org_unit.search",
426 flesh_fields => { aou => [qw/children/] }
430 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
432 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
437 if (@$statuses || @$copy_locations) {
442 call_number => { '=' => { '+acn' => 'id' } },
444 ((@$statuses) ? ( status => $statuses) : ()),
445 ((@$copy_locations) ? ( location => $copy_locations) : ())
451 my $label_sortkey = _label_sortkey_from_label($label, $_storage, \@ou_ids, \@cp_filter);
454 my $before = $_storage->request(
455 "open-ils.cstore.direct.asset.call_number.search.atomic",
456 { label_sortkey => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
457 owning_lib => \@ou_ids,
462 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
463 order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" },
468 push @list, reverse(@$before);
472 my $after = $_storage->request(
473 "open-ils.cstore.direct.asset.call_number.search.atomic",
474 { label_sortkey => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label_sortkey] } },
475 owning_lib => \@ou_ids,
480 flesh_fields => { acn => [qw/record owning_lib prefix suffix/] },
481 order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" },
491 __PACKAGE__->register_method(
492 method => 'cn_startwith',
493 api_name => 'open-ils.supercat.call_number.startwith',
498 Returns the XML representation of the requested bibliographic record's holdings
503 desc => 'The target call number label',
505 { name => 'org_unit',
506 desc => 'The org unit shortname (or "-" or undef for global) to browse',
508 { name => 'page_size',
509 desc => 'Count of call numbers to retrieve, default is 9',
512 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
514 { name => 'statuses',
515 desc => 'Array of statuses to filter copies by, optional and can be undef.',
517 { name => 'locations',
518 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
522 { desc => 'Call numbers with owning_lib and record fleshed',
528 sub new_books_by_item {
533 my $page_size = shift || 10;
534 my $page = shift || 1;
535 my $statuses = shift || [];
536 my $copy_locations = shift || [];
538 my $offset = $page_size * ($page - 1);
540 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
543 if ($ou && $ou ne '-') {
544 my $orgs = $_storage->request(
545 "open-ils.cstore.direct.actor.org_unit.search",
546 { shortname => $ou },
548 flesh_fields => { aou => [qw/children/] }
551 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
554 $logger->debug("Searching for records with new copies at orgs [".join(',',@ou_ids)."], based on $ou");
555 my $cns = $_storage->request(
556 "open-ils.cstore.json_query.atomic",
557 { select => { acn => ['record'],
558 acp => [{ aggregate => 1 => transform => max => column => create_date => alias => 'create_date'}]
560 from => { 'acn' => { 'acp' => { field => call_number => fkey => 'id' } } },
564 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
565 ((@$statuses) ? ( status => $statuses) : ()),
566 ((@$copy_locations) ? ( location => $copy_locations) : ())
568 '+acn' => { record => { '>' => 0 } },
570 order_by => { acp => { create_date => { transform => 'max', direction => 'desc' } } },
576 return [ map { $_->{record} } @$cns ];
578 __PACKAGE__->register_method(
579 method => 'new_books_by_item',
580 api_name => 'open-ils.supercat.new_book_list',
585 Returns the XML representation of the requested bibliographic record's holdings
589 { name => 'org_unit',
590 desc => 'The org unit shortname (or "-" or undef for global) to list',
592 { name => 'page_size',
593 desc => 'Count of records to retrieve, default is 10',
596 desc => 'The page of records to retrieve, calculated based on page_size. Starts at 1.',
598 { name => 'statuses',
599 desc => 'Array of statuses to filter copies by, optional and can be undef.',
601 { name => 'locations',
602 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
606 { desc => 'Record IDs',
615 return tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
617 __PACKAGE__->register_method(
618 method => 'general_browse',
619 api_name => 'open-ils.supercat.title.browse',
620 tag => 'tnf', subfield => 'a',
624 { desc => "Returns a list of the requested org-scoped record IDs held",
626 [ { name => 'value', desc => 'The target title', type => 'string' },
627 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
628 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
629 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
630 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
631 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
632 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
635 __PACKAGE__->register_method(
636 method => 'general_browse',
637 api_name => 'open-ils.supercat.author.browse',
638 tag => [qw/100 110 111/], subfield => 'a',
642 { desc => "Returns a list of the requested org-scoped record IDs held",
644 [ { name => 'value', desc => 'The target author', type => 'string' },
645 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
646 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
647 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
648 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
649 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
650 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
653 __PACKAGE__->register_method(
654 method => 'general_browse',
655 api_name => 'open-ils.supercat.subject.browse',
656 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
660 { desc => "Returns a list of the requested org-scoped record IDs held",
662 [ { name => 'value', desc => 'The target subject', type => 'string' },
663 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
664 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
665 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
666 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
667 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
668 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
671 __PACKAGE__->register_method(
672 method => 'general_browse',
673 api_name => 'open-ils.supercat.topic.browse',
674 tag => [qw/650 690/], subfield => 'a',
678 { desc => "Returns a list of the requested org-scoped record IDs held",
680 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
681 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
682 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
683 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
684 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
685 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
686 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
689 __PACKAGE__->register_method(
690 method => 'general_browse',
691 api_name => 'open-ils.supercat.series.browse',
692 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
696 { desc => "Returns a list of the requested org-scoped record IDs held",
698 [ { name => 'value', desc => 'The target series', type => 'string' },
699 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
700 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
701 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
702 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
703 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
704 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
714 my $subfield = shift;
717 my $page_size = shift || 9;
718 my $page = shift || 0;
719 my $statuses = shift || [];
720 my $copy_locations = shift || [];
722 my ($before_limit,$after_limit) = (0,0);
723 my ($before_offset,$after_offset) = (0,0);
726 $before_limit = $after_limit = int($page_size / 2);
727 $after_limit += 1 if ($page_size % 2);
729 $before_offset = $after_offset = int($page_size / 2);
730 $before_offset += 1 if ($page_size % 2);
731 $before_limit = $after_limit = $page_size;
734 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
737 if ($ou && $ou ne '-') {
738 my $orgs = $_storage->request(
739 "open-ils.cstore.direct.actor.org_unit.search",
740 { shortname => $ou },
742 flesh_fields => { aou => [qw/children/] }
745 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
748 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
753 my $before = $_storage->request(
754 "open-ils.cstore.json_query.atomic",
755 { select => { mfr => [qw/record value/] },
760 subfield => $subfield,
761 value => { '<' => lc($value) }
765 { select=> { acp => [ 'id' ] },
766 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
768 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
771 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
772 ((@$statuses) ? ( status => $statuses) : ()),
773 ((@$copy_locations) ? ( location => $copy_locations) : ())
780 { select=> { auri => [ 'id' ] },
781 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
783 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
784 '+auri' => { active => 't' }
791 order_by => { mfr => { value => 'desc' } },
792 limit => $before_limit,
793 offset => abs($page) * $page_size - $before_offset,
796 push @list, map { $_->{record} } reverse(@$before);
800 my $after = $_storage->request(
801 "open-ils.cstore.json_query.atomic",
802 { select => { mfr => [qw/record value/] },
807 subfield => $subfield,
808 value => { '>=' => lc($value) }
812 { select=> { acp => [ 'id' ] },
813 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
815 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
818 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
819 ((@$statuses) ? ( status => $statuses) : ()),
820 ((@$copy_locations) ? ( location => $copy_locations) : ())
827 { select=> { auri => [ 'id' ] },
828 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
830 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
831 '+auri' => { active => 't' }
838 order_by => { mfr => { value => 'asc' } },
839 limit => $after_limit,
840 offset => abs($page) * $page_size - $after_offset,
843 push @list, map { $_->{record} } @$after;
848 __PACKAGE__->register_method(
849 method => 'tag_sf_browse',
850 api_name => 'open-ils.supercat.tag.browse',
855 Returns a list of the requested org-scoped record IDs held
860 desc => 'The target MARC tag',
862 { name => 'subfield',
863 desc => 'The target MARC subfield',
866 desc => 'The target string',
868 { name => 'org_unit',
869 desc => 'The org unit shortname (or "-" or undef for global) to browse',
871 { name => 'page_size',
872 desc => 'Count of call numbers to retrieve, default is 9',
875 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
877 { name => 'statuses',
878 desc => 'Array of statuses to filter copies by, optional and can be undef.',
880 { name => 'locations',
881 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
885 { desc => 'Record IDs that have copies at the relevant org units',
890 sub grab_authority_browse_axes {
892 unless(scalar(keys(%authority_browse_axis_cache))) {
893 my $axes = new_editor->search_authority_browse_axis([
894 { code => { '<>' => undef } },
895 { flesh => 2, flesh_fields => { aba => ['fields'], acsaf => ['bib_fields','sub_entries'] } }
897 $authority_browse_axis_cache{$_->code} = $_ for (@$axes);
900 return [keys %authority_browse_axis_cache];
902 __PACKAGE__->register_method(
903 method => 'grab_authority_browse_axes',
904 api_name => 'open-ils.supercat.authority.browse_axis_list',
907 note => "Returns a list of valid authority browse/startswith axes"
910 sub axis_authority_browse {
915 $axis =~ s/^authority\.//;
916 $axis =~ s/(\.refs)$//;
919 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
922 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
925 push @tags, $_->tag for @{$f->sub_entries};
929 return authority_tag_sf_browse($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
931 __PACKAGE__->register_method(
932 method => 'axis_authority_browse',
933 api_name => 'open-ils.supercat.authority.browse.by_axis',
937 { desc => "Returns a list of the requested authority record IDs held",
939 [ { name => 'axis', desc => 'The target axis', type => 'string' },
940 { name => 'value', desc => 'The target value', type => 'string' },
941 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
942 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
943 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
949 sub general_authority_browse {
952 return authority_tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
954 __PACKAGE__->register_method(
955 method => 'general_authority_browse',
956 api_name => 'open-ils.supercat.authority.title.browse',
957 tag => ['130'], subfield => 'a',
961 { desc => "Returns a list of the requested authority record IDs held",
963 [ { name => 'value', desc => 'The target title', type => 'string' },
964 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
965 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
966 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
969 __PACKAGE__->register_method(
970 method => 'general_authority_browse',
971 api_name => 'open-ils.supercat.authority.author.browse',
972 tag => [qw/100 110 111/], subfield => 'a',
976 { desc => "Returns a list of the requested authority record IDs held",
978 [ { name => 'value', desc => 'The target author', type => 'string' },
979 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
980 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
981 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
984 __PACKAGE__->register_method(
985 method => 'general_authority_browse',
986 api_name => 'open-ils.supercat.authority.subject.browse',
987 tag => [qw/148 150 151 155/], subfield => 'a',
991 { desc => "Returns a list of the requested authority record IDs held",
993 [ { name => 'value', desc => 'The target subject', type => 'string' },
994 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
995 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
996 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
999 __PACKAGE__->register_method(
1000 method => 'general_authority_browse',
1001 api_name => 'open-ils.supercat.authority.topic.browse',
1002 tag => ['150'], subfield => 'a',
1006 { desc => "Returns a list of the requested authority record IDs held",
1008 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1009 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1010 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1011 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1014 __PACKAGE__->register_method(
1015 method => 'general_authority_browse',
1016 api_name => 'open-ils.supercat.authority.title.refs.browse',
1017 tag => ['130'], subfield => 'a',
1021 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1023 [ { name => 'value', desc => 'The target title', type => 'string' },
1024 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1025 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1026 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1029 __PACKAGE__->register_method(
1030 method => 'general_authority_browse',
1031 api_name => 'open-ils.supercat.authority.author.refs.browse',
1032 tag => [qw/100 110 111/], subfield => 'a',
1036 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1038 [ { name => 'value', desc => 'The target author', type => 'string' },
1039 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1040 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1041 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1044 __PACKAGE__->register_method(
1045 method => 'general_authority_browse',
1046 api_name => 'open-ils.supercat.authority.subject.refs.browse',
1047 tag => [qw/148 150 151 155/], subfield => 'a',
1051 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1053 [ { name => 'value', desc => 'The target subject', type => 'string' },
1054 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1055 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1056 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1059 __PACKAGE__->register_method(
1060 method => 'general_authority_browse',
1061 api_name => 'open-ils.supercat.authority.topic.refs.browse',
1062 tag => ['150'], subfield => 'a',
1066 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1068 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1069 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1070 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1071 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1077 sub authority_tag_sf_browse {
1082 my $subfield = shift;
1084 my $page_size = shift || 9;
1085 my $page = shift || 0;
1087 # Match authority.full_rec normalization
1088 $value = naco_normalize($value, $subfield);
1090 my ($before_limit,$after_limit) = (0,0);
1091 my ($before_offset,$after_offset) = (0,0);
1094 $before_limit = $after_limit = int($page_size / 2);
1095 $after_limit += 1 if ($page_size % 2);
1097 $before_offset = $after_offset = int($page_size / 2);
1098 $before_offset += 1 if ($page_size % 2);
1099 $before_limit = $after_limit = $page_size;
1102 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1104 # .refs variant includes 4xx and 5xx variants for see / see also
1106 foreach my $tagname (@$tag) {
1107 push(@ref_tags, $tagname);
1108 if ($self->api_name =~ /\.refs\./) {
1109 push(@ref_tags, '4' . substr($tagname, 1, 2));
1110 push(@ref_tags, '5' . substr($tagname, 1, 2));
1116 my $before = $_storage->request(
1117 "open-ils.cstore.json_query.atomic",
1118 { select => { afr => [qw/record value/] },
1120 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1121 order_by => { afr => { value => 'desc' } },
1122 limit => $before_limit,
1123 offset => abs($page) * $page_size - $before_offset,
1126 push @list, map { $_->{record} } reverse(@$before);
1130 my $after = $_storage->request(
1131 "open-ils.cstore.json_query.atomic",
1132 { select => { afr => [qw/record value/] },
1134 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1135 order_by => { afr => { value => 'asc' } },
1136 limit => $after_limit,
1137 offset => abs($page) * $page_size - $after_offset,
1140 push @list, map { $_->{record} } @$after;
1143 # If we're not pulling in see/see also references, just return the raw list
1144 if ($self->api_name !~ /\.refs\./) {
1148 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1151 foreach my $record (@list) {
1152 next if exists $seen{$record};
1153 push @retlist, int($record);
1159 __PACKAGE__->register_method(
1160 method => 'authority_tag_sf_browse',
1161 api_name => 'open-ils.supercat.authority.tag.browse',
1165 { desc => <<" DESC",
1166 Returns a list of the requested authority record IDs held
1171 desc => 'The target Authority MARC tag',
1173 { name => 'subfield',
1174 desc => 'The target Authority MARC subfield',
1177 desc => 'The target string',
1179 { name => 'page_size',
1180 desc => 'Count of call numbers to retrieve, default is 9',
1183 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1187 { desc => 'Authority Record IDs that are near the target string',
1192 sub general_startwith {
1195 return tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1197 __PACKAGE__->register_method(
1198 method => 'general_startwith',
1199 api_name => 'open-ils.supercat.title.startwith',
1200 tag => 'tnf', subfield => 'a',
1204 { desc => "Returns a list of the requested org-scoped record IDs held",
1206 [ { name => 'value', desc => 'The target title', type => 'string' },
1207 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1208 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1209 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1210 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1211 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1212 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1215 __PACKAGE__->register_method(
1216 method => 'general_startwith',
1217 api_name => 'open-ils.supercat.author.startwith',
1218 tag => [qw/100 110 111/], subfield => 'a',
1222 { desc => "Returns a list of the requested org-scoped record IDs held",
1224 [ { name => 'value', desc => 'The target author', type => 'string' },
1225 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1226 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1227 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1228 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1229 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1230 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1233 __PACKAGE__->register_method(
1234 method => 'general_startwith',
1235 api_name => 'open-ils.supercat.subject.startwith',
1236 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
1240 { desc => "Returns a list of the requested org-scoped record IDs held",
1242 [ { name => 'value', desc => 'The target subject', type => 'string' },
1243 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1244 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1245 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1246 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1247 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1248 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1251 __PACKAGE__->register_method(
1252 method => 'general_startwith',
1253 api_name => 'open-ils.supercat.topic.startwith',
1254 tag => [qw/650 690/], subfield => 'a',
1258 { desc => "Returns a list of the requested org-scoped record IDs held",
1260 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1261 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1262 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1263 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1264 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1265 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1266 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1269 __PACKAGE__->register_method(
1270 method => 'general_startwith',
1271 api_name => 'open-ils.supercat.series.startwith',
1272 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
1276 { desc => "Returns a list of the requested org-scoped record IDs held",
1278 [ { name => 'value', desc => 'The target series', type => 'string' },
1279 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1280 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1281 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1282 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1283 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1284 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1289 sub tag_sf_startwith {
1294 my $subfield = shift;
1297 my $limit = shift || 10;
1298 my $page = shift || 0;
1299 my $statuses = shift || [];
1300 my $copy_locations = shift || [];
1302 my $offset = $limit * abs($page);
1303 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1306 if ($ou && $ou ne '-') {
1307 my $orgs = $_storage->request(
1308 "open-ils.cstore.direct.actor.org_unit.search",
1309 { shortname => $ou },
1311 flesh_fields => { aou => [qw/children/] }
1314 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1317 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
1322 my $before = $_storage->request(
1323 "open-ils.cstore.json_query.atomic",
1324 { select => { mfr => [qw/record value/] },
1329 subfield => $subfield,
1330 value => { '<' => lc($value) }
1334 { select=> { acp => [ 'id' ] },
1335 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1337 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1340 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1341 ((@$statuses) ? ( status => $statuses) : ()),
1342 ((@$copy_locations) ? ( location => $copy_locations) : ())
1349 { select=> { auri => [ 'id' ] },
1350 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1352 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1353 '+auri' => { active => 't' }
1360 order_by => { mfr => { value => 'desc' } },
1365 push @list, map { $_->{record} } reverse(@$before);
1369 my $after = $_storage->request(
1370 "open-ils.cstore.json_query.atomic",
1371 { select => { mfr => [qw/record value/] },
1376 subfield => $subfield,
1377 value => { '>=' => lc($value) }
1381 { select=> { acp => [ 'id' ] },
1382 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1384 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1387 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1388 ((@$statuses) ? ( status => $statuses) : ()),
1389 ((@$copy_locations) ? ( location => $copy_locations) : ())
1396 { select=> { auri => [ 'id' ] },
1397 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1399 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1400 '+auri' => { active => 't' }
1407 order_by => { mfr => { value => 'asc' } },
1412 push @list, map { $_->{record} } @$after;
1417 __PACKAGE__->register_method(
1418 method => 'tag_sf_startwith',
1419 api_name => 'open-ils.supercat.tag.startwith',
1423 { desc => <<" DESC",
1424 Returns a list of the requested org-scoped record IDs held
1429 desc => 'The target MARC tag',
1431 { name => 'subfield',
1432 desc => 'The target MARC subfield',
1435 desc => 'The target string',
1437 { name => 'org_unit',
1438 desc => 'The org unit shortname (or "-" or undef for global) to browse',
1440 { name => 'page_size',
1441 desc => 'Count of call numbers to retrieve, default is 9',
1444 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1446 { name => 'statuses',
1447 desc => 'Array of statuses to filter copies by, optional and can be undef.',
1449 { name => 'locations',
1450 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
1454 { desc => 'Record IDs that have copies at the relevant org units',
1459 sub axis_authority_startwith {
1464 $axis =~ s/^authority\.//;
1465 $axis =~ s/(\.refs)$//;
1468 return undef unless ( grep { /$axis/ } @{ grab_authority_browse_axes() } );
1471 for my $f (@{$authority_browse_axis_cache{$axis}->fields}) {
1472 push @tags, $f->tag;
1474 push @tags, $_->tag for @{$f->sub_entries};
1478 return authority_tag_sf_startwith($self, $client, \@tags, 'a', @_); # XXX TODO figure out something more correct for the subfield param
1480 __PACKAGE__->register_method(
1481 method => 'axis_authority_startwith',
1482 api_name => 'open-ils.supercat.authority.startwith.by_axis',
1486 { desc => "Returns a list of the requested authority record IDs held",
1488 [ { name => 'axis', desc => 'The target axis', type => 'string' },
1489 { name => 'value', desc => 'The target value', type => 'string' },
1490 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1491 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1492 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1498 sub general_authority_startwith {
1501 return authority_tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1503 __PACKAGE__->register_method(
1504 method => 'general_authority_startwith',
1505 api_name => 'open-ils.supercat.authority.title.startwith',
1506 tag => ['130'], subfield => 'a',
1510 { desc => "Returns a list of the requested authority record IDs held",
1512 [ { name => 'value', desc => 'The target title', type => 'string' },
1513 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1514 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1515 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1518 __PACKAGE__->register_method(
1519 method => 'general_authority_startwith',
1520 api_name => 'open-ils.supercat.authority.author.startwith',
1521 tag => [qw/100 110 111/], subfield => 'a',
1525 { desc => "Returns a list of the requested authority record IDs held",
1527 [ { name => 'value', desc => 'The target author', type => 'string' },
1528 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1529 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1530 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1533 __PACKAGE__->register_method(
1534 method => 'general_authority_startwith',
1535 api_name => 'open-ils.supercat.authority.subject.startwith',
1536 tag => [qw/148 150 151 155/], subfield => 'a',
1540 { desc => "Returns a list of the requested authority record IDs held",
1542 [ { name => 'value', desc => 'The target subject', type => 'string' },
1543 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1544 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1545 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1548 __PACKAGE__->register_method(
1549 method => 'general_authority_startwith',
1550 api_name => 'open-ils.supercat.authority.topic.startwith',
1551 tag => ['150'], subfield => 'a',
1555 { desc => "Returns a list of the requested authority record IDs held",
1557 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1558 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1559 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1560 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1563 __PACKAGE__->register_method(
1564 method => 'general_authority_startwith',
1565 api_name => 'open-ils.supercat.authority.title.refs.startwith',
1566 tag => ['130'], subfield => 'a',
1570 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1572 [ { name => 'value', desc => 'The target title', type => 'string' },
1573 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1574 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1575 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1578 __PACKAGE__->register_method(
1579 method => 'general_authority_startwith',
1580 api_name => 'open-ils.supercat.authority.author.refs.startwith',
1581 tag => [qw/100 110 111/], subfield => 'a',
1585 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1587 [ { name => 'value', desc => 'The target author', type => 'string' },
1588 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1589 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1590 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1593 __PACKAGE__->register_method(
1594 method => 'general_authority_startwith',
1595 api_name => 'open-ils.supercat.authority.subject.refs.startwith',
1596 tag => [qw/148 150 151 155/], subfield => 'a',
1600 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1602 [ { name => 'value', desc => 'The target subject', type => 'string' },
1603 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1604 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1605 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1608 __PACKAGE__->register_method(
1609 method => 'general_authority_startwith',
1610 api_name => 'open-ils.supercat.authority.topic.refs.startwith',
1611 tag => ['150'], subfield => 'a',
1615 { desc => "Returns a list of the requested authority record IDs held, including see (4xx) and see also (5xx) references",
1617 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1618 { name => 'page_size', desc => 'Count of records to retrieve, default is 10', type => 'number' },
1619 { name => 'page', desc => 'The page of records retrieved, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1620 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1626 sub authority_tag_sf_startwith {
1631 my $subfield = shift;
1634 my $limit = shift || 10;
1635 my $page = shift || 0;
1637 # Match authority.full_rec normalization
1638 $value = naco_normalize($value, $subfield);
1640 my $ref_limit = $limit;
1641 my $offset = $limit * abs($page);
1642 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1645 # .refs variant includes 4xx and 5xx variants for see / see also
1646 foreach my $tagname (@$tag) {
1647 push(@ref_tags, $tagname);
1648 if ($self->api_name =~ /\.refs\./) {
1649 push(@ref_tags, '4' . substr($tagname, 1, 2));
1650 push(@ref_tags, '5' . substr($tagname, 1, 2));
1657 # Don't skip the first actual page of results in descending order
1658 $offset = $offset - $limit;
1660 my $before = $_storage->request(
1661 "open-ils.cstore.json_query.atomic",
1662 { select => { afr => [qw/record value/] },
1664 where => { tag => \@ref_tags, subfield => $subfield, value => { '<' => $value } },
1665 order_by => { afr => { value => 'desc' } },
1666 limit => $ref_limit,
1670 push @list, map { $_->{record} } reverse(@$before);
1674 my $after = $_storage->request(
1675 "open-ils.cstore.json_query.atomic",
1676 { select => { afr => [qw/record value/] },
1678 where => { tag => \@ref_tags, subfield => $subfield, value => { '>=' => $value } },
1679 order_by => { afr => { value => 'asc' } },
1680 limit => $ref_limit,
1684 push @list, map { $_->{record} } @$after;
1687 # If we're not pulling in see/see also references, just return the raw list
1688 if ($self->api_name !~ /\.refs\./) {
1692 # Remove dupe record IDs that turn up due to 4xx and 5xx matches
1695 foreach my $record (@list) {
1696 next if exists $seen{$record};
1697 push @retlist, int($record);
1703 __PACKAGE__->register_method(
1704 method => 'authority_tag_sf_startwith',
1705 api_name => 'open-ils.supercat.authority.tag.startwith',
1709 { desc => <<" DESC",
1710 Returns a list of the requested authority record IDs held
1715 desc => 'The target Authority MARC tag',
1717 { name => 'subfield',
1718 desc => 'The target Authority MARC subfield',
1721 desc => 'The target string',
1723 { name => 'page_size',
1724 desc => 'Count of call numbers to retrieve, default is 10',
1727 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1731 { desc => 'Authority Record IDs that are near the target string',
1737 sub holding_data_formats {
1740 namespace_uri => 'http://www.loc.gov/MARC21/slim',
1741 docs => 'http://www.loc.gov/marcxml/',
1742 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
1746 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acn.formats', api_level => 1 );
1747 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acp.formats', api_level => 1 );
1748 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.auri.formats', api_level => 1 );
1751 __PACKAGE__->register_method(
1752 method => 'retrieve_uri',
1753 api_name => 'open-ils.supercat.auri.marcxml.retrieve',
1757 { desc => <<" DESC",
1758 Returns a fleshed call number object
1763 desc => 'An OpenILS asset::uri id',
1767 { desc => 'fleshed uri',
1775 my $args = shift || {};
1777 return OpenILS::Application::SuperCat::unAPI
1778 ->new(OpenSRF::AppSession
1779 ->create( 'open-ils.cstore' )
1781 "open-ils.cstore.direct.asset.uri.retrieve",
1785 auri => [qw/call_number_maps/],
1786 auricnm => [qw/call_number/],
1787 acn => [qw/owning_lib record prefix suffix/],
1794 __PACKAGE__->register_method(
1795 method => 'retrieve_copy',
1796 api_name => 'open-ils.supercat.acp.marcxml.retrieve',
1800 { desc => <<" DESC",
1801 Returns a fleshed call number object
1806 desc => 'An OpenILS asset::copy id',
1810 { desc => 'fleshed copy',
1818 my $args = shift || {};
1820 return OpenILS::Application::SuperCat::unAPI
1821 ->new(OpenSRF::AppSession
1822 ->create( 'open-ils.cstore' )
1824 "open-ils.cstore.direct.asset.copy.retrieve",
1828 acn => [qw/owning_lib record prefix suffix/],
1829 acp => [qw/call_number location status circ_lib stat_cat_entries notes parts/],
1836 __PACKAGE__->register_method(
1837 method => 'retrieve_callnumber',
1838 api_name => 'open-ils.supercat.acn.marcxml.retrieve',
1843 { desc => <<" DESC",
1844 Returns a fleshed call number object
1849 desc => 'An OpenILS asset::call_number id',
1853 { desc => 'call number with copies',
1857 sub retrieve_callnumber {
1861 my $args = shift || {};
1863 return OpenILS::Application::SuperCat::unAPI
1864 ->new(OpenSRF::AppSession
1865 ->create( 'open-ils.cstore' )
1867 "open-ils.cstore.direct.asset.call_number.retrieve",
1871 acn => [qw/owning_lib record copies uri_maps prefix suffix/],
1872 auricnm => [qw/uri/],
1873 acp => [qw/location status circ_lib stat_cat_entries notes parts/],
1881 __PACKAGE__->register_method(
1882 method => 'basic_record_holdings',
1883 api_name => 'open-ils.supercat.record.basic_holdings.retrieve',
1888 { desc => <<" DESC",
1889 Returns a basic hash representation of the requested bibliographic record's holdings
1894 desc => 'An OpenILS biblio::record_entry id',
1898 { desc => 'Hash of bib record holdings hierarchy (call numbers and copies)',
1902 sub basic_record_holdings {
1908 # holdings hold an array of call numbers, which hold an array of copies
1909 # holdings => [ label: { library, [ copies: { barcode, location, status, circ_lib } ] } ]
1912 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1914 my $tree = $_storage->request(
1915 "open-ils.cstore.direct.biblio.record_entry.retrieve",
1919 bre => [qw/call_numbers/],
1920 acn => [qw/copies owning_lib prefix suffix/],
1921 acp => [qw/location status circ_lib parts/],
1926 my $o_search = { shortname => uc($ou) };
1927 if (!$ou || $ou eq '-') {
1928 $o_search = { parent_ou => undef };
1931 my $orgs = $_storage->request(
1932 "open-ils.cstore.direct.actor.org_unit.search",
1935 flesh_fields => { aou => [qw/children/] }
1939 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1941 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
1943 for my $cn (@{$tree->call_numbers}) {
1944 next unless ( $cn->deleted eq 'f' || $cn->deleted == 0 );
1947 for my $c (@{$cn->copies}) {
1948 next unless grep {$c->circ_lib->id == $_} @ou_ids;
1949 next unless ( $c->deleted eq 'f' || $c->deleted == 0 );
1955 $holdings{$cn->label}{'owning_lib'} = $cn->owning_lib->shortname;
1957 for my $cp (@{$cn->copies}) {
1959 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
1960 next unless ( $cp->deleted eq 'f' || $cp->deleted == 0 );
1962 push @{$holdings{$cn->label}{'copies'}}, {
1963 barcode => $cp->barcode,
1964 status => $cp->status->name,
1965 location => $cp->location->name,
1966 circlib => $cp->circ_lib->shortname
1975 #__PACKAGE__->register_method(
1976 # method => 'new_record_holdings',
1977 # api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
1982 # { desc => <<" DESC",
1983 #Returns the XML representation of the requested bibliographic record's holdings
1987 # { name => 'bibId',
1988 # desc => 'An OpenILS biblio::record_entry id',
1989 # type => 'number' },
1992 # { desc => 'Stream of bib record holdings hierarchy in XML',
1993 # type => 'string' }
1998 sub new_record_holdings {
2007 $paging = [-1,0] if (!$paging or !ref($paging) or @$paging == 0);
2008 my $limit = $$paging[0];
2009 my $offset = $$paging[1] || 0;
2011 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2012 my $_search = OpenSRF::AppSession->create( 'open-ils.search' );
2014 my $o_search = { shortname => uc($ou) };
2015 if (!$ou || $ou eq '-') {
2016 $o_search = { parent_ou => undef };
2019 my $one_org = $_storage->request(
2020 "open-ils.cstore.direct.actor.org_unit.search",
2024 my $count_req = $_search->request('open-ils.search.biblio.record.copy_count' => $one_org->id => $bib);
2025 my $staff_count_req = $_search->request('open-ils.search.biblio.record.copy_count.staff' => $one_org->id => $bib);
2027 my $orgs = $_storage->request(
2028 'open-ils.cstore.json_query.atomic',
2029 { from => [ 'actor.org_unit_descendants', defined($depth) ? ( $one_org->id, $depth ) : ( $one_org->id ) ] }
2033 my @ou_ids = map { $_->{id} } @$orgs;
2035 $logger->info("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2037 my %subselect = ( '-or' => [
2038 { owning_lib => \@ou_ids },
2042 call_number => { '=' => {'+acn'=>'id'} },
2044 circ_lib => \@ou_ids
2050 if ($flesh and $flesh eq 'uris') {
2052 owning_lib => \@ou_ids,
2054 from => { auricnm => 'auri' },
2056 call_number => { '=' => {'+acn'=>'id'} },
2057 '+auri' => { active => 't' }
2064 my $cns = $_storage->request(
2065 "open-ils.cstore.direct.asset.call_number.search.atomic",
2072 acn => [qw/copies owning_lib uri_maps prefix suffix/],
2073 auricnm => [qw/uri/],
2074 acp => [qw/circ_lib location status stat_cat_entries notes parts/],
2075 asce => [qw/stat_cat/],
2077 ( $limit > -1 ? ( limit => $limit ) : () ),
2078 ( $offset ? ( offset => $offset ) : () ),
2079 order_by => { acn => { label_sortkey => {} } }
2083 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2087 $client->respond("<holdings xmlns='http://open-ils.org/spec/holdings/v1'><counts>\n");
2089 my $copy_counts = $count_req->gather(1);
2090 my $staff_copy_counts = $staff_count_req->gather(1);
2092 for my $c (@$copy_counts) {
2093 $$c{transcendant} ||= 0;
2094 my $out = "<count type='public'";
2095 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2096 $client->respond("$out/>\n")
2099 for my $c (@$staff_copy_counts) {
2100 $$c{transcendant} ||= 0;
2101 my $out = "<count type='staff'";
2102 $out .= " $_='$$c{$_}'" for (qw/count available unshadow transcendant org_unit depth/);
2103 $client->respond("$out/>\n")
2106 $client->respond("</counts><volumes>\n");
2108 for my $cn (@$cns) {
2109 next unless (@{$cn->copies} > 0 or (ref($cn->uri_maps) and @{$cn->uri_maps}));
2111 # We don't want O:A:S:unAPI::acn to return the record, we've got that already
2112 # In the context of BibTemplate, copies aren't necessary because we pull those
2113 # in a separate call
2115 OpenILS::Application::SuperCat::unAPI::acn
2117 ->as_xml( {no_record => 1, no_copies => ($flesh ? 0 : 1)} )
2121 $client->respond("</volumes><subscriptions>\n");
2123 $logger->info("Searching for serial holdings at orgs [".join(',',@ou_ids)."], based on $ou");
2125 %subselect = ( '-or' => [
2126 { owning_lib => \@ou_ids },
2129 where => { holding_lib => \@ou_ids }
2134 my $ssubs = $_storage->request(
2135 "open-ils.cstore.direct.serial.subscription.search.atomic",
2136 { record_entry => $bib,
2141 ssub => [qw/distributions issuances scaps owning_lib/],
2142 sdist => [qw/basic_summary supplement_summary index_summary streams holding_lib/],
2143 sstr => [qw/items/],
2144 sitem => [qw/notes unit/],
2145 sunit => [qw/notes location status circ_lib stat_cat_entries call_number/],
2146 acn => [qw/owning_lib prefix suffix/],
2148 ( $limit > -1 ? ( limit => $limit ) : () ),
2149 ( $offset ? ( offset => $offset ) : () ),
2161 date_expected => {},
2168 for my $ssub (@$ssubs) {
2169 next unless (@{$ssub->distributions} or @{$ssub->issuances} or @{$ssub->scaps});
2171 # We don't want O:A:S:unAPI::ssub to return the record, we've got that already
2172 # In the context of BibTemplate, copies aren't necessary because we pull those
2173 # in a separate call
2175 OpenILS::Application::SuperCat::unAPI::ssub
2177 ->as_xml( {no_record => 1, no_items => ($flesh ? 0 : 1)} )
2182 return "</subscriptions></holdings>\n";
2184 __PACKAGE__->register_method(
2185 method => 'new_record_holdings',
2186 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
2191 { desc => <<" DESC",
2192 Returns the XML representation of the requested bibliographic record's holdings
2197 desc => 'An OpenILS biblio::record_entry ID',
2199 { name => 'orgUnit',
2200 desc => 'An OpenILS actor::org_unit short name that limits the scope of returned holdings',
2203 desc => 'An OpenILS actor::org_unit_type depththat limits the scope of returned holdings',
2205 { name => 'hideCopies',
2206 desc => 'Flag that prevents the inclusion of copies in the returned holdings',
2207 type => 'boolean' },
2209 desc => 'Arry of limit and offset for holdings paging',
2213 { desc => 'Stream of bib record holdings hierarchy in XML',
2223 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2225 my $recs = $_storage->request(
2226 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2227 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2230 return undef unless (@$recs);
2232 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
2234 __PACKAGE__->register_method(
2235 method => 'isbn_holdings',
2236 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
2240 { desc => <<" DESC",
2241 Returns the XML representation of the requested bibliographic record's holdings
2250 { desc => 'The bib record holdings hierarchy in XML',
2258 return '' unless $text;
2259 $text =~ s/&/&/gsom;
2260 $text =~ s/</</gsom;
2261 $text =~ s/>/>/gsom;
2262 $text =~ s/"/"/gsom;
2263 $text =~ s/'/'/gsom;
2267 sub recent_changes {
2270 my $when = shift || '1-01-01';
2273 my $type = 'biblio';
2276 if ($self->api_name =~ /authority/o) {
2277 $type = 'authority';
2281 my $axis = 'create_date';
2282 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
2284 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2286 return $_storage->request(
2287 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
2288 { $axis => { ">" => $when }, id => { '>' => 0 }, deleted => 'f', active => 't' },
2289 { order_by => { $hint => "$axis desc" }, limit => $limit }
2293 for my $t ( qw/biblio authority/ ) {
2294 for my $a ( qw/import edit/ ) {
2296 __PACKAGE__->register_method(
2297 method => 'recent_changes',
2298 api_name => "open-ils.supercat.$t.record.$a.recent",
2302 { desc => "Returns a list of recently ${a}ed $t records",
2306 desc => "Date to start looking for ${a}ed records",
2307 default => '1-01-01',
2311 desc => "Maximum count to retrieve",
2315 { desc => "An id list of $t records",
2323 sub retrieve_authority_marcxml {
2328 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2330 my $record = $_storage->request( 'open-ils.cstore.direct.authority.record_entry.retrieve' => $rid )->gather(1);
2331 return $U->entityize( $record->marc ) if ($record);
2335 __PACKAGE__->register_method(
2336 method => 'retrieve_authority_marcxml',
2337 api_name => 'open-ils.supercat.authority.marcxml.retrieve',
2341 { desc => <<" DESC",
2342 Returns the MARCXML representation of the requested authority record
2346 { name => 'authorityId',
2347 desc => 'An OpenILS authority::record_entry id',
2351 { desc => 'The authority record in MARCXML',
2356 sub retrieve_record_marcxml {
2361 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2363 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
2364 return $U->entityize( $record->marc ) if ($record);
2368 __PACKAGE__->register_method(
2369 method => 'retrieve_record_marcxml',
2370 api_name => 'open-ils.supercat.record.marcxml.retrieve',
2374 { desc => <<" DESC",
2375 Returns the MARCXML representation of the requested bibliographic record
2380 desc => 'An OpenILS biblio::record_entry id',
2384 { desc => 'The bib record in MARCXML',
2389 sub retrieve_isbn_marcxml {
2394 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2396 my $recs = $_storage->request(
2397 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2398 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2401 return undef unless (@$recs);
2403 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2404 return $U->entityize( $record->marc ) if ($record);
2408 __PACKAGE__->register_method(
2409 method => 'retrieve_isbn_marcxml',
2410 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
2414 { desc => <<" DESC",
2415 Returns the MARCXML representation of the requested ISBN
2420 desc => 'An ... um ... ISBN',
2424 { desc => 'The bib record in MARCXML',
2429 sub retrieve_record_transform {
2434 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
2436 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2437 #$_storage->connect;
2439 my $record = $_storage->request(
2440 'open-ils.cstore.direct.biblio.record_entry.retrieve',
2444 return undef unless ($record);
2446 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2449 sub retrieve_isbn_transform {
2454 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2456 my $recs = $_storage->request(
2457 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2458 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2461 return undef unless (@$recs);
2463 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
2465 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2467 return undef unless ($record);
2469 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2472 sub retrieve_record_objects {
2477 my $type = 'biblio';
2479 if ($self->api_name =~ /authority/) {
2480 $type = 'authority';
2483 $ids = [$ids] unless (ref $ids);
2484 $ids = [grep {$_} @$ids];
2486 return [] unless (@$ids);
2488 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2489 return $_storage->request("open-ils.cstore.direct.$type.record_entry.search.atomic" => { id => [grep {$_} @$ids] })->gather(1);
2491 __PACKAGE__->register_method(
2492 method => 'retrieve_record_objects',
2493 api_name => 'open-ils.supercat.record.object.retrieve',
2497 { desc => <<" DESC",
2498 Returns the Fieldmapper object representation of the requested bibliographic records
2503 desc => 'OpenILS biblio::record_entry ids',
2507 { desc => 'The bib records',
2512 __PACKAGE__->register_method(
2513 method => 'retrieve_record_objects',
2514 api_name => 'open-ils.supercat.authority.object.retrieve',
2518 { desc => <<" DESC",
2519 Returns the Fieldmapper object representation of the requested authority records
2523 { name => 'authIds',
2524 desc => 'OpenILS authority::record_entry ids',
2528 { desc => 'The authority records',
2533 sub retrieve_isbn_object {
2538 return undef unless ($isbn);
2540 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2541 my $recs = $_storage->request(
2542 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2543 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2546 return undef unless (@$recs);
2548 return $_storage->request(
2549 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
2550 { id => $recs->[0]->record }
2553 __PACKAGE__->register_method(
2554 method => 'retrieve_isbn_object',
2555 api_name => 'open-ils.supercat.isbn.object.retrieve',
2559 { desc => <<" DESC",
2560 Returns the Fieldmapper object representation of the requested bibliographic record
2569 { desc => 'The bib record',
2576 sub retrieve_metarecord_mods {
2581 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
2583 # Get the metarecord in question
2586 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
2589 # Now get the map of all bib records for the metarecord
2592 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2593 {metarecord => $rid}
2596 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
2598 # and retrieve the lead (master) record as MODS
2600 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2601 ->run($mr->master_record);
2602 my $master_mods = $_parser->parse_string($master)->documentElement;
2603 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods" );
2604 $master_mods->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2606 # ... and a MODS clone to populate, with guts removed.
2607 my $mods = $_parser->parse_string($master)->documentElement;
2608 $mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # modsCollection element
2609 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2610 ($mods) = $mods->findnodes('//mods:mods');
2611 #$mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # mods element
2612 $mods->removeChildNodes;
2613 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2615 # Add the metarecord ID as a (locally defined) info URI
2616 my $recordInfo = $mods
2618 ->createElement("recordInfo");
2620 my $recordIdentifier = $mods
2622 ->createElement("recordIdentifier");
2624 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2629 $recordIdentifier->appendTextNode(
2630 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
2633 $recordInfo->appendChild($recordIdentifier);
2634 $mods->appendChild($recordInfo);
2636 # Grab the title, author and ISBN for the master record and populate the metarecord
2637 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
2640 $title->setNamespace( "http://www.loc.gov/mods/", "mods" );
2641 $title->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2642 $title = $mods->ownerDocument->importNode($title);
2643 $mods->appendChild($title);
2646 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
2648 $author->setNamespace( "http://www.loc.gov/mods/", "mods" );
2649 $author->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2650 $author = $mods->ownerDocument->importNode($author);
2651 $mods->appendChild($author);
2654 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
2656 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2657 $isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2658 $isbn = $mods->ownerDocument->importNode($isbn);
2659 $mods->appendChild($isbn);
2662 # ... and loop over the constituent records
2663 for my $map ( @$recs ) {
2667 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2668 ->run($map->source);
2670 my $part_mods = $_parser->parse_string($rec);
2671 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods" );
2672 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2673 ($part_mods) = $part_mods->findnodes('//mods:mods');
2675 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
2676 $node->setNamespace( "http://www.loc.gov/mods/", "mods" );
2677 $node->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2678 $node = $mods->ownerDocument->importNode($node);
2679 $mods->appendChild( $node );
2682 my $relatedItem = $mods
2684 ->createElement("relatedItem");
2686 $relatedItem->setAttribute( type => 'constituent' );
2688 my $identifier = $mods
2690 ->createElement("identifier");
2692 $identifier->setAttribute( type => 'uri' );
2694 my $subRecordInfo = $mods
2696 ->createElement("recordInfo");
2698 my $subRecordIdentifier = $mods
2700 ->createElement("recordIdentifier");
2702 my $subid = $map->source;
2703 $subRecordIdentifier->appendTextNode(
2704 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
2709 $subRecordInfo->appendChild($subRecordIdentifier);
2711 $relatedItem->appendChild( $subRecordInfo );
2713 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
2714 $tor->setNamespace( "http://www.loc.gov/mods/", "mods" );
2715 $tor->setNamespace( "http://www.loc.gov/mods/", undef, 1 ) if ($tor);
2716 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
2717 $relatedItem->appendChild($tor) if ($tor);
2719 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
2720 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2721 $part_isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2722 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
2723 $relatedItem->appendChild( $part_isbn );
2726 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
2730 $mods->appendChild( $relatedItem );
2734 $_storage->disconnect;
2736 return $U->entityize($mods->toString);
2739 __PACKAGE__->register_method(
2740 method => 'retrieve_metarecord_mods',
2741 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
2745 { desc => <<" DESC",
2746 Returns the MODS representation of the requested metarecord
2750 { name => 'metarecordId',
2751 desc => 'An OpenILS metabib::metarecord id',
2755 { desc => 'The metarecord in MODS',
2760 sub list_metarecord_formats {
2763 { namespace_uri => 'http://www.loc.gov/mods/',
2764 docs => 'http://www.loc.gov/mods/',
2765 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
2770 for my $type ( keys %metarecord_xslt ) {
2773 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
2774 docs => $metarecord_xslt{$type}{docs},
2775 schema_location => $metarecord_xslt{$type}{schema_location},
2782 __PACKAGE__->register_method(
2783 method => 'list_metarecord_formats',
2784 api_name => 'open-ils.supercat.metarecord.formats',
2788 { desc => <<" DESC",
2789 Returns the list of valid metarecord formats that supercat understands.
2792 { desc => 'The format list',
2798 sub list_authority_formats {
2801 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2802 docs => 'http://www.loc.gov/marcxml/',
2803 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
2808 # for my $type ( keys %record_xslt ) {
2811 # { namespace_uri => $record_xslt{$type}{namespace_uri},
2812 # docs => $record_xslt{$type}{docs},
2813 # schema_location => $record_xslt{$type}{schema_location},
2820 __PACKAGE__->register_method(
2821 method => 'list_authority_formats',
2822 api_name => 'open-ils.supercat.authority.formats',
2826 { desc => <<" DESC",
2827 Returns the list of valid authority formats that supercat understands.
2830 { desc => 'The format list',
2835 sub list_record_formats {
2838 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2839 docs => 'http://www.loc.gov/marcxml/',
2840 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
2845 for my $type ( keys %record_xslt ) {
2848 { namespace_uri => $record_xslt{$type}{namespace_uri},
2849 docs => $record_xslt{$type}{docs},
2850 schema_location => $record_xslt{$type}{schema_location},
2857 __PACKAGE__->register_method(
2858 method => 'list_record_formats',
2859 api_name => 'open-ils.supercat.record.formats',
2863 { desc => <<" DESC",
2864 Returns the list of valid record formats that supercat understands.
2867 { desc => 'The format list',
2871 __PACKAGE__->register_method(
2872 method => 'list_record_formats',
2873 api_name => 'open-ils.supercat.isbn.formats',
2877 { desc => <<" DESC",
2878 Returns the list of valid record formats that supercat understands.
2881 { desc => 'The format list',
2894 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
2895 unless (length($isbn) >= 10);
2897 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2899 # Create a storage session, since we'll be making muliple requests.
2902 # Find the record that has that ISBN.
2903 my $bibrec = $_storage->request(
2904 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2905 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
2908 # Go away if we don't have one.
2909 return {} unless (@$bibrec);
2911 # Find the metarecord for that bib record.
2912 my $mr = $_storage->request(
2913 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2914 {source => $bibrec->[0]->record}
2917 # Find the other records for that metarecord.
2918 my $records = $_storage->request(
2919 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2920 {metarecord => $mr->[0]->metarecord}
2923 # Just to be safe. There's currently no unique constraint on sources...
2924 my %unique_recs = map { ($_->source, 1) } @$records;
2925 my @rec_list = sort keys %unique_recs;
2927 # And now fetch the ISBNs for thos records.
2931 'open-ils.cstore.direct.metabib.full_rec.search',
2932 { tag => '020', subfield => 'a', record => $_ }
2933 )->gather(1) for (@rec_list);
2935 # We're done with the storage server session.
2936 $_storage->disconnect;
2938 # Return the oISBN data structure. This will be XMLized at a higher layer.
2940 { metarecord => $mr->[0]->metarecord,
2941 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
2944 __PACKAGE__->register_method(
2946 api_name => 'open-ils.supercat.oisbn',
2950 { desc => <<" DESC",
2951 Returns the ISBN list for the metarecord of the requested isbn
2956 desc => 'An ISBN. Duh.',
2960 { desc => 'record to isbn map',
2965 sub return_bib_search_aliases {
2968 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2970 my $cmsa = $_storage->request(
2971 'open-ils.cstore.direct.config.metabib_search_alias.search.atomic',
2972 { alias => { '!=' => undef } }
2976 if ($_->alias =~ /\./) {
2977 my ($qualifier, $name) = $_->alias =~ m/^(.+?)\.(.+)$/;
2978 $aliases{$qualifier}{$name}{'index'} = $_->alias;
2979 # We will add a 'title' property in a subsequent schema
2980 $aliases{$qualifier}{$name}{'title'} = $name;
2982 # au/kw/se/su/ti go into the default 'eg' qualifier
2983 $aliases{'eg'}{$_->alias}{'index'} = $_->alias;
2984 $aliases{'eg'}{$_->alias}{'title'} = $_->alias;
2991 __PACKAGE__->register_method(
2992 method => 'return_bib_search_aliases',
2993 api_name => 'open-ils.supercat.biblio.search_aliases',
2997 { desc => <<" DESC",
2998 Returns the set of qualified search aliases in the system
3002 { desc => 'Hash of qualified search aliases',
3008 package OpenILS::Application::SuperCat::unAPI;
3009 use base qw/OpenILS::Application::SuperCat/;
3012 die "dummy superclass, use a real class";
3018 return unless ($obj);
3020 $class = ref($class) || $class;
3022 if ($class eq __PACKAGE__) {
3023 return unless (ref($obj));
3024 $class .= '::' . $obj->json_hint;
3027 return bless { obj => $obj } => $class;
3032 return $self->{obj};
3035 package OpenILS::Application::SuperCat::unAPI::auri;
3036 use base qw/OpenILS::Application::SuperCat::unAPI/;
3042 my $xml = ' <uri xmlns="http://open-ils.org/spec/holdings/v1" ';
3043 $xml .= 'id="tag:open-ils.org:asset-uri/' . $self->obj->id . '" ';
3044 $xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" ';
3045 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3046 $xml .= 'href="' . $self->escape( $self->obj->href ) . '">';
3048 if (!$args->{no_volumes}) {
3049 if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) {
3050 $xml .= " <volumes>\n" . join(
3053 OpenILS::Application::SuperCat::unAPI
3054 ->new( $_->call_number )
3055 ->as_xml({ %$args, no_uris=>1, no_copies=>1 })
3056 } @{ $self->obj->call_number_maps }
3057 ) . " </volumes>\n";
3060 $xml .= " <volumes/>\n";
3064 $xml .= " </uri>\n";
3069 package OpenILS::Application::SuperCat::unAPI::acn;
3070 use base qw/OpenILS::Application::SuperCat::unAPI/;
3076 my $xml = ' <volume xmlns="http://open-ils.org/spec/holdings/v1" ';
3078 $xml .= 'id="tag:open-ils.org:asset-call_number/' . $self->obj->id . '" ';
3079 $xml .= 'lib="' . $self->escape( $self->obj->owning_lib->shortname ) . '" ';
3080 $xml .= 'opac_visible="' . $self->obj->owning_lib->opac_visible . '" ';
3081 $xml .= 'deleted="' . $self->obj->deleted . '" ';
3082 $xml .= 'label="' . $self->escape( $self->obj->label ) . '">';
3085 if (!$args->{no_copies}) {
3086 if (ref($self->obj->copies) && @{ $self->obj->copies }) {
3087 $xml .= " <copies>\n" . join(
3090 OpenILS::Application::SuperCat::unAPI
3092 ->as_xml({ %$args, no_volume=>1 })
3093 } @{ $self->obj->copies }
3097 $xml .= " <copies/>\n";
3101 if (!$args->{no_uris}) {
3102 if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) {
3103 $xml .= " <uris>\n" . join(
3106 OpenILS::Application::SuperCat::unAPI
3108 ->as_xml({ %$args, no_volumes=>1 })
3109 } @{ $self->obj->uri_maps }
3113 $xml .= " <uris/>\n";
3118 $xml .= ' <prefix ';
3119 $xml .= 'ident="' . $self->obj->prefix->id . '" ';
3120 $xml .= 'id="tag:open-ils.org:asset-call_number_prefix/' . $self->obj->prefix->id . '" ';
3121 $xml .= 'label_sortkey="'.$self->escape( $self->obj->prefix->label_sortkey ) .'">';
3122 $xml .= $self->escape( $self->obj->prefix->label ) .'</prefix>';
3125 $xml .= ' <suffix ';
3126 $xml .= 'ident="' . $self->obj->suffix->id . '" ';
3127 $xml .= 'id="tag:open-ils.org:asset-call_number_suffix/' . $self->obj->suffix->id . '" ';
3128 $xml .= 'label_sortkey="'.$self->escape( $self->obj->suffix->label_sortkey ) .'">';
3129 $xml .= $self->escape( $self->obj->suffix->label ) .'</suffix>';
3132 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3133 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3134 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3135 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3138 unless ($args->{no_record}) {
3139 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3141 my $r_doc = $parser->parse_string($self->obj->record->marc);
3142 $r_doc->documentElement->setAttribute( id => $rec_tag );
3143 $xml .= $U->entityize($r_doc->documentElement->toString);
3146 $xml .= " </volume>\n";
3151 package OpenILS::Application::SuperCat::unAPI::ssub;
3152 use base qw/OpenILS::Application::SuperCat::unAPI/;
3158 my $xml = ' <subscription xmlns="http://open-ils.org/spec/holdings/v1" ';
3160 $xml .= 'id="tag:open-ils.org:serial-subscription/' . $self->obj->id . '" ';
3161 $xml .= 'start="' . $self->escape( $self->obj->start_date ) . '" ';
3162 $xml .= 'end="' . $self->escape( $self->obj->end_date ) . '" ';
3163 $xml .= 'expected_date_offset="' . $self->escape( $self->obj->expected_date_offset ) . '">';
3166 if (!$args->{no_distributions}) {
3167 if (ref($self->obj->distributions) && @{ $self->obj->distributions }) {
3168 $xml .= " <distributions>\n" . join(
3171 OpenILS::Application::SuperCat::unAPI
3173 ->as_xml({ %$args, no_subscription=>1, no_issuance=>1 })
3174 } @{ $self->obj->distributions }
3175 ) . " </distributions>\n";
3178 $xml .= " <distributions/>\n";
3182 if (!$args->{no_captions_and_patterns}) {
3183 if (ref($self->obj->scaps) && @{ $self->obj->scaps }) {
3184 $xml .= " <captions_and_patterns>\n" . join(
3187 OpenILS::Application::SuperCat::unAPI
3189 ->as_xml({ %$args, no_subscription=>1 })
3190 } @{ $self->obj->scaps }
3191 ) . " </captions_and_patterns>\n";
3194 $xml .= " <captions_and_patterns/>\n";
3198 if (!$args->{no_issuances}) {
3199 if (ref($self->obj->issuances) && @{ $self->obj->issuances }) {
3200 $xml .= " <issuances>\n" . join(
3203 OpenILS::Application::SuperCat::unAPI
3205 ->as_xml({ %$args, no_subscription=>1, no_items=>1 })
3206 } @{ $self->obj->issuances }
3207 ) . " </issuances>\n";
3210 $xml .= " <issuances/>\n";
3215 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3216 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
3217 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
3218 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
3221 unless ($args->{no_record}) {
3222 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
3224 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3225 $r_doc->documentElement->setAttribute( id => $rec_tag );
3226 $xml .= $U->entityize($r_doc->documentElement->toString);
3229 $xml .= " </subscription>\n";
3234 package OpenILS::Application::SuperCat::unAPI::ssum_base;
3235 use base qw/OpenILS::Application::SuperCat::unAPI/;
3241 (my $type = ref($self)) =~ s/^.+([^:]+)$/$1/;
3243 my $xml = " <serial_summary xmlns=\"http://open-ils.org/spec/holdings/v1\" type=\"$type\" ";
3245 $xml .= "id=\"tag:open-ils.org:serial-summary-$type/" . $self->obj->id . '" ';
3246 $xml .= 'generated_coverage="' . $self->escape( $self->obj->generated_coverage ) . '" ';
3247 $xml .= 'show_generated="' . $self->escape( $self->obj->show_generated ) . '" ';
3248 $xml .= 'textual_holdings="' . $self->escape( $self->obj->textual_holdings ) . '">';
3251 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_summaries=>1 }) if (!$args->{no_distribution});
3253 $xml .= " </serial_summary>\n";
3259 package OpenILS::Application::SuperCat::unAPI::sssum;
3260 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3262 package OpenILS::Application::SuperCat::unAPI::sbsum;
3263 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3265 package OpenILS::Application::SuperCat::unAPI::sisum;
3266 use base qw/OpenILS::Application::SuperCat::unAPI::ssum_base/;
3268 package OpenILS::Application::SuperCat::unAPI::sdist;
3269 use base qw/OpenILS::Application::SuperCat::unAPI/;
3275 my $xml = ' <distribution xmlns="http://open-ils.org/spec/holdings/v1" ';
3277 $xml .= 'id="tag:open-ils.org:serial-distribution/' . $self->obj->id . '" ';
3278 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
3279 $xml .= 'unit_label_prefix="' . $self->escape( $self->obj->unit_label_prefix ) . '" ';
3280 $xml .= 'unit_label_suffix="' . $self->escape( $self->obj->unit_label_suffix ) . '">';
3283 if (!$args->{no_distributions}) {
3284 if (ref($self->obj->streams) && @{ $self->obj->streams }) {
3285 $xml .= " <streams>\n" . join(
3288 OpenILS::Application::SuperCat::unAPI
3290 ->as_xml({ %$args, no_distribution=>1 })
3291 } @{ $self->obj->streams }
3292 ) . " </streams>\n";
3295 $xml .= " <streams/>\n";
3299 if (!$args->{no_summaries}) {
3300 $xml .= " <summaries>\n";
3304 OpenILS::Application::SuperCat::unAPI
3306 ->as_xml({ %$args, no_distribution=>1 }) : ""
3307 } ($self->obj->basic_summary, $self->obj->supplement_summary, $self->obj->index_summary)
3310 $xml .= " </summaries>\n";
3314 $xml .= ' <holding_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3315 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->holding_lib->id . '" ';
3316 $xml .= 'shortname="'.$self->escape( $self->obj->holding_lib->shortname ) .'" ';
3317 $xml .= 'name="'.$self->escape( $self->obj->holding_lib->name ) .'"/>';
3320 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_distributions=>1 }) if (!$args->{no_subscription});
3322 if (!$args->{no_record} && $self->obj->record_entry) {
3323 my $rec_tag = "tag:open-ils.org:serial-record_entry/".$self->obj->record_entry->id ;
3325 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
3326 $r_doc->documentElement->setAttribute( id => $rec_tag );
3327 $xml .= $U->entityize($r_doc->documentElement->toString);
3330 $xml .= " </distribution>\n";
3335 package OpenILS::Application::SuperCat::unAPI::sstr;
3336 use base qw/OpenILS::Application::SuperCat::unAPI/;
3342 my $xml = ' <stream xmlns="http://open-ils.org/spec/holdings/v1" ';
3344 $xml .= 'id="tag:open-ils.org:serial-stream/' . $self->obj->id . '" ';
3345 $xml .= 'routing_label="' . $self->escape( $self->obj->routing_label ) . '">';
3348 if (!$args->{no_items}) {
3349 if (ref($self->obj->items) && @{ $self->obj->items }) {
3350 $xml .= " <items>\n" . join(
3353 OpenILS::Application::SuperCat::unAPI
3355 ->as_xml({ %$args, no_stream=>1 })
3356 } @{ $self->obj->items }
3360 $xml .= " <items/>\n";
3364 #XXX routing_list_user's?
3366 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_streams=>1 }) if (!$args->{no_distribution});
3368 $xml .= " </stream>\n";
3373 package OpenILS::Application::SuperCat::unAPI::sitem;
3374 use base qw/OpenILS::Application::SuperCat::unAPI/;
3380 my $xml = ' <serial_item xmlns="http://open-ils.org/spec/holdings/v1" ';
3382 $xml .= 'id="tag:open-ils.org:serial-item/' . $self->obj->id . '" ';
3383 $xml .= 'date_expected="' . $self->escape( $self->obj->date_expected ) . '"';
3384 $xml .= ' date_received="' . $self->escape( $self->obj->date_received ) .'"'if ($self->obj->date_received);
3386 if ($args->{no_issuance}) {
3387 my $siss = ref($self->obj->issuance) ? $self->obj->issuance->id : $self->obj->issuance;
3388 $xml .= ' issuance="tag:open-ils.org:serial-issuance/' . $siss . '"';
3393 if (ref($self->obj->notes) && $self->obj->notes) {
3394 $xml .= " <notes>\n";
3395 for my $note ( @{$self->obj->notes} ) {
3396 next unless ( $note->pub eq 't' );
3397 $xml .= sprintf(' <note date="%s" title="%s">%s</note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3400 $xml .= " </notes>\n";
3402 $xml .= " <notes/>\n";
3405 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->issuance )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_issuance});
3406 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->stream )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_stream});
3407 $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});
3408 $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});
3410 $xml .= " </serial_item>\n";
3415 package OpenILS::Application::SuperCat::unAPI::sunit;
3416 use base qw/OpenILS::Application::SuperCat::unAPI/;
3422 my $xml = ' <serial_unit xmlns="http://open-ils.org/spec/holdings/v1" '.
3423 'id="tag:open-ils.org:serial-unit/' . $self->obj->id . '" ';
3425 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3426 create_date edit_date copy_number circulate deposit ref holdable deleted
3427 deposit_amount price barcode circ_modifier circ_as_type opac_visible cost
3428 status_changed_time floating mint_condition detailed_contents sort_key summary_contents
3433 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3434 $xml .= ' <location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3435 $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
3437 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3438 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3439 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3440 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'"/>';
3443 $xml .= " <copy_notes>\n";
3444 if (ref($self->obj->notes) && $self->obj->notes) {
3445 for my $note ( @{$self->obj->notes} ) {
3446 next unless ( $note->pub eq 't' );
3447 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3452 $xml .= " </copy_notes>\n";
3453 $xml .= " <statcats>\n";
3455 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3456 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3457 next unless ( $sce->stat_cat->opac_visible eq 't' );
3458 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3462 $xml .= " </statcats>\n";
3464 unless ($args->{no_volume}) {
3465 if (ref($self->obj->call_number)) {
3466 $xml .= OpenILS::Application::SuperCat::unAPI
3467 ->new( $self->obj->call_number )
3468 ->as_xml({ %$args, no_copies=>1 });
3470 $xml .= " <volume/>\n";
3474 $xml .= " </serial_unit>\n";
3479 package OpenILS::Application::SuperCat::unAPI::scap;
3480 use base qw/OpenILS::Application::SuperCat::unAPI/;
3486 my $xml = ' <caption_and_pattern xmlns="http://open-ils.org/spec/holdings/v1" '.
3487 'id="tag:open-ils.org:serial-caption_and_pattern/' . $self->obj->id . '" ';
3489 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3490 create_date type active pattern_code enum_1 enum_2 enum_3 enum_4
3491 enum_5 enum_6 chron_1 chron_2 chron_3 chron_4 chron_5 start_date end_date
3494 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_captions_and_patterns=>1 }) if (!$args->{no_subscription});
3495 $xml .= " </caption_and_pattern>\n";
3500 package OpenILS::Application::SuperCat::unAPI::siss;
3501 use base qw/OpenILS::Application::SuperCat::unAPI/;
3507 my $xml = ' <issuance xmlns="http://open-ils.org/spec/holdings/v1" '.
3508 'id="tag:open-ils.org:serial-issuance/' . $self->obj->id . '" ';
3510 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" '
3511 for (qw/create_date edit_date label date_published holding_code holding_type holding_link_id/);
3515 if (!$args->{no_items}) {
3516 if (ref($self->obj->items) && @{ $self->obj->items }) {
3517 $xml .= " <items>\n" . join(
3520 OpenILS::Application::SuperCat::unAPI
3522 ->as_xml({ %$args, no_stream=>1 })
3523 } @{ $self->obj->items }
3527 $xml .= " <items/>\n";
3531 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_issuances=>1 }) if (!$args->{no_subscription});
3532 $xml .= " </issuance>\n";
3537 package OpenILS::Application::SuperCat::unAPI::acp;
3538 use base qw/OpenILS::Application::SuperCat::unAPI/;
3544 my $xml = ' <copy xmlns="http://open-ils.org/spec/holdings/v1" '.
3545 'id="tag:open-ils.org:asset-copy/' . $self->obj->id . '" ';
3547 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3548 create_date edit_date copy_number circulate deposit ref holdable deleted
3549 deposit_amount price barcode circ_modifier circ_as_type opac_visible
3554 $xml .= ' <status ident="' . $self->obj->status->id . '" opac_visible="' . $self->obj->status->opac_visible . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3555 $xml .= ' <location ident="' . $self->obj->location->id . '" opac_visible="'.$self->obj->location->opac_visible.'">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3556 $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";
3558 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3559 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3560 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3561 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'" opac_visible="'.$self->obj->circ_lib->opac_visible.'"/>';
3564 $xml .= " <monograph_parts>\n";
3565 if (ref($self->obj->parts) && $self->obj->parts) {
3566 for my $part ( @{$self->obj->parts} ) {
3567 $xml .= sprintf(' <monograph_part record="%s" sortkey="%s">%s</monograph_part>',$part->record, $self->escape($part->label_sortkey), $self->escape($part->label));
3572 $xml .= " </monograph_parts>\n";
3573 $xml .= " <copy_notes>\n";
3574 if (ref($self->obj->notes) && $self->obj->notes) {
3575 for my $note ( @{$self->obj->notes} ) {
3576 next unless ( $note->pub eq 't' );
3577 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3582 $xml .= " </copy_notes>\n";
3583 $xml .= " <statcats>\n";
3585 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3586 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3587 next unless ( $sce->stat_cat->opac_visible eq 't' );
3588 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3592 $xml .= " </statcats>\n";
3594 unless ($args->{no_volume}) {
3595 if (ref($self->obj->call_number)) {
3596 $xml .= OpenILS::Application::SuperCat::unAPI
3597 ->new( $self->obj->call_number )
3598 ->as_xml({ %$args, no_copies=>1 });
3600 $xml .= " <volume/>\n";
3604 $xml .= " </copy>\n";