1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::ModsParser;
10 use OpenSRF::Utils::SettingsClient;
12 use OpenSRF::Utils::Logger qw/:logger/;
17 use Time::HiRes qw(time);
18 use OpenSRF::EX qw(:try);
19 use Digest::MD5 qw(md5_hex);
25 $Data::Dumper::Indent = 0;
27 use OpenILS::Application::AppUtils;
28 my $apputils = "OpenILS::Application::AppUtils";
32 # useful for MARC based searches
33 my $cat_search_hash = {
34 isbn => [ { tag => '020', subfield => 'a' }, ],
35 issn => [ { tag => '022', subfield => 'a' }, ],
41 # ---------------------------------------------------------------------------
42 # takes a list of record id's and turns the docs into friendly
43 # mods structures. Creates one MODS structure for each doc id.
44 # ---------------------------------------------------------------------------
45 sub _records_to_mods {
51 my $session = OpenSRF::AppSession->create("open-ils.storage");
52 my $request = $session->request(
53 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
55 while( my $resp = $request->recv ) {
56 my $content = $resp->content;
57 my $u = OpenILS::Utils::ModsParser->new();
58 $u->start_mods_batch( $content->marc );
59 my $mods = $u->finish_mods_batch();
60 $mods->doc_id($content->id());
61 $mods->tcn($content->tcn_value);
65 $session->disconnect();
69 __PACKAGE__->register_method(
70 method => "record_id_to_mods",
71 api_name => "open-ils.search.biblio.record.mods.retrieve",
73 note => "Provide ID, we provide the mods"
76 # converts a record into a mods object with copy counts attached
77 sub record_id_to_mods {
79 my( $self, $client, $org_id, $id ) = @_;
81 my $mods_list = _records_to_mods( $id );
82 my $mods_obj = $mods_list->[0];
83 my $cmethod = $self->method_lookup(
84 "open-ils.search.biblio.record.copy_count");
85 my ($count) = $cmethod->run($org_id, $id);
86 $mods_obj->copy_count($count);
93 __PACKAGE__->register_method(
94 method => "record_id_to_mods_slim",
95 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
97 note => "Provide ID, we provide the mods"
100 # converts a record into a mods object with NO copy counts attached
101 sub record_id_to_mods_slim {
102 my( $self, $client, $id ) = @_;
103 return undef unless defined $id;
105 if(ref($id) and ref($id) == 'ARRAY') {
106 return _records_to_mods( @$id );
108 my $mods_list = _records_to_mods( $id );
109 my $mods_obj = $mods_list->[0];
114 # Returns the number of copies attached to a record based on org location
115 __PACKAGE__->register_method(
116 method => "record_id_to_copy_count",
117 api_name => "open-ils.search.biblio.record.copy_count",
120 __PACKAGE__->register_method(
121 method => "record_id_to_copy_count",
122 api_name => "open-ils.search.biblio.metarecord.copy_count",
125 __PACKAGE__->register_method(
126 method => "record_id_to_copy_count",
127 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
129 sub record_id_to_copy_count {
130 my( $self, $client, $org_id, $record_id, $format ) = @_;
132 $format = undef if ($format eq 'all');
134 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
136 if($self->api_name =~ /metarecord/) {
137 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
141 if($self->api_name =~ /staff/ ) {
142 $method =~ s/atomic/staff\.atomic/og;
143 warn "Doing staff search $method\n";
147 my $session = OpenSRF::AppSession->create("open-ils.storage");
148 warn "copy_count retrieve $record_id\n";
149 return undef unless(defined $record_id);
151 my $request = $session->request(
152 $method, org_unit => $org_id => $key => $record_id, format => $format );
155 my $count = $request->gather(1);
156 $session->disconnect();
157 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
164 __PACKAGE__->register_method(
165 method => "biblio_search_tcn",
166 api_name => "open-ils.search.biblio.tcn",
168 note => "Retrieve a record by TCN",
171 sub biblio_search_tcn {
173 my( $self, $client, $tcn ) = @_;
175 $tcn =~ s/.*?(\w+)\s*$/$1/o;
176 warn "Searching TCN $tcn\n";
178 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
179 my $request = $session->request(
180 "open-ils.storage.direct.biblio.record_entry.search_where.atomic",
181 { tcn_value => $tcn, deleted => 'f' } );
182 #"open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
183 my $record_entry = $request->gather(1);
186 for my $record (@$record_entry) {
187 push @ids, $record->id;
190 $session->disconnect();
193 return { count => $size, ids => \@ids };
197 # --------------------------------------------------------------------------------
199 __PACKAGE__->register_method(
200 method => "biblio_barcode_to_copy",
201 api_name => "open-ils.search.asset.copy.find_by_barcode",);
202 sub biblio_barcode_to_copy {
203 my( $self, $client, $barcode ) = @_;
204 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
209 __PACKAGE__->register_method(
210 method => "biblio_id_to_copy",
211 api_name => "open-ils.search.asset.copy.batch.retrieve",);
212 sub biblio_id_to_copy {
213 my( $self, $client, $ids ) = @_;
214 $logger->info("Fetching copies @$ids");
215 return $U->storagereq(
216 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
220 __PACKAGE__->register_method(
221 method => "copy_retrieve",
222 api_name => "open-ils.search.asset.copy.retrieve",);
224 my( $self, $client, $cid ) = @_;
225 my( $copy, $evt ) = $U->fetch_copy($cid);
231 __PACKAGE__->register_method(
232 method => "fleshed_copy_retrieve_batch",
233 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",);
235 sub fleshed_copy_retrieve_batch {
236 my( $self, $client, $ids ) = @_;
237 $logger->info("Fetching fleshed copies @$ids");
238 return $U->storagereq(
239 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
243 __PACKAGE__->register_method(
244 method => "fleshed_copy_retrieve",
245 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
247 sub fleshed_copy_retrieve {
248 my( $self, $client, $id ) = @_;
249 my( $c, $e) = $U->fetch_fleshed_copy($id);
256 __PACKAGE__->register_method(
257 method => "biblio_barcode_to_title",
258 api_name => "open-ils.search.biblio.find_by_barcode",
261 sub biblio_barcode_to_title {
262 my( $self, $client, $barcode ) = @_;
264 my $title = $apputils->simple_scalar_request(
266 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
268 return { ids => [ $title->id ], count => 1 } if $title;
269 return { count => 0 };
273 __PACKAGE__->register_method(
274 method => "biblio_copy_to_mods",
275 api_name => "open-ils.search.biblio.copy.mods.retrieve",
278 # takes a copy object and returns it fleshed mods object
279 sub biblio_copy_to_mods {
280 my( $self, $client, $copy ) = @_;
282 my $volume = $U->storagereq(
283 "open-ils.storage.direct.asset.call_number.retrieve",
284 $copy->call_number() );
286 my $mods = _records_to_mods($volume->record());
287 $mods = shift @$mods;
288 $volume->copies([$copy]);
289 push @{$mods->call_numbers()}, $volume;
295 # ----------------------------------------------------------------------------
296 # These are the main OPAC search methods
297 # ----------------------------------------------------------------------------
299 __PACKAGE__->register_method(
300 method => "record_search_class",
301 api_name => "open-ils.search.biblio.record.class.search",
303 Performs a class search for biblio records (not metarecords)
304 @param class The search class to use
305 @param args A hash of named parameters including:
306 term : The search string,
307 org_unit : The org id to focus the search at
308 depth : The org depth
309 limit : The search limit
310 offset : The search offset
311 format : The MARC format
312 sort : What field to sort the results on [ author | title | pubdate ]
313 sort_dir : What direction do we sort? [ asc | desc ]
314 The only required argument is the term.
318 __PACKAGE__->register_method(
319 method => "record_search_class",
320 api_name => "open-ils.search.biblio.record.class.search.staff",
321 signature => q/@see open-ils.search.biblio.record.class.search/);
322 __PACKAGE__->register_method(
323 method => "record_search_class",
324 api_name => "open-ils.search.biblio.metabib.class.search",
325 signature => q/@see open-ils.search.biblio.record.class.search/);
326 __PACKAGE__->register_method(
327 method => "record_search_class",
328 api_name => "open-ils.search.biblio.metabib.class.search.staff",
329 signature => q/@see open-ils.search.biblio.record.class.search/);
331 sub record_search_class {
332 my( $self, $client, $class, $args ) = @_;
334 my $type = ($self->api_name =~ /metabib/) ? 1 : 0;
335 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
336 $method = "open-ils.storage.biblio.$class.search_fts.record.atomic" unless $type;
338 if(!$$args{'sort'}) {
339 delete $$args{'sort'};
340 delete $$args{'sort_dir'};
342 $$args{limit} = 200 if (!$$args{limit} || $$args{limit} > 1000);
343 $$args{offset} ||= 0;
345 $logger->info("Class search with args: ".Dumper($args));
347 $method =~ s/\.atomic/.staff.atomic/o if $self->api_name =~ /staff/o;
348 my $result = $U->storagereq( $method, %$args );
350 if($result and $result->[0]) {
352 for my $r (@$result) { push(@$recs, $r) if ($r and $r->[0]); }
353 return { ids => $recs,
354 count => ($type) ? $result->[0]->[3] : $result->[0]->[2] };
356 return { count => 0 };
362 __PACKAGE__->register_method(
363 method => "biblio_mrid_to_modsbatch_batch",
364 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
366 sub biblio_mrid_to_modsbatch_batch {
367 my( $self, $client, $mrids) = @_;
368 warn "Performing mrid_to_modsbatch_batch...";
370 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
371 for my $id (@$mrids) {
372 next unless defined $id;
373 my ($m) = $method->run($id);
380 __PACKAGE__->register_method(
381 method => "biblio_mrid_to_modsbatch",
382 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
383 notes => <<" NOTES");
384 Returns the mvr associated with a given metarecod. If none exists,
388 __PACKAGE__->register_method(
389 method => "biblio_mrid_to_modsbatch",
390 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
391 notes => <<" NOTES");
392 Returns the mvr associated with a given metarecod. If none exists,
396 sub biblio_mrid_to_modsbatch {
397 my( $self, $client, $mrid ) = @_;
399 warn "Grabbing mvr for $mrid\n";
401 my $mr = _grab_metarecord($mrid);
402 return undef unless $mr;
404 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
408 return $self->biblio_mrid_make_modsbatch( $client, $mr );
411 # converts a metarecord to an mvr
414 my $perl = JSON->JSON2perl($mr->mods());
415 return Fieldmapper::metabib::virtual_record->new($perl);
418 # checks to see if a metarecord has mods, if so returns true;
420 __PACKAGE__->register_method(
421 method => "biblio_mrid_check_mvr",
422 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
423 notes => <<" NOTES");
424 Takes a metarecord ID or a metarecord object and returns true
425 if the metarecord already has an mvr associated with it.
428 sub biblio_mrid_check_mvr {
429 my( $self, $client, $mrid ) = @_;
432 if(ref($mrid)) { $mr = $mrid; }
433 else { $mr = _grab_metarecord($mrid); }
435 warn "Checking mvr for mr " . $mr->id . "\n";
437 return _mr_to_mvr($mr) if $mr->mods();
441 sub _grab_metarecord {
444 warn "Grabbing MR $mrid\n";
446 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
448 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
451 throw OpenSRF::EX::ERROR
452 ("No metarecord exists with the given id: $mrid");
458 __PACKAGE__->register_method(
459 method => "biblio_mrid_make_modsbatch",
460 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
461 notes => <<" NOTES");
462 Takes either a metarecord ID or a metarecord object.
463 Forces the creations of an mvr for the given metarecord.
464 The created mvr is returned.
467 sub biblio_mrid_make_modsbatch {
469 my( $self, $client, $mrid ) = @_;
472 if(ref($mrid)) { $mr = $mrid; }
473 else { $mr = _grab_metarecord($mrid); }
476 warn "Forcing mvr creation for mr " . $mr->id . "\n";
477 my $master_id = $mr->master_record;
479 my $session = OpenSRF::AppSession->create("open-ils.storage");
481 # grab the records attached to this metarecod
482 warn "Creating mods batch for metarecord $mrid\n";
483 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
484 $meth = $self->method_lookup($meth);
485 my ($id_hash) = $meth->run($mrid);
486 my @ids = @{$id_hash->{ids}};
487 if(@ids < 1) { return undef; }
489 warn "Master ID is $master_id\n";
490 # grab the master record to start the mods batch
492 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
494 my $record = $session->request(
495 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
496 $record = $record->gather(1);
498 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
501 warn "No record returned with id $master_id";
502 throw OpenSRF::EX::ERROR
505 my $u = OpenILS::Utils::ModsParser->new();
506 $u->start_mods_batch( $record->marc );
507 my $main_doc_id = $record->id();
509 @ids = grep { $_ ne $master_id } @ids;
511 # now we have to collect all of the marc objects and push them into a mods batch
512 my $request = $session->request(
513 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
515 while( my $response = $request->recv() ) {
517 next unless $response;
518 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
519 throw $response ($response->stringify);
522 my $content = $response->content;
525 $u->push_mods_batch( $content->marc );
529 my $mods = $u->finish_mods_batch();
530 $mods->doc_id($mrid);
533 $client->respond_complete($mods);
535 my $mods_string = JSON->perl2JSON($mods->decast);
537 $mr->mods($mods_string);
539 my $req = $session->request(
540 "open-ils.storage.direct.metabib.metarecord.update", $mr );
545 $session->disconnect();
552 # converts a mr id into a list of record ids
554 __PACKAGE__->register_method(
555 method => "biblio_mrid_to_record_ids",
556 api_name => "open-ils.search.biblio.metarecord_to_records",
559 __PACKAGE__->register_method(
560 method => "biblio_mrid_to_record_ids",
561 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
564 sub biblio_mrid_to_record_ids {
565 my( $self, $client, $mrid, $format ) = @_;
567 throw OpenSRF::EX::InvalidArg
568 ("search.biblio.metarecord_to_record_ids requires mr id")
569 unless defined( $mrid );
571 warn "Searching for record for MR $mrid and format $format\n";
573 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
574 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
575 warn "Performing record retrieval with method $method\n";
578 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
579 "open-ils.storage", $method, $mrid, $format );
585 return { count => $size, ids => $mrmaps };
590 __PACKAGE__->register_method(
591 method => "biblio_record_to_marc_html",
592 api_name => "open-ils.search.biblio.record.html" );
594 my $parser = XML::LibXML->new();
595 my $xslt = XML::LibXSLT->new();
598 my $settings_client = OpenSRF::Utils::SettingsClient->new();
599 sub biblio_record_to_marc_html {
600 my( $self, $client, $recordid ) = @_;
603 my $dir = $settings_client->config_value( "dirs", "xsl" );
604 my $xsl = $settings_client->config_value(
605 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
607 $xsl = $parser->parse_file("$dir/$xsl");
608 $marc_sheet = $xslt->parse_stylesheet( $xsl );
612 my $record = $apputils->simple_scalar_request(
614 "open-ils.storage.direct.biblio.record_entry.retrieve",
617 my $xmldoc = $parser->parse_string($record->marc);
618 my $html = $marc_sheet->transform($xmldoc);
619 $html = $html->toString();
626 __PACKAGE__->register_method(
627 method => "retrieve_all_copy_locations",
628 api_name => "open-ils.search.config.copy_location.retrieve.all" );
630 my $shelving_locations;
631 sub retrieve_all_copy_locations {
632 my( $self, $client ) = @_;
633 if(!$shelving_locations) {
634 $shelving_locations = $apputils->simple_scalar_request(
636 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
638 return $shelving_locations;
643 __PACKAGE__->register_method(
644 method => "retrieve_all_copy_statuses",
645 api_name => "open-ils.search.config.copy_status.retrieve.all" );
648 sub retrieve_all_copy_statuses {
649 my( $self, $client ) = @_;
650 if(!$copy_statuses) {
651 $copy_statuses = $apputils->simple_scalar_request(
653 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
655 return $copy_statuses;
659 __PACKAGE__->register_method(
660 method => "copy_counts_per_org",
661 api_name => "open-ils.search.biblio.copy_counts.retrieve");
663 __PACKAGE__->register_method(
664 method => "copy_counts_per_org",
665 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
667 sub copy_counts_per_org {
668 my( $self, $client, $record_id ) = @_;
670 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
672 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
673 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
675 my $counts = $apputils->simple_scalar_request(
676 "open-ils.storage", $method, $record_id );
678 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
683 __PACKAGE__->register_method(
684 method => "copy_count_summary",
685 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
686 notes => <<" NOTES");
687 returns an array of these:
688 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
689 where statusx is a copy status name. the statuses are sorted
693 sub copy_count_summary {
694 my( $self, $client, $rid ) = @_;
695 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
696 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
701 __PACKAGE__->register_method(
702 method => "multiclass_search",
703 api_name => "open-ils.search.biblio.multiclass",
704 notes => <<" NOTES");
705 Performs a multiclass search
706 PARAMS( searchBlob, org_unit, format, limit )
707 where searchBlob is defined like this:
709 "title" : { "term" : "water" },
710 "author" : { "term" : "smith" },
715 __PACKAGE__->register_method(
716 method => "multiclass_search",
717 api_name => "open-ils.search.biblio.multiclass.staff",
718 notes => "see open-ils.search.biblio.multiclass" );
720 sub multiclass_search {
721 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
723 $logger->debug("Performing multiclass search with org => $orgid, " .
724 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
726 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
727 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
730 my $records = $apputils->simplereq(
731 'open-ils.storage', $meth,
732 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
737 if( ref($records) and $records->[0] and
738 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
740 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
742 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
743 return { ids => $recs, count => $count };
749 __PACKAGE__->register_method(
750 method => "multiclass_search",
751 api_name => "open-ils.search.biblio.multiclass",
753 Performs a multiclass search
754 @param args A names hash of arguments:
755 org_unit : The org to focus the search on
756 depth : The search depth
759 offset : Search offset
760 searches : A named hash of searches which has the following format:
762 "title" : { "term" : "water" },
763 "author" : { "term" : "smith" },
766 @return { ids : <array of ids>, count : hitcount }
770 __PACKAGE__->register_method(
771 method => "multiclass_search",
772 api_name => "open-ils.search.biblio.multiclass.staff",
773 notes => q/@see open-ils.search.biblio.multiclass/ );
775 sub multiclass_search {
776 my( $self, $client, $args ) = @_;
778 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
779 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
780 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
782 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
787 if( ref($records) and $records->[0] and
788 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
790 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
792 return { ids => $recs, count => $count };
798 __PACKAGE__->register_method(
799 method => "marc_search",
800 api_name => "open-ils.search.biblio.marc",
801 notes => <<" NOTES");
802 Performs a multiclass search
803 PARAMS( searchBlob, org_unit, format )
804 where searchBlob is defined like this:
807 "term":"shakespeare",
808 "restrict":[{"tag":"245","subfield":"a"}]
812 "restrict":[{"tag":"100","subfield":"a"}]
819 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
821 $logger->debug("Performing MARC search with org => $orgid, " .
822 "format => $format and search blob " . Dumper($searchBlob) );
824 my $records = $apputils->simplereq(
826 'open-ils.storage.metabib.full_rec.multi_search.atomic',
827 searches => $searchBlob, org_unit => $orgid, format => $format );
832 if( ref($records) and $records->[0] and
833 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
835 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
837 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
838 return { ids => $recs, count => $count };
844 __PACKAGE__->register_method(
845 method => "biblio_search_isbn",
846 api_name => "open-ils.search.biblio.isbn",
849 sub biblio_search_isbn {
850 my( $self, $client, $isbn ) = @_;
852 $logger->debug("Searching ISBN $isbn");
854 my $method = $self->method_lookup("open-ils.search.biblio.marc");
856 my ($records) = $method->run(
858 restrict => $cat_search_hash->{isbn} } ], 1);
864 __PACKAGE__->register_method(
865 method => "biblio_search_issn",
866 api_name => "open-ils.search.biblio.issn",
869 sub biblio_search_issn {
870 my( $self, $client, $issn ) = @_;
872 $logger->debug("Searching ISSN $issn");
874 my $method = $self->method_lookup("open-ils.search.biblio.marc");
876 my ($records) = $method->run(
878 restrict => $cat_search_hash->{issn} } ], 1);
886 __PACKAGE__->register_method(
887 method => "fetch_mods_by_copy",
888 api_name => "open-ils.search.biblio.mods_from_copy",
891 sub fetch_mods_by_copy {
892 my( $self, $client, $copyid ) = @_;
893 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
895 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
896 return $apputils->record_to_mvr($record);
903 # -------------------------------------------------------------------------------------
905 __PACKAGE__->register_method(
906 method => "cn_browse",
907 api_name => "open-ils.search.callnumber.browse.target",
908 notes => "Starts a callnumber browse"
911 __PACKAGE__->register_method(
912 method => "cn_browse",
913 api_name => "open-ils.search.callnumber.browse.page_up",
914 notes => "Returns the previous page of callnumbers",
917 __PACKAGE__->register_method(
918 method => "cn_browse",
919 api_name => "open-ils.search.callnumber.browse.page_down",
920 notes => "Returns the next page of callnumbers",
924 # RETURNS array of arrays like so: label, owning_lib, record, id
926 my( $self, $client, @params ) = @_;
929 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
930 if( $self->api_name =~ /target/ );
931 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
932 if( $self->api_name =~ /page_up/ );
933 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
934 if( $self->api_name =~ /page_down/ );
936 return $apputils->simplereq( 'open-ils.storage', $method, @params );
938 # -------------------------------------------------------------------------------------
940 __PACKAGE__->register_method(
941 method => "fetch_cn",
942 api_name => "open-ils.search.callnumber.retrieve",
943 notes => "retrieves a callnumber based on ID",
947 my( $self, $client, $id ) = @_;
948 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
953 __PACKAGE__->register_method (
954 method => "fetch_copy_by_cn",
955 api_name => 'open-ils.search.copies_by_call_number.retrieve',
957 Returns an array of copy id's by callnumber id
958 @param cnid The callnumber id
959 @return An array of copy ids
963 sub fetch_copy_by_cn {
964 my( $self, $conn, $cnid ) = @_;
965 return $U->storagereq(
966 'open-ils.storage.id_list.asset.copy.search_where.atomic',
967 { call_number => $cnid, deleted => 'f' } );
970 __PACKAGE__->register_method (
971 method => 'fetch_cn_by_info',
972 api_name => 'open-ils.search.call_number.retrieve_by_info',
974 @param label The callnumber label
975 @param record The record the cn is attached to
976 @param org The owning library of the cn
977 @return The callnumber object
981 sub fetch_cn_by_info {
982 my( $self, $conn, $label, $record, $org ) = @_;
983 return $U->storagereq(
984 'open-ils.storage.direct.asset.call_number.search_where',
985 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });