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 OpenSRF::Application;
9 use base qw/OpenSRF::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;
43 # we need an XML parser
44 $_parser = new XML::LibXML;
47 $_xslt = new XML::LibXSLT;
49 # parse the MODS xslt ...
50 my $mods3_xslt = $_parser->parse_file(
51 OpenSRF::Utils::SettingsClient
53 ->config_value( dirs => 'xsl' ).
54 "/MARC21slim2MODS3.xsl"
56 # and stash a transformer
57 $record_xslt{mods3}{xslt} = $_xslt->parse_stylesheet( $mods3_xslt );
58 $record_xslt{mods3}{namespace_uri} = 'http://www.loc.gov/mods/v3';
59 $record_xslt{mods3}{docs} = 'http://www.loc.gov/mods/';
60 $record_xslt{mods3}{schema_location} = 'http://www.loc.gov/standards/mods/v3/mods-3-1.xsd';
62 # parse the MODS xslt ...
63 my $mods_xslt = $_parser->parse_file(
64 OpenSRF::Utils::SettingsClient
66 ->config_value( dirs => 'xsl' ).
67 "/MARC21slim2MODS.xsl"
69 # and stash a transformer
70 $record_xslt{mods}{xslt} = $_xslt->parse_stylesheet( $mods_xslt );
71 $record_xslt{mods}{namespace_uri} = 'http://www.loc.gov/mods/';
72 $record_xslt{mods}{docs} = 'http://www.loc.gov/mods/';
73 $record_xslt{mods}{schema_location} = 'http://www.loc.gov/standards/mods/mods.xsd';
75 # parse the ATOM entry xslt ...
76 my $atom_xslt = $_parser->parse_file(
77 OpenSRF::Utils::SettingsClient
79 ->config_value( dirs => 'xsl' ).
80 "/MARC21slim2ATOM.xsl"
82 # and stash a transformer
83 $record_xslt{atom}{xslt} = $_xslt->parse_stylesheet( $atom_xslt );
84 $record_xslt{atom}{namespace_uri} = 'http://www.w3.org/2005/Atom';
85 $record_xslt{atom}{docs} = 'http://www.ietf.org/rfc/rfc4287.txt';
87 # parse the RDFDC xslt ...
88 my $rdf_dc_xslt = $_parser->parse_file(
89 OpenSRF::Utils::SettingsClient
91 ->config_value( dirs => 'xsl' ).
92 "/MARC21slim2RDFDC.xsl"
94 # and stash a transformer
95 $record_xslt{rdf_dc}{xslt} = $_xslt->parse_stylesheet( $rdf_dc_xslt );
96 $record_xslt{rdf_dc}{namespace_uri} = 'http://purl.org/dc/elements/1.1/';
97 $record_xslt{rdf_dc}{schema_location} = 'http://purl.org/dc/elements/1.1/';
99 # parse the SRWDC xslt ...
100 my $srw_dc_xslt = $_parser->parse_file(
101 OpenSRF::Utils::SettingsClient
103 ->config_value( dirs => 'xsl' ).
104 "/MARC21slim2SRWDC.xsl"
106 # and stash a transformer
107 $record_xslt{srw_dc}{xslt} = $_xslt->parse_stylesheet( $srw_dc_xslt );
108 $record_xslt{srw_dc}{namespace_uri} = 'info:srw/schema/1/dc-schema';
109 $record_xslt{srw_dc}{schema_location} = 'http://www.loc.gov/z3950/agency/zing/srw/dc-schema.xsd';
111 # parse the OAIDC xslt ...
112 my $oai_dc_xslt = $_parser->parse_file(
113 OpenSRF::Utils::SettingsClient
115 ->config_value( dirs => 'xsl' ).
116 "/MARC21slim2OAIDC.xsl"
118 # and stash a transformer
119 $record_xslt{oai_dc}{xslt} = $_xslt->parse_stylesheet( $oai_dc_xslt );
120 $record_xslt{oai_dc}{namespace_uri} = 'http://www.openarchives.org/OAI/2.0/oai_dc/';
121 $record_xslt{oai_dc}{schema_location} = 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd';
123 # parse the RSS xslt ...
124 my $rss_xslt = $_parser->parse_file(
125 OpenSRF::Utils::SettingsClient
127 ->config_value( dirs => 'xsl' ).
128 "/MARC21slim2RSS2.xsl"
130 # and stash a transformer
131 $record_xslt{rss2}{xslt} = $_xslt->parse_stylesheet( $rss_xslt );
133 register_record_transforms();
138 sub register_record_transforms {
139 for my $type ( keys %record_xslt ) {
140 __PACKAGE__->register_method(
141 method => 'retrieve_record_transform',
142 api_name => "open-ils.supercat.record.$type.retrieve",
146 { desc => "Returns the \U$type\E representation ".
147 "of the requested bibliographic record",
151 desc => 'An OpenILS biblio::record_entry id',
155 { desc => "The bib record in \U$type\E",
160 __PACKAGE__->register_method(
161 method => 'retrieve_isbn_transform',
162 api_name => "open-ils.supercat.isbn.$type.retrieve",
166 { desc => "Returns the \U$type\E representation ".
167 "of the requested bibliographic record",
175 { desc => "The bib record in \U$type\E",
184 my $stuff = NFC(shift());
185 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
194 return unless ($tree && ref($tree->$field));
196 my @things = $filter->($tree);
197 for my $v ( @{$tree->$field} ){
198 push @things, $filter->($v);
199 push @things, tree_walker($v, $field, $filter);
210 my $page_size = shift || 9;
211 my $page = shift || 0;
213 my ($before_limit,$after_limit) = (0,0);
214 my ($before_offset,$after_offset) = (0,0);
217 $before_limit = $after_limit = int($page_size / 2);
218 $after_limit += 1 if ($page_size % 2);
220 $before_offset = $after_offset = int($page_size / 2);
221 $before_offset += 1 if ($page_size % 2);
222 $before_limit = $after_limit = $page_size;
225 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
227 my $o_search = { shortname => $ou };
228 if (!$ou || $ou eq '-') {
229 $o_search = { parent_ou => undef };
232 my $orgs = $_storage->request(
233 "open-ils.cstore.direct.actor.org_unit.search",
236 flesh_fields => { aou => [qw/children/] }
240 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
242 $logger->debug("Searching for CNs at orgs [".join(',',@ou_ids)."], based on $ou");
247 my $before = $_storage->request(
248 "open-ils.cstore.direct.asset.call_number.search.atomic",
249 { label => { "<" => { transform => "upper", value => ["upper", $label] } },
250 owning_lib => \@ou_ids,
253 flesh_fields => { acn => [qw/record owning_lib/] },
254 order_by => { acn => "upper(label) desc, id desc, owning_lib desc" },
255 limit => $before_limit,
256 offset => abs($page) * $page_size - $before_offset,
259 push @list, reverse(@$before);
263 my $after = $_storage->request(
264 "open-ils.cstore.direct.asset.call_number.search.atomic",
265 { label => { ">=" => { transform => "upper", value => ["upper", $label] } },
266 owning_lib => \@ou_ids,
269 flesh_fields => { acn => [qw/record owning_lib/] },
270 order_by => { acn => "upper(label), id, owning_lib" },
271 limit => $after_limit,
272 offset => abs($page) * $page_size - $after_offset,
280 __PACKAGE__->register_method(
281 method => 'cn_browse',
282 api_name => 'open-ils.supercat.call_number.browse',
287 Returns the XML representation of the requested bibliographic record's holdings
292 desc => 'The target call number lable',
294 { name => 'org_unit',
295 desc => 'The org unit shortname (or "-" or undef for global) to browse',
297 { name => 'page_size',
298 desc => 'Count of call numbers to retrieve, default is 9',
301 desc => 'The page of call numbers to retrieve, calculated based on page_size. Can be positive, negative or 0.',
305 { desc => 'Call numbers with owning_lib and record fleshed',
311 sub new_record_holdings {
317 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
319 my $tree = $_storage->request(
320 "open-ils.cstore.direct.biblio.record_entry.retrieve",
324 bre => [qw/call_numbers/],
325 acn => [qw/copies owning_lib/],
326 acp => [qw/location status circ_lib stat_cat_entries notes/],
327 asce => [qw/stat_cat/],
332 my $o_search = { shortname => uc($ou) };
333 if (!$ou || $ou eq '-') {
334 $o_search = { parent_ou => undef };
337 my $orgs = $_storage->request(
338 "open-ils.cstore.direct.actor.org_unit.search",
341 flesh_fields => { aou => [qw/children/] }
345 my @ou_ids = tree_walker($orgs, 'children', sub {shift->id}) if $orgs;
347 $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."], based on $ou");
349 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
353 $client->respond("<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>");
355 for my $cn (@{$tree->call_numbers}) {
358 for my $c (@{$cn->copies}) {
359 next unless grep {$c->circ_lib->id == $_} @ou_ids;
365 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
366 $cn_class =~ s/Fieldmapper-//gso;
367 my $cn_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cn_class/".$cn->id, $month, $day);
369 my $cn_lib = $cn->owning_lib->shortname;
371 my $cn_label = $cn->label;
373 my $xml = "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'><hold:copies>";
375 for my $cp (@{$cn->copies}) {
377 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
379 (my $cp_class = $cp->class_name) =~ s/::/-/gso;
380 $cp_class =~ s/Fieldmapper-//gso;
381 my $cp_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cp_class/".$cp->id, $month, $day);
383 my $cp_stat = escape($cp->status->name);
384 my $cp_loc = escape($cp->location->name);
385 my $cp_lib = escape($cp->circ_lib->shortname);
386 my $cp_bc = escape($cp->barcode);
388 $xml .= "<hold:copy id='$cp_tag' barcode='$cp_bc'><hold:status>$cp_stat</hold:status>".
389 "<hold:location>$cp_loc</hold:location><hold:circlib>$cp_lib</hold:circlib><hold:copy_notes>";
392 for my $note ( @{$cp->notes} ) {
393 next unless ( $note->pub eq 't' );
394 $xml .= sprintf('<hold:copy_note date="%s" title="%s">%s</hold:copy_note>',$note->create_date, escape($note->title), escape($note->value));
398 $xml .= "</hold:copy_notes><hold:statcats>";
400 if ($cp->stat_cat_entries) {
401 for my $sce ( @{$cp->stat_cat_entries} ) {
402 next unless ( $sce->stat_cat->opac_visible eq 't' );
403 $xml .= sprintf('<hold:statcat name="%s">%s</hold:statcat>',escape($sce->stat_cat->name) ,escape($sce->value));
407 $xml .= "</hold:statcats></hold:copy>";
410 $xml .= "</hold:copies></hold:volume>";
412 $client->respond($xml)
415 return "</hold:volumes>";
417 __PACKAGE__->register_method(
418 method => 'new_record_holdings',
419 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
425 Returns the XML representation of the requested bibliographic record's holdings
430 desc => 'An OpenILS biblio::record_entry id',
434 { desc => 'Stream of bib record holdings hierarchy in XML',
444 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
446 my $recs = $_storage->request(
447 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
448 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
451 return undef unless (@$recs);
453 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
455 __PACKAGE__->register_method(
456 method => 'isbn_holdings',
457 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
462 Returns the XML representation of the requested bibliographic record's holdings
471 { desc => 'The bib record holdings hierarchy in XML',
478 $text =~ s/&/&/gsom;
479 $text =~ s/</</gsom;
480 $text =~ s/>/>/gsom;
481 $text =~ s/"/\\"/gsom;
488 my $when = shift || '1-01-01';
492 $type = 'authority' if ($self->api_name =~ /authority/o);
494 my $axis = 'create_date';
495 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
497 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
499 return $_storage->request(
500 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
501 { $axis => { ">" => $when }, id => { '>' => 0 } },
502 { order_by => { bre => "$axis desc" }, limit => $limit }
506 for my $t ( qw/biblio authority/ ) {
507 for my $a ( qw/import edit/ ) {
509 __PACKAGE__->register_method(
510 method => 'recent_changes',
511 api_name => "open-ils.supercat.$t.record.$a.recent",
515 { desc => "Returns a list of recently ${a}ed $t records",
519 desc => "Date to start looking for ${a}ed records",
520 default => '1-01-01',
524 desc => "Maximum count to retrieve",
528 { desc => "An id list of $t records",
536 sub retrieve_record_marcxml {
541 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
543 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
544 return entityize( $record->marc ) if ($record);
548 __PACKAGE__->register_method(
549 method => 'retrieve_record_marcxml',
550 api_name => 'open-ils.supercat.record.marcxml.retrieve',
555 Returns the MARCXML representation of the requested bibliographic record
560 desc => 'An OpenILS biblio::record_entry id',
564 { desc => 'The bib record in MARCXML',
569 sub retrieve_isbn_marcxml {
574 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
576 my $recs = $_storage->request(
577 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
578 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
581 return undef unless (@$recs);
583 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
584 return entityize( $record->marc ) if ($record);
588 __PACKAGE__->register_method(
589 method => 'retrieve_isbn_marcxml',
590 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
595 Returns the MARCXML representation of the requested ISBN
600 desc => 'An ... um ... ISBN',
604 { desc => 'The bib record in MARCXML',
609 sub retrieve_record_transform {
614 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
616 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
619 my $record = $_storage->request(
620 'open-ils.cstore.direct.biblio.record_entry.retrieve',
624 return undef unless ($record);
626 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
629 sub retrieve_isbn_transform {
634 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
636 my $recs = $_storage->request(
637 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
638 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
641 return undef unless (@$recs);
643 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
645 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
647 return undef unless ($record);
649 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
652 sub retrieve_record_objects {
657 $ids = [$ids] unless (ref $ids);
658 $ids = [grep {$_} @$ids];
660 return [] unless (@$ids);
662 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
663 return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
665 __PACKAGE__->register_method(
666 method => 'retrieve_record_objects',
667 api_name => 'open-ils.supercat.record.object.retrieve',
672 Returns the Fieldmapper object representation of the requested bibliographic records
677 desc => 'OpenILS biblio::record_entry ids',
681 { desc => 'The bib records',
687 sub retrieve_isbn_object {
692 return undef unless ($isbn);
694 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
695 my $recs = $_storage->request(
696 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
697 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
700 return undef unless (@$recs);
702 return $_storage->request(
703 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
704 { id => $recs->[0]->record }
707 __PACKAGE__->register_method(
708 method => 'retrieve_isbn_object',
709 api_name => 'open-ils.supercat.isbn.object.retrieve',
714 Returns the Fieldmapper object representation of the requested bibliographic record
723 { desc => 'The bib record',
730 sub retrieve_metarecord_mods {
735 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
737 # Get the metarecord in question
740 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
743 # Now get the map of all bib records for the metarecord
746 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
750 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
752 # and retrieve the lead (master) record as MODS
754 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
755 ->run($mr->master_record);
756 my $master_mods = $_parser->parse_string($master)->documentElement;
757 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
759 # ... and a MODS clone to populate, with guts removed.
760 my $mods = $_parser->parse_string($master)->documentElement;
761 $mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
762 ($mods) = $mods->findnodes('//mods:mods');
763 $mods->removeChildNodes;
765 # Add the metarecord ID as a (locally defined) info URI
766 my $recordInfo = $mods
768 ->createElement("mods:recordInfo");
770 my $recordIdentifier = $mods
772 ->createElement("mods:recordIdentifier");
774 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
779 $recordIdentifier->appendTextNode(
780 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
783 $recordInfo->appendChild($recordIdentifier);
784 $mods->appendChild($recordInfo);
786 # Grab the title, author and ISBN for the master record and populate the metarecord
787 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
790 $title->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
791 $title = $mods->ownerDocument->importNode($title);
792 $mods->appendChild($title);
795 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
797 $author->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
798 $author = $mods->ownerDocument->importNode($author);
799 $mods->appendChild($author);
802 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
804 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
805 $isbn = $mods->ownerDocument->importNode($isbn);
806 $mods->appendChild($isbn);
809 # ... and loop over the constituent records
810 for my $map ( @$recs ) {
814 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
817 my $part_mods = $_parser->parse_string($rec);
818 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
819 ($part_mods) = $part_mods->findnodes('//mods:mods');
821 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
822 $node->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
823 $node = $mods->ownerDocument->importNode($node);
824 $mods->appendChild( $node );
827 my $relatedItem = $mods
829 ->createElement("mods:relatedItem");
831 $relatedItem->setAttribute( type => 'constituent' );
833 my $identifier = $mods
835 ->createElement("mods:identifier");
837 $identifier->setAttribute( type => 'uri' );
839 my $subRecordInfo = $mods
841 ->createElement("mods:recordInfo");
843 my $subRecordIdentifier = $mods
845 ->createElement("mods:recordIdentifier");
847 my $subid = $map->source;
848 $subRecordIdentifier->appendTextNode(
849 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
854 $subRecordInfo->appendChild($subRecordIdentifier);
856 $relatedItem->appendChild( $subRecordInfo );
858 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
859 $tor->setNamespace( "http://www.loc.gov/mods/", "mods", 1 ) if ($tor);
860 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
861 $relatedItem->appendChild($tor) if ($tor);
863 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
864 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
865 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
866 $relatedItem->appendChild( $part_isbn );
869 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
873 $mods->appendChild( $relatedItem );
877 $_storage->disconnect;
879 return entityize($mods->toString);
882 __PACKAGE__->register_method(
883 method => 'retrieve_metarecord_mods',
884 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
889 Returns the MODS representation of the requested metarecord
893 { name => 'metarecordId',
894 desc => 'An OpenILS metabib::metarecord id',
898 { desc => 'The metarecord in MODS',
903 sub list_metarecord_formats {
906 { namespace_uri => 'http://www.loc.gov/mods/',
907 docs => 'http://www.loc.gov/mods/',
908 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
913 for my $type ( keys %metarecord_xslt ) {
916 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
917 docs => $metarecord_xslt{$type}{docs},
918 schema_location => $metarecord_xslt{$type}{schema_location},
925 __PACKAGE__->register_method(
926 method => 'list_metarecord_formats',
927 api_name => 'open-ils.supercat.metarecord.formats',
932 Returns the list of valid metarecord formats that supercat understands.
935 { desc => 'The format list',
941 sub list_record_formats {
944 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
945 docs => 'http://www.loc.gov/marcxml/',
946 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
951 for my $type ( keys %record_xslt ) {
954 { namespace_uri => $record_xslt{$type}{namespace_uri},
955 docs => $record_xslt{$type}{docs},
956 schema_location => $record_xslt{$type}{schema_location},
963 __PACKAGE__->register_method(
964 method => 'list_record_formats',
965 api_name => 'open-ils.supercat.record.formats',
970 Returns the list of valid record formats that supercat understands.
973 { desc => 'The format list',
977 __PACKAGE__->register_method(
978 method => 'list_record_formats',
979 api_name => 'open-ils.supercat.isbn.formats',
984 Returns the list of valid record formats that supercat understands.
987 { desc => 'The format list',
998 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
999 unless (length($isbn) >= 10);
1001 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1003 # Create a storage session, since we'll be making muliple requests.
1006 # Find the record that has that ISBN.
1007 my $bibrec = $_storage->request(
1008 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
1009 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
1012 # Go away if we don't have one.
1013 return {} unless (@$bibrec);
1015 # Find the metarecord for that bib record.
1016 my $mr = $_storage->request(
1017 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1018 {source => $bibrec->[0]->record}
1021 # Find the other records for that metarecord.
1022 my $records = $_storage->request(
1023 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1024 {metarecord => $mr->[0]->metarecord}
1027 # Just to be safe. There's currently no unique constraint on sources...
1028 my %unique_recs = map { ($_->source, 1) } @$records;
1029 my @rec_list = sort keys %unique_recs;
1031 # And now fetch the ISBNs for thos records.
1035 'open-ils.cstore.direct.metabib.full_rec.search',
1036 { tag => '020', subfield => 'a', record => $_ }
1037 )->gather(1) for (@rec_list);
1039 # We're done with the storage server session.
1040 $_storage->disconnect;
1042 # Return the oISBN data structure. This will be XMLized at a higher layer.
1044 { metarecord => $mr->[0]->metarecord,
1045 record_list => { map { ($_->record, $_->value) } @$recs } };
1048 __PACKAGE__->register_method(
1050 api_name => 'open-ils.supercat.oisbn',
1054 { desc => <<" DESC",
1055 Returns the ISBN list for the metarecord of the requested isbn
1060 desc => 'An ISBN. Duh.',
1064 { desc => 'record to isbn map',