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,
267 flesh_fields => { acn => [qw/record owning_lib/] },
268 order_by => { acn => "upper(label) desc, id desc, owning_lib desc" },
269 limit => $before_limit,
270 offset => abs($page) * $page_size - $before_offset,
273 push @list, reverse(@$before);
277 my $after = $_storage->request(
278 "open-ils.cstore.direct.asset.call_number.search.atomic",
279 { label => { ">=" => { transform => "upper", value => ["upper", $label] } },
280 owning_lib => \@ou_ids,
284 flesh_fields => { acn => [qw/record owning_lib/] },
285 order_by => { acn => "upper(label), id, owning_lib" },
286 limit => $after_limit,
287 offset => abs($page) * $page_size - $after_offset,
295 __PACKAGE__->register_method(
296 method => 'cn_browse',
297 api_name => 'open-ils.supercat.call_number.browse',
302 Returns the XML representation of the requested bibliographic record's holdings
307 desc => 'The target call number lable',
309 { name => 'org_unit',
310 desc => 'The org unit shortname (or "-" or undef for global) to browse',
312 { name => 'page_size',
313 desc => 'Count of call numbers to retrieve, default is 9',
316 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
320 { desc => 'Call numbers with owning_lib and record fleshed',
326 sub new_record_holdings {
332 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
334 my $tree = $_storage->request(
335 "open-ils.cstore.direct.biblio.record_entry.retrieve",
339 bre => [qw/call_numbers/],
340 acn => [qw/copies owning_lib/],
341 acp => [qw/location status circ_lib stat_cat_entries notes/],
342 asce => [qw/stat_cat/],
347 my $o_search = { shortname => uc($ou) };
348 if (!$ou || $ou eq '-') {
349 $o_search = { parent_ou => undef };
352 my $orgs = $_storage->request(
353 "open-ils.cstore.direct.actor.org_unit.search",
356 flesh_fields => { aou => [qw/children/] }
360 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
362 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
364 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
368 $client->respond("<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>");
370 for my $cn (@{$tree->call_numbers}) {
373 for my $c (@{$cn->copies}) {
374 next unless grep {$c->circ_lib->id == $_} @ou_ids;
380 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
381 $cn_class =~ s/Fieldmapper-//gso;
382 my $cn_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cn_class/".$cn->id, $month, $day);
384 my $cn_lib = $cn->owning_lib->shortname;
386 my $cn_label = $cn->label;
388 my $xml = "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'><hold:copies>";
390 for my $cp (@{$cn->copies}) {
392 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
394 (my $cp_class = $cp->class_name) =~ s/::/-/gso;
395 $cp_class =~ s/Fieldmapper-//gso;
396 my $cp_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cp_class/".$cp->id, $month, $day);
398 my $cp_stat = escape($cp->status->name);
399 my $cp_loc = escape($cp->location->name);
400 my $cp_lib = escape($cp->circ_lib->shortname);
401 my $cp_bc = escape($cp->barcode);
403 $xml .= "<hold:copy id='$cp_tag' barcode='$cp_bc'><hold:status>$cp_stat</hold:status>".
404 "<hold:location>$cp_loc</hold:location><hold:circlib>$cp_lib</hold:circlib><hold:copy_notes>";
407 for my $note ( @{$cp->notes} ) {
408 next unless ( $note->pub eq 't' );
409 $xml .= sprintf('<hold:copy_note date="%s" title="%s">%s</hold:copy_note>',$note->create_date, escape($note->title), escape($note->value));
413 $xml .= "</hold:copy_notes><hold:statcats>";
415 if ($cp->stat_cat_entries) {
416 for my $sce ( @{$cp->stat_cat_entries} ) {
417 next unless ( $sce->stat_cat->opac_visible eq 't' );
418 $xml .= sprintf('<hold:statcat name="%s">%s</hold:statcat>',escape($sce->stat_cat->name) ,escape($sce->value));
422 $xml .= "</hold:statcats></hold:copy>";
425 $xml .= "</hold:copies></hold:volume>";
427 $client->respond($xml)
430 return "</hold:volumes>";
432 __PACKAGE__->register_method(
433 method => 'new_record_holdings',
434 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
440 Returns the XML representation of the requested bibliographic record's holdings
445 desc => 'An OpenILS biblio::record_entry id',
449 { desc => 'Stream of bib record holdings hierarchy in XML',
459 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
461 my $recs = $_storage->request(
462 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
463 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
466 return undef unless (@$recs);
468 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
470 __PACKAGE__->register_method(
471 method => 'isbn_holdings',
472 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
477 Returns the XML representation of the requested bibliographic record's holdings
486 { desc => 'The bib record holdings hierarchy in XML',
493 $text =~ s/&/&/gsom;
494 $text =~ s/</</gsom;
495 $text =~ s/>/>/gsom;
496 $text =~ s/"/\\"/gsom;
503 my $when = shift || '1-01-01';
507 $type = 'authority' if ($self->api_name =~ /authority/o);
509 my $axis = 'create_date';
510 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
512 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
514 return $_storage->request(
515 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
516 { $axis => { ">" => $when }, id => { '>' => 0 } },
517 { order_by => { bre => "$axis desc" }, limit => $limit }
521 for my $t ( qw/biblio authority/ ) {
522 for my $a ( qw/import edit/ ) {
524 __PACKAGE__->register_method(
525 method => 'recent_changes',
526 api_name => "open-ils.supercat.$t.record.$a.recent",
530 { desc => "Returns a list of recently ${a}ed $t records",
534 desc => "Date to start looking for ${a}ed records",
535 default => '1-01-01',
539 desc => "Maximum count to retrieve",
543 { desc => "An id list of $t records",
551 sub retrieve_record_marcxml {
556 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
558 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
559 return entityize( $record->marc ) if ($record);
563 __PACKAGE__->register_method(
564 method => 'retrieve_record_marcxml',
565 api_name => 'open-ils.supercat.record.marcxml.retrieve',
570 Returns the MARCXML representation of the requested bibliographic record
575 desc => 'An OpenILS biblio::record_entry id',
579 { desc => 'The bib record in MARCXML',
584 sub retrieve_isbn_marcxml {
589 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
591 my $recs = $_storage->request(
592 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
593 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
596 return undef unless (@$recs);
598 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
599 return entityize( $record->marc ) if ($record);
603 __PACKAGE__->register_method(
604 method => 'retrieve_isbn_marcxml',
605 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
610 Returns the MARCXML representation of the requested ISBN
615 desc => 'An ... um ... ISBN',
619 { desc => 'The bib record in MARCXML',
624 sub retrieve_record_transform {
629 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
631 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
634 my $record = $_storage->request(
635 'open-ils.cstore.direct.biblio.record_entry.retrieve',
639 return undef unless ($record);
641 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
644 sub retrieve_isbn_transform {
649 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
651 my $recs = $_storage->request(
652 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
653 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
656 return undef unless (@$recs);
658 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
660 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
662 return undef unless ($record);
664 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
667 sub retrieve_record_objects {
672 $ids = [$ids] unless (ref $ids);
673 $ids = [grep {$_} @$ids];
675 return [] unless (@$ids);
677 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
678 return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
680 __PACKAGE__->register_method(
681 method => 'retrieve_record_objects',
682 api_name => 'open-ils.supercat.record.object.retrieve',
687 Returns the Fieldmapper object representation of the requested bibliographic records
692 desc => 'OpenILS biblio::record_entry ids',
696 { desc => 'The bib records',
702 sub retrieve_isbn_object {
707 return undef unless ($isbn);
709 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
710 my $recs = $_storage->request(
711 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
712 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
715 return undef unless (@$recs);
717 return $_storage->request(
718 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
719 { id => $recs->[0]->record }
722 __PACKAGE__->register_method(
723 method => 'retrieve_isbn_object',
724 api_name => 'open-ils.supercat.isbn.object.retrieve',
729 Returns the Fieldmapper object representation of the requested bibliographic record
738 { desc => 'The bib record',
745 sub retrieve_metarecord_mods {
750 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
752 # Get the metarecord in question
755 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
758 # Now get the map of all bib records for the metarecord
761 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
765 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
767 # and retrieve the lead (master) record as MODS
769 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
770 ->run($mr->master_record);
771 my $master_mods = $_parser->parse_string($master)->documentElement;
772 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
774 # ... and a MODS clone to populate, with guts removed.
775 my $mods = $_parser->parse_string($master)->documentElement;
776 $mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
777 ($mods) = $mods->findnodes('//mods:mods');
778 $mods->removeChildNodes;
780 # Add the metarecord ID as a (locally defined) info URI
781 my $recordInfo = $mods
783 ->createElement("mods:recordInfo");
785 my $recordIdentifier = $mods
787 ->createElement("mods:recordIdentifier");
789 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
794 $recordIdentifier->appendTextNode(
795 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
798 $recordInfo->appendChild($recordIdentifier);
799 $mods->appendChild($recordInfo);
801 # Grab the title, author and ISBN for the master record and populate the metarecord
802 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
805 $title->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
806 $title = $mods->ownerDocument->importNode($title);
807 $mods->appendChild($title);
810 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
812 $author->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
813 $author = $mods->ownerDocument->importNode($author);
814 $mods->appendChild($author);
817 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
819 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
820 $isbn = $mods->ownerDocument->importNode($isbn);
821 $mods->appendChild($isbn);
824 # ... and loop over the constituent records
825 for my $map ( @$recs ) {
829 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
832 my $part_mods = $_parser->parse_string($rec);
833 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
834 ($part_mods) = $part_mods->findnodes('//mods:mods');
836 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
837 $node->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
838 $node = $mods->ownerDocument->importNode($node);
839 $mods->appendChild( $node );
842 my $relatedItem = $mods
844 ->createElement("mods:relatedItem");
846 $relatedItem->setAttribute( type => 'constituent' );
848 my $identifier = $mods
850 ->createElement("mods:identifier");
852 $identifier->setAttribute( type => 'uri' );
854 my $subRecordInfo = $mods
856 ->createElement("mods:recordInfo");
858 my $subRecordIdentifier = $mods
860 ->createElement("mods:recordIdentifier");
862 my $subid = $map->source;
863 $subRecordIdentifier->appendTextNode(
864 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
869 $subRecordInfo->appendChild($subRecordIdentifier);
871 $relatedItem->appendChild( $subRecordInfo );
873 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
874 $tor->setNamespace( "http://www.loc.gov/mods/", "mods", 1 ) if ($tor);
875 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
876 $relatedItem->appendChild($tor) if ($tor);
878 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
879 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
880 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
881 $relatedItem->appendChild( $part_isbn );
884 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
888 $mods->appendChild( $relatedItem );
892 $_storage->disconnect;
894 return entityize($mods->toString);
897 __PACKAGE__->register_method(
898 method => 'retrieve_metarecord_mods',
899 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
904 Returns the MODS representation of the requested metarecord
908 { name => 'metarecordId',
909 desc => 'An OpenILS metabib::metarecord id',
913 { desc => 'The metarecord in MODS',
918 sub list_metarecord_formats {
921 { namespace_uri => 'http://www.loc.gov/mods/',
922 docs => 'http://www.loc.gov/mods/',
923 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
928 for my $type ( keys %metarecord_xslt ) {
931 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
932 docs => $metarecord_xslt{$type}{docs},
933 schema_location => $metarecord_xslt{$type}{schema_location},
940 __PACKAGE__->register_method(
941 method => 'list_metarecord_formats',
942 api_name => 'open-ils.supercat.metarecord.formats',
947 Returns the list of valid metarecord formats that supercat understands.
950 { desc => 'The format list',
956 sub list_record_formats {
959 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
960 docs => 'http://www.loc.gov/marcxml/',
961 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
966 for my $type ( keys %record_xslt ) {
969 { namespace_uri => $record_xslt{$type}{namespace_uri},
970 docs => $record_xslt{$type}{docs},
971 schema_location => $record_xslt{$type}{schema_location},
978 __PACKAGE__->register_method(
979 method => 'list_record_formats',
980 api_name => 'open-ils.supercat.record.formats',
985 Returns the list of valid record formats that supercat understands.
988 { desc => 'The format list',
992 __PACKAGE__->register_method(
993 method => 'list_record_formats',
994 api_name => 'open-ils.supercat.isbn.formats',
999 Returns the list of valid record formats that supercat understands.
1002 { desc => 'The format list',
1015 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
1016 unless (length($isbn) >= 10);
1018 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1020 # Create a storage session, since we'll be making muliple requests.
1023 # Find the record that has that ISBN.
1024 my $bibrec = $_storage->request(
1025 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
1026 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
1029 # Go away if we don't have one.
1030 return {} unless (@$bibrec);
1032 # Find the metarecord for that bib record.
1033 my $mr = $_storage->request(
1034 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1035 {source => $bibrec->[0]->record}
1038 # Find the other records for that metarecord.
1039 my $records = $_storage->request(
1040 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1041 {metarecord => $mr->[0]->metarecord}
1044 # Just to be safe. There's currently no unique constraint on sources...
1045 my %unique_recs = map { ($_->source, 1) } @$records;
1046 my @rec_list = sort keys %unique_recs;
1048 # And now fetch the ISBNs for thos records.
1052 'open-ils.cstore.direct.metabib.full_rec.search',
1053 { tag => '020', subfield => 'a', record => $_ }
1054 )->gather(1) for (@rec_list);
1056 # We're done with the storage server session.
1057 $_storage->disconnect;
1059 # Return the oISBN data structure. This will be XMLized at a higher layer.
1061 { metarecord => $mr->[0]->metarecord,
1062 record_list => { map { $_ ? ($_->record, $_->value) : () } @$recs } };
1065 __PACKAGE__->register_method(
1067 api_name => 'open-ils.supercat.oisbn',
1071 { desc => <<" DESC",
1072 Returns the ISBN list for the metarecord of the requested isbn
1077 desc => 'An ISBN. Duh.',
1081 { desc => 'record to isbn map',