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 my $xml = "<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;
364 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
365 $cn_class =~ s/Fieldmapper-//gso;
366 my $cn_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cn_class/".$cn->id, $month, $day);
368 my $cn_lib = $cn->owning_lib->shortname;
370 my $cn_label = $cn->label;
372 $xml .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'><hold:copies>";
374 for my $cp (@{$cn->copies}) {
376 next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
378 (my $cp_class = $cp->class_name) =~ s/::/-/gso;
379 $cp_class =~ s/Fieldmapper-//gso;
380 my $cp_tag = sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:$cp_class/".$cp->id, $month, $day);
382 my $cp_stat = $cp->status->name;
384 my $cp_loc = $cp->location->name;
386 my $cp_lib = $cp->circ_lib->shortname;
388 my $cp_bc = $cp->barcode;
390 $xml .= "<hold:copy id='$cp_tag' barcode='$cp_bc'><hold:status>$cp_stat</hold:status>".
391 "<hold:location>$cp_loc</hold:location><hold:circlib>$cp_lib</hold:circlib><hold:notes>";
394 # for my $note ( @{$cp->notes} ) {
395 # next unless ( $sce->stat_cat->pub eq 't' );
396 # $xml .= sprintf('<hold:note date="%s" title="%s">%s</hold:note>',$note->create_date, escape($note->title), escape($note->value));
400 $xml .= "</hold:notes><hold:statcats>";
402 if ($cp->stat_cat_entries) {
403 for my $sce ( @{$cp->stat_cat_entries} ) {
404 next unless ( $sce->stat_cat->opac_visible eq 't' );
405 $xml .= sprintf('<hold:statcat name="%s">%s</hold:statcat>',escape($sce->stat_cat->name) ,escape($sce->value));
409 $xml .= "</hold:statcats></hold:copy>";
412 $xml .= "</hold:copies></hold:volume>";
415 $xml .= "</hold:volumes>";
419 __PACKAGE__->register_method(
420 method => 'new_record_holdings',
421 api_name => 'open-ils.supercat.record.holdings_xml.retrieve',
426 Returns the XML representation of the requested bibliographic record's holdings
431 desc => 'An OpenILS biblio::record_entry id',
435 { desc => 'The bib record holdings hierarchy in XML',
445 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
447 my $recs = $_storage->request(
448 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
449 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
452 return undef unless (@$recs);
454 return ($self->method_lookup( 'open-ils.supercat.record.holdings_xml.retrieve')->run( $recs->[0]->record ))[0];
456 __PACKAGE__->register_method(
457 method => 'isbn_holdings',
458 api_name => 'open-ils.supercat.isbn.holdings_xml.retrieve',
463 Returns the XML representation of the requested bibliographic record's holdings
472 { desc => 'The bib record holdings hierarchy in XML',
479 $text =~ s/&/&/gsom;
480 $text =~ s/</</gsom;
481 $text =~ s/>/>/gsom;
482 $text =~ s/"/\\"/gsom;
489 my $when = shift || '1-01-01';
493 $type = 'authority' if ($self->api_name =~ /authority/o);
495 my $axis = 'create_date';
496 $axis = 'edit_date' if ($self->api_name =~ /edit/o);
498 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
502 "open-ils.cstore.direct.$type.record_entry.id_list.atomic",
503 { $axis => { ">" => $when }, id => { '>' => 0 } },
504 { order_by => "$axis desc", limit => $limit } )
508 for my $t ( qw/biblio authority/ ) {
509 for my $a ( qw/import edit/ ) {
511 __PACKAGE__->register_method(
512 method => 'recent_changes',
513 api_name => "open-ils.supercat.$t.record.$a.recent",
517 { desc => "Returns a list of recently ${a}ed $t records",
521 desc => "Date to start looking for ${a}ed records",
526 desc => "Maximum count to retrieve",
530 { desc => "An id list of $t records",
538 sub retrieve_record_marcxml {
543 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
545 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $rid )->gather(1);
546 return entityize( $record->marc ) if ($record);
550 __PACKAGE__->register_method(
551 method => 'retrieve_record_marcxml',
552 api_name => 'open-ils.supercat.record.marcxml.retrieve',
557 Returns the MARCXML representation of the requested bibliographic record
562 desc => 'An OpenILS biblio::record_entry id',
566 { desc => 'The bib record in MARCXML',
571 sub retrieve_isbn_marcxml {
576 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
578 my $recs = $_storage->request(
579 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
580 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
583 return undef unless (@$recs);
585 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
586 return entityize( $record->marc ) if ($record);
590 __PACKAGE__->register_method(
591 method => 'retrieve_isbn_marcxml',
592 api_name => 'open-ils.supercat.isbn.marcxml.retrieve',
597 Returns the MARCXML representation of the requested ISBN
602 desc => 'An ... um ... ISBN',
606 { desc => 'The bib record in MARCXML',
611 sub retrieve_record_transform {
616 (my $transform = $self->api_name) =~ s/^.+record\.([^\.]+)\.retrieve$/$1/o;
618 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
621 my $record = $_storage->request(
622 'open-ils.cstore.direct.biblio.record_entry.retrieve',
626 return undef unless ($record);
628 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
631 sub retrieve_isbn_transform {
636 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
638 my $recs = $_storage->request(
639 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
640 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
643 return undef unless (@$recs);
645 (my $transform = $self->api_name) =~ s/^.+isbn\.([^\.]+)\.retrieve$/$1/o;
647 my $record = $_storage->request( 'open-ils.cstore.direct.biblio.record_entry.retrieve' => $recs->[0]->record )->gather(1);
649 return undef unless ($record);
651 return entityize($record_xslt{$transform}{xslt}->transform( $_parser->parse_string( $record->marc ) )->toString);
654 sub retrieve_record_objects {
659 $ids = [$ids] unless (ref $ids);
660 $ids = [grep {$_} @$ids];
662 return [] unless (@$ids);
664 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
665 return $_storage->request('open-ils.cstore.direct.biblio.record_entry.search.atomic' => { id => [grep {$_} @$ids] })->gather(1);
667 __PACKAGE__->register_method(
668 method => 'retrieve_record_objects',
669 api_name => 'open-ils.supercat.record.object.retrieve',
674 Returns the Fieldmapper object representation of the requested bibliographic records
679 desc => 'OpenILS biblio::record_entry ids',
683 { desc => 'The bib records',
689 sub retrieve_isbn_object {
694 return undef unless ($isbn);
696 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
697 my $recs = $_storage->request(
698 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
699 { tag => { like => '02%'}, value => {like => "$isbn\%"}}
702 return undef unless (@$recs);
704 return $_storage->request(
705 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
706 { id => $recs->[0]->record }
709 __PACKAGE__->register_method(
710 method => 'retrieve_isbn_object',
711 api_name => 'open-ils.supercat.isbn.object.retrieve',
716 Returns the Fieldmapper object representation of the requested bibliographic record
725 { desc => 'The bib record',
732 sub retrieve_metarecord_mods {
737 my $_storage = OpenSRF::AppSession->connect( 'open-ils.cstore' );
739 # Get the metarecord in question
742 'open-ils.cstore.direct.metabib.metarecord.retrieve' => $rid
745 # Now get the map of all bib records for the metarecord
748 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
752 $logger->debug("Adding ".scalar(@$recs)." bib record to the MODS of the metarecord");
754 # and retrieve the lead (master) record as MODS
756 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
757 ->run($mr->master_record);
758 my $master_mods = $_parser->parse_string($master)->documentElement;
759 $master_mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
761 # ... and a MODS clone to populate, with guts removed.
762 my $mods = $_parser->parse_string($master)->documentElement;
763 $mods->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
764 ($mods) = $mods->findnodes('//mods:mods');
765 $mods->removeChildNodes;
767 # Add the metarecord ID as a (locally defined) info URI
768 my $recordInfo = $mods
770 ->createElement("mods:recordInfo");
772 my $recordIdentifier = $mods
774 ->createElement("mods:recordIdentifier");
776 my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
781 $recordIdentifier->appendTextNode(
782 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:metabib-metarecord/$id", $month, $day)
785 $recordInfo->appendChild($recordIdentifier);
786 $mods->appendChild($recordInfo);
788 # Grab the title, author and ISBN for the master record and populate the metarecord
789 my ($title) = $master_mods->findnodes( './mods:titleInfo[not(@type)]' );
792 $title->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
793 $title = $mods->ownerDocument->importNode($title);
794 $mods->appendChild($title);
797 my ($author) = $master_mods->findnodes( './mods:name[mods:role/mods:text[text()="creator"]]' );
799 $author->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
800 $author = $mods->ownerDocument->importNode($author);
801 $mods->appendChild($author);
804 my ($isbn) = $master_mods->findnodes( './mods:identifier[@type="isbn"]' );
806 $isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
807 $isbn = $mods->ownerDocument->importNode($isbn);
808 $mods->appendChild($isbn);
811 # ... and loop over the constituent records
812 for my $map ( @$recs ) {
816 $self ->method_lookup('open-ils.supercat.record.mods.retrieve')
819 my $part_mods = $_parser->parse_string($rec);
820 $part_mods->documentElement->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
821 ($part_mods) = $part_mods->findnodes('//mods:mods');
823 for my $node ( ($part_mods->findnodes( './mods:subject' )) ) {
824 $node->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
825 $node = $mods->ownerDocument->importNode($node);
826 $mods->appendChild( $node );
829 my $relatedItem = $mods
831 ->createElement("mods:relatedItem");
833 $relatedItem->setAttribute( type => 'constituent' );
835 my $identifier = $mods
837 ->createElement("mods:identifier");
839 $identifier->setAttribute( type => 'uri' );
841 my $subRecordInfo = $mods
843 ->createElement("mods:recordInfo");
845 my $subRecordIdentifier = $mods
847 ->createElement("mods:recordIdentifier");
849 my $subid = $map->source;
850 $subRecordIdentifier->appendTextNode(
851 sprintf("tag:open-ils.org,$year-\%0.2d-\%0.2d:biblio-record_entry/$subid",
856 $subRecordInfo->appendChild($subRecordIdentifier);
858 $relatedItem->appendChild( $subRecordInfo );
860 my ($tor) = $part_mods->findnodes( './mods:typeOfResource' );
861 $tor->setNamespace( "http://www.loc.gov/mods/", "mods", 1 ) if ($tor);
862 $tor = $mods->ownerDocument->importNode($tor) if ($tor);
863 $relatedItem->appendChild($tor) if ($tor);
865 if ( my ($part_isbn) = $part_mods->findnodes( './mods:identifier[@type="isbn"]' ) ) {
866 $part_isbn->setNamespace( "http://www.loc.gov/mods/", "mods", 1 );
867 $part_isbn = $mods->ownerDocument->importNode($part_isbn);
868 $relatedItem->appendChild( $part_isbn );
871 $isbn = $mods->appendChild( $part_isbn->cloneNode(1) );
875 $mods->appendChild( $relatedItem );
879 $_storage->disconnect;
881 return entityize($mods->toString);
884 __PACKAGE__->register_method(
885 method => 'retrieve_metarecord_mods',
886 api_name => 'open-ils.supercat.metarecord.mods.retrieve',
891 Returns the MODS representation of the requested metarecord
895 { name => 'metarecordId',
896 desc => 'An OpenILS metabib::metarecord id',
900 { desc => 'The metarecord in MODS',
905 sub list_metarecord_formats {
908 { namespace_uri => 'http://www.loc.gov/mods/',
909 docs => 'http://www.loc.gov/mods/',
910 schema_location => 'http://www.loc.gov/standards/mods/mods.xsd',
915 for my $type ( keys %metarecord_xslt ) {
918 { namespace_uri => $metarecord_xslt{$type}{namespace_uri},
919 docs => $metarecord_xslt{$type}{docs},
920 schema_location => $metarecord_xslt{$type}{schema_location},
927 __PACKAGE__->register_method(
928 method => 'list_metarecord_formats',
929 api_name => 'open-ils.supercat.metarecord.formats',
934 Returns the list of valid metarecord formats that supercat understands.
937 { desc => 'The format list',
943 sub list_record_formats {
946 { namespace_uri => 'http://www.loc.gov/MARC21/slim',
947 docs => 'http://www.loc.gov/marcxml/',
948 schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd',
953 for my $type ( keys %record_xslt ) {
956 { namespace_uri => $record_xslt{$type}{namespace_uri},
957 docs => $record_xslt{$type}{docs},
958 schema_location => $record_xslt{$type}{schema_location},
965 __PACKAGE__->register_method(
966 method => 'list_record_formats',
967 api_name => 'open-ils.supercat.record.formats',
972 Returns the list of valid record formats that supercat understands.
975 { desc => 'The format list',
979 __PACKAGE__->register_method(
980 method => 'list_record_formats',
981 api_name => 'open-ils.supercat.isbn.formats',
986 Returns the list of valid record formats that supercat understands.
989 { desc => 'The format list',
1000 throw OpenSRF::EX::InvalidArg ('I need an ISBN please')
1001 unless (length($isbn) >= 10);
1003 my $_storage = OpenSRF::AppSession->create( 'open-ils.cstore' );
1005 # Create a storage session, since we'll be making muliple requests.
1008 # Find the record that has that ISBN.
1009 my $bibrec = $_storage->request(
1010 'open-ils.cstore.direct.metabib.full_rec.search.atomic',
1011 { tag => '020', subfield => 'a', value => { like => lc($isbn).'%'} }
1014 # Go away if we don't have one.
1015 return {} unless (@$bibrec);
1017 # Find the metarecord for that bib record.
1018 my $mr = $_storage->request(
1019 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1020 {source => $bibrec->[0]->record}
1023 # Find the other records for that metarecord.
1024 my $records = $_storage->request(
1025 'open-ils.cstore.direct.metabib.metarecord_source_map.search.atomic',
1026 {metarecord => $mr->[0]->metarecord}
1029 # Just to be safe. There's currently no unique constraint on sources...
1030 my %unique_recs = map { ($_->source, 1) } @$records;
1031 my @rec_list = sort keys %unique_recs;
1033 # And now fetch the ISBNs for thos records.
1037 'open-ils.cstore.direct.metabib.full_rec.search',
1038 { tag => '020', subfield => 'a', record => $_ }
1039 )->gather(1) for (@rec_list);
1041 # We're done with the storage server session.
1042 $_storage->disconnect;
1044 # Return the oISBN data structure. This will be XMLized at a higher layer.
1046 { metarecord => $mr->[0]->metarecord,
1047 record_list => { map { ($_->record, $_->value) } @$recs } };
1050 __PACKAGE__->register_method(
1052 api_name => 'open-ils.supercat.oisbn',
1056 { desc => <<" DESC",
1057 Returns the ISBN list for the metarecord of the requested isbn
1062 desc => 'An ISBN. Duh.',
1066 { desc => 'record to isbn map',