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 OpenILS::Application::AppUtils;
16 use Time::HiRes qw(time);
17 use OpenSRF::EX qw(:try);
18 use Digest::MD5 qw(md5_hex);
23 my $apputils = "OpenILS::Application::AppUtils";
25 # Houses biblio search utilites
28 __PACKAGE__->register_method(
30 api_name => "open-ils.search.test");
32 sub test { return "test"; }
36 __PACKAGE__->register_method(
37 method => "biblio_search_marc",
38 api_name => "open-ils.search.biblio.marc",
40 note => "Searches biblio information by marc tag",
43 sub biblio_search_marc {
45 my( $self, $client, $search_hash, $string ) = @_;
47 warn "Building biblio marc session\n";
48 my $session = OpenSRF::AppSession->create("open-ils.storage");
51 warn "Sending biblio marc request. String $string\nSearch hash: " . Dumper($search_hash);
52 my $request = $session->request(
53 "open-ils.storage.direct.metabib.full_rec.search_fts.index_vector.atomic",
54 restrict => $search_hash,
56 my $data = $request->gather(1);
61 $session->disconnect();
69 # ---------------------------------------------------------------------------
70 # takes a list of record id's and turns the docs into friendly
71 # mods structures. Creates one MODS structure for each doc id.
72 # ---------------------------------------------------------------------------
73 sub _records_to_mods {
79 my $session = OpenSRF::AppSession->create("open-ils.storage");
80 my $request = $session->request(
81 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
83 my $last_content = undef;
85 while( my $response = $request->recv() ) {
88 my $u = OpenILS::Utils::ModsParser->new();
89 $u->start_mods_batch( $last_content->marc );
90 my $mods = $u->finish_mods_batch();
91 $mods->doc_id($last_content->id());
92 warn "Turning doc " . $mods->doc_id() . " into MODS\n";
93 $last_content = undef;
97 next unless $response;
99 if($response->isa("OpenSRF::EX")) {
100 throw $response ($response->stringify);
103 $last_content = $response->content;
107 if( $last_content ) {
108 my $u = OpenILS::Utils::ModsParser->new();
109 $u->start_mods_batch( $last_content->marc );
110 my $mods = $u->finish_mods_batch();
111 $mods->doc_id($last_content->id());
112 push @results, $mods;
117 $session->disconnect();
123 __PACKAGE__->register_method(
124 method => "record_id_to_mods",
125 api_name => "open-ils.search.biblio.record.mods.retrieve",
127 note => "Provide ID, we provide the mods"
130 # converts a record into a mods object with copy counts attached
131 sub record_id_to_mods {
133 my( $self, $client, $org_id, $id ) = @_;
135 my $mods_list = _records_to_mods( $id );
136 my $mods_obj = $mods_list->[0];
137 my $cmethod = $self->method_lookup(
138 "open-ils.search.biblio.record.copy_count");
139 my ($count) = $cmethod->run($org_id, $id);
140 $mods_obj->copy_count($count);
147 __PACKAGE__->register_method(
148 method => "record_id_to_mods_slim",
149 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
151 note => "Provide ID, we provide the mods"
154 # converts a record into a mods object with NO copy counts attached
155 sub record_id_to_mods_slim {
156 my( $self, $client, $id ) = @_;
157 return undef unless defined $id;
159 if(ref($id) and ref($id) == 'ARRAY') {
160 return _records_to_mods( @$id );
162 my $mods_list = _records_to_mods( $id );
163 my $mods_obj = $mods_list->[0];
168 # Returns the number of copies attached to a record based on org location
169 __PACKAGE__->register_method(
170 method => "record_id_to_copy_count",
171 api_name => "open-ils.search.biblio.record.copy_count",
174 __PACKAGE__->register_method(
175 method => "record_id_to_copy_count",
176 api_name => "open-ils.search.biblio.metarecord.copy_count",
179 __PACKAGE__->register_method(
180 method => "record_id_to_copy_count",
181 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
183 sub record_id_to_copy_count {
184 my( $self, $client, $org_id, $record_id ) = @_;
186 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
188 if($self->api_name =~ /metarecord/) {
189 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
193 if($self->api_name =~ /staff/ ) {
194 $method =~ s/atomic/staff\.atomic/og;
195 warn "Doing staff search $method\n";
199 my $session = OpenSRF::AppSession->create("open-ils.storage");
200 warn "copy_count retrieve $record_id\n";
201 return undef unless(defined $record_id);
203 my $request = $session->request(
204 $method, org_unit => $org_id => $key => $record_id );
207 my $count = $request->gather(1);
208 $session->disconnect();
209 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
214 # used for cat search classes
215 my $cat_search_hash = {
218 { tag => "100", subfield => "a"} ,
219 { tag => "700", subfield => "a"},
223 { tag => "245", subfield => "a"},
224 { tag => "242", subfield => "a"},
225 { tag => "240", subfield => "a"},
226 { tag => "210", subfield => "a"},
230 { tag => "650", subfield => "_" },
234 { tag => "035", subfield => "_" },
238 { tag => "020", subfield => "a" },
244 __PACKAGE__->register_method(
245 method => "biblio_search_tcn",
246 api_name => "open-ils.search.biblio.tcn",
248 note => "Retrieve a record by TCN",
251 sub biblio_search_tcn {
253 my( $self, $client, $tcn ) = @_;
255 $tcn =~ s/.*?(\w+)\s*$/$1/o;
256 warn "Searching TCN $tcn\n";
258 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
259 my $request = $session->request(
260 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
261 my $record_entry = $request->gather(1);
264 for my $record (@$record_entry) {
265 push @ids, $record->id;
268 $session->disconnect();
270 warn "received ID's for tcn search @ids\n";
273 return { count => $size, ids => \@ids };
278 # --------------------------------------------------------------------------------
281 __PACKAGE__->register_method(
282 method => "biblio_search_isbn",
283 api_name => "open-ils.search.biblio.isbn",
286 sub biblio_search_isbn {
287 my( $self, $client, $isbn ) = @_;
288 throw OpenSRF::EX::InvalidArg
290 ("biblio_search_isbn needs an ISBN to search")
291 unless defined $isbn;
293 warn "biblio search for ISBN $isbn\n";
294 my $method = $self->method_lookup("open-ils.search.biblio.marc");
295 my ($records) = $method->run( $cat_search_hash->{isbn}, $isbn );
297 return { count => 0 } unless($records and @$records);
298 my $size = @$records;
299 return { count => $size, ids => $records };
304 # --------------------------------------------------------------------------------
306 __PACKAGE__->register_method(
307 method => "biblio_barcode_to_copy",
308 api_name => "open-ils.search.asset.copy.find_by_barcode",
311 # turns a barcode into a copy object
312 sub biblio_barcode_to_copy {
313 my( $self, $client, $barcode ) = @_;
315 throw OpenSRF::EX::InvalidArg
316 ("search.biblio.barcode needs a barcode to search")
317 unless defined $barcode;
319 warn "copy search for barcode $barcode\n";
320 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
322 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
325 return undef unless($record);
330 __PACKAGE__->register_method(
331 method => "biblio_id_to_copy",
332 api_name => "open-ils.search.asset.copy.batch.retrieve",
335 # turns a barcode into a copy object
336 sub biblio_id_to_copy {
337 my( $self, $client, $ids ) = @_;
339 throw OpenSRF::EX::InvalidArg
340 ("search.biblio.batch.retrieve needs a id to search")
343 warn "copy search for ids @$ids\n";
344 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
346 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
354 __PACKAGE__->register_method(
355 method => "fleshed_copy_retrieve_batch",
356 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
359 sub fleshed_copy_retrieve_batch {
360 my( $self, $client, $ids ) = @_;
362 throw OpenSRF::EX::InvalidArg
363 ("search.biblio.batch.retrieve needs a id to search")
366 warn "fleshed copy search for id @$ids\n";
367 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
369 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
375 __PACKAGE__->register_method(
376 method => "fleshed_copy_retrieve",
377 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
380 sub fleshed_copy_retrieve {
381 my( $self, $client, $id ) = @_;
383 return undef unless defined $id;
384 warn "copy retrieve for id $id\n";
385 return OpenILS::Application::AppUtils->simple_scalar_request(
387 "open-ils.storage.fleshed.asset.copy.retrieve.atomic",
393 __PACKAGE__->register_method(
394 method => "biblio_barcode_to_title",
395 api_name => "open-ils.search.biblio.find_by_barcode",
398 sub biblio_barcode_to_title {
399 my( $self, $client, $barcode ) = @_;
402 throw OpenSRF::EX::ERROR
403 ("Not enough args to find_by_barcode");
406 my $title = $apputils->simple_scalar_request(
408 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
412 return { ids => [ $title->id ], count => 1 };
414 return { count => 0 };
420 __PACKAGE__->register_method(
421 method => "biblio_copy_to_mods",
422 api_name => "open-ils.search.biblio.copy.mods.retrieve",
425 # takes a copy object and returns it fleshed mods object
426 sub biblio_copy_to_mods {
427 my( $self, $client, $copy ) = @_;
429 throw OpenSRF::EX::InvalidArgs
430 ("copy.mods.retrieve needs a copy") unless( $copy );
432 new Fieldmapper::asset::copy($copy);
434 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
436 "open-ils.storage.direct.asset.call_number.retrieve",
437 $copy->call_number() );
439 my $mods = _records_to_mods($volume->record());
440 $mods = shift @$mods;
441 $volume->copies([$copy]);
442 push @{$mods->call_numbers()}, $volume;
448 sub barcode_to_mods {
453 # --------------------------------------------------------------------------------
457 __PACKAGE__->register_method(
458 method => "cat_biblio_search_class",
459 api_name => "open-ils.search.cat.biblio.class",
463 sub cat_biblio_search_class {
465 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
467 throw OpenSRF::EX::InvalidArg
468 ("Not enough args to open-ils.search.cat.biblio.class")
469 unless( defined($org_id) and $class and $sort and $string );
474 my $method = $self->method_lookup("open-ils.search.biblio.marc");
476 throw OpenSRF::EX::PANIC
477 ("Can't lookup method 'open-ils.search.biblio.marc'");
480 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
483 for my $i (@$records) { push @ids, $i->[0]; }
485 my $mods_list = _records_to_mods( @ids );
486 return undef unless (ref($mods_list) eq "ARRAY");
488 # ---------------------------------------------------------------
489 # append copy count information to the mods objects
490 my $session = OpenSRF::AppSession->create("open-ils.storage");
492 my $request = $session->request(
493 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
497 warn "receiving copy counts for doc $id\n";
499 my $response = $request->recv();
500 next unless $response;
502 if( $response and UNIVERSAL::isa($response, "Error")) {
503 throw $response ($response->stringify);
506 my $count = $response->content;
507 my $mods_obj = undef;
508 for my $m (@$mods_list) {
509 $mods_obj = $m if ($m->doc_id() == $id)
512 $mods_obj->copy_count($count);
515 $client->respond( $mods_obj );
521 $session->disconnect();
523 # ---------------------------------------------------------------
531 __PACKAGE__->register_method(
532 method => "biblio_search_class_count",
533 api_name => "open-ils.search.biblio.class.count",
536 __PACKAGE__->register_method(
537 method => "biblio_search_class_count",
538 api_name => "open-ils.search.biblio.class.count.staff",
541 sub biblio_search_class_count {
543 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
545 warn "org: $org_id : depth: $org_type\n";
547 $org_id = "1" unless defined($org_id); # xxx
548 $org_type = 0 unless defined($org_type);
550 warn "Searching biblio.class.id\n" .
552 "org_id: $org_id\n" .
553 "depth: $org_type\n" .
556 # my $bool = ($class eq "subject" || $class eq "keyword");
557 # $string = OpenILS::Application::Search->filter_search($string, $bool);
560 # return OpenILS::EX->new("SEARCH_TOO_LARGE")->ex;
564 if( !defined($org_id) or !$class or !$string ) {
565 warn "not enbough args to metarecord search\n";
566 throw OpenSRF::EX::InvalidArg
567 ("Not enough args to open-ils.search.cat.biblio.class")
572 if( ($class ne "title") and ($class ne "author") and
573 ($class ne "subject") and ($class ne "keyword")
574 and ($class ne "series" )) {
575 warn "Invalid search class: $class\n";
576 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
579 # grab the mr id's from storage
581 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
582 if($self->api_name =~ /staff/) {
583 $method = "$method.staff";
584 $method =~ s/\.cachable//o;
586 warn "Performing count method $method\n";
587 warn "API name " . $self->api_name() . "\n";
589 my $session = OpenSRF::AppSession->create('open-ils.storage');
591 my $request = $session->request( $method,
594 cache_page_size => 1,
598 my $count = $request->gather(1);
599 warn "Received count $count\n";
605 __PACKAGE__->register_method(
606 method => "biblio_search_class",
607 api_name => "open-ils.search.biblio.class",
610 __PACKAGE__->register_method(
611 method => "biblio_search_class",
612 api_name => "open-ils.search.biblio.class.unordered",
615 __PACKAGE__->register_method(
616 method => "biblio_search_class",
617 api_name => "open-ils.search.biblio.class.staff",
620 __PACKAGE__->register_method(
621 method => "biblio_search_class",
622 api_name => "open-ils.search.biblio.class.unordered.staff",
625 sub biblio_search_class {
627 my( $self, $client, $class, $string,
628 $org_id, $org_type, $limit, $offset, $format ) = @_;
630 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
632 $offset = 0 unless (defined($offset) and $offset > 0);
633 $limit = 100 unless (defined($limit) and $limit > 0);
634 $org_id = "1" unless (defined($org_id)); # xxx
635 $org_type = 0 unless (defined($org_type));
637 warn "Searching biblio.class.id\n" .
639 "\noffset: $offset\n" .
641 "org_id: $org_id\n" .
642 "depth: $org_type\n" .
645 warn "Search filtering string " . time() . "\n";
646 $string = OpenILS::Application::Search->filter_search($string);
647 if(!$string) { return undef; }
649 if( !defined($org_id) or !$class or !$string ) {
650 warn "not enbough args to metarecord search\n";
651 throw OpenSRF::EX::InvalidArg
652 ("Not enough args to open-ils.search.cat.biblio.class")
657 if( ($class ne "title") and ($class ne "author") and
658 ($class ne "subject") and ($class ne "keyword")
659 and ($class ne "series") ) {
660 warn "Invalid search class: $class\n";
661 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
664 #my $method = "open-ils.storage.metabib.$class.search_fts.metarecord.atomic";
665 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic";
667 if($self->api_name =~ /order/) {
668 $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.unordered.atomic",
669 #$method = "open-ils.storage.metabib.$class.search_fts.metarecord.unordered.atomic";
672 if($self->api_name =~ /staff/) {
673 $method =~ s/atomic/staff\.atomic/og;
674 $method =~ s/\.cachable//o;
677 warn "Performing search method $method\n";
678 warn "MR search method is $method\n";
680 my $session = OpenSRF::AppSession->create('open-ils.storage');
682 warn "Search making request " . time() . "\n";
683 my $request = $session->request(
691 cache_page_size => 200,
694 my $records = $request->gather(1);
695 if(!$records) {return { ids => [] }};
697 warn "Search request complete " . time() . "\n";
702 warn "Received " . scalar(@$records) . " id's from class search\n";
704 # if we just get one, it won't be wrapped in an array
705 if(!ref($records->[0])) {
706 $records = [$records]; }
707 for my $i (@$records) {
714 @ids = grep { defined($_->[0]) } @ids;
717 $session->disconnect();
719 return { ids => \@ids };
724 __PACKAGE__->register_method(
725 method => "biblio_mrid_to_modsbatch_batch",
726 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
728 sub biblio_mrid_to_modsbatch_batch {
729 my( $self, $client, $mrids) = @_;
730 warn "Performing mrid_to_modsbatch_batch...";
732 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
734 warn "Grabbing mods for " . Dumper($mrids) . "\n";
736 for my $id (@$mrids) {
737 next unless defined $id;
738 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
739 my ($m) = $method->run($id);
746 __PACKAGE__->register_method(
747 method => "biblio_mrid_to_modsbatch",
748 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve");
750 __PACKAGE__->register_method(
751 method => "biblio_mrid_to_modsbatch",
752 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff");
754 sub biblio_mrid_to_modsbatch {
755 my( $self, $client, $mrid ) = @_;
757 throw OpenSRF::EX::InvalidArg
758 ("search.biblio.metarecord_to_mods requires mr id")
759 unless defined( $mrid );
762 my $metarecord = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
763 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
766 throw OpenSRF::EX::ERROR ("No metarecord exists with the given id: $mrid");
769 my $master_id = $metarecord->master_record();
772 # check for existing mods
773 if($metarecord->mods()){
774 warn "We already have mods for " . $metarecord->id . "\n";
775 my $perl = JSON->JSON2perl($metarecord->mods());
776 return Fieldmapper::metabib::virtual_record->new($perl);
781 warn "Creating mods batch for metarecord $mrid\n";
782 my $meth = "open-ils.search.biblio.metarecord_to_records";
783 if( $self->api_name =~ /staff/ ) { $meth .= ".staff";}
784 $meth = $self->method_lookup($meth);
786 my ($id_hash) = $meth->run($mrid);
788 my @ids = @{$id_hash->{ids}};
790 if(@ids < 1) { return undef; }
792 warn "Master ID is $master_id\n";
793 # grab the master record to start the mods batch
795 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
797 my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
798 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
801 throw OpenSRF::EX::ERROR
802 ("No record returned with id $master_id");
805 my $u = OpenILS::Utils::ModsParser->new();
807 $u->start_mods_batch( $record->marc );
808 my $main_doc_id = $record->id();
810 @ids = grep { $_ ne $master_id } @ids;
812 # now we have to collect all of the marc objects and push them into a mods batch
813 my $session = OpenSRF::AppSession->create("open-ils.storage");
814 my $request = $session->request(
815 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
817 while( my $response = $request->recv() ) {
819 next unless $response;
820 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
821 throw $response ($response->stringify);
824 my $content = $response->content;
827 $u->push_mods_batch( $content->marc );
831 my $mods = $u->finish_mods_batch();
832 $mods->doc_id($mrid);
835 $client->respond_complete($mods);
837 my $mods_string = JSON->perl2JSON($mods->decast);
839 $metarecord->mods($mods_string);
841 my $req = $session->request(
842 "open-ils.storage.direct.metabib.metarecord.update",
849 $session->disconnect();
857 # converts a mr id into a list of record ids
859 __PACKAGE__->register_method(
860 method => "biblio_mrid_to_record_ids",
861 api_name => "open-ils.search.biblio.metarecord_to_records",
864 __PACKAGE__->register_method(
865 method => "biblio_mrid_to_record_ids",
866 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
869 sub biblio_mrid_to_record_ids {
870 my( $self, $client, $mrid, $format ) = @_;
872 throw OpenSRF::EX::InvalidArg
873 ("search.biblio.metarecord_to_record_ids requires mr id")
874 unless defined( $mrid );
876 warn "Searching for record for MR $mrid and format $format\n";
878 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
879 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
880 warn "Performing record retrieval with method $method\n";
883 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
885 #"open-ils.storage.direct.metabib.metarecord_source_map.search.metarecord", $mrid );
891 #for my $map (@$mrmaps) { push @ids, $map->source(); }
892 #warn "Recovered id's [@ids] for mr $mrid\n";
900 return { count => $size, ids => $mrmaps };
906 __PACKAGE__->register_method(
907 method => "biblio_record_to_marc_html",
908 api_name => "open-ils.search.biblio.record.html" );
910 my $parser = XML::LibXML->new();
911 my $xslt = XML::LibXSLT->new();
914 my $settings_client = OpenSRF::Utils::SettingsClient->new();
915 sub biblio_record_to_marc_html {
916 my( $self, $client, $recordid ) = @_;
919 my $dir = $settings_client->config_value( "dirs", "xsl" );
920 my $xsl = $settings_client->config_value(
921 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
923 $xsl = $parser->parse_file("$dir/$xsl");
924 $marc_sheet = $xslt->parse_stylesheet( $xsl );
928 my $record = $apputils->simple_scalar_request(
930 "open-ils.storage.direct.biblio.record_entry.retrieve",
933 my $xmldoc = $parser->parse_string($record->marc);
934 my $html = $marc_sheet->transform($xmldoc);
935 $html = $html->toString();
942 __PACKAGE__->register_method(
943 method => "retrieve_all_copy_locations",
944 api_name => "open-ils.search.config.copy_location.retrieve.all" );
946 my $shelving_locations;
947 sub retrieve_all_copy_locations {
948 my( $self, $client ) = @_;
949 if(!$shelving_locations) {
950 $shelving_locations = $apputils->simple_scalar_request(
952 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
954 return $shelving_locations;
959 __PACKAGE__->register_method(
960 method => "retrieve_all_copy_statuses",
961 api_name => "open-ils.search.config.copy_status.retrieve.all" );
964 sub retrieve_all_copy_statuses {
965 my( $self, $client ) = @_;
966 if(!$copy_statuses) {
967 $copy_statuses = $apputils->simple_scalar_request(
969 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
971 return $copy_statuses;
975 __PACKAGE__->register_method(
976 method => "copy_counts_per_org",
977 api_name => "open-ils.search.biblio.copy_counts.retrieve");
979 __PACKAGE__->register_method(
980 method => "copy_counts_per_org",
981 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
983 sub copy_counts_per_org {
984 my( $self, $client, $record_id ) = @_;
986 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
988 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
989 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
991 my $counts = $apputils->simple_scalar_request(
992 "open-ils.storage", $method, $record_id );
994 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];