]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
aaahhhh, demo
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Biblio.pm
1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4
5 use JSON;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Utils::ModsParser;
8 use OpenSRF::Utils::SettingsClient;
9
10 use OpenILS::Application::AppUtils;
11
12 use JSON;
13
14 use Time::HiRes qw(time);
15 use OpenSRF::EX qw(:try);
16 use Digest::MD5 qw(md5_hex);
17
18 use XML::LibXML;
19 use XML::LibXSLT;
20
21 my $apputils = "OpenILS::Application::AppUtils";
22
23 # Houses biblio search utilites 
24
25 __PACKAGE__->register_method(
26         method  => "biblio_search_marc",
27         api_name        => "open-ils.search.biblio.marc",
28         argc            => 1, 
29         note            => "Searches biblio information by marc tag",
30 );
31
32 sub biblio_search_marc {
33
34         my( $self, $client, $search_hash, $string ) = @_;
35
36         warn "Building biblio marc session\n";
37         my $session = OpenSRF::AppSession->create("open-ils.storage");
38
39         use Data::Dumper;
40         warn "Sending biblio marc request. String $string\nSearch hash: " . Dumper($search_hash);
41         my $request = $session->request( 
42                         "open-ils.storage.direct.metabib.full_rec.search_fts.index_vector.atomic", 
43                         restrict => $search_hash, 
44                         term            => $string );
45         my $data = $request->gather(1);
46
47         warn Dumper $data;
48
49         $session->finish();
50         $session->disconnect();
51
52         return $data;
53
54 }
55
56
57
58 # ---------------------------------------------------------------------------
59 # takes a list of record id's and turns the docs into friendly 
60 # mods structures. Creates one MODS structure for each doc id.
61 # ---------------------------------------------------------------------------
62 sub _records_to_mods {
63         my @ids = @_;
64         
65         my @results;
66         my @marcxml_objs;
67
68         my $session = OpenSRF::AppSession->create("open-ils.storage");
69         my $request = $session->request(
70                         "open-ils.storage.direct.biblio.record_entry.batch.retrieve",  @ids );
71
72         my $last_content = undef;
73
74         while( my $response = $request->recv() ) {
75
76                 if( $last_content ) {
77                         my $u = OpenILS::Utils::ModsParser->new();
78                         $u->start_mods_batch( $last_content->marc );
79                         my $mods = $u->finish_mods_batch();
80                         $mods->doc_id($last_content->id());
81                         warn "Turning doc " . $mods->doc_id() . " into MODS\n";
82                         $last_content = undef;
83                         push @results, $mods;
84                 }
85
86                 next unless $response;
87
88                 if($response->isa("OpenSRF::EX")) {
89                         throw $response ($response->stringify);
90                 }
91
92                 $last_content = $response->content;
93
94         }
95
96         if( $last_content ) {
97                 my $u = OpenILS::Utils::ModsParser->new();
98                 $u->start_mods_batch( $last_content->marc );
99                 my $mods = $u->finish_mods_batch();
100                 $mods->doc_id($last_content->id());
101                 push @results, $mods;
102         }
103
104         $request->finish();
105         $session->finish();
106         $session->disconnect();
107
108         return \@results;
109
110 }
111
112 __PACKAGE__->register_method(
113         method  => "record_id_to_mods",
114         api_name        => "open-ils.search.biblio.record.mods.retrieve",
115         argc            => 1, 
116         note            => "Provide ID, we provide the mods"
117 );
118
119 # converts a record into a mods object with copy counts attached
120 sub record_id_to_mods {
121
122         my( $self, $client, $org_id, $id ) = @_;
123
124         my $mods_list = _records_to_mods( $id );
125         my $mods_obj = $mods_list->[0];
126         my $cmethod = $self->method_lookup(
127                         "open-ils.search.biblio.record.copy_count");
128         my ($count) = $cmethod->run($org_id, $id);
129         $mods_obj->copy_count($count);
130
131         return $mods_obj;
132 }
133
134
135 __PACKAGE__->register_method(
136         method  => "record_id_to_mods_slim",
137         api_name        => "open-ils.search.biblio.record.mods_slim.retrieve",
138         argc            => 1, 
139         note            => "Provide ID, we provide the mods"
140 );
141
142 # converts a record into a mods object with NO copy counts attached
143 sub record_id_to_mods_slim {
144
145         my( $self, $client, $id ) = @_;
146         warn "Retrieving MODS object for record $id\n";
147         return undef unless(defined $id);
148
149         my $mods_list = _records_to_mods( $id );
150         my $mods_obj = $mods_list->[0];
151         return $mods_obj;
152 }
153
154
155 # Returns the number of copies attached to a record based on org location
156 __PACKAGE__->register_method(
157         method  => "record_id_to_copy_count",
158         api_name        => "open-ils.search.biblio.record.copy_count",
159 );
160
161 __PACKAGE__->register_method(
162         method  => "record_id_to_copy_count",
163         api_name        => "open-ils.search.biblio.metarecord.copy_count",
164 );
165 sub record_id_to_copy_count {
166         my( $self, $client, $org_id, $record_id ) = @_;
167
168         my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
169         my $key = "record";
170         if($self->api_name =~ /metarecord/) {
171                 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
172                 $key = "metarecord";
173         }
174
175         my $session = OpenSRF::AppSession->create("open-ils.storage");
176         warn "copy_count retrieve $record_id\n";
177         return undef unless(defined $record_id);
178
179         my $request = $session->request(
180                 $method, org_unit => $org_id => $key => $record_id );
181
182
183         my $count = $request->gather(1);
184         $session->disconnect();
185         return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
186
187 }
188
189
190 # used for cat search classes
191 my $cat_search_hash =  {
192
193         author => [ 
194                 { tag => "100", subfield => "a"} ,
195                 { tag => "700", subfield => "a"}, 
196         ],
197
198         title => [ 
199                 { tag => "245", subfield => "a"},
200                 { tag => "242", subfield => "a"}, 
201                 { tag => "240", subfield => "a"},
202                 { tag => "210", subfield => "a"},
203         ],
204
205         subject => [ 
206                 { tag => "650", subfield => "_" }, 
207         ],
208
209         tcn     => [
210                 { tag => "035", subfield => "_" },
211         ],
212
213         isbn    => [
214                 { tag => "020", subfield => "a" },
215         ],
216
217 };
218
219
220 __PACKAGE__->register_method(
221         method  => "biblio_search_tcn",
222         api_name        => "open-ils.search.biblio.tcn",
223         argc            => 3, 
224         note            => "Retrieve a record by TCN",
225 );
226
227 sub biblio_search_tcn {
228
229         my( $self, $client, $tcn ) = @_;
230
231         $tcn =~ s/.*?(\w+)\s*$/$1/o;
232         warn "Searching TCN $tcn\n";
233
234         my $session = OpenSRF::AppSession->create( "open-ils.storage" );
235         my $request = $session->request( 
236                         "open-ils.storage.direct.biblio.record_entry.search.tcn_value", $tcn );
237         my $response = $request->recv();
238
239
240         unless ($response) { return []; }
241
242         if(UNIVERSAL::isa($response,"OpenSRF::EX")) {
243                 warn "Received exception for tcn search\n";
244                 throw $response ($response->stringify);
245         }
246
247         my $record_entry = $response->content;
248         my @ids;
249         for my $record (@$record_entry) {
250                 push @ids, $record->id;
251         }
252
253         warn "received ID's for tcn search @ids\n";
254
255         my $size = @ids;
256         return { count => $size, ids => \@ids };
257
258 }
259
260
261 # --------------------------------------------------------------------------------
262 # ISBN
263
264 __PACKAGE__->register_method(
265         method  => "biblio_search_isbn",
266         api_name        => "open-ils.search.biblio.isbn",
267 );
268
269 sub biblio_search_isbn { 
270         my( $self, $client, $isbn ) = @_;
271         throw OpenSRF::EX::InvalidArg 
272
273                 ("biblio_search_isbn needs an ISBN to search")
274                         unless defined $isbn;
275
276         warn "biblio search for ISBN $isbn\n";
277         my $method = $self->method_lookup("open-ils.search.biblio.marc");
278         my ($records) = $method->run( $cat_search_hash->{isbn}, $isbn );
279
280         my $size = @$records;
281         return { count => $size, ids => $records };
282 }
283
284
285
286 # --------------------------------------------------------------------------------
287
288 __PACKAGE__->register_method(
289         method  => "biblio_barcode_to_copy",
290         api_name        => "open-ils.search.asset.copy.find_by_barcode",
291 );
292
293 # turns a barcode into a copy object
294 sub biblio_barcode_to_copy { 
295         my( $self, $client, $barcode ) = @_;
296
297         throw OpenSRF::EX::InvalidArg 
298                 ("search.biblio.barcode needs a barcode to search")
299                         unless defined $barcode;
300
301         warn "copy search for barcode $barcode\n";
302         my $record = OpenILS::Application::AppUtils->simple_scalar_request(
303                         "open-ils.storage", 
304                         "open-ils.storage.direct.asset.copy.search.barcode",
305                         $barcode );
306
307         return undef unless($record);
308         return $record->[0];
309
310 }
311
312 __PACKAGE__->register_method(
313         method  => "biblio_id_to_copy",
314         api_name        => "open-ils.search.asset.copy.batch.retrieve",
315 );
316
317 # turns a barcode into a copy object
318 sub biblio_id_to_copy { 
319         my( $self, $client, $ids ) = @_;
320
321         throw OpenSRF::EX::InvalidArg 
322                 ("search.biblio.batch.retrieve needs a id to search")
323                         unless defined $ids;
324
325         warn "copy search for ids @$ids\n";
326         my $record = OpenILS::Application::AppUtils->simple_scalar_request(
327                         "open-ils.storage", 
328                         "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
329                         @$ids );
330
331         return $record;
332
333 }
334
335
336 __PACKAGE__->register_method(
337         method  => "fleshed_copy_retrieve",
338         api_name        => "open-ils.search.asset.copy.fleshed.batch.retrieve",
339 );
340
341 # turns a barcode into a copy object
342 sub fleshed_copy_retrieve { 
343         my( $self, $client, $ids ) = @_;
344
345         throw OpenSRF::EX::InvalidArg 
346                 ("search.biblio.batch.retrieve needs a id to search")
347                         unless defined $ids;
348
349         warn "fleshed copy search for id @$ids\n";
350         my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
351                         "open-ils.storage", 
352                         "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
353                         @$ids );
354
355         return $copy;
356 }
357
358
359
360 __PACKAGE__->register_method(
361         method  => "biblio_barcode_to_title",
362         api_name        => "open-ils.search.biblio.find_by_barcode",
363 );
364
365 sub biblio_barcode_to_title {
366         my( $self, $client, $barcode ) = @_;
367
368         if(!$barcode) {
369                 throw OpenSRF::EX::ERROR 
370                         ("Not enough args to find_by_barcode");
371         }
372
373         my $title = $apputils->simple_scalar_request(
374                 "open-ils.storage",
375                 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
376                 $barcode );
377
378         return { ids => $title->id, count => 1 };
379
380 =head
381         my $u = OpenILS::Utils::ModsParser->new();
382         $u->start_mods_batch( $title->marc );
383         my $mods = $u->finish_mods_batch();
384         $mods->doc_id($title->id());
385         return $mods;
386 =cut
387         
388 }
389
390
391 __PACKAGE__->register_method(
392         method  => "biblio_copy_to_mods",
393         api_name        => "open-ils.search.biblio.copy.mods.retrieve",
394 );
395
396 # takes a copy object and returns it fleshed mods object
397 sub biblio_copy_to_mods {
398         my( $self, $client, $copy ) = @_;
399
400         throw OpenSRF::EX::InvalidArgs 
401                 ("copy.mods.retrieve needs a copy") unless( $copy );
402
403         new Fieldmapper::asset::copy($copy);
404
405         my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
406                 "open-ils.storage",
407                 "open-ils.storage.direct.asset.call_number.retrieve",
408                 $copy->call_number() );
409
410         my $mods = _records_to_mods($volume->record());
411         $mods = shift @$mods;
412         $volume->copies([$copy]);
413         push @{$mods->call_numbers()}, $volume;
414
415         return $mods;
416 }
417
418
419 sub barcode_to_mods {
420
421 }
422
423
424 # --------------------------------------------------------------------------------
425
426 __PACKAGE__->register_method(
427         method  => "cat_biblio_search_class",
428         api_name        => "open-ils.search.cat.biblio.class",
429         argc            => 3, 
430         note            => "Searches biblio information by search class",
431 );
432
433 sub cat_biblio_search_class {
434
435         my( $self, $client, $org_id, $class, $sort, $string ) = @_;
436
437         throw OpenSRF::EX::InvalidArg 
438                 ("Not enough args to open-ils.search.cat.biblio.class")
439                         unless( defined($org_id) and $class and $sort and $string );
440
441
442         my $search_hash;
443
444         my $method = $self->method_lookup("open-ils.search.biblio.marc");
445         if(!$method) {
446                 throw OpenSRF::EX::PANIC 
447                         ("Can't lookup method 'open-ils.search.biblio.marc'");
448         }
449
450         my ($records) = $method->run( $cat_search_hash->{$class}, $string );
451
452         my @ids;
453         for my $i (@$records) { push @ids, $i->[0]; }
454
455         my $mods_list = _records_to_mods( @ids );
456         return undef unless (ref($mods_list) eq "ARRAY");
457
458         # ---------------------------------------------------------------
459         # append copy count information to the mods objects
460         my $session = OpenSRF::AppSession->create("open-ils.storage");
461
462         my $request = $session->request(
463                 "open-ils.storage.direct.biblio.record_copy_count.batch",  $org_id, @ids );
464
465         for my $id (@ids) {
466
467                 warn "receiving copy counts for doc $id\n";
468
469                 my $response = $request->recv();
470                 next unless $response;
471
472                 if( $response and UNIVERSAL::isa($response, "Error")) {
473                         throw $response ($response->stringify);
474                 }
475
476                 my $count = $response->content;
477                 my $mods_obj = undef;
478                 for my $m (@$mods_list) {
479                         $mods_obj = $m if ($m->doc_id() == $id)
480                 }
481                 if($mods_obj) {
482                         $mods_obj->copy_count($count);
483                 }
484
485                 $client->respond( $mods_obj );
486
487         }       
488         $request->finish();
489
490         $session->finish();
491         $session->disconnect();
492         $session->kill_me();
493         # ---------------------------------------------------------------
494
495         return undef;
496 }
497
498
499
500 __PACKAGE__->register_method(
501         method  => "cat_biblio_search_class_id",
502         api_name        => "open-ils.search.cat.biblio.class.id",
503         argc            => 3, 
504         note            => "Searches biblio information by search class and returns the IDs",
505 );
506
507 sub cat_biblio_search_class_id {
508
509         my( $self, $client, $org_id, $class, $string, $limit, $offset ) = @_;
510
511         $offset ||= 0;
512         $limit  ||= 100;
513         $limit -= 1;
514
515
516         $string = OpenILS::Application::Search->filter_search($string);
517         if(!$string) { return undef; }
518
519         warn "Searching cat.biblio.class.id string: $string offset: $offset limit: $limit\n";
520
521         throw OpenSRF::EX::InvalidArg 
522                 ("Not enough args to open-ils.search.cat.biblio.class")
523                         unless( defined($org_id) and $class and $string );
524
525
526         my $search_hash;
527
528         my $cache_key = md5_hex( $org_id . $class . $string );
529         my $id_array = OpenILS::Application::SearchCache->get_cache($cache_key);
530
531         if(ref($id_array)) {
532                 warn "Returning class search from cache\n";
533                 my $size = @$id_array;
534                 my @ids = @$id_array[ $offset..($offset+$limit) ];
535                 return { count => $size, ids => \@ids };
536         }
537
538         my $method = $self->method_lookup("open-ils.search.biblio.marc");
539         if(!$method) {
540                 throw OpenSRF::EX::PANIC 
541                         ("Can't lookup method 'open-ils.search.biblio.marc'");
542         }
543
544         my ($records) = $method->run( $cat_search_hash->{$class}, $string );
545
546         my @cache_ids;
547
548         for my $i (@$records) { 
549                 if(defined($i->[0])) {
550                         push @cache_ids, $i->[0]; 
551                 }
552         }
553
554         my @ids = @cache_ids[ $offset..($offset+$limit) ];
555         my $size = @$records;
556
557         OpenILS::Application::SearchCache->put_cache( 
558                         $cache_key, \@cache_ids, $size );
559
560         return { count =>$size, ids => \@ids };
561
562 }
563
564
565 __PACKAGE__->register_method(
566         method  => "biblio_search_class",
567         api_name        => "open-ils.search.biblio.class",
568         argc            => 3, 
569         note            => "Searches biblio information by search class and returns the IDs",
570 );
571
572 sub biblio_search_class {
573
574         my( $self, $client, $class, $string, 
575                         $org_id, $org_type, $limit, $offset ) = @_;
576
577         warn "org: $org_id : depth: $org_type : limit: $limit :  offset: $offset\n";
578
579         $offset         ||= 0;
580         $limit          = 100 unless defined($limit and $limit > 0 );
581         $org_id         = "1" unless defined($org_id); # xxx
582         $org_type       = 0     unless defined($org_type);
583
584         warn "Searching biblio.class.id\n" . 
585                 "string: $string "              . 
586                 "\noffset: $offset\n"   .
587                 "limit: $limit\n"                       .
588                 "org_id: $org_id\n"             .
589                 "depth: $org_type\n" ;
590
591         $string = OpenILS::Application::Search->filter_search($string);
592         if(!$string) { return undef; }
593
594         if( !defined($org_id) or !$class or !$string ) {
595                 warn "not enbough args to metarecord search\n";
596                 throw OpenSRF::EX::InvalidArg 
597                         ("Not enough args to open-ils.search.cat.biblio.class")
598         }
599
600         $class =~ s/\s+//g;
601
602         if( ($class ne "title") and ($class ne "author") and 
603                 ($class ne "subject") and ($class ne "keyword") ) {
604                 warn "Invalid search class: $class\n";
605                 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
606         }
607
608         # grab the mr id's from storage
609
610         my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
611         warn "Performing count method $method\n";
612         my $session = OpenSRF::AppSession->create('open-ils.storage');
613
614         my $request = $session->request( $method, 
615                         term => $string, 
616                         org_unit => $org_id, 
617                         depth =>$org_type );
618
619         my $response = $request->recv();
620
621         if(UNIVERSAL::isa($response, "OpenSRF::EX")) {
622                 throw $response ($response->stringify);
623         }
624
625         my $count = $response->content;
626         warn "Received count $count\n";
627         # XXX check count size and respond accordingly
628
629         $request->finish();
630         $request = $session->request(   
631                 #"open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic",
632                 "open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic",
633                 term            => $string, 
634                 org_unit => $org_id, 
635                 depth           => $org_type, 
636                 limit           => $limit,
637                 offset  => $offset,
638                 );
639
640         my $records = $request->gather(1);
641         my @all_ids;
642
643         use Data::Dumper;
644         warn Dumper $records;
645
646         # if we just get one, it won't be wrapped in an array
647         if(!ref($records->[0])) {
648                 $records = [$records];
649         }
650
651         for my $i (@$records) { 
652                 if(defined($i)) {
653                         push @all_ids, $i; 
654                 }
655         }
656
657         #my @ids = @all_ids[ $offset..($offset+$limit) ];
658         my @ids = @all_ids;
659         @ids = grep { defined($_->[0]) } @ids;
660
661         $session->finish();
662         $session->disconnect();
663
664         return { count =>$count, ids => \@ids };
665
666 }
667
668
669
670
671 __PACKAGE__->register_method(
672         method  => "biblio_mrid_to_modsbatch",
673         api_name        => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
674 );
675
676 sub biblio_mrid_to_modsbatch {
677         my( $self, $client, $mrid ) = @_;
678
679         throw OpenSRF::EX::InvalidArg 
680                 ("search.biblio.metarecord_to_mods requires mr id")
681                         unless defined( $mrid );
682
683
684         my $metarecord = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
685                         "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
686
687         if(!$metarecord) {
688                 throw OpenSRF::EX::ERROR ("No metarecord exists with the given id: $mrid");
689         }
690
691         my $master_id = $metarecord->master_record();
692
693
694         # check for existing mods
695         if($metarecord->mods()){
696                 warn "We already have mods for " . $metarecord->id . "\n";
697                 my $perl = JSON->JSON2perl($metarecord->mods());
698                 return Fieldmapper::metabib::virtual_record->new($perl);
699         }
700
701
702
703         warn "Creating mods batch for metarecord $mrid\n";
704         my $id_hash = biblio_mrid_to_record_ids( undef, undef,  $mrid );
705         my @ids = @{$id_hash->{ids}};
706
707         if(@ids < 1) { return undef; }
708
709         warn "Master ID is $master_id\n";
710         # grab the master record to start the mods batch 
711
712         my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
713                         "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
714
715         if(!$record) {
716                 throw OpenSRF::EX::ERROR 
717                         ("No record returned with id $master_id");
718         }
719
720         my $u = OpenILS::Utils::ModsParser->new();
721         use Data::Dumper;
722         $u->start_mods_batch( $record->marc );
723         my $main_doc_id = $record->id();
724
725         @ids = grep { $_ ne $master_id } @ids;
726
727         # now we have to collect all of the marc objects and push them into a mods batch
728         my $session = OpenSRF::AppSession->create("open-ils.storage");
729         my $request = $session->request(
730                 "open-ils.storage.direct.biblio.record_entry.batch.retrieve",  @ids );
731
732         while( my $response = $request->recv() ) {
733
734                 next unless $response;
735                 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
736                         throw $response ($response->stringify);
737                 }
738
739                 my $content = $response->content;
740
741                 if( $content ) {
742                         $u->push_mods_batch( $content->marc );
743                 }
744         }
745
746         my $mods = $u->finish_mods_batch();
747         $mods->doc_id($mrid);
748         $request->finish();
749
750         $client->respond_complete($mods);
751
752         my $mods_string = JSON->perl2JSON($mods->decast);
753
754         $metarecord->mods($mods_string);
755
756         my $req = $session->request( 
757                         "open-ils.storage.direct.metabib.metarecord.update", 
758                         $metarecord );
759
760
761         $req->gather(1);
762
763         $session->finish();
764         $session->disconnect();
765
766         return undef;
767
768 }
769
770
771
772 # converts a mr id into a list of record ids
773
774 __PACKAGE__->register_method(
775         method  => "biblio_mrid_to_record_ids",
776         api_name        => "open-ils.search.biblio.metarecord_to_records",
777 );
778
779 sub biblio_mrid_to_record_ids {
780         my( $self, $client, $mrid ) = @_;
781
782         throw OpenSRF::EX::InvalidArg 
783                 ("search.biblio.metarecord_to_record_ids requires mr id")
784                         unless defined( $mrid );
785
786         warn "Searching for record for MR $mrid\n";
787
788         my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
789                         "open-ils.storage.direct.metabib.metarecord_source_map.search.metarecord", $mrid );
790
791         my @ids;
792         for my $map (@$mrmaps) { push @ids, $map->source(); }
793
794         warn "Recovered id's [@ids] for mr $mrid\n";
795
796         my $size = @ids;
797
798         return { count => $size, ids => \@ids };
799
800 }
801
802
803
804 __PACKAGE__->register_method(
805         method  => "biblio_record_to_marc_html",
806         api_name        => "open-ils.search.biblio.record.html" );
807
808 my $parser              = XML::LibXML->new();
809 my $xslt                        = XML::LibXSLT->new();
810 my $marc_sheet;
811
812 my $settings_client = OpenSRF::Utils::SettingsClient->new();
813 sub biblio_record_to_marc_html {
814         my( $self, $client, $recordid ) = @_;
815
816         if( !$marc_sheet ) {
817                 my $dir = $settings_client->config_value( "dirs", "xsl" );
818                 my $xsl = $settings_client->config_value(
819                         "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
820
821                 $xsl = $parser->parse_file("$dir/$xsl");
822                 $marc_sheet = $xslt->parse_stylesheet( $xsl );
823         }
824
825
826         my $record = $apputils->simple_scalar_request(
827                 "open-ils.storage", 
828                 "open-ils.storage.direct.biblio.record_entry.retrieve",
829                 $recordid );
830
831         my $xmldoc = $parser->parse_string($record->marc);
832         my $html = $marc_sheet->transform($xmldoc);
833         $html = $html->toString();
834         return $html;
835
836 }
837
838
839
840 __PACKAGE__->register_method(
841         method  => "retrieve_all_copy_locations",
842         api_name        => "open-ils.search.config.copy_location.retrieve.all" );
843
844 my $shelving_locations;
845 sub retrieve_all_copy_locations {
846         my( $self, $client ) = @_;
847         if(!$shelving_locations) {
848                 $shelving_locations = $apputils->simple_scalar_request(
849                         "open-ils.storage", 
850                         "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
851         }
852         return $shelving_locations;
853 }
854
855
856
857 __PACKAGE__->register_method(
858         method  => "retrieve_all_copy_statuses",
859         api_name        => "open-ils.search.config.copy_status.retrieve.all" );
860
861 my $copy_statuses;
862 sub retrieve_all_copy_statuses {
863         my( $self, $client ) = @_;
864         if(!$copy_statuses) {
865                 $copy_statuses = $apputils->simple_scalar_request(
866                         "open-ils.storage",
867                         "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
868         }
869         return $copy_statuses;
870 }
871
872
873
874
875
876 1;