1 package OpenILS::Application::SuperCat;
6 # All OpenSRF applications must be based on OpenSRF::Application or
7 # a subclass thereof. Makes sense, eh?
8 use OpenILS::Application;
9 use base qw/OpenILS::Application/;
11 # This is the client class, used for connecting to open-ils.storage
12 use OpenSRF::AppSession;
14 # This is an extention of Error.pm that supplies some error types to throw
15 use OpenSRF::EX qw(:try);
17 # This is a helper class for querying the OpenSRF Settings application ...
18 use OpenSRF::Utils::SettingsClient;
20 # ... and here we have the built in logging helper ...
21 use OpenSRF::Utils::Logger qw($logger);
23 # ... and this is our OpenILS object (en|de)coder and psuedo-ORM package.
24 use OpenILS::Utils::Fieldmapper;
27 # We'll be working with XML, so...
30 use Unicode::Normalize;
32 use OpenSRF::Utils::JSON;
43 # we need an XML parser
44 $_parser = new XML::LibXML;
47 $_xslt = new XML::LibXSLT;
49 # parse the MODS xslt ...
50 my $mods32_xslt = $_parser->parse_file(
51 OpenSRF::Utils::SettingsClient
53 ->config_value( dirs => 'xsl' ).
54 "/MARC21slim2MODS32.xsl"
56 # and stash a transformer
57 $record_xslt{mods32}{xslt} = $_xslt->parse_stylesheet( $mods32_xslt );
58 $record_xslt{mods32}{namespace_uri} = 'http://www.loc.gov/mods/v3';
59 $record_xslt{mods32}{docs} = 'http://www.loc.gov/mods/';
60 $record_xslt{mods32}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-2.xsd';
62 # parse the MODS xslt ...
63 my $mods3_xslt = $_parser->parse_file(
64 OpenSRF::Utils::SettingsClient
66 ->config_value( dirs => 'xsl' ).
67 "/MARC21slim2MODS3.xsl"
69 # and stash a transformer
70 $record_xslt{mods3}{xslt} = $_xslt->parse_stylesheet( $mods3_xslt );
71 $record_xslt{mods3}{namespace_uri} = 'http://www.loc.gov/mods/v3';
72 $record_xslt{mods3}{docs} = 'http://www.loc.gov/mods/';
73 $record_xslt{mods3}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-1.xsd';
75 # parse the MODS xslt ...
76 my $mods_xslt = $_parser->parse_file(
77 OpenSRF::Utils::SettingsClient
79 ->config_value( dirs => 'xsl' ).
80 "/MARC21slim2MODS.xsl"
82 # and stash a transformer
83 $record_xslt{mods}{xslt} = $_xslt->parse_stylesheet( $mods_xslt );
84 $record_xslt{mods}{namespace_uri} = 'http://www.loc.gov/mods/';
85 $record_xslt{mods}{docs} = 'http://www.loc.gov/mods/';
86 $record_xslt{mods}{schema_location} = 'http://www.loc.gov/standards/mods/mods.xsd';
88 # parse the ATOM entry xslt ...
89 my $atom_xslt = $_parser->parse_file(
90 OpenSRF::Utils::SettingsClient
92 ->config_value( dirs => 'xsl' ).
93 "/MARC21slim2ATOM.xsl"
95 # and stash a transformer
96 $record_xslt{atom}{xslt} = $_xslt->parse_stylesheet( $atom_xslt );
97 $record_xslt{atom}{namespace_uri} = 'http://www.w3.org/2005/Atom';
98 $record_xslt{atom}{docs} = 'http://www.ietf.org/rfc/rfc4287.txt';
100 # parse the RDFDC xslt ...
101 my $rdf_dc_xslt = $_parser->parse_file(
102 OpenSRF::Utils::SettingsClient
104 ->config_value( dirs => 'xsl' ).
105 "/MARC21slim2RDFDC.xsl"
107 # and stash a transformer
108 $record_xslt{rdf_dc}{xslt} = $_xslt->parse_stylesheet( $rdf_dc_xslt );
109 $record_xslt{rdf_dc}{namespace_uri} = 'http://purl.org/dc/elements/1.1/';
110 $record_xslt{rdf_dc}{schema_location} = 'http://purl.org/dc/elements/1.1/';
112 # parse the SRWDC xslt ...
113 my $srw_dc_xslt = $_parser->parse_file(
114 OpenSRF::Utils::SettingsClient
116 ->config_value( dirs => 'xsl' ).
117 "/MARC21slim2SRWDC.xsl"
119 # and stash a transformer
120 $record_xslt{srw_dc}{xslt} = $_xslt->parse_stylesheet( $srw_dc_xslt );
121 $record_xslt{srw_dc}{namespace_uri} = 'info:srw/schema/1/dc-schema';
122 $record_xslt{srw_dc}{schema_location} = 'http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd';
124 # parse the OAIDC xslt ...
125 my $oai_dc_xslt = $_parser->parse_file(
126 OpenSRF::Utils::SettingsClient
128 ->config_value( dirs => 'xsl' ).
129 "/MARC21slim2OAIDC.xsl"
131 # and stash a transformer
132 $record_xslt{oai_dc}{xslt} = $_xslt->parse_stylesheet( $oai_dc_xslt );
133 $record_xslt{oai_dc}{namespace_uri} = 'http://www.openarchives.org/OAI/2.0/oai_dc/';
134 $record_xslt{oai_dc}{schema_location} = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd';
136 # parse the RSS xslt ...
137 my $rss_xslt = $_parser->parse_file(
138 OpenSRF::Utils::SettingsClient
140 ->config_value( dirs => 'xsl' ).
141 "/MARC21slim2RSS2.xsl"
143 # and stash a transformer
144 $record_xslt{rss2}{xslt} = $_xslt->parse_stylesheet( $rss_xslt );
146 register_record_transforms();
151 sub register_record_transforms {
152 for my $type ( keys %record_xslt ) {
153 __PACKAGE__->register_method(
154 method => 'retrieve_record_transform',
155 api_name => "open-ils.supercat.record.$type.retrieve",
159 { desc => "Returns the \U$type\E representation ".
160 "of the requested bibliographic record",
164 desc => 'An OpenILS biblio::record_entry id',
168 { desc => "The bib record in \U$type\E",
173 __PACKAGE__->register_method(
174 method => 'retrieve_isbn_transform',
175 api_name => "open-ils.supercat.isbn.$type.retrieve",
179 { desc => "Returns the \U$type\E representation ".
180 "of the requested bibliographic record",
188 { desc => "The bib record in \U$type\E",
197 my $stuff = NFC(shift());
198 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
207 return unless ($tree && ref($tree->$field));
209 my @things = $filter->($tree);
210 for my $v ( @{$tree->$field} ){
211 push @things, $filter->($v);
212 push @things, tree_walker($v, $field, $filter);
223 my $page_size = shift || 9;
224 my $page = shift || 0;
226 my ($before_limit,$after_limit) = (0,0);
227 my ($before_offset,$after_offset) = (0,0);
230 $before_limit = $after_limit = int($page_size / 2);
231 $after_limit += 1 if ($page_size % 2);
233 $before_offset = $after_offset = int($page_size / 2);
234 $before_offset += 1 if ($page_size % 2);
235 $before_limit = $after_limit = $page_size;
238 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
240 my $o_search = { shortname => $ou };
241 if (!$ou || $ou eq '-') {
242 $o_search = { parent_ou => undef };
245 my $orgs = $_storage->request(
246 "open-ils.cstore.direct.actor.org_unit.search",
249 flesh_fields => { aou => [qw/children/] }
253 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
255 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
260 my $before = $_storage->request(
261 "open-ils.cstore.direct.asset.call_number.search.atomic",
262 { label => { "<" => { transform => "upper", value => ["upper", $label] } },
263 owning_lib => \@ou_ids,
266 flesh_fields => { acn => [qw/record owning_lib/] },
267 order_by => { acn => "upper(label) desc, id desc, owning_lib desc" },
268 limit => $before_limit,
269 offset => abs($page) * $page_size - $before_offset,
272 push @list, reverse(@$before);
276 my $after = $_storage->request(
277 "open-ils.cstore.direct.asset.call_number.search.atomic",
278 { label => { ">=" => { transform => "upper", value => ["upper", $label] } },
279 owning_lib => \@ou_ids,
282 flesh_fields => { acn => [qw/record owning_lib/] },
283 order_by => { acn => "upper(label), id, owning_lib" },
284 limit => $after_limit,
285 offset => abs($page) * $page_size - $after_offset,
293 __PACKAGE__->register_method(
294 method => 'cn_browse',
295 api_name => 'open-ils.supercat.call_number.browse',
300 Returns the XML representation of the requested bibliographic record's holdings
305 desc => 'The target call number lable',
307 { name => 'org_unit',
308 desc => 'The org unit shortname (or "-" or undef for global) to browse',
310 { name => 'page_size',
311 desc => 'Count of call numbers to retrieve, default is 9',
314 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
318 { desc => 'Call numbers with owning_lib and record fleshed',
324 sub new_record_holdings {
330 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
332 my $tree = $_storage->request(
333 "open-ils.cstore.direct.biblio.record_entry.retrieve",
337 bre => [qw/call_numbers/],
338 acn => [qw/copies owning_lib/],
339 acp => [qw/location status circ_lib stat_cat_entries notes/],
340 asce => [qw/stat_cat/],
345 my $o_search = { shortname => uc($ou) };
346 if (!$ou || $ou eq '-') {
347 $o_search = { parent_ou => undef };
350 my $orgs = $_storage->request(
351 "open-ils.cstore.direct.actor.org_unit.search",
354 flesh_fields => { aou => [qw/children/] }
358 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
360 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
362 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
366 $client->respond("<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>");
368 for my $cn (@{$tree->call_numbers}) {
371 for my $c (@{$cn->copies}) {
372 next unless grep {$c->circ_lib->id == $_} @ou_ids;
378 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
379 $cn_class =~ s/Fieldmapper-//gso;
380 my $cn_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cn_class/".$cn->id, $month, $day);
382 my $cn_lib = $cn->owning_lib->shortname;
384 my $cn_label = $cn->label;
386 my $xml = "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'><hold:copies>";
388 for my $cp (@{$cn->copies}) {
390 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
392 (my $cp_class = $cp->class_name) =~ s/::/-/gso;
393 $cp_class =~ s/Fieldmapper-//gso;
394 my $cp_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cp_class/".$cp->id, $month, $day);
396 my $cp_stat = escape($cp->status->name);
397 my $cp_loc = escape($cp->location->name);
398 my $cp_lib = escape($cp->circ_lib->shortname);
399 my $cp_bc = escape($cp->barcode);
401 $xml .= "<hold:copy id='$cp_tag' barcode='$cp_bc'><hold:status>$cp_stat</hold:status>".
402 "<hold:location>$cp_loc</hold:location><hold:circlib>$cp_lib</hold:circlib><hold:copy_notes>";
405 for my $note ( @{$cp->notes} ) {
406 next unless ( $note->pub eq 't' );
407 $xml .= sprintf('<hold:copy_note date="%s" title="%s">%s</hold:copy_note>',$note->create_date, escape($note->title), escape($note->value));
411 $xml .= "</hold:copy_notes><hold:statcats>";
413 if ($cp->stat_cat_entries) {
414 for my $sce ( @{$cp->stat_cat_entries} ) {
415 next unless ( $sce->stat_cat->opac_visible eq 't' );
416 $xml .= sprintf('<hold:statcat name="%s">%s</hold:statcat>',escape($sce->stat_cat->name) ,escape($sce->value));
420 $xml .= "</hold:statcats></hold:copy>";
423 $xml .= "</hold:copies></hold:volume>";
425 $client->respond($xml)
428 return "</hold:volumes>";
430 __PACKAGE__->register_method(
431 method => 'new_record_holdings',
432 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
438 Returns the XML representation of the requested bibliographic record's holdings
443 desc => 'An OpenILS biblio::record_entry id',
447 { desc => 'Stream of bib record holdings hierarchy in XML',
457 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
459 my $recs = $_storage->request(
460 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
461 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
464 return undef unless (@$recs);
466 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
468 __PACKAGE__->register_method(
469 method => 'isbn_holdings',
470 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
475 Returns the XML representation of the requested bibliographic record's holdings
484 { desc => 'The bib record holdings hierarchy in XML',
491 $text =~ s/&/&/gsom;
492 $text =~ s/</</gsom;
493 $text =~ s/>/>/gsom;
494 $text =~ s/"/\\"/gsom;
501 my $when = shift || '1-01-01';
505 $type = 'authority' if ($self->api_name =~ /authority/o);
507 my $axis = 'create_date';
508 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
510 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
512 return $_storage->request(
513 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
514 { $axis => { ">" => $when }, id => { '>' => 0 } },
515 { order_by => { bre => "$axis desc" }, limit => $limit }
519 for my $t ( qw/biblio authority/ ) {
520 for my $a ( qw/import edit/ ) {
522 __PACKAGE__->register_method(
523 method => 'recent_changes',
524 api_name => "open-ils.supercat.$t.record.$a.recent",
528 { desc => "Returns a list of recently ${a}ed $t records",
532 desc => "Date to start looking for ${a}ed records",
533 default => '1-01-01',
537 desc => "Maximum count to retrieve",
541 { desc => "An id list of $t records",
549 sub retrieve_record_marcxml {
554 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
556 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
557 return entityize( $record->marc ) if ($record);
561 __PACKAGE__->register_method(
562 method => 'retrieve_record_marcxml',
563 api_name => 'open-ils.supercat.record.marcxml.retrieve',
568 Returns the MARCXML representation of the requested bibliographic record
573 desc => 'An OpenILS biblio::record_entry id',
577 { desc => 'The bib record in MARCXML',
582 sub retrieve_isbn_marcxml {
587 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
589 my $recs = $_storage->request(
590 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
591 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
594 return undef unless (@$recs);
596 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
597 return entityize( $record->marc ) if ($record);
601 __PACKAGE__->register_method(
602 method => 'retrieve_isbn_marcxml',
603 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
608 Returns the MARCXML representation of the requested ISBN
613 desc => 'An ... um ... ISBN',
617 { desc => 'The bib record in MARCXML',
622 sub retrieve_record_transform {
627 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
629 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
632 my $record = $_storage->request(
633 'open-ils.cstore.direct.biblio.record_entry.retrieve',
637 return undef unless ($record);
639 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
642 sub retrieve_isbn_transform {
647 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
649 my $recs = $_storage->request(
650 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
651 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
654 return undef unless (@$recs);
656 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
658 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
660 return undef unless ($record);
662 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
665 sub retrieve_record_objects {
670 $ids = [$ids] unless (ref $ids);
671 $ids = [grep {$_} @$ids];
673 return [] unless (@$ids);
675 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
676 return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
678 __PACKAGE__->register_method(
679 method => 'retrieve_record_objects',
680 api_name => 'open-ils.supercat.record.object.retrieve',
685 Returns the Fieldmapper object representation of the requested bibliographic records
690 desc => 'OpenILS biblio::record_entry ids',
694 { desc => 'The bib records',
700 sub retrieve_isbn_object {
705 return undef unless ($isbn);
707 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
708 my $recs = $_storage->request(
709 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
710 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
713 return undef unless (@$recs);
715 return $_storage->request(
716 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
717 { id => $recs->[0]->record }
720 __PACKAGE__->register_method(
721 method => 'retrieve_isbn_object',
722 api_name => 'open-ils.supercat.isbn.object.retrieve',
727 Returns the Fieldmapper object representation of the requested bibliographic record
736 { desc => 'The bib record',
743 sub retrieve_metarecord_mods {
748 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
750 # Get the metarecord in question
753 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
756 # Now get the map of all bib records for the metarecord
759 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
763 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
765 # and retrieve the lead (master) record as MODS
767 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
768 ->run($mr->master_record);
769 my $master_mods = $_parser->parse_string($master)->documentElement;
770 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
772 # ... and a MODS clone to populate, with guts removed.
773 my $mods = $_parser->parse_string($master)->documentElement;
774 $mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
775 ($mods) = $mods->findnodes('//mods:mods');
776 $mods->removeChildNodes;
778 # Add the metarecord ID as a (locally defined) info URI
779 my $recordInfo = $mods
781 ->createElement("mods:recordInfo");
783 my $recordIdentifier = $mods
785 ->createElement("mods:recordIdentifier");
787 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
792 $recordIdentifier->appendTextNode(
793 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
796 $recordInfo->appendChild($recordIdentifier);
797 $mods->appendChild($recordInfo);
799 # Grab the title, author and ISBN for the master record and populate the metarecord
800 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
803 $title->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
804 $title = $mods->ownerDocument->importNode($title);
805 $mods->appendChild($title);
808 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
810 $author->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
811 $author = $mods->ownerDocument->importNode($author);
812 $mods->appendChild($author);
815 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
817 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
818 $isbn = $mods->ownerDocument->importNode($isbn);
819 $mods->appendChild($isbn);
822 # ... and loop over the constituent records
823 for my $map ( @$recs ) {
827 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
830 my $part_mods = $_parser->parse_string($rec);
831 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
832 ($part_mods) = $part_mods->findnodes('//mods:mods');
834 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
835 $node->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
836 $node = $mods->ownerDocument->importNode($node);
837 $mods->appendChild( $node );
840 my $relatedItem = $mods
842 ->createElement("mods:relatedItem");
844 $relatedItem->setAttribute( type => 'constituent' );
846 my $identifier = $mods
848 ->createElement("mods:identifier");
850 $identifier->setAttribute( type => 'uri' );
852 my $subRecordInfo = $mods
854 ->createElement("mods:recordInfo");
856 my $subRecordIdentifier = $mods
858 ->createElement("mods:recordIdentifier");
860 my $subid = $map->source;
861 $subRecordIdentifier->appendTextNode(
862 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
867 $subRecordInfo->appendChild($subRecordIdentifier);
869 $relatedItem->appendChild( $subRecordInfo );
871 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
872 $tor->setNamespace( "http://www.loc.gov/mods/", "mods", 1 ) if ($tor);
873 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
874 $relatedItem->appendChild($tor) if ($tor);
876 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
877 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
878 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
879 $relatedItem->appendChild( $part_isbn );
882 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
886 $mods->appendChild( $relatedItem );
890 $_storage->disconnect;
892 return entityize($mods->toString);
895 __PACKAGE__->register_method(
896 method => 'retrieve_metarecord_mods',
897 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
902 Returns the MODS representation of the requested metarecord
906 { name => 'metarecordId',
907 desc => 'An OpenILS metabib::metarecord id',
911 { desc => 'The metarecord in MODS',
916 sub list_metarecord_formats {
919 { namespace_uri => 'http://www.loc.gov/mods/',
920 docs => 'http://www.loc.gov/mods/',
921 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
926 for my $type ( keys %metarecord_xslt ) {
929 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
930 docs => $metarecord_xslt{$type}{docs},
931 schema_location => $metarecord_xslt{$type}{schema_location},
938 __PACKAGE__->register_method(
939 method => 'list_metarecord_formats',
940 api_name => 'open-ils.supercat.metarecord.formats',
945 Returns the list of valid metarecord formats that supercat understands.
948 { desc => 'The format list',
954 sub list_record_formats {
957 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
958 docs => 'http://www.loc.gov/marcxml/',
959 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
964 for my $type ( keys %record_xslt ) {
967 { namespace_uri => $record_xslt{$type}{namespace_uri},
968 docs => $record_xslt{$type}{docs},
969 schema_location => $record_xslt{$type}{schema_location},
976 __PACKAGE__->register_method(
977 method => 'list_record_formats',
978 api_name => 'open-ils.supercat.record.formats',
983 Returns the list of valid record formats that supercat understands.
986 { desc => 'The format list',
990 __PACKAGE__->register_method(
991 method => 'list_record_formats',
992 api_name => 'open-ils.supercat.isbn.formats',
997 Returns the list of valid record formats that supercat understands.
1000 { desc => 'The format list',
1013 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
1014 unless (length($isbn) >= 10);
1016 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1018 # Create a storage session, since we'll be making muliple requests.
1021 # Find the record that has that ISBN.
1022 my $bibrec = $_storage->request(
1023 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
1024 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
1027 # Go away if we don't have one.
1028 return {} unless (@$bibrec);
1030 # Find the metarecord for that bib record.
1031 my $mr = $_storage->request(
1032 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1033 {source => $bibrec->[0]->record}
1036 # Find the other records for that metarecord.
1037 my $records = $_storage->request(
1038 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1039 {metarecord => $mr->[0]->metarecord}
1042 # Just to be safe. There's currently no unique constraint on sources...
1043 my %unique_recs = map { ($_->source, 1) } @$records;
1044 my @rec_list = sort keys %unique_recs;
1046 # And now fetch the ISBNs for thos records.
1050 'open-ils.cstore.direct.metabib.full_rec.search',
1051 { tag => '020', subfield => 'a', record => $_ }
1052 )->gather(1) for (@rec_list);
1054 # We're done with the storage server session.
1055 $_storage->disconnect;
1057 # Return the oISBN data structure. This will be XMLized at a higher layer.
1059 { metarecord => $mr->[0]->metarecord,
1060 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
1063 __PACKAGE__->register_method(
1065 api_name => 'open-ils.supercat.oisbn',
1069 { desc => <<" DESC",
1070 Returns the ISBN list for the metarecord of the requested isbn
1075 desc => 'An ISBN. Duh.',
1079 { desc => 'record to isbn map',