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;
18 # All OpenSRF applications must be based on OpenSRF::Application or
19 # a subclass thereof. Makes sense, eh?
20 use OpenILS::Application;
21 use base qw/OpenILS::Application/;
23 # This is the client class, used for connecting to open-ils.storage
24 use OpenSRF::AppSession;
26 # This is an extention of Error.pm that supplies some error types to throw
27 use OpenSRF::EX qw(:try);
29 # This is a helper class for querying the OpenSRF Settings application ...
30 use OpenSRF::Utils::SettingsClient;
32 # ... and here we have the built in logging helper ...
33 use OpenSRF::Utils::Logger qw($logger);
35 # ... and this is our OpenILS object (en|de)coder and psuedo-ORM package.
36 use OpenILS::Utils::Fieldmapper;
47 # we need an XML parser
48 $_parser = new XML::LibXML;
51 $_xslt = new XML::LibXSLT;
53 # parse the MODS xslt ...
54 my $mods33_xslt = $_parser->parse_file(
55 OpenSRF::Utils::SettingsClient
57 ->config_value( dirs => 'xsl' ).
58 "/MARC21slim2MODS33.xsl"
60 # and stash a transformer
61 $record_xslt{mods33}{xslt} = $_xslt->parse_stylesheet( $mods33_xslt );
62 $record_xslt{mods33}{namespace_uri} = 'http://www.loc.gov/mods/v3';
63 $record_xslt{mods33}{docs} = 'http://www.loc.gov/mods/';
64 $record_xslt{mods33}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-3.xsd';
66 # parse the MODS xslt ...
67 my $mods32_xslt = $_parser->parse_file(
68 OpenSRF::Utils::SettingsClient
70 ->config_value( dirs => 'xsl' ).
71 "/MARC21slim2MODS32.xsl"
73 # and stash a transformer
74 $record_xslt{mods32}{xslt} = $_xslt->parse_stylesheet( $mods32_xslt );
75 $record_xslt{mods32}{namespace_uri} = 'http://www.loc.gov/mods/v3';
76 $record_xslt{mods32}{docs} = 'http://www.loc.gov/mods/';
77 $record_xslt{mods32}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-2.xsd';
79 # parse the MODS xslt ...
80 my $mods3_xslt = $_parser->parse_file(
81 OpenSRF::Utils::SettingsClient
83 ->config_value( dirs => 'xsl' ).
84 "/MARC21slim2MODS3.xsl"
86 # and stash a transformer
87 $record_xslt{mods3}{xslt} = $_xslt->parse_stylesheet( $mods3_xslt );
88 $record_xslt{mods3}{namespace_uri} = 'http://www.loc.gov/mods/v3';
89 $record_xslt{mods3}{docs} = 'http://www.loc.gov/mods/';
90 $record_xslt{mods3}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-1.xsd';
92 # parse the MODS xslt ...
93 my $mods_xslt = $_parser->parse_file(
94 OpenSRF::Utils::SettingsClient
96 ->config_value( dirs => 'xsl' ).
97 "/MARC21slim2MODS.xsl"
99 # and stash a transformer
100 $record_xslt{mods}{xslt} = $_xslt->parse_stylesheet( $mods_xslt );
101 $record_xslt{mods}{namespace_uri} = 'http://www.loc.gov/mods/';
102 $record_xslt{mods}{docs} = 'http://www.loc.gov/mods/';
103 $record_xslt{mods}{schema_location} = 'http://www.loc.gov/standards/mods/mods.xsd';
105 # parse the ATOM entry xslt ...
106 my $atom_xslt = $_parser->parse_file(
107 OpenSRF::Utils::SettingsClient
109 ->config_value( dirs => 'xsl' ).
110 "/MARC21slim2ATOM.xsl"
112 # and stash a transformer
113 $record_xslt{atom}{xslt} = $_xslt->parse_stylesheet( $atom_xslt );
114 $record_xslt{atom}{namespace_uri} = 'http://www.w3.org/2005/Atom';
115 $record_xslt{atom}{docs} = 'http://www.ietf.org/rfc/rfc4287.txt';
117 # parse the RDFDC xslt ...
118 my $rdf_dc_xslt = $_parser->parse_file(
119 OpenSRF::Utils::SettingsClient
121 ->config_value( dirs => 'xsl' ).
122 "/MARC21slim2RDFDC.xsl"
124 # and stash a transformer
125 $record_xslt{rdf_dc}{xslt} = $_xslt->parse_stylesheet( $rdf_dc_xslt );
126 $record_xslt{rdf_dc}{namespace_uri} = 'http://purl.org/dc/elements/1.1/';
127 $record_xslt{rdf_dc}{schema_location} = 'http://purl.org/dc/elements/1.1/';
129 # parse the SRWDC xslt ...
130 my $srw_dc_xslt = $_parser->parse_file(
131 OpenSRF::Utils::SettingsClient
133 ->config_value( dirs => 'xsl' ).
134 "/MARC21slim2SRWDC.xsl"
136 # and stash a transformer
137 $record_xslt{srw_dc}{xslt} = $_xslt->parse_stylesheet( $srw_dc_xslt );
138 $record_xslt{srw_dc}{namespace_uri} = 'info:srw/schema/1/dc-schema';
139 $record_xslt{srw_dc}{schema_location} = 'http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd';
141 # parse the OAIDC xslt ...
142 my $oai_dc_xslt = $_parser->parse_file(
143 OpenSRF::Utils::SettingsClient
145 ->config_value( dirs => 'xsl' ).
146 "/MARC21slim2OAIDC.xsl"
148 # and stash a transformer
149 $record_xslt{oai_dc}{xslt} = $_xslt->parse_stylesheet( $oai_dc_xslt );
150 $record_xslt{oai_dc}{namespace_uri} = 'http://www.openarchives.org/OAI/2.0/oai_dc/';
151 $record_xslt{oai_dc}{schema_location} = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd';
153 # parse the RSS xslt ...
154 my $rss_xslt = $_parser->parse_file(
155 OpenSRF::Utils::SettingsClient
157 ->config_value( dirs => 'xsl' ).
158 "/MARC21slim2RSS2.xsl"
160 # and stash a transformer
161 $record_xslt{rss2}{xslt} = $_xslt->parse_stylesheet( $rss_xslt );
163 # parse the FGDC xslt ...
164 my $fgdc_xslt = $_parser->parse_file(
165 OpenSRF::Utils::SettingsClient
167 ->config_value( dirs => 'xsl' ).
168 "/MARC21slim2FGDC.xsl"
170 # and stash a transformer
171 $record_xslt{fgdc}{xslt} = $_xslt->parse_stylesheet( $fgdc_xslt );
172 $record_xslt{fgdc}{docs} = 'http://www.fgdc.gov/metadata/csdgm/index_html';
173 $record_xslt{fgdc}{schema_location} = 'http://www.fgdc.gov/metadata/fgdc-std-001-1998.xsd';
175 register_record_transforms();
180 sub register_record_transforms {
181 for my $type ( keys %record_xslt ) {
182 __PACKAGE__->register_method(
183 method => 'retrieve_record_transform',
184 api_name => "open-ils.supercat.record.$type.retrieve",
188 { desc => "Returns the \U$type\E representation ".
189 "of the requested bibliographic record",
193 desc => 'An OpenILS biblio::record_entry id',
197 { desc => "The bib record in \U$type\E",
202 __PACKAGE__->register_method(
203 method => 'retrieve_isbn_transform',
204 api_name => "open-ils.supercat.isbn.$type.retrieve",
208 { desc => "Returns the \U$type\E representation ".
209 "of the requested bibliographic record",
217 { desc => "The bib record in \U$type\E",
229 return unless ($tree && ref($tree->$field));
231 my @things = $filter->($tree);
232 for my $v ( @{$tree->$field} ){
233 push @things, $filter->($v);
234 push @things, tree_walker($v, $field, $filter);
245 my $page_size = shift || 9;
246 my $page = shift || 0;
247 my $statuses = shift || [];
248 my $copy_locations = shift || [];
250 my ($before_limit,$after_limit) = (0,0);
251 my ($before_offset,$after_offset) = (0,0);
254 $before_limit = $after_limit = int($page_size / 2);
255 $after_limit += 1 if ($page_size % 2);
257 $before_offset = $after_offset = int($page_size / 2);
258 $before_offset += 1 if ($page_size % 2);
259 $before_limit = $after_limit = $page_size;
262 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
264 my $o_search = { shortname => $ou };
265 if (!$ou || $ou eq '-') {
266 $o_search = { parent_ou => undef };
269 my $orgs = $_storage->request(
270 "open-ils.cstore.direct.actor.org_unit.search",
273 flesh_fields => { aou => [qw/children/] }
277 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
279 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
284 if (@$statuses || @$copy_locations) {
289 call_number => { '=' => { '+acn' => 'id' } },
291 ((@$statuses) ? ( status => $statuses) : ()),
292 ((@$copy_locations) ? ( location => $copy_locations) : ())
299 my $before = $_storage->request(
300 "open-ils.cstore.direct.asset.call_number.search.atomic",
301 { label => { "<" => { transform => "upper", value => ["upper", $label] } },
302 owning_lib => \@ou_ids,
307 flesh_fields => { acn => [qw/record owning_lib/] },
308 order_by => { acn => "cast(label_sortkey as bytea) desc, upper(label) desc, id desc, owning_lib desc" },
309 limit => $before_limit,
310 offset => abs($page) * $page_size - $before_offset,
313 push @list, reverse(@$before);
317 my $after = $_storage->request(
318 "open-ils.cstore.direct.asset.call_number.search.atomic",
319 { label => { ">=" => { transform => "upper", value => ["upper", $label] } },
320 owning_lib => \@ou_ids,
325 flesh_fields => { acn => [qw/record owning_lib/] },
326 order_by => { acn => "cast(label_sortkey as bytea), upper(label), id, owning_lib" },
327 limit => $after_limit,
328 offset => abs($page) * $page_size - $after_offset,
336 __PACKAGE__->register_method(
337 method => 'cn_browse',
338 api_name => 'open-ils.supercat.call_number.browse',
343 Returns the XML representation of the requested bibliographic record's holdings
348 desc => 'The target call number lable',
350 { name => 'org_unit',
351 desc => 'The org unit shortname (or "-" or undef for global) to browse',
353 { name => 'page_size',
354 desc => 'Count of call numbers to retrieve, default is 9',
357 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
359 { name => 'statuses',
360 desc => 'Array of statuses to filter copies by, optional and can be undef.',
362 { name => 'locations',
363 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
367 { desc => 'Call numbers with owning_lib and record fleshed',
378 my $limit = shift || 10;
379 my $page = shift || 0;
380 my $statuses = shift || [];
381 my $copy_locations = shift || [];
384 my $offset = abs($page) * $limit;
385 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
387 my $o_search = { shortname => $ou };
388 if (!$ou || $ou eq '-') {
389 $o_search = { parent_ou => undef };
392 my $orgs = $_storage->request(
393 "open-ils.cstore.direct.actor.org_unit.search",
396 flesh_fields => { aou => [qw/children/] }
400 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
402 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
407 if (@$statuses || @$copy_locations) {
412 call_number => { '=' => { '+acn' => 'id' } },
414 ((@$statuses) ? ( status => $statuses) : ()),
415 ((@$copy_locations) ? ( location => $copy_locations) : ())
422 my $before = $_storage->request(
423 "open-ils.cstore.direct.asset.call_number.search.atomic",
424 { label => { "<" => { transform => "upper", value => ["upper", $label] } },
425 owning_lib => \@ou_ids,
430 flesh_fields => { acn => [qw/record owning_lib/] },
431 order_by => { acn => "cast(label_sortkey as bytea) desc, upper(label) desc, id desc, owning_lib desc" },
436 push @list, reverse(@$before);
440 my $after = $_storage->request(
441 "open-ils.cstore.direct.asset.call_number.search.atomic",
442 { label => { ">=" => { transform => "upper", value => ["upper", $label] } },
443 owning_lib => \@ou_ids,
448 flesh_fields => { acn => [qw/record owning_lib/] },
449 order_by => { acn => "cast(label_sortkey as bytea), upper(label), id, owning_lib" },
459 __PACKAGE__->register_method(
460 method => 'cn_startwith',
461 api_name => 'open-ils.supercat.call_number.startwith',
466 Returns the XML representation of the requested bibliographic record's holdings
471 desc => 'The target call number lable',
473 { name => 'org_unit',
474 desc => 'The org unit shortname (or "-" or undef for global) to browse',
476 { name => 'page_size',
477 desc => 'Count of call numbers to retrieve, default is 9',
480 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
482 { name => 'statuses',
483 desc => 'Array of statuses to filter copies by, optional and can be undef.',
485 { name => 'locations',
486 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
490 { desc => 'Call numbers with owning_lib and record fleshed',
496 sub new_books_by_item {
501 my $page_size = shift || 10;
502 my $page = shift || 1;
503 my $statuses = shift || [];
504 my $copy_locations = shift || [];
506 my $offset = $page_size * ($page - 1);
508 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
511 if ($ou && $ou ne '-') {
512 my $orgs = $_storage->request(
513 "open-ils.cstore.direct.actor.org_unit.search",
514 { shortname => $ou },
516 flesh_fields => { aou => [qw/children/] }
519 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
522 $logger->debug("Searching for records with new copies at orgs [".join(',',@ou_ids)."], based on $ou");
523 my $cns = $_storage->request(
524 "open-ils.cstore.json_query.atomic",
525 { select => { acn => ['record'],
526 acp => [{ aggregate => 1 => transform => max => column => create_date => alias => 'create_date'}]
528 from => { 'acn' => { 'acp' => { field => call_number => fkey => 'id' } } },
532 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
533 ((@$statuses) ? ( status => $statuses) : ()),
534 ((@$copy_locations) ? ( location => $copy_locations) : ())
536 '+acn' => { record => { '>' => 0 } },
538 order_by => { acp => { create_date => { transform => 'max', direction => 'desc' } } },
544 return [ map { $_->{record} } @$cns ];
546 __PACKAGE__->register_method(
547 method => 'new_books_by_item',
548 api_name => 'open-ils.supercat.new_book_list',
553 Returns the XML representation of the requested bibliographic record's holdings
557 { name => 'org_unit',
558 desc => 'The org unit shortname (or "-" or undef for global) to list',
560 { name => 'page_size',
561 desc => 'Count of records to retrieve, default is 10',
564 desc => 'The page of records to retrieve, calculated based on page_size. Starts at 1.',
566 { name => 'statuses',
567 desc => 'Array of statuses to filter copies by, optional and can be undef.',
569 { name => 'locations',
570 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
574 { desc => 'Record IDs',
583 return tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
585 __PACKAGE__->register_method(
586 method => 'general_browse',
587 api_name => 'open-ils.supercat.title.browse',
588 tag => 'tnf', subfield => 'a',
592 { desc => "Returns a list of the requested org-scoped record ids held",
594 [ { name => 'value', desc => 'The target title', type => 'string' },
595 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
596 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
597 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
598 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
599 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
600 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
603 __PACKAGE__->register_method(
604 method => 'general_browse',
605 api_name => 'open-ils.supercat.author.browse',
606 tag => [qw/100 110 111/], subfield => 'a',
610 { desc => "Returns a list of the requested org-scoped record ids held",
612 [ { name => 'value', desc => 'The target author', type => 'string' },
613 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
614 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
615 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
616 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
617 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
618 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
621 __PACKAGE__->register_method(
622 method => 'general_browse',
623 api_name => 'open-ils.supercat.subject.browse',
624 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
628 { desc => "Returns a list of the requested org-scoped record ids held",
630 [ { name => 'value', desc => 'The target subject', type => 'string' },
631 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
632 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
633 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
634 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
635 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
636 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
639 __PACKAGE__->register_method(
640 method => 'general_browse',
641 api_name => 'open-ils.supercat.topic.browse',
642 tag => [qw/650 690/], subfield => 'a',
646 { desc => "Returns a list of the requested org-scoped record ids held",
648 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
649 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
650 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
651 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
652 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
653 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
654 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
657 __PACKAGE__->register_method(
658 method => 'general_browse',
659 api_name => 'open-ils.supercat.series.browse',
660 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
664 { desc => "Returns a list of the requested org-scoped record ids held",
666 [ { name => 'value', desc => 'The target series', type => 'string' },
667 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
668 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
669 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
670 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
671 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
672 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
682 my $subfield = shift;
685 my $page_size = shift || 9;
686 my $page = shift || 0;
687 my $statuses = shift || [];
688 my $copy_locations = shift || [];
690 my ($before_limit,$after_limit) = (0,0);
691 my ($before_offset,$after_offset) = (0,0);
694 $before_limit = $after_limit = int($page_size / 2);
695 $after_limit += 1 if ($page_size % 2);
697 $before_offset = $after_offset = int($page_size / 2);
698 $before_offset += 1 if ($page_size % 2);
699 $before_limit = $after_limit = $page_size;
702 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
705 if ($ou && $ou ne '-') {
706 my $orgs = $_storage->request(
707 "open-ils.cstore.direct.actor.org_unit.search",
708 { shortname => $ou },
710 flesh_fields => { aou => [qw/children/] }
713 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
716 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
721 my $before = $_storage->request(
722 "open-ils.cstore.json_query.atomic",
723 { select => { mfr => [qw/record value/] },
728 subfield => $subfield,
729 value => { '<' => lc($value) }
733 { select=> { acp => [ 'id' ] },
734 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
736 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
739 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
740 ((@$statuses) ? ( status => $statuses) : ()),
741 ((@$copy_locations) ? ( location => $copy_locations) : ())
748 { select=> { auri => [ 'id' ] },
749 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
751 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
752 '+auri' => { active => 't' }
759 order_by => { mfr => { value => 'desc' } },
760 limit => $before_limit,
761 offset => abs($page) * $page_size - $before_offset,
764 push @list, map { $_->{record} } reverse(@$before);
768 my $after = $_storage->request(
769 "open-ils.cstore.json_query.atomic",
770 { select => { mfr => [qw/record value/] },
775 subfield => $subfield,
776 value => { '>=' => lc($value) }
780 { select=> { acp => [ 'id' ] },
781 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
783 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
786 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
787 ((@$statuses) ? ( status => $statuses) : ()),
788 ((@$copy_locations) ? ( location => $copy_locations) : ())
795 { select=> { auri => [ 'id' ] },
796 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
798 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
799 '+auri' => { active => 't' }
806 order_by => { mfr => { value => 'asc' } },
807 limit => $after_limit,
808 offset => abs($page) * $page_size - $after_offset,
811 push @list, map { $_->{record} } @$after;
816 __PACKAGE__->register_method(
817 method => 'tag_sf_browse',
818 api_name => 'open-ils.supercat.tag.browse',
823 Returns a list of the requested org-scoped record ids held
828 desc => 'The target MARC tag',
830 { name => 'subfield',
831 desc => 'The target MARC subfield',
834 desc => 'The target string',
836 { name => 'org_unit',
837 desc => 'The org unit shortname (or "-" or undef for global) to browse',
839 { name => 'page_size',
840 desc => 'Count of call numbers to retrieve, default is 9',
843 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
845 { name => 'statuses',
846 desc => 'Array of statuses to filter copies by, optional and can be undef.',
848 { name => 'locations',
849 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
853 { desc => 'Record IDs that have copies at the relevant org units',
858 sub general_authority_browse {
861 return authority_tag_sf_browse($self, $client, $self->{tag}, $self->{subfield}, @_);
863 __PACKAGE__->register_method(
864 method => 'general_authority_browse',
865 api_name => 'open-ils.supercat.authority.title.browse',
866 tag => '130', subfield => 'a',
870 { desc => "Returns a list of the requested authority record ids held",
872 [ { name => 'value', desc => 'The target title', type => 'string' },
873 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
874 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
875 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
878 __PACKAGE__->register_method(
879 method => 'general_authority_browse',
880 api_name => 'open-ils.supercat.authority.author.browse',
881 tag => [qw/100 110 111/], subfield => 'a',
885 { desc => "Returns a list of the requested authority record ids held",
887 [ { name => 'value', desc => 'The target author', type => 'string' },
888 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
889 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
890 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
893 __PACKAGE__->register_method(
894 method => 'general_authority_browse',
895 api_name => 'open-ils.supercat.authority.subject.browse',
896 tag => [qw/148 150 151 155/], subfield => 'a',
900 { desc => "Returns a list of the requested authority record ids held",
902 [ { name => 'value', desc => 'The target subject', type => 'string' },
903 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
904 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
905 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
908 __PACKAGE__->register_method(
909 method => 'general_authority_browse',
910 api_name => 'open-ils.supercat.authority.topic.browse',
911 tag => '150', subfield => 'a',
915 { desc => "Returns a list of the requested authority record ids held",
917 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
918 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
919 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
920 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
924 sub authority_tag_sf_browse {
929 my $subfield = shift;
931 my $page_size = shift || 9;
932 my $page = shift || 0;
934 my ($before_limit,$after_limit) = (0,0);
935 my ($before_offset,$after_offset) = (0,0);
938 $before_limit = $after_limit = int($page_size / 2);
939 $after_limit += 1 if ($page_size % 2);
941 $before_offset = $after_offset = int($page_size / 2);
942 $before_offset += 1 if ($page_size % 2);
943 $before_limit = $after_limit = $page_size;
946 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
951 my $before = $_storage->request(
952 "open-ils.cstore.json_query.atomic",
953 { select => { afr => [qw/record value/] },
954 from => { 'are', 'afr' },
956 '+afr' => { tag => $tag, subfield => $subfield, value => { '<' => lc($value) } },
957 '+are' => { 'deleted' => 'f' }
959 order_by => { afr => { value => 'desc' } },
960 limit => $before_limit,
961 offset => abs($page) * $page_size - $before_offset,
964 push @list, map { $_->{record} } reverse(@$before);
968 my $after = $_storage->request(
969 "open-ils.cstore.json_query.atomic",
970 { select => { afr => [qw/record value/] },
971 from => { 'are', 'afr' },
973 '+afr' => { tag => $tag, subfield => $subfield, value => { '>=' => lc($value) } },
974 '+are' => { 'deleted' => 'f' }
976 order_by => { afr => { value => 'asc' } },
977 limit => $after_limit,
978 offset => abs($page) * $page_size - $after_offset,
981 push @list, map { $_->{record} } @$after;
986 __PACKAGE__->register_method(
987 method => 'authority_tag_sf_browse',
988 api_name => 'open-ils.supercat.authority.tag.browse',
993 Returns a list of the requested authority record ids held
998 desc => 'The target Authority MARC tag',
1000 { name => 'subfield',
1001 desc => 'The target Authority MARC subfield',
1004 desc => 'The target string',
1006 { name => 'page_size',
1007 desc => 'Count of call numbers to retrieve, default is 9',
1010 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1014 { desc => 'Authority Record IDs that are near the target string',
1019 sub general_startwith {
1022 return tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1024 __PACKAGE__->register_method(
1025 method => 'general_startwith',
1026 api_name => 'open-ils.supercat.title.startwith',
1027 tag => 'tnf', subfield => 'a',
1031 { desc => "Returns a list of the requested org-scoped record ids held",
1033 [ { name => 'value', desc => 'The target title', type => 'string' },
1034 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1035 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1036 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1037 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1038 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1039 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1042 __PACKAGE__->register_method(
1043 method => 'general_startwith',
1044 api_name => 'open-ils.supercat.author.startwith',
1045 tag => [qw/100 110 111/], subfield => 'a',
1049 { desc => "Returns a list of the requested org-scoped record ids held",
1051 [ { name => 'value', desc => 'The target author', type => 'string' },
1052 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1053 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1054 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1055 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1056 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1057 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1060 __PACKAGE__->register_method(
1061 method => 'general_startwith',
1062 api_name => 'open-ils.supercat.subject.startwith',
1063 tag => [qw/600 610 611 630 648 650 651 653 655 656 662 690 691 696 697 698 699/], subfield => 'a',
1067 { desc => "Returns a list of the requested org-scoped record ids held",
1069 [ { name => 'value', desc => 'The target subject', type => 'string' },
1070 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1071 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1072 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1073 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1074 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1075 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1078 __PACKAGE__->register_method(
1079 method => 'general_startwith',
1080 api_name => 'open-ils.supercat.topic.startwith',
1081 tag => [qw/650 690/], subfield => 'a',
1085 { desc => "Returns a list of the requested org-scoped record ids held",
1087 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1088 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1089 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1090 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1091 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1092 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1093 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1096 __PACKAGE__->register_method(
1097 method => 'general_startwith',
1098 api_name => 'open-ils.supercat.series.startwith',
1099 tag => [qw/440 490 800 810 811 830/], subfield => 'a',
1103 { desc => "Returns a list of the requested org-scoped record ids held",
1105 [ { name => 'value', desc => 'The target series', type => 'string' },
1106 { name => 'org_unit', desc => 'The org unit shortname (or "-" or undef for global) to browse', type => 'string' },
1107 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1108 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' },
1109 { name => 'statuses', desc => 'Array of statuses to filter copies by, optional and can be undef.', type => 'array' },
1110 { name => 'locations', desc => 'Array of copy locations to filter copies by, optional and can be undef.', type => 'array' }, ],
1111 'return' => { desc => 'Record IDs that have copies at the relevant org units', type => 'array' }
1116 sub tag_sf_startwith {
1121 my $subfield = shift;
1124 my $limit = shift || 10;
1125 my $page = shift || 0;
1126 my $statuses = shift || [];
1127 my $copy_locations = shift || [];
1129 my $offset = $limit * abs($page);
1130 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1133 if ($ou && $ou ne '-') {
1134 my $orgs = $_storage->request(
1135 "open-ils.cstore.direct.actor.org_unit.search",
1136 { shortname => $ou },
1138 flesh_fields => { aou => [qw/children/] }
1141 @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1144 $logger->debug("Searching for records at orgs [".join(',',@ou_ids)."], based on $ou");
1149 my $before = $_storage->request(
1150 "open-ils.cstore.json_query.atomic",
1151 { select => { mfr => [qw/record value/] },
1156 subfield => $subfield,
1157 value => { '<' => lc($value) }
1161 { select=> { acp => [ 'id' ] },
1162 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1164 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1167 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1168 ((@$statuses) ? ( status => $statuses) : ()),
1169 ((@$copy_locations) ? ( location => $copy_locations) : ())
1176 { select=> { auri => [ 'id' ] },
1177 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1179 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1180 '+auri' => { active => 't' }
1187 order_by => { mfr => { value => 'desc' } },
1192 push @list, map { $_->{record} } reverse(@$before);
1196 my $after = $_storage->request(
1197 "open-ils.cstore.json_query.atomic",
1198 { select => { mfr => [qw/record value/] },
1203 subfield => $subfield,
1204 value => { '>=' => lc($value) }
1208 { select=> { acp => [ 'id' ] },
1209 from => { acn => { acp => { field => 'call_number', fkey => 'id' } } },
1211 { '+acn' => { record => { '=' => { '+mfr' => 'record' } } },
1214 ((@ou_ids) ? ( circ_lib => \@ou_ids) : ()),
1215 ((@$statuses) ? ( status => $statuses) : ()),
1216 ((@$copy_locations) ? ( location => $copy_locations) : ())
1223 { select=> { auri => [ 'id' ] },
1224 from => { acn => { auricnm => { field => 'call_number', fkey => 'id', join => { auri => { field => 'id', fkey => 'uri' } } } } },
1226 { '+acn' => { record => { '=' => { '+mfr' => 'record' } }, (@ou_ids) ? ( owning_lib => \@ou_ids) : () },
1227 '+auri' => { active => 't' }
1234 order_by => { mfr => { value => 'asc' } },
1239 push @list, map { $_->{record} } @$after;
1244 __PACKAGE__->register_method(
1245 method => 'tag_sf_startwith',
1246 api_name => 'open-ils.supercat.tag.startwith',
1250 { desc => <<" DESC",
1251 Returns a list of the requested org-scoped record ids held
1256 desc => 'The target MARC tag',
1258 { name => 'subfield',
1259 desc => 'The target MARC subfield',
1262 desc => 'The target string',
1264 { name => 'org_unit',
1265 desc => 'The org unit shortname (or "-" or undef for global) to browse',
1267 { name => 'page_size',
1268 desc => 'Count of call numbers to retrieve, default is 9',
1271 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1273 { name => 'statuses',
1274 desc => 'Array of statuses to filter copies by, optional and can be undef.',
1276 { name => 'locations',
1277 desc => 'Array of copy locations to filter copies by, optional and can be undef.',
1281 { desc => 'Record IDs that have copies at the relevant org units',
1286 sub general_authority_startwith {
1289 return authority_tag_sf_startwith($self, $client, $self->{tag}, $self->{subfield}, @_);
1291 __PACKAGE__->register_method(
1292 method => 'general_authority_startwith',
1293 api_name => 'open-ils.supercat.authority.title.startwith',
1294 tag => '130', subfield => 'a',
1298 { desc => "Returns a list of the requested authority record ids held",
1300 [ { name => 'value', desc => 'The target title', type => 'string' },
1301 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1302 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1303 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1306 __PACKAGE__->register_method(
1307 method => 'general_authority_startwith',
1308 api_name => 'open-ils.supercat.authority.author.startwith',
1309 tag => [qw/100 110 111/], subfield => 'a',
1313 { desc => "Returns a list of the requested authority record ids held",
1315 [ { name => 'value', desc => 'The target author', type => 'string' },
1316 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1317 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1318 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1321 __PACKAGE__->register_method(
1322 method => 'general_authority_startwith',
1323 api_name => 'open-ils.supercat.authority.subject.startwith',
1324 tag => [qw/148 150 151 155/], subfield => 'a',
1328 { desc => "Returns a list of the requested authority record ids held",
1330 [ { name => 'value', desc => 'The target subject', type => 'string' },
1331 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1332 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1333 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1336 __PACKAGE__->register_method(
1337 method => 'general_authority_startwith',
1338 api_name => 'open-ils.supercat.authority.topic.startwith',
1339 tag => '150', subfield => 'a',
1343 { desc => "Returns a list of the requested authority record ids held",
1345 [ { name => 'value', desc => 'The target topical subject', type => 'string' },
1346 { name => 'page_size', desc => 'Count of records to retrieve, default is 9', type => 'number' },
1347 { name => 'page', desc => 'The page of records retrieve, calculated based on page_size. Can be positive, negative or 0.', type => 'number' }, ],
1348 'return' => { desc => 'Authority Record IDs that are near the target string', type => 'array' }
1352 sub authority_tag_sf_startwith {
1357 my $subfield = shift;
1359 my $limit = shift || 10;
1360 my $page = shift || 0;
1362 my $offset = $limit * abs($page);
1363 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1368 my $before = $_storage->request(
1369 "open-ils.cstore.json_query.atomic",
1370 { select => { afr => [qw/record value/] },
1371 from => { 'afr', 'are' },
1373 '+afr' => { tag => $tag, subfield => $subfield, value => { '<' => lc($value) } },
1374 '+are' => { deleted => 'f' }
1376 order_by => { afr => { value => 'desc' } },
1381 push @list, map { $_->{record} } reverse(@$before);
1385 my $after = $_storage->request(
1386 "open-ils.cstore.json_query.atomic",
1387 { select => { afr => [qw/record value/] },
1388 from => { 'afr', 'are' },
1390 '+afr' => { tag => $tag, subfield => $subfield, value => { '>=' => lc($value) } },
1391 '+are' => { deleted => 'f' }
1393 order_by => { afr => { value => 'asc' } },
1398 push @list, map { $_->{record} } @$after;
1403 __PACKAGE__->register_method(
1404 method => 'authority_tag_sf_startwith',
1405 api_name => 'open-ils.supercat.authority.tag.startwith',
1409 { desc => <<" DESC",
1410 Returns a list of the requested authority record ids held
1415 desc => 'The target Authority MARC tag',
1417 { name => 'subfield',
1418 desc => 'The target Authority MARC subfield',
1421 desc => 'The target string',
1423 { name => 'page_size',
1424 desc => 'Count of call numbers to retrieve, default is 9',
1427 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
1431 { desc => 'Authority Record IDs that are near the target string',
1437 sub holding_data_formats {
1440 namespace_uri => 'http://www.loc.gov/MARC21/slim',
1441 docs => 'http://www.loc.gov/marcxml/',
1442 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
1446 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acn.formats', api_level => 1 );
1447 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.acp.formats', api_level => 1 );
1448 __PACKAGE__->register_method( method => 'holding_data_formats', api_name => 'open-ils.supercat.auri.formats', api_level => 1 );
1451 __PACKAGE__->register_method(
1452 method => 'retrieve_uri',
1453 api_name => 'open-ils.supercat.auri.marcxml.retrieve',
1457 { desc => <<" DESC",
1458 Returns a fleshed call number object
1463 desc => 'An OpenILS asset::uri id',
1467 { desc => 'fleshed uri',
1475 my $args = shift || {};
1477 return OpenILS::Application::SuperCat::unAPI
1478 ->new(OpenSRF::AppSession
1479 ->create( 'open-ils.cstore' )
1481 "open-ils.cstore.direct.asset.uri.retrieve",
1485 auri => [qw/call_number_maps/],
1486 auricnm => [qw/call_number/],
1487 acn => [qw/owning_lib record/],
1494 __PACKAGE__->register_method(
1495 method => 'retrieve_copy',
1496 api_name => 'open-ils.supercat.acp.marcxml.retrieve',
1500 { desc => <<" DESC",
1501 Returns a fleshed call number object
1506 desc => 'An OpenILS asset::copy id',
1510 { desc => 'fleshed copy',
1518 my $args = shift || {};
1520 return OpenILS::Application::SuperCat::unAPI
1521 ->new(OpenSRF::AppSession
1522 ->create( 'open-ils.cstore' )
1524 "open-ils.cstore.direct.asset.copy.retrieve",
1528 acn => [qw/owning_lib record/],
1529 acp => [qw/call_number location status circ_lib stat_cat_entries notes/],
1536 __PACKAGE__->register_method(
1537 method => 'retrieve_callnumber',
1538 api_name => 'open-ils.supercat.acn.marcxml.retrieve',
1543 { desc => <<" DESC",
1544 Returns a fleshed call number object
1549 desc => 'An OpenILS asset::call_number id',
1553 { desc => 'call number with copies',
1557 sub retrieve_callnumber {
1561 my $args = shift || {};
1563 return OpenILS::Application::SuperCat::unAPI
1564 ->new(OpenSRF::AppSession
1565 ->create( 'open-ils.cstore' )
1567 "open-ils.cstore.direct.asset.call_number.retrieve",
1571 acn => [qw/owning_lib record copies uri_maps/],
1572 auricnm => [qw/uri/],
1573 acp => [qw/location status circ_lib stat_cat_entries notes/],
1581 __PACKAGE__->register_method(
1582 method => 'basic_record_holdings',
1583 api_name => 'open-ils.supercat.record.basic_holdings.retrieve',
1588 { desc => <<" DESC",
1589 Returns a basic hash representation of the requested bibliographic record's holdings
1594 desc => 'An OpenILS biblio::record_entry id',
1598 { desc => 'Hash of bib record holdings hierarchy (call numbers and copies)',
1602 sub basic_record_holdings {
1608 # holdings hold an array of call numbers, which hold an array of copies
1609 # holdings => [ label: { library, [ copies: { barcode, location, status, circ_lib } ] } ]
1612 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1614 my $tree = $_storage->request(
1615 "open-ils.cstore.direct.biblio.record_entry.retrieve",
1619 bre => [qw/call_numbers/],
1620 acn => [qw/copies owning_lib/],
1621 acp => [qw/location status circ_lib/],
1626 my $o_search = { shortname => uc($ou) };
1627 if (!$ou || $ou eq '-') {
1628 $o_search = { parent_ou => undef };
1631 my $orgs = $_storage->request(
1632 "open-ils.cstore.direct.actor.org_unit.search",
1635 flesh_fields => { aou => [qw/children/] }
1639 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
1641 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
1643 for my $cn (@{$tree->call_numbers}) {
1644 next unless ( $cn->deleted eq 'f' || $cn->deleted == 0 );
1647 for my $c (@{$cn->copies}) {
1648 next unless grep {$c->circ_lib->id == $_} @ou_ids;
1649 next unless ( $c->deleted eq 'f' || $c->deleted == 0 );
1655 $holdings{$cn->label}{'owning_lib'} = $cn->owning_lib->shortname;
1657 for my $cp (@{$cn->copies}) {
1659 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
1660 next unless ( $cp->deleted eq 'f' || $cp->deleted == 0 );
1662 push @{$holdings{$cn->label}{'copies'}}, {
1663 barcode => $cp->barcode,
1664 status => $cp->status->name,
1665 location => $cp->location->name,
1666 circlib => $cp->circ_lib->shortname
1675 #__PACKAGE__->register_method(
1676 # method => 'new_record_holdings',
1677 # api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
1682 # { desc => <<" DESC",
1683 #Returns the XML representation of the requested bibliographic record's holdings
1687 # { name => 'bibId',
1688 # desc => 'An OpenILS biblio::record_entry id',
1689 # type => 'number' },
1692 # { desc => 'Stream of bib record holdings hierarchy in XML',
1693 # type => 'string' }
1698 sub new_record_holdings {
1707 $paging = [-1,0] if (!$paging or !ref($paging) or @$paging == 0);
1708 my $limit = $$paging[0];
1709 my $offset = $$paging[1] || 0;
1711 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1713 my $o_search = { shortname => uc($ou) };
1714 if (!$ou || $ou eq '-') {
1715 $o_search = { parent_ou => undef };
1718 my $one_org = $_storage->request(
1719 "open-ils.cstore.direct.actor.org_unit.search",
1723 my $orgs = $_storage->request(
1724 'open-ils.cstore.json_query.atomic',
1725 { from => [ 'actor.org_unit_descendants', defined($depth) ? ( $one_org->id, $depth ) : ( $one_org->id ) ] }
1729 my @ou_ids = map { $_->{id} } @$orgs;
1731 $logger->info("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
1733 my %subselect = ( '-or' => [
1734 { owning_lib => \@ou_ids },
1738 call_number => { '=' => {'+acn'=>'id'} },
1740 circ_lib => \@ou_ids
1746 if ($flesh and $flesh eq 'uris') {
1748 owning_lib => \@ou_ids,
1750 from => { auricnm => 'auri' },
1752 call_number => { '=' => {'+acn'=>'id'} },
1753 '+auri' => { active => 't' }
1760 my $cns = $_storage->request(
1761 "open-ils.cstore.direct.asset.call_number.search.atomic",
1768 acn => [qw/copies owning_lib uri_maps/],
1769 auricnm => [qw/uri/],
1770 acp => [qw/circ_lib location status stat_cat_entries notes/],
1771 asce => [qw/stat_cat/],
1773 ( $limit > -1 ? ( limit => $limit ) : () ),
1774 ( $offset ? ( offset => $offset ) : () ),
1775 order_by => { acn => { label_sortkey => {} } }
1779 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
1783 $client->respond("<holdings xmlns='http://open-ils.org/spec/holdings/v1'><volumes>\n");
1785 for my $cn (@$cns) {
1786 next unless (@{$cn->copies} > 0 or (ref($cn->uri_maps) and @{$cn->uri_maps}));
1788 # We don't want O:A:S:unAPI::acn to return the record, we've got that already
1789 # In the context of BibTemplate, copies aren't necessary because we pull those
1790 # in a separate call
1792 OpenILS::Application::SuperCat::unAPI::acn
1794 ->as_xml( {no_record => 1, no_copies => ($flesh ? 0 : 1)} )
1798 $client->respond("</volumes><subscriptions>\n");
1800 $logger->info("Searching for serial holdings at orgs [".join(',',@ou_ids)."], based on $ou");
1802 %subselect = ( '-or' => [
1803 { owning_lib => \@ou_ids },
1806 where => { holding_lib => \@ou_ids }
1811 my $ssubs = $_storage->request(
1812 "open-ils.cstore.direct.serial.subscription.search.atomic",
1813 { record_entry => $bib,
1818 ssub => [qw/sdist siss sercap/],
1819 sdist => [qw/bib_summaries sup_summaries index_summaries streams/],
1820 sstr => [qw/items/],
1821 sitem => [qw/notes unit/],
1823 ( $limit > -1 ? ( limit => $limit ) : () ),
1824 ( $offset ? ( offset => $offset ) : () ),
1836 date_expected => {},
1843 for my $ssub (@$ssubs) {
1844 next unless (@{$ssub->distributions} or @{$ssub->issuances} or @{$ssub->captions_and_patterns});
1846 # We don't want O:A:S:unAPI::ssub to return the record, we've got that already
1847 # In the context of BibTemplate, copies aren't necessary because we pull those
1848 # in a separate call
1850 OpenILS::Application::SuperCat::unAPI::ssub
1852 ->as_xml( {no_record => 1, no_items => ($flesh ? 0 : 1)} )
1857 return "</subscriptions></holdings>\n";
1859 __PACKAGE__->register_method(
1860 method => 'new_record_holdings',
1861 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
1866 { desc => <<" DESC",
1867 Returns the XML representation of the requested bibliographic record's holdings
1872 desc => 'An OpenILS biblio::record_entry ID',
1874 { name => 'orgUnit',
1875 desc => 'An OpenILS actor::org_unit short name that limits the scope of returned holdings',
1878 desc => 'An OpenILS actor::org_unit_type depththat limits the scope of returned holdings',
1880 { name => 'hideCopies',
1881 desc => 'Flag that prevents the inclusion of copies in the returned holdings',
1882 type => 'boolean' },
1884 desc => 'Arry of limit and offset for holdings paging',
1888 { desc => 'Stream of bib record holdings hierarchy in XML',
1898 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1900 my $recs = $_storage->request(
1901 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
1902 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
1905 return undef unless (@$recs);
1907 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
1909 __PACKAGE__->register_method(
1910 method => 'isbn_holdings',
1911 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
1915 { desc => <<" DESC",
1916 Returns the XML representation of the requested bibliographic record's holdings
1925 { desc => 'The bib record holdings hierarchy in XML',
1933 return '' unless $text;
1934 $text =~ s/&/&/gsom;
1935 $text =~ s/</</gsom;
1936 $text =~ s/>/>/gsom;
1937 $text =~ s/"/\\"/gsom;
1941 sub recent_changes {
1944 my $when = shift || '1-01-01';
1947 my $type = 'biblio';
1948 $type = 'authority' if ($self->api_name =~ /authority/o);
1950 my $axis = 'create_date';
1951 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
1953 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1955 return $_storage->request(
1956 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
1957 { $axis => { ">" => $when }, id => { '>' => 0 } },
1958 { order_by => { bre => "$axis desc" }, limit => $limit }
1962 for my $t ( qw/biblio authority/ ) {
1963 for my $a ( qw/import edit/ ) {
1965 __PACKAGE__->register_method(
1966 method => 'recent_changes',
1967 api_name => "open-ils.supercat.$t.record.$a.recent",
1971 { desc => "Returns a list of recently ${a}ed $t records",
1975 desc => "Date to start looking for ${a}ed records",
1976 default => '1-01-01',
1980 desc => "Maximum count to retrieve",
1984 { desc => "An id list of $t records",
1992 sub retrieve_authority_marcxml {
1997 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1999 my $record = $_storage->request( 'open-ils.cstore.direct.authority.record_entry.retrieve' => $rid )->gather(1);
2000 return $U->entityize( $record->marc ) if ($record);
2004 __PACKAGE__->register_method(
2005 method => 'retrieve_authority_marcxml',
2006 api_name => 'open-ils.supercat.authority.marcxml.retrieve',
2010 { desc => <<" DESC",
2011 Returns the MARCXML representation of the requested authority record
2015 { name => 'authorityId',
2016 desc => 'An OpenILS authority::record_entry id',
2020 { desc => 'The authority record in MARCXML',
2025 sub retrieve_record_marcxml {
2030 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2032 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
2033 return $U->entityize( $record->marc ) if ($record);
2037 __PACKAGE__->register_method(
2038 method => 'retrieve_record_marcxml',
2039 api_name => 'open-ils.supercat.record.marcxml.retrieve',
2043 { desc => <<" DESC",
2044 Returns the MARCXML representation of the requested bibliographic record
2049 desc => 'An OpenILS biblio::record_entry id',
2053 { desc => 'The bib record in MARCXML',
2058 sub retrieve_isbn_marcxml {
2063 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2065 my $recs = $_storage->request(
2066 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2067 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2070 return undef unless (@$recs);
2072 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2073 return $U->entityize( $record->marc ) if ($record);
2077 __PACKAGE__->register_method(
2078 method => 'retrieve_isbn_marcxml',
2079 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
2083 { desc => <<" DESC",
2084 Returns the MARCXML representation of the requested ISBN
2089 desc => 'An ... um ... ISBN',
2093 { desc => 'The bib record in MARCXML',
2098 sub retrieve_record_transform {
2103 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
2105 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2106 #$_storage->connect;
2108 my $record = $_storage->request(
2109 'open-ils.cstore.direct.biblio.record_entry.retrieve',
2113 return undef unless ($record);
2115 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2118 sub retrieve_isbn_transform {
2123 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2125 my $recs = $_storage->request(
2126 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2127 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2130 return undef unless (@$recs);
2132 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
2134 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
2136 return undef unless ($record);
2138 return $U->entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
2141 sub retrieve_record_objects {
2146 $ids = [$ids] unless (ref $ids);
2147 $ids = [grep {$_} @$ids];
2149 return [] unless (@$ids);
2151 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2152 return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
2154 __PACKAGE__->register_method(
2155 method => 'retrieve_record_objects',
2156 api_name => 'open-ils.supercat.record.object.retrieve',
2160 { desc => <<" DESC",
2161 Returns the Fieldmapper object representation of the requested bibliographic records
2166 desc => 'OpenILS biblio::record_entry ids',
2170 { desc => 'The bib records',
2176 sub retrieve_isbn_object {
2181 return undef unless ($isbn);
2183 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2184 my $recs = $_storage->request(
2185 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2186 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
2189 return undef unless (@$recs);
2191 return $_storage->request(
2192 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
2193 { id => $recs->[0]->record }
2196 __PACKAGE__->register_method(
2197 method => 'retrieve_isbn_object',
2198 api_name => 'open-ils.supercat.isbn.object.retrieve',
2202 { desc => <<" DESC",
2203 Returns the Fieldmapper object representation of the requested bibliographic record
2212 { desc => 'The bib record',
2219 sub retrieve_metarecord_mods {
2224 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
2226 # Get the metarecord in question
2229 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
2232 # Now get the map of all bib records for the metarecord
2235 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2236 {metarecord => $rid}
2239 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
2241 # and retrieve the lead (master) record as MODS
2243 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2244 ->run($mr->master_record);
2245 my $master_mods = $_parser->parse_string($master)->documentElement;
2246 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods" );
2247 $master_mods->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2249 # ... and a MODS clone to populate, with guts removed.
2250 my $mods = $_parser->parse_string($master)->documentElement;
2251 $mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # modsCollection element
2252 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2253 ($mods) = $mods->findnodes('//mods:mods');
2254 #$mods->setNamespace( "http://www.loc.gov/mods/", "mods" ); # mods element
2255 $mods->removeChildNodes;
2256 $mods->setNamespace('http://www.loc.gov/mods/', undef, 1);
2258 # Add the metarecord ID as a (locally defined) info URI
2259 my $recordInfo = $mods
2261 ->createElement("recordInfo");
2263 my $recordIdentifier = $mods
2265 ->createElement("recordIdentifier");
2267 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
2272 $recordIdentifier->appendTextNode(
2273 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
2276 $recordInfo->appendChild($recordIdentifier);
2277 $mods->appendChild($recordInfo);
2279 # Grab the title, author and ISBN for the master record and populate the metarecord
2280 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
2283 $title->setNamespace( "http://www.loc.gov/mods/", "mods" );
2284 $title->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2285 $title = $mods->ownerDocument->importNode($title);
2286 $mods->appendChild($title);
2289 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
2291 $author->setNamespace( "http://www.loc.gov/mods/", "mods" );
2292 $author->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2293 $author = $mods->ownerDocument->importNode($author);
2294 $mods->appendChild($author);
2297 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
2299 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2300 $isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2301 $isbn = $mods->ownerDocument->importNode($isbn);
2302 $mods->appendChild($isbn);
2305 # ... and loop over the constituent records
2306 for my $map ( @$recs ) {
2310 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
2311 ->run($map->source);
2313 my $part_mods = $_parser->parse_string($rec);
2314 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods" );
2315 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2316 ($part_mods) = $part_mods->findnodes('//mods:mods');
2318 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
2319 $node->setNamespace( "http://www.loc.gov/mods/", "mods" );
2320 $node->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2321 $node = $mods->ownerDocument->importNode($node);
2322 $mods->appendChild( $node );
2325 my $relatedItem = $mods
2327 ->createElement("relatedItem");
2329 $relatedItem->setAttribute( type => 'constituent' );
2331 my $identifier = $mods
2333 ->createElement("identifier");
2335 $identifier->setAttribute( type => 'uri' );
2337 my $subRecordInfo = $mods
2339 ->createElement("recordInfo");
2341 my $subRecordIdentifier = $mods
2343 ->createElement("recordIdentifier");
2345 my $subid = $map->source;
2346 $subRecordIdentifier->appendTextNode(
2347 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
2352 $subRecordInfo->appendChild($subRecordIdentifier);
2354 $relatedItem->appendChild( $subRecordInfo );
2356 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
2357 $tor->setNamespace( "http://www.loc.gov/mods/", "mods" );
2358 $tor->setNamespace( "http://www.loc.gov/mods/", undef, 1 ) if ($tor);
2359 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
2360 $relatedItem->appendChild($tor) if ($tor);
2362 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
2363 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods" );
2364 $part_isbn->setNamespace( "http://www.loc.gov/mods/", undef, 1 );
2365 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
2366 $relatedItem->appendChild( $part_isbn );
2369 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
2373 $mods->appendChild( $relatedItem );
2377 $_storage->disconnect;
2379 return $U->entityize($mods->toString);
2382 __PACKAGE__->register_method(
2383 method => 'retrieve_metarecord_mods',
2384 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
2388 { desc => <<" DESC",
2389 Returns the MODS representation of the requested metarecord
2393 { name => 'metarecordId',
2394 desc => 'An OpenILS metabib::metarecord id',
2398 { desc => 'The metarecord in MODS',
2403 sub list_metarecord_formats {
2406 { namespace_uri => 'http://www.loc.gov/mods/',
2407 docs => 'http://www.loc.gov/mods/',
2408 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
2413 for my $type ( keys %metarecord_xslt ) {
2416 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
2417 docs => $metarecord_xslt{$type}{docs},
2418 schema_location => $metarecord_xslt{$type}{schema_location},
2425 __PACKAGE__->register_method(
2426 method => 'list_metarecord_formats',
2427 api_name => 'open-ils.supercat.metarecord.formats',
2431 { desc => <<" DESC",
2432 Returns the list of valid metarecord formats that supercat understands.
2435 { desc => 'The format list',
2441 sub list_authority_formats {
2444 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2445 docs => 'http://www.loc.gov/marcxml/',
2446 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
2451 # for my $type ( keys %record_xslt ) {
2454 # { namespace_uri => $record_xslt{$type}{namespace_uri},
2455 # docs => $record_xslt{$type}{docs},
2456 # schema_location => $record_xslt{$type}{schema_location},
2463 __PACKAGE__->register_method(
2464 method => 'list_authority_formats',
2465 api_name => 'open-ils.supercat.authority.formats',
2469 { desc => <<" DESC",
2470 Returns the list of valid authority formats that supercat understands.
2473 { desc => 'The format list',
2478 sub list_record_formats {
2481 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
2482 docs => 'http://www.loc.gov/marcxml/',
2483 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
2488 for my $type ( keys %record_xslt ) {
2491 { namespace_uri => $record_xslt{$type}{namespace_uri},
2492 docs => $record_xslt{$type}{docs},
2493 schema_location => $record_xslt{$type}{schema_location},
2500 __PACKAGE__->register_method(
2501 method => 'list_record_formats',
2502 api_name => 'open-ils.supercat.record.formats',
2506 { desc => <<" DESC",
2507 Returns the list of valid record formats that supercat understands.
2510 { desc => 'The format list',
2514 __PACKAGE__->register_method(
2515 method => 'list_record_formats',
2516 api_name => 'open-ils.supercat.isbn.formats',
2520 { desc => <<" DESC",
2521 Returns the list of valid record formats that supercat understands.
2524 { desc => 'The format list',
2537 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
2538 unless (length($isbn) >= 10);
2540 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
2542 # Create a storage session, since we'll be making muliple requests.
2545 # Find the record that has that ISBN.
2546 my $bibrec = $_storage->request(
2547 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
2548 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
2551 # Go away if we don't have one.
2552 return {} unless (@$bibrec);
2554 # Find the metarecord for that bib record.
2555 my $mr = $_storage->request(
2556 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2557 {source => $bibrec->[0]->record}
2560 # Find the other records for that metarecord.
2561 my $records = $_storage->request(
2562 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
2563 {metarecord => $mr->[0]->metarecord}
2566 # Just to be safe. There's currently no unique constraint on sources...
2567 my %unique_recs = map { ($_->source, 1) } @$records;
2568 my @rec_list = sort keys %unique_recs;
2570 # And now fetch the ISBNs for thos records.
2574 'open-ils.cstore.direct.metabib.full_rec.search',
2575 { tag => '020', subfield => 'a', record => $_ }
2576 )->gather(1) for (@rec_list);
2578 # We're done with the storage server session.
2579 $_storage->disconnect;
2581 # Return the oISBN data structure. This will be XMLized at a higher layer.
2583 { metarecord => $mr->[0]->metarecord,
2584 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
2587 __PACKAGE__->register_method(
2589 api_name => 'open-ils.supercat.oisbn',
2593 { desc => <<" DESC",
2594 Returns the ISBN list for the metarecord of the requested isbn
2599 desc => 'An ISBN. Duh.',
2603 { desc => 'record to isbn map',
2608 package OpenILS::Application::SuperCat::unAPI;
2609 use base qw/OpenILS::Application::SuperCat/;
2612 die "dummy superclass, use a real class";
2618 return unless ($obj);
2620 $class = ref($class) || $class;
2622 if ($class eq __PACKAGE__) {
2623 return unless (ref($obj));
2624 $class .= '::' . $obj->json_hint;
2627 return bless { obj => $obj } => $class;
2632 return $self->{obj};
2635 package OpenILS::Application::SuperCat::unAPI::auri;
2636 use base qw/OpenILS::Application::SuperCat::unAPI/;
2642 my $xml = ' <uri xmlns="http://open-ils.org/spec/holdings/v1" ';
2643 $xml .= 'id="tag:open-ils.org:asset-uri/' . $self->obj->id . '" ';
2644 $xml .= 'use_restriction="' . $self->escape( $self->obj->use_restriction ) . '" ';
2645 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
2646 $xml .= 'href="' . $self->escape( $self->obj->href ) . '">';
2648 if (!$args->{no_volumes}) {
2649 if (ref($self->obj->call_number_maps) && @{ $self->obj->call_number_maps }) {
2650 $xml .= " <volumes>\n" . join(
2653 OpenILS::Application::SuperCat::unAPI
2654 ->new( $_->call_number )
2655 ->as_xml({ %$args, no_uris=>1, no_copies=>1 })
2656 } @{ $self->obj->call_number_maps }
2657 ) . " </volumes>\n";
2660 $xml .= " <volumes/>\n";
2664 $xml .= " </uri>\n";
2669 package OpenILS::Application::SuperCat::unAPI::acn;
2670 use base qw/OpenILS::Application::SuperCat::unAPI/;
2676 my $xml = ' <volume xmlns="http://open-ils.org/spec/holdings/v1" ';
2678 $xml .= 'id="tag:open-ils.org:asset-call_number/' . $self->obj->id . '" ';
2679 $xml .= 'lib="' . $self->escape( $self->obj->owning_lib->shortname ) . '" ';
2680 $xml .= 'opac_visible="' . $self->obj->owning_lib->opac_visible . '" ';
2681 $xml .= 'label="' . $self->escape( $self->obj->label ) . '">';
2684 if (!$args->{no_copies}) {
2685 if (ref($self->obj->copies) && @{ $self->obj->copies }) {
2686 $xml .= " <copies>\n" . join(
2689 OpenILS::Application::SuperCat::unAPI
2691 ->as_xml({ %$args, no_volume=>1 })
2692 } @{ $self->obj->copies }
2696 $xml .= " <copies/>\n";
2700 if (!$args->{no_uris}) {
2701 if (ref($self->obj->uri_maps) && @{ $self->obj->uri_maps }) {
2702 $xml .= " <uris>\n" . join(
2705 OpenILS::Application::SuperCat::unAPI
2707 ->as_xml({ %$args, no_volumes=>1 })
2708 } @{ $self->obj->uri_maps }
2712 $xml .= " <uris/>\n";
2717 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
2718 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
2719 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
2720 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
2723 unless ($args->{no_record}) {
2724 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
2726 my $r_doc = $parser->parse_string($self->obj->record->marc);
2727 $r_doc->documentElement->setAttribute( id => $rec_tag );
2728 $xml .= $U->entityize($r_doc->documentElement->toString);
2731 $xml .= " </volume>\n";
2736 package OpenILS::Application::SuperCat::unAPI::ssub;
2737 use base qw/OpenILS::Application::SuperCat::unAPI/;
2743 my $xml = ' <subscription xmlns="http://open-ils.org/spec/holdings/v1" ';
2745 $xml .= 'id="tag:open-ils.org:serial-subscription/' . $self->obj->id . '" ';
2746 $xml .= 'start="' . $self->escape( $self->obj->start_date ) . '" ';
2747 $xml .= 'end="' . $self->escape( $self->obj->end_date ) . '" ';
2748 $xml .= 'expected_date_offset="' . $self->escape( $self->obj->expected_date_offset ) . '">';
2751 if (!$args->{no_distributions}) {
2752 if (ref($self->obj->distributions) && @{ $self->obj->distributions }) {
2753 $xml .= " <distributions>\n" . join(
2756 OpenILS::Application::SuperCat::unAPI
2758 ->as_xml({ %$args, no_subscription=>1, no_issuance=>1 })
2759 } @{ $self->obj->distributions }
2760 ) . " </distributions>\n";
2763 $xml .= " <distributions/>\n";
2767 if (!$args->{no_captions_and_patterns}) {
2768 if (ref($self->obj->captions_and_patterns) && @{ $self->obj->captions_and_patterns }) {
2769 $xml .= " <captions_and_patterns>\n" . join(
2772 OpenILS::Application::SuperCat::unAPI
2774 ->as_xml({ %$args, no_subscription=>1 })
2775 } @{ $self->obj->captions_and_patterns }
2776 ) . " </captions_and_patterns>\n";
2779 $xml .= " <captions_and_patterns/>\n";
2783 if (!$args->{no_issuances}) {
2784 if (ref($self->obj->issuances) && @{ $self->obj->issuances }) {
2785 $xml .= " <issuances>\n" . join(
2788 OpenILS::Application::SuperCat::unAPI
2790 ->as_xml({ %$args, no_subscription=>1, no_items=>1 })
2791 } @{ $self->obj->issuances }
2792 ) . " </issuances>\n";
2795 $xml .= " <issuances/>\n";
2800 $xml .= ' <owning_lib xmlns="http://open-ils.org/spec/actors/v1" ';
2801 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
2802 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
2803 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
2806 unless ($args->{no_record}) {
2807 my $rec_tag = "tag:open-ils.org:biblio-record_entry/".$self->obj->record->id.'/'.$self->escape( $self->obj->owning_lib->shortname ) ;
2809 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
2810 $r_doc->documentElement->setAttribute( id => $rec_tag );
2811 $xml .= $U->entityize($r_doc->documentElement->toString);
2814 $xml .= " </subscription>\n";
2819 package OpenILS::Application::SuperCat::unAPI::sdist;
2820 use base qw/OpenILS::Application::SuperCat::unAPI/;
2826 my $xml = ' <distribution xmlns="http://open-ils.org/spec/holdings/v1" ';
2828 $xml .= 'id="tag:open-ils.org:serial-distribution/' . $self->obj->id . '" ';
2829 $xml .= 'label="' . $self->escape( $self->obj->label ) . '" ';
2830 $xml .= 'unit_label_base="' . $self->escape( $self->obj->unit_label_base ) . '" ';
2831 $xml .= 'unit_label_suffix="' . $self->escape( $self->obj->unit_label_suffix ) . '">';
2834 if (!$args->{no_distributions}) {
2835 if (ref($self->obj->distributions) && @{ $self->obj->distributions }) {
2836 $xml .= " <streams>\n" . join(
2839 OpenILS::Application::SuperCat::unAPI
2841 ->as_xml({ %$args, no_distribution=>1 })
2842 } @{ $self->obj->streams }
2843 ) . " </streams>\n";
2846 $xml .= " <streams/>\n";
2850 if (!$args->{no_summaries}) {
2851 $xml .= " <summaries>\n";
2852 if (ref($self->obj->bib_summaries) && @{ $self->obj->bib_summaries }) {
2855 OpenILS::Application::SuperCat::unAPI
2857 ->as_xml({ %$args, no_distribution=>1 })
2858 } ( @{ $self->obj->bib_summaries }, @{ $self->obj->sup_summaries }, @{ $self->obj->index_summaries } )
2862 $xml .= " </summaries>\n";
2866 $xml .= ' <holding_lib xmlns="http://open-ils.org/spec/actors/v1" ';
2867 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->owning_lib->id . '" ';
2868 $xml .= 'shortname="'.$self->escape( $self->obj->owning_lib->shortname ) .'" ';
2869 $xml .= 'name="'.$self->escape( $self->obj->owning_lib->name ) .'"/>';
2872 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_distributions=>1 }) if (!$args->{no_subscription});
2874 if (!$args->{no_record} && $self->obj->record_entry) {
2875 my $rec_tag = "tag:open-ils.org:serial-record_entry/".$self->obj->record->id ;
2877 my $r_doc = $parser->parse_string($self->obj->record_entry->marc);
2878 $r_doc->documentElement->setAttribute( id => $rec_tag );
2879 $xml .= $U->entityize($r_doc->documentElement->toString);
2882 $xml .= " </distribution>\n";
2887 package OpenILS::Application::SuperCat::unAPI::sstr;
2888 use base qw/OpenILS::Application::SuperCat::unAPI/;
2894 my $xml = ' <stream xmlns="http://open-ils.org/spec/holdings/v1" ';
2896 $xml .= 'id="tag:open-ils.org:serial-stream/' . $self->obj->id . '" ';
2897 $xml .= 'routing_label="' . $self->escape( $self->obj->routing_label ) . '">';
2900 if (!$args->{no_items}) {
2901 if (ref($self->obj->items) && @{ $self->obj->items }) {
2902 $xml .= " <items>\n" . join(
2905 OpenILS::Application::SuperCat::unAPI
2907 ->as_xml({ %$args, no_stream=>1 })
2908 } @{ $self->obj->items }
2912 $xml .= " <items/>\n";
2916 #XXX routing_list_user's?
2918 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->distribution )->as_xml({ %$args, no_streams=>1 }) if (!$args->{no_distribution});
2920 $xml .= " </stream>\n";
2925 package OpenILS::Application::SuperCat::unAPI::sitem;
2926 use base qw/OpenILS::Application::SuperCat::unAPI/;
2932 my $xml = ' <serial_item xmlns="http://open-ils.org/spec/holdings/v1" ';
2934 $xml .= 'id="tag:open-ils.org:serial-item/' . $self->obj->id . '" ';
2935 $xml .= 'date_expected="' . $self->escape( $self->obj->date_expected ) . '"';
2936 $xml .= ' date_received="' . $self->escape( $self->obj->date_received ) .'"'if ($self->obj->date_received);
2938 if ($args->{no_issuance}) {
2939 my $siss = ref($self->obj->issuance) ? $self->obj->issuance->id : $self->obj->issuance;
2940 $xml .= ' issuance="tag:open-ils.org:serial-issuance/' . $siss . '"';
2945 if (ref($self->obj->notes) && $self->obj->notes) {
2946 $xml .= " <notes>\n";
2947 for my $note ( @{$self->obj->notes} ) {
2948 next unless ( $note->pub eq 't' );
2949 $xml .= sprintf(' <note date="%s" title="%s">%s</note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
2952 $xml .= " </notes>\n";
2954 $xml .= " <notes/>\n";
2957 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->issuance )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_issuance});
2958 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->stream )->as_xml({ %$args, no_items=>1 }) if (!$args->{no_stream});
2959 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->unit )->as_xml({ %$args, no_items=>1, no_volumes=>1 }) if (!$args->{no_unit});
2960 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->uri )->as_xml({ %$args, no_items=>1, no_volumes=>1 }) if (!$args->{no_uri});
2962 $xml .= " </stream>\n";
2967 package OpenILS::Application::SuperCat::unAPI::sunit;
2968 use base qw/OpenILS::Application::SuperCat::unAPI/;
2974 my $xml = ' <serial_item xmlns="http://open-ils.org/spec/holdings/v1" '.
2975 'id="tag:open-ils.org:serial-unit/' . $self->obj->id . '" ';
2977 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
2978 create_date edit_date copy_number circulate deposit ref holdable deleted
2979 deposit_amount price barcode circ_modifier circ_as_type opac_visible
2980 status_changed_time floating mint_condition label label_sort_key contents
2985 $xml .= ' <status ident="' . $self->obj->status->id . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
2986 $xml .= ' <location ident="' . $self->obj->location->id . '">' . $self->escape( $self->obj->location->name ) . "</location>\n";
2987 $xml .= ' <circlib ident="' . $self->obj->circ_lib->id . '">' . $self->escape( $self->obj->circ_lib->name ) . "</circlib>\n";
2989 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
2990 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
2991 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
2992 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'"/>';
2995 $xml .= " <copy_notes>\n";
2996 if (ref($self->obj->notes) && $self->obj->notes) {
2997 for my $note ( @{$self->obj->notes} ) {
2998 next unless ( $note->pub eq 't' );
2999 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3004 $xml .= " </copy_notes>\n";
3005 $xml .= " <statcats>\n";
3007 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3008 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3009 next unless ( $sce->stat_cat->opac_visible eq 't' );
3010 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3014 $xml .= " </statcats>\n";
3016 unless ($args->{no_volume}) {
3017 if (ref($self->obj->call_number)) {
3018 $xml .= OpenILS::Application::SuperCat::unAPI
3019 ->new( $self->obj->call_number )
3020 ->as_xml({ %$args, no_copies=>1 });
3022 $xml .= " <volume/>\n";
3026 $xml .= " </serial_item>\n";
3031 package OpenILS::Application::SuperCat::unAPI::sercap;
3032 use base qw/OpenILS::Application::SuperCat::unAPI/;
3038 my $xml = ' <caption_and_pattern xmlns="http://open-ils.org/spec/holdings/v1" '.
3039 'id="tag:open-ils.org:serial-caption_and_pattern/' . $self->obj->id . '" ';
3041 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3042 create_time type active pattern_code enum_1 enum_2 enum_3 enum_4
3043 enum_5 enum_6 chron_1 chron_2 chron_3 chron_4 chron_5
3046 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_captions_and_patterns=>1 }) if (!$args->{no_subscription});
3047 $xml .= " </caption_and_pattern>\n";
3052 package OpenILS::Application::SuperCat::unAPI::siss;
3053 use base qw/OpenILS::Application::SuperCat::unAPI/;
3059 my $xml = ' <issuance xmlns="http://open-ils.org/spec/holdings/v1" '.
3060 'id="tag:open-ils.org:serial-issuance/' . $self->obj->id . '" ';
3062 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" '
3063 for (qw/create_date edit_date label date_published holding_code holding_type holding_link_id/);
3067 if (!$args->{no_items}) {
3068 if (ref($self->obj->items) && @{ $self->obj->items }) {
3069 $xml .= " <items>\n" . join(
3072 OpenILS::Application::SuperCat::unAPI
3074 ->as_xml({ %$args, no_stream=>1 })
3075 } @{ $self->obj->items }
3079 $xml .= " <items/>\n";
3083 $xml .= OpenILS::Application::SuperCat::unAPI->new( $self->obj->subscription )->as_xml({ %$args, no_issuances=>1 }) if (!$args->{no_subscription});
3084 $xml .= " </issuance>\n";
3089 package OpenILS::Application::SuperCat::unAPI::acp;
3090 use base qw/OpenILS::Application::SuperCat::unAPI/;
3096 my $xml = ' <copy xmlns="http://open-ils.org/spec/holdings/v1" '.
3097 'id="tag:open-ils.org:asset-copy/' . $self->obj->id . '" ';
3099 $xml .= $_ . '="' . $self->escape( $self->obj->$_ ) . '" ' for (qw/
3100 create_date edit_date copy_number circulate deposit ref holdable deleted
3101 deposit_amount price barcode circ_modifier circ_as_type opac_visible
3106 $xml .= ' <status ident="' . $self->obj->status->id . '">' . $self->escape( $self->obj->status->name ) . "</status>\n";
3107 $xml .= ' <location ident="' . $self->obj->location->id . '" opac_visible="'.$self->obj->location->opac_visible.'">' . $self->escape( $self->obj->location->name ) . "</location>\n";
3108 $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";
3110 $xml .= ' <circ_lib xmlns="http://open-ils.org/spec/actors/v1" ';
3111 $xml .= 'id="tag:open-ils.org:actor-org_unit/' . $self->obj->circ_lib->id . '" ';
3112 $xml .= 'shortname="'.$self->escape( $self->obj->circ_lib->shortname ) .'" ';
3113 $xml .= 'name="'.$self->escape( $self->obj->circ_lib->name ) .'" opac_visible="'.$self->obj->circ_lib->opac_visible.'"/>';
3116 $xml .= " <copy_notes>\n";
3117 if (ref($self->obj->notes) && $self->obj->notes) {
3118 for my $note ( @{$self->obj->notes} ) {
3119 next unless ( $note->pub eq 't' );
3120 $xml .= sprintf(' <copy_note date="%s" title="%s">%s</copy_note>',$note->create_date, $self->escape($note->title), $self->escape($note->value));
3125 $xml .= " </copy_notes>\n";
3126 $xml .= " <statcats>\n";
3128 if (ref($self->obj->stat_cat_entries) && $self->obj->stat_cat_entries) {
3129 for my $sce ( @{$self->obj->stat_cat_entries} ) {
3130 next unless ( $sce->stat_cat->opac_visible eq 't' );
3131 $xml .= sprintf(' <statcat name="%s">%s</statcat>',$self->escape($sce->stat_cat->name) ,$self->escape($sce->value));
3135 $xml .= " </statcats>\n";
3137 unless ($args->{no_volume}) {
3138 if (ref($self->obj->call_number)) {
3139 $xml .= OpenILS::Application::SuperCat::unAPI
3140 ->new( $self->obj->call_number )
3141 ->as_xml({ %$args, no_copies=>1 });
3143 $xml .= " <volume/>\n";
3147 $xml .= " </copy>\n";
3154 # vim: noet:ts=4:sw=4