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 if( !defined($org_id) or !$class or !$string ) {
557 warn "not enbough args to metarecord search\n";
558 throw OpenSRF::EX::InvalidArg
559 ("Not enough args to open-ils.search.cat.biblio.class")
564 if( ($class ne "title") and ($class ne "author") and
565 ($class ne "subject") and ($class ne "keyword")
566 and ($class ne "series" )) {
567 warn "Invalid search class: $class\n";
568 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
571 # grab the mr id's from storage
573 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
574 if($self->api_name =~ /staff/) {
575 $method = "$method.staff";
576 $method =~ s/\.cachable//o;
578 warn "Performing count method $method\n";
579 warn "API name " . $self->api_name() . "\n";
581 my $session = OpenSRF::AppSession->create('open-ils.storage');
583 my $request = $session->request( $method,
586 cache_page_size => 1,
590 my $count = $request->gather(1);
591 warn "Received count $count\n";
597 __PACKAGE__->register_method(
598 method => "biblio_search_class",
599 api_name => "open-ils.search.biblio.class",
602 __PACKAGE__->register_method(
603 method => "biblio_search_class",
604 api_name => "open-ils.search.biblio.class.full",
607 __PACKAGE__->register_method(
608 method => "biblio_search_class",
609 api_name => "open-ils.search.biblio.class.full.staff",
612 #__PACKAGE__->register_method(
613 # method => "biblio_search_class",
614 # api_name => "open-ils.search.biblio.class.unordered",
617 __PACKAGE__->register_method(
618 method => "biblio_search_class",
619 api_name => "open-ils.search.biblio.class.staff",
622 #__PACKAGE__->register_method(
623 # method => "biblio_search_class",
624 # api_name => "open-ils.search.biblio.class.unordered.staff",
627 sub biblio_search_class {
629 my( $self, $client, $class, $string,
630 $org_id, $org_type, $limit, $offset, $format ) = @_;
632 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
635 # new method: metabib.<class>.new_search_fts.metarecord.<staff>
638 $offset = 0 unless (defined($offset) and $offset > 0);
639 $limit = 100 unless (defined($limit) and $limit > 0);
640 $org_id = "1" unless (defined($org_id)); # xxx
641 $org_type = 0 unless (defined($org_type));
643 warn "Searching biblio.class.id\n" .
645 "\noffset: $offset\n" .
647 "org_id: $org_id\n" .
648 "depth: $org_type\n" .
651 warn "Search filtering string " . time() . "\n";
652 $string = OpenILS::Application::Search->filter_search($string);
653 if(!$string) { return undef; }
655 if( !defined($org_id) or !$class or !$string ) {
656 warn "not enbough args to metarecord search\n";
657 throw OpenSRF::EX::InvalidArg
658 ("Not enough args to open-ils.search.cat.biblio.class")
663 if( ($class ne "title") and ($class ne "author") and
664 ($class ne "subject") and ($class ne "keyword")
665 and ($class ne "series") ) {
666 warn "Invalid search class: $class\n";
667 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
670 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic";
672 # if($self->api_name =~ /order/) {
673 # $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.unordered.atomic",
676 if($self->api_name =~ /staff/) {
677 $method =~ s/atomic/staff\.atomic/og;
678 $method =~ s/\.cachable//o;
681 if($self->api_name =~ /full/) {
682 $method =~ s/search_fts/new_search_fts/o;
683 $method =~ s/\.cachable//o; #XXX testing..
686 warn "Performing search method $method\n";
687 warn "MR search method is $method\n";
689 my $session = OpenSRF::AppSession->create('open-ils.storage');
691 warn "Search making request " . time() . "\n";
692 my $request = $session->request(
700 cache_page_size => 200,
703 my $records = $request->gather(1);
704 if(!$records) {return { ids => [] }};
706 warn "Search request complete " . time() . "\n";
711 warn "Received " . scalar(@$records) . " id's from class search\n";
713 # if we just get one, it won't be wrapped in an array
715 if(!ref($records->[0])) {
716 $records = [$records]; }
717 for my $i (@$records) {
724 @ids = grep { defined($_->[0]) } @ids;
727 $session->disconnect();
730 if($self->api_name =~ /full/) {
731 if(ref($records) && $records->[0]) {
732 $count = $records->[0]->[3];
736 return { ids => \@ids, count => $count };
743 __PACKAGE__->register_method(
744 method => "biblio_mrid_to_modsbatch_batch",
745 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
747 sub biblio_mrid_to_modsbatch_batch {
748 my( $self, $client, $mrids) = @_;
749 warn "Performing mrid_to_modsbatch_batch...";
751 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
753 warn "Grabbing mods for " . Dumper($mrids) . "\n";
755 for my $id (@$mrids) {
756 next unless defined $id;
757 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
758 my ($m) = $method->run($id);
765 __PACKAGE__->register_method(
766 method => "biblio_mrid_to_modsbatch",
767 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve");
769 __PACKAGE__->register_method(
770 method => "biblio_mrid_to_modsbatch",
771 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff");
773 sub biblio_mrid_to_modsbatch {
774 my( $self, $client, $mrid ) = @_;
776 throw OpenSRF::EX::InvalidArg
777 ("search.biblio.metarecord_to_mods requires mr id")
778 unless defined( $mrid );
781 my $metarecord = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
782 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
785 throw OpenSRF::EX::ERROR ("No metarecord exists with the given id: $mrid");
788 my $master_id = $metarecord->master_record();
791 # check for existing mods
792 if($metarecord->mods()){
793 warn "We already have mods for " . $metarecord->id . "\n";
794 my $perl = JSON->JSON2perl($metarecord->mods());
795 return Fieldmapper::metabib::virtual_record->new($perl);
800 warn "Creating mods batch for metarecord $mrid\n";
801 my $meth = "open-ils.search.biblio.metarecord_to_records";
802 if( $self->api_name =~ /staff/ ) { $meth .= ".staff";}
803 $meth = $self->method_lookup($meth);
805 my ($id_hash) = $meth->run($mrid);
807 my @ids = @{$id_hash->{ids}};
809 if(@ids < 1) { return undef; }
811 warn "Master ID is $master_id\n";
812 # grab the master record to start the mods batch
814 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
816 my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
817 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
820 throw OpenSRF::EX::ERROR
821 ("No record returned with id $master_id");
824 my $u = OpenILS::Utils::ModsParser->new();
826 $u->start_mods_batch( $record->marc );
827 my $main_doc_id = $record->id();
829 @ids = grep { $_ ne $master_id } @ids;
831 # now we have to collect all of the marc objects and push them into a mods batch
832 my $session = OpenSRF::AppSession->create("open-ils.storage");
833 my $request = $session->request(
834 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
836 while( my $response = $request->recv() ) {
838 next unless $response;
839 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
840 throw $response ($response->stringify);
843 my $content = $response->content;
846 $u->push_mods_batch( $content->marc );
850 my $mods = $u->finish_mods_batch();
851 $mods->doc_id($mrid);
854 $client->respond_complete($mods);
856 my $mods_string = JSON->perl2JSON($mods->decast);
858 $metarecord->mods($mods_string);
860 my $req = $session->request(
861 "open-ils.storage.direct.metabib.metarecord.update",
868 $session->disconnect();
876 # converts a mr id into a list of record ids
878 __PACKAGE__->register_method(
879 method => "biblio_mrid_to_record_ids",
880 api_name => "open-ils.search.biblio.metarecord_to_records",
883 __PACKAGE__->register_method(
884 method => "biblio_mrid_to_record_ids",
885 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
888 sub biblio_mrid_to_record_ids {
889 my( $self, $client, $mrid, $format ) = @_;
891 throw OpenSRF::EX::InvalidArg
892 ("search.biblio.metarecord_to_record_ids requires mr id")
893 unless defined( $mrid );
895 warn "Searching for record for MR $mrid and format $format\n";
897 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
898 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
899 warn "Performing record retrieval with method $method\n";
902 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
903 "open-ils.storage", $method, $mrid, $format );
910 return { count => $size, ids => $mrmaps };
915 __PACKAGE__->register_method(
916 method => "biblio_record_to_marc_html",
917 api_name => "open-ils.search.biblio.record.html" );
919 my $parser = XML::LibXML->new();
920 my $xslt = XML::LibXSLT->new();
923 my $settings_client = OpenSRF::Utils::SettingsClient->new();
924 sub biblio_record_to_marc_html {
925 my( $self, $client, $recordid ) = @_;
928 my $dir = $settings_client->config_value( "dirs", "xsl" );
929 my $xsl = $settings_client->config_value(
930 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
932 $xsl = $parser->parse_file("$dir/$xsl");
933 $marc_sheet = $xslt->parse_stylesheet( $xsl );
937 my $record = $apputils->simple_scalar_request(
939 "open-ils.storage.direct.biblio.record_entry.retrieve",
942 my $xmldoc = $parser->parse_string($record->marc);
943 my $html = $marc_sheet->transform($xmldoc);
944 $html = $html->toString();
951 __PACKAGE__->register_method(
952 method => "retrieve_all_copy_locations",
953 api_name => "open-ils.search.config.copy_location.retrieve.all" );
955 my $shelving_locations;
956 sub retrieve_all_copy_locations {
957 my( $self, $client ) = @_;
958 if(!$shelving_locations) {
959 $shelving_locations = $apputils->simple_scalar_request(
961 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
963 return $shelving_locations;
968 __PACKAGE__->register_method(
969 method => "retrieve_all_copy_statuses",
970 api_name => "open-ils.search.config.copy_status.retrieve.all" );
973 sub retrieve_all_copy_statuses {
974 my( $self, $client ) = @_;
975 if(!$copy_statuses) {
976 $copy_statuses = $apputils->simple_scalar_request(
978 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
980 return $copy_statuses;
984 __PACKAGE__->register_method(
985 method => "copy_counts_per_org",
986 api_name => "open-ils.search.biblio.copy_counts.retrieve");
988 __PACKAGE__->register_method(
989 method => "copy_counts_per_org",
990 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
992 sub copy_counts_per_org {
993 my( $self, $client, $record_id ) = @_;
995 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
997 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
998 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1000 my $counts = $apputils->simple_scalar_request(
1001 "open-ils.storage", $method, $record_id );
1003 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];