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 $mods->tcn($last_content->tcn_value);
93 warn "Turning doc " . $mods->doc_id() . " into MODS\n";
94 $last_content = undef;
98 next unless $response;
100 if($response->isa("OpenSRF::EX")) {
101 throw $response ($response->stringify);
104 $last_content = $response->content;
108 if( $last_content ) {
109 my $u = OpenILS::Utils::ModsParser->new();
110 $u->start_mods_batch( $last_content->marc );
111 my $mods = $u->finish_mods_batch();
112 $mods->doc_id($last_content->id());
113 $mods->tcn($last_content->tcn_value);
114 push @results, $mods;
119 $session->disconnect();
125 __PACKAGE__->register_method(
126 method => "record_id_to_mods",
127 api_name => "open-ils.search.biblio.record.mods.retrieve",
129 note => "Provide ID, we provide the mods"
132 # converts a record into a mods object with copy counts attached
133 sub record_id_to_mods {
135 my( $self, $client, $org_id, $id ) = @_;
137 my $mods_list = _records_to_mods( $id );
138 my $mods_obj = $mods_list->[0];
139 my $cmethod = $self->method_lookup(
140 "open-ils.search.biblio.record.copy_count");
141 my ($count) = $cmethod->run($org_id, $id);
142 $mods_obj->copy_count($count);
149 __PACKAGE__->register_method(
150 method => "record_id_to_mods_slim",
151 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
153 note => "Provide ID, we provide the mods"
156 # converts a record into a mods object with NO copy counts attached
157 sub record_id_to_mods_slim {
158 my( $self, $client, $id ) = @_;
159 return undef unless defined $id;
161 if(ref($id) and ref($id) == 'ARRAY') {
162 return _records_to_mods( @$id );
164 my $mods_list = _records_to_mods( $id );
165 my $mods_obj = $mods_list->[0];
170 # Returns the number of copies attached to a record based on org location
171 __PACKAGE__->register_method(
172 method => "record_id_to_copy_count",
173 api_name => "open-ils.search.biblio.record.copy_count",
176 __PACKAGE__->register_method(
177 method => "record_id_to_copy_count",
178 api_name => "open-ils.search.biblio.metarecord.copy_count",
181 __PACKAGE__->register_method(
182 method => "record_id_to_copy_count",
183 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
185 sub record_id_to_copy_count {
186 my( $self, $client, $org_id, $record_id ) = @_;
188 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
190 if($self->api_name =~ /metarecord/) {
191 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
195 if($self->api_name =~ /staff/ ) {
196 $method =~ s/atomic/staff\.atomic/og;
197 warn "Doing staff search $method\n";
201 my $session = OpenSRF::AppSession->create("open-ils.storage");
202 warn "copy_count retrieve $record_id\n";
203 return undef unless(defined $record_id);
205 my $request = $session->request(
206 $method, org_unit => $org_id => $key => $record_id );
209 my $count = $request->gather(1);
210 $session->disconnect();
211 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
216 # used for cat search classes
217 my $cat_search_hash = {
220 { tag => "100", subfield => "a"} ,
221 { tag => "700", subfield => "a"},
225 { tag => "245", subfield => "a"},
226 { tag => "242", subfield => "a"},
227 { tag => "240", subfield => "a"},
228 { tag => "210", subfield => "a"},
232 { tag => "650", subfield => "_" },
236 { tag => "035", subfield => "_" },
240 { tag => "020", subfield => "a" },
246 __PACKAGE__->register_method(
247 method => "biblio_search_tcn",
248 api_name => "open-ils.search.biblio.tcn",
250 note => "Retrieve a record by TCN",
253 sub biblio_search_tcn {
255 my( $self, $client, $tcn ) = @_;
257 $tcn =~ s/.*?(\w+)\s*$/$1/o;
258 warn "Searching TCN $tcn\n";
260 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
261 my $request = $session->request(
262 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
263 my $record_entry = $request->gather(1);
266 for my $record (@$record_entry) {
267 push @ids, $record->id;
270 $session->disconnect();
272 warn "received ID's for tcn search @ids\n";
275 return { count => $size, ids => \@ids };
280 # --------------------------------------------------------------------------------
283 __PACKAGE__->register_method(
284 method => "biblio_search_isbn",
285 api_name => "open-ils.search.biblio.isbn",
288 sub biblio_search_isbn {
289 my( $self, $client, $isbn ) = @_;
290 throw OpenSRF::EX::InvalidArg
292 ("biblio_search_isbn needs an ISBN to search")
293 unless defined $isbn;
295 warn "biblio search for ISBN $isbn\n";
296 my $method = $self->method_lookup("open-ils.search.biblio.marc");
297 my ($records) = $method->run( $cat_search_hash->{isbn}, $isbn );
299 return { count => 0 } unless($records and @$records);
300 my $size = @$records;
301 return { count => $size, ids => $records };
306 # --------------------------------------------------------------------------------
308 __PACKAGE__->register_method(
309 method => "biblio_barcode_to_copy",
310 api_name => "open-ils.search.asset.copy.find_by_barcode",
313 # turns a barcode into a copy object
314 sub biblio_barcode_to_copy {
315 my( $self, $client, $barcode ) = @_;
317 throw OpenSRF::EX::InvalidArg
318 ("search.biblio.barcode needs a barcode to search")
319 unless defined $barcode;
321 warn "copy search for barcode $barcode\n";
322 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
324 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
327 return undef unless($record);
332 __PACKAGE__->register_method(
333 method => "biblio_id_to_copy",
334 api_name => "open-ils.search.asset.copy.batch.retrieve",
337 # turns a barcode into a copy object
338 sub biblio_id_to_copy {
339 my( $self, $client, $ids ) = @_;
341 throw OpenSRF::EX::InvalidArg
342 ("search.biblio.batch.retrieve needs a id to search")
345 warn "copy search for ids @$ids\n";
346 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
348 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
356 __PACKAGE__->register_method(
357 method => "fleshed_copy_retrieve_batch",
358 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
361 sub fleshed_copy_retrieve_batch {
362 my( $self, $client, $ids ) = @_;
364 throw OpenSRF::EX::InvalidArg
365 ("search.biblio.batch.retrieve needs a id to search")
368 warn "fleshed copy search for id @$ids\n";
369 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
371 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
377 __PACKAGE__->register_method(
378 method => "fleshed_copy_retrieve",
379 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
382 sub fleshed_copy_retrieve {
383 my( $self, $client, $id ) = @_;
385 return undef unless defined $id;
386 warn "copy retrieve for id $id\n";
387 return OpenILS::Application::AppUtils->simple_scalar_request(
389 "open-ils.storage.fleshed.asset.copy.retrieve.atomic",
395 __PACKAGE__->register_method(
396 method => "biblio_barcode_to_title",
397 api_name => "open-ils.search.biblio.find_by_barcode",
400 sub biblio_barcode_to_title {
401 my( $self, $client, $barcode ) = @_;
404 throw OpenSRF::EX::ERROR
405 ("Not enough args to find_by_barcode");
408 my $title = $apputils->simple_scalar_request(
410 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
414 return { ids => [ $title->id ], count => 1 };
416 return { count => 0 };
422 __PACKAGE__->register_method(
423 method => "biblio_copy_to_mods",
424 api_name => "open-ils.search.biblio.copy.mods.retrieve",
427 # takes a copy object and returns it fleshed mods object
428 sub biblio_copy_to_mods {
429 my( $self, $client, $copy ) = @_;
431 throw OpenSRF::EX::InvalidArgs
432 ("copy.mods.retrieve needs a copy") unless( $copy );
434 new Fieldmapper::asset::copy($copy);
436 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
438 "open-ils.storage.direct.asset.call_number.retrieve",
439 $copy->call_number() );
441 my $mods = _records_to_mods($volume->record());
442 $mods = shift @$mods;
443 $volume->copies([$copy]);
444 push @{$mods->call_numbers()}, $volume;
450 sub barcode_to_mods {
455 # --------------------------------------------------------------------------------
459 __PACKAGE__->register_method(
460 method => "cat_biblio_search_class",
461 api_name => "open-ils.search.cat.biblio.class",
465 sub cat_biblio_search_class {
467 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
469 throw OpenSRF::EX::InvalidArg
470 ("Not enough args to open-ils.search.cat.biblio.class")
471 unless( defined($org_id) and $class and $sort and $string );
476 my $method = $self->method_lookup("open-ils.search.biblio.marc");
478 throw OpenSRF::EX::PANIC
479 ("Can't lookup method 'open-ils.search.biblio.marc'");
482 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
485 for my $i (@$records) { push @ids, $i->[0]; }
487 my $mods_list = _records_to_mods( @ids );
488 return undef unless (ref($mods_list) eq "ARRAY");
490 # ---------------------------------------------------------------
491 # append copy count information to the mods objects
492 my $session = OpenSRF::AppSession->create("open-ils.storage");
494 my $request = $session->request(
495 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
499 warn "receiving copy counts for doc $id\n";
501 my $response = $request->recv();
502 next unless $response;
504 if( $response and UNIVERSAL::isa($response, "Error")) {
505 throw $response ($response->stringify);
508 my $count = $response->content;
509 my $mods_obj = undef;
510 for my $m (@$mods_list) {
511 $mods_obj = $m if ($m->doc_id() == $id)
514 $mods_obj->copy_count($count);
517 $client->respond( $mods_obj );
523 $session->disconnect();
525 # ---------------------------------------------------------------
533 __PACKAGE__->register_method(
534 method => "biblio_search_class_count",
535 api_name => "open-ils.search.biblio.class.count",
538 __PACKAGE__->register_method(
539 method => "biblio_search_class_count",
540 api_name => "open-ils.search.biblio.class.count.staff",
543 sub biblio_search_class_count {
545 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
547 warn "org: $org_id : depth: $org_type\n";
549 $org_id = "1" unless defined($org_id); # xxx
550 $org_type = 0 unless defined($org_type);
552 warn "Searching biblio.class.id\n" .
554 "org_id: $org_id\n" .
555 "depth: $org_type\n" .
558 if( !defined($org_id) or !$class or !$string ) {
559 warn "not enbough args to metarecord search\n";
560 throw OpenSRF::EX::InvalidArg
561 ("Not enough args to open-ils.search.cat.biblio.class")
566 if( ($class ne "title") and ($class ne "author") and
567 ($class ne "subject") and ($class ne "keyword")
568 and ($class ne "series" )) {
569 warn "Invalid search class: $class\n";
570 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
573 # grab the mr id's from storage
575 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
576 if($self->api_name =~ /staff/) {
577 $method = "$method.staff";
578 $method =~ s/\.cachable//o;
580 warn "Performing count method $method\n";
581 warn "API name " . $self->api_name() . "\n";
583 my $session = OpenSRF::AppSession->create('open-ils.storage');
585 my $request = $session->request( $method,
588 cache_page_size => 1,
592 my $count = $request->gather(1);
593 warn "Received count $count\n";
599 __PACKAGE__->register_method(
600 method => "biblio_search_class",
601 api_name => "open-ils.search.biblio.class",
604 __PACKAGE__->register_method(
605 method => "biblio_search_class",
606 api_name => "open-ils.search.biblio.class.full",
609 __PACKAGE__->register_method(
610 method => "biblio_search_class",
611 api_name => "open-ils.search.biblio.class.full.staff",
614 #__PACKAGE__->register_method(
615 # method => "biblio_search_class",
616 # api_name => "open-ils.search.biblio.class.unordered",
619 __PACKAGE__->register_method(
620 method => "biblio_search_class",
621 api_name => "open-ils.search.biblio.class.staff",
624 #__PACKAGE__->register_method(
625 # method => "biblio_search_class",
626 # api_name => "open-ils.search.biblio.class.unordered.staff",
629 sub biblio_search_class {
631 my( $self, $client, $class, $string,
632 $org_id, $org_type, $limit, $offset, $format ) = @_;
634 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
637 # new method: metabib.<class>.new_search_fts.metarecord.<staff>
640 $offset = 0 unless (defined($offset) and $offset > 0);
641 $limit = 100 unless (defined($limit) and $limit > 0);
642 $org_id = "1" unless (defined($org_id)); # xxx
643 $org_type = 0 unless (defined($org_type));
645 warn "Searching biblio.class.id\n" .
647 "\noffset: $offset\n" .
649 "org_id: $org_id\n" .
650 "depth: $org_type\n" .
653 warn "Search filtering string " . time() . "\n";
654 $string = OpenILS::Application::Search->filter_search($string);
655 if(!$string) { return undef; }
657 if( !defined($org_id) or !$class or !$string ) {
658 warn "not enbough args to metarecord search\n";
659 throw OpenSRF::EX::InvalidArg
660 ("Not enough args to open-ils.search.cat.biblio.class")
665 if( ($class ne "title") and ($class ne "author") and
666 ($class ne "subject") and ($class ne "keyword")
667 and ($class ne "series") ) {
668 warn "Invalid search class: $class\n";
669 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
672 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic";
674 # if($self->api_name =~ /order/) {
675 # $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.unordered.atomic",
678 if($self->api_name =~ /staff/) {
679 $method =~ s/atomic/staff\.atomic/og;
680 $method =~ s/\.cachable//o;
683 if($self->api_name =~ /full/) {
684 $method =~ s/search_fts/new_search_fts/o;
685 $method =~ s/\.cachable//o; #XXX testing..
688 warn "Performing search method $method\n";
689 warn "MR search method is $method\n";
691 my $session = OpenSRF::AppSession->create('open-ils.storage');
693 warn "Search making request " . time() . "\n";
694 my $request = $session->request(
702 cache_page_size => 200,
705 my $records = $request->gather(1);
706 if(!$records) {return { ids => [] }};
708 warn "Search request complete " . time() . "\n";
713 warn "Received " . scalar(@$records) . " id's from class search\n";
715 # if we just get one, it won't be wrapped in an array
717 if(!ref($records->[0])) {
718 $records = [$records]; }
719 for my $i (@$records) {
726 @ids = grep { defined($_->[0]) } @ids;
729 $session->disconnect();
732 if($self->api_name =~ /full/) {
733 if(ref($records) && $records->[0]) {
734 $count = $records->[0]->[3];
738 return { ids => \@ids, count => $count };
745 __PACKAGE__->register_method(
746 method => "biblio_mrid_to_modsbatch_batch",
747 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
749 sub biblio_mrid_to_modsbatch_batch {
750 my( $self, $client, $mrids) = @_;
751 warn "Performing mrid_to_modsbatch_batch...";
753 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
755 warn "Grabbing mods for " . Dumper($mrids) . "\n";
757 for my $id (@$mrids) {
758 next unless defined $id;
759 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
760 my ($m) = $method->run($id);
767 __PACKAGE__->register_method(
768 method => "biblio_mrid_to_modsbatch",
769 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
770 notes => <<" NOTES");
771 Returns the mvr associated with a given metarecod. If none exists,
775 __PACKAGE__->register_method(
776 method => "biblio_mrid_to_modsbatch",
777 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
778 notes => <<" NOTES");
779 Returns the mvr associated with a given metarecod. If none exists,
783 sub biblio_mrid_to_modsbatch {
784 my( $self, $client, $mrid ) = @_;
786 warn "Grabbing mvr for $mrid\n";
788 my $mr = _grab_metarecord($mrid);
789 return undef unless $mr;
791 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
795 return biblio_mrid_make_modsbatch( $client, $mr );
798 # converts a metarecord to an mvr
801 my $perl = JSON->JSON2perl($mr->mods());
802 return Fieldmapper::metabib::virtual_record->new($perl);
805 # checks to see if a metarecord has mods, if so returns true;
807 __PACKAGE__->register_method(
808 method => "biblio_mrid_check_mvr",
809 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
810 notes => <<" NOTES");
811 Takes a metarecord ID or a metarecord object and returns true
812 if the metarecord already has an mvr associated with it.
815 sub biblio_mrid_check_mvr {
816 my( $self, $client, $mrid ) = @_;
819 if(ref($mrid)) { $mr = $mrid; }
820 else { $mr = _grab_metarecord($mrid); }
822 warn "Checking mvr for mr " . $mr->id . "\n";
824 return _mr_to_mvr($mr) if $mr->mods();
828 sub _grab_metarecord {
831 warn "Grabbing MR $mrid\n";
833 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
835 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
838 throw OpenSRF::EX::ERROR
839 ("No metarecord exists with the given id: $mrid");
845 __PACKAGE__->register_method(
846 method => "biblio_mrid_make_modsbatch",
847 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
848 notes => <<" NOTES");
849 Takes either a metarecord ID or a metarecord object.
850 Forces the creations of an mvr for the given metarecord.
851 The created mvr is returned.
854 sub biblio_mrid_make_modsbatch {
856 my( $self, $client, $mrid ) = @_;
859 if(ref($mrid)) { $mr = $mrid; }
860 else { $mr = _grab_metarecord($mrid); }
862 warn "Forcing mvr creation for mr " . $mr->id . "\n";
863 my $master_id = $mr->master_record;
865 my $session = OpenSRF::AppSession->create("open-ils.storage");
867 # grab the records attached to this metarecod
868 warn "Creating mods batch for metarecord $mrid\n";
869 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
870 $meth = $self->method_lookup($meth);
871 my ($id_hash) = $meth->run($mrid);
872 my @ids = @{$id_hash->{ids}};
873 if(@ids < 1) { return undef; }
875 warn "Master ID is $master_id\n";
876 # grab the master record to start the mods batch
878 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
880 my $record = $session->request(
881 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
882 $record = $record->gather(1);
884 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
887 warn "No record returned with id $master_id";
888 throw OpenSRF::EX::ERROR
891 my $u = OpenILS::Utils::ModsParser->new();
893 $u->start_mods_batch( $record->marc );
894 my $main_doc_id = $record->id();
896 @ids = grep { $_ ne $master_id } @ids;
898 # now we have to collect all of the marc objects and push them into a mods batch
899 my $request = $session->request(
900 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
902 while( my $response = $request->recv() ) {
904 next unless $response;
905 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
906 throw $response ($response->stringify);
909 my $content = $response->content;
912 $u->push_mods_batch( $content->marc );
916 my $mods = $u->finish_mods_batch();
917 $mods->doc_id($mrid);
920 $client->respond_complete($mods);
922 my $mods_string = JSON->perl2JSON($mods->decast);
924 $mr->mods($mods_string);
926 my $req = $session->request(
927 "open-ils.storage.direct.metabib.metarecord.update", $mr );
932 $session->disconnect();
939 # converts a mr id into a list of record ids
941 __PACKAGE__->register_method(
942 method => "biblio_mrid_to_record_ids",
943 api_name => "open-ils.search.biblio.metarecord_to_records",
946 __PACKAGE__->register_method(
947 method => "biblio_mrid_to_record_ids",
948 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
951 sub biblio_mrid_to_record_ids {
952 my( $self, $client, $mrid, $format ) = @_;
954 throw OpenSRF::EX::InvalidArg
955 ("search.biblio.metarecord_to_record_ids requires mr id")
956 unless defined( $mrid );
958 warn "Searching for record for MR $mrid and format $format\n";
960 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
961 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
962 warn "Performing record retrieval with method $method\n";
965 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
966 "open-ils.storage", $method, $mrid, $format );
973 return { count => $size, ids => $mrmaps };
978 __PACKAGE__->register_method(
979 method => "biblio_record_to_marc_html",
980 api_name => "open-ils.search.biblio.record.html" );
982 my $parser = XML::LibXML->new();
983 my $xslt = XML::LibXSLT->new();
986 my $settings_client = OpenSRF::Utils::SettingsClient->new();
987 sub biblio_record_to_marc_html {
988 my( $self, $client, $recordid ) = @_;
991 my $dir = $settings_client->config_value( "dirs", "xsl" );
992 my $xsl = $settings_client->config_value(
993 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
995 $xsl = $parser->parse_file("$dir/$xsl");
996 $marc_sheet = $xslt->parse_stylesheet( $xsl );
1000 my $record = $apputils->simple_scalar_request(
1002 "open-ils.storage.direct.biblio.record_entry.retrieve",
1005 my $xmldoc = $parser->parse_string($record->marc);
1006 my $html = $marc_sheet->transform($xmldoc);
1007 $html = $html->toString();
1014 __PACKAGE__->register_method(
1015 method => "retrieve_all_copy_locations",
1016 api_name => "open-ils.search.config.copy_location.retrieve.all" );
1018 my $shelving_locations;
1019 sub retrieve_all_copy_locations {
1020 my( $self, $client ) = @_;
1021 if(!$shelving_locations) {
1022 $shelving_locations = $apputils->simple_scalar_request(
1024 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
1026 return $shelving_locations;
1031 __PACKAGE__->register_method(
1032 method => "retrieve_all_copy_statuses",
1033 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1036 sub retrieve_all_copy_statuses {
1037 my( $self, $client ) = @_;
1038 if(!$copy_statuses) {
1039 $copy_statuses = $apputils->simple_scalar_request(
1041 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
1043 return $copy_statuses;
1047 __PACKAGE__->register_method(
1048 method => "copy_counts_per_org",
1049 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1051 __PACKAGE__->register_method(
1052 method => "copy_counts_per_org",
1053 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1055 sub copy_counts_per_org {
1056 my( $self, $client, $record_id ) = @_;
1058 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1060 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1061 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1063 my $counts = $apputils->simple_scalar_request(
1064 "open-ils.storage", $method, $record_id );
1066 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1071 __PACKAGE__->register_method(
1072 method => "copy_count_summary",
1073 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1074 notes => <<" NOTES");
1075 returns an array of these:
1076 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1077 where statusx is a copy status name. the statuses are sorted
1081 sub copy_count_summary {
1082 my( $self, $client, $rid ) = @_;
1083 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
1084 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );