]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Let the onslaught continue...
[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 $record_entry = $request->gather(1);
238
239         my @ids;
240         for my $record (@$record_entry) {
241                 push @ids, $record->id;
242         }
243
244         $session->disconnect();
245
246         warn "received ID's for tcn search @ids\n";
247         my $size = @ids;
248
249         return { count => $size, ids => \@ids };
250
251 }
252
253
254 # --------------------------------------------------------------------------------
255 # ISBN
256
257 __PACKAGE__->register_method(
258         method  => "biblio_search_isbn",
259         api_name        => "open-ils.search.biblio.isbn",
260 );
261
262 sub biblio_search_isbn { 
263         my( $self, $client, $isbn ) = @_;
264         throw OpenSRF::EX::InvalidArg 
265
266                 ("biblio_search_isbn needs an ISBN to search")
267                         unless defined $isbn;
268
269         warn "biblio search for ISBN $isbn\n";
270         my $method = $self->method_lookup("open-ils.search.biblio.marc");
271         my ($records) = $method->run( $cat_search_hash->{isbn}, $isbn );
272
273         my $size = @$records;
274         return { count => $size, ids => $records };
275 }
276
277
278
279 # --------------------------------------------------------------------------------
280
281 __PACKAGE__->register_method(
282         method  => "biblio_barcode_to_copy",
283         api_name        => "open-ils.search.asset.copy.find_by_barcode",
284 );
285
286 # turns a barcode into a copy object
287 sub biblio_barcode_to_copy { 
288         my( $self, $client, $barcode ) = @_;
289
290         throw OpenSRF::EX::InvalidArg 
291                 ("search.biblio.barcode needs a barcode to search")
292                         unless defined $barcode;
293
294         warn "copy search for barcode $barcode\n";
295         my $record = OpenILS::Application::AppUtils->simple_scalar_request(
296                         "open-ils.storage", 
297                         "open-ils.storage.direct.asset.copy.search.barcode",
298                         $barcode );
299
300         return undef unless($record);
301         return $record->[0];
302
303 }
304
305 __PACKAGE__->register_method(
306         method  => "biblio_id_to_copy",
307         api_name        => "open-ils.search.asset.copy.batch.retrieve",
308 );
309
310 # turns a barcode into a copy object
311 sub biblio_id_to_copy { 
312         my( $self, $client, $ids ) = @_;
313
314         throw OpenSRF::EX::InvalidArg 
315                 ("search.biblio.batch.retrieve needs a id to search")
316                         unless defined $ids;
317
318         warn "copy search for ids @$ids\n";
319         my $record = OpenILS::Application::AppUtils->simple_scalar_request(
320                         "open-ils.storage", 
321                         "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
322                         @$ids );
323
324         return $record;
325
326 }
327
328
329 __PACKAGE__->register_method(
330         method  => "fleshed_copy_retrieve",
331         api_name        => "open-ils.search.asset.copy.fleshed.batch.retrieve",
332 );
333
334 # turns a barcode into a copy object
335 sub fleshed_copy_retrieve { 
336         my( $self, $client, $ids ) = @_;
337
338         throw OpenSRF::EX::InvalidArg 
339                 ("search.biblio.batch.retrieve needs a id to search")
340                         unless defined $ids;
341
342         warn "fleshed copy search for id @$ids\n";
343         my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
344                         "open-ils.storage", 
345                         "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
346                         @$ids );
347
348         return $copy;
349 }
350
351
352
353 __PACKAGE__->register_method(
354         method  => "biblio_barcode_to_title",
355         api_name        => "open-ils.search.biblio.find_by_barcode",
356 );
357
358 sub biblio_barcode_to_title {
359         my( $self, $client, $barcode ) = @_;
360
361         if(!$barcode) {
362                 throw OpenSRF::EX::ERROR 
363                         ("Not enough args to find_by_barcode");
364         }
365
366         my $title = $apputils->simple_scalar_request(
367                 "open-ils.storage",
368                 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
369                 $barcode );
370
371         return { ids => $title->id, count => 1 };
372
373 =head
374         my $u = OpenILS::Utils::ModsParser->new();
375         $u->start_mods_batch( $title->marc );
376         my $mods = $u->finish_mods_batch();
377         $mods->doc_id($title->id());
378         return $mods;
379 =cut
380         
381 }
382
383
384 __PACKAGE__->register_method(
385         method  => "biblio_copy_to_mods",
386         api_name        => "open-ils.search.biblio.copy.mods.retrieve",
387 );
388
389 # takes a copy object and returns it fleshed mods object
390 sub biblio_copy_to_mods {
391         my( $self, $client, $copy ) = @_;
392
393         throw OpenSRF::EX::InvalidArgs 
394                 ("copy.mods.retrieve needs a copy") unless( $copy );
395
396         new Fieldmapper::asset::copy($copy);
397
398         my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
399                 "open-ils.storage",
400                 "open-ils.storage.direct.asset.call_number.retrieve",
401                 $copy->call_number() );
402
403         my $mods = _records_to_mods($volume->record());
404         $mods = shift @$mods;
405         $volume->copies([$copy]);
406         push @{$mods->call_numbers()}, $volume;
407
408         return $mods;
409 }
410
411
412 sub barcode_to_mods {
413
414 }
415
416
417 # --------------------------------------------------------------------------------
418
419 __PACKAGE__->register_method(
420         method  => "cat_biblio_search_class",
421         api_name        => "open-ils.search.cat.biblio.class",
422         argc            => 3, 
423         note            => "Searches biblio information by search class",
424 );
425
426 sub cat_biblio_search_class {
427
428         my( $self, $client, $org_id, $class, $sort, $string ) = @_;
429
430         throw OpenSRF::EX::InvalidArg 
431                 ("Not enough args to open-ils.search.cat.biblio.class")
432                         unless( defined($org_id) and $class and $sort and $string );
433
434
435         my $search_hash;
436
437         my $method = $self->method_lookup("open-ils.search.biblio.marc");
438         if(!$method) {
439                 throw OpenSRF::EX::PANIC 
440                         ("Can't lookup method 'open-ils.search.biblio.marc'");
441         }
442
443         my ($records) = $method->run( $cat_search_hash->{$class}, $string );
444
445         my @ids;
446         for my $i (@$records) { push @ids, $i->[0]; }
447
448         my $mods_list = _records_to_mods( @ids );
449         return undef unless (ref($mods_list) eq "ARRAY");
450
451         # ---------------------------------------------------------------
452         # append copy count information to the mods objects
453         my $session = OpenSRF::AppSession->create("open-ils.storage");
454
455         my $request = $session->request(
456                 "open-ils.storage.direct.biblio.record_copy_count.batch",  $org_id, @ids );
457
458         for my $id (@ids) {
459
460                 warn "receiving copy counts for doc $id\n";
461
462                 my $response = $request->recv();
463                 next unless $response;
464
465                 if( $response and UNIVERSAL::isa($response, "Error")) {
466                         throw $response ($response->stringify);
467                 }
468
469                 my $count = $response->content;
470                 my $mods_obj = undef;
471                 for my $m (@$mods_list) {
472                         $mods_obj = $m if ($m->doc_id() == $id)
473                 }
474                 if($mods_obj) {
475                         $mods_obj->copy_count($count);
476                 }
477
478                 $client->respond( $mods_obj );
479
480         }       
481         $request->finish();
482
483         $session->finish();
484         $session->disconnect();
485         $session->kill_me();
486         # ---------------------------------------------------------------
487
488         return undef;
489 }
490
491
492
493 __PACKAGE__->register_method(
494         method  => "cat_biblio_search_class_id",
495         api_name        => "open-ils.search.cat.biblio.class.id",
496         argc            => 3, 
497         note            => "Searches biblio information by search class and returns the IDs",
498 );
499
500 sub cat_biblio_search_class_id {
501
502         my( $self, $client, $org_id, $class, $string, $limit, $offset ) = @_;
503
504         $offset ||= 0;
505         $limit  ||= 100;
506         $limit -= 1;
507
508
509         $string = OpenILS::Application::Search->filter_search($string);
510         if(!$string) { return undef; }
511
512         warn "Searching cat.biblio.class.id string: $string offset: $offset limit: $limit\n";
513
514         throw OpenSRF::EX::InvalidArg 
515                 ("Not enough args to open-ils.search.cat.biblio.class")
516                         unless( defined($org_id) and $class and $string );
517
518
519         my $search_hash;
520
521         my $cache_key = md5_hex( $org_id . $class . $string );
522         my $id_array = OpenILS::Application::SearchCache->get_cache($cache_key);
523
524         if(ref($id_array)) {
525                 warn "Returning class search from cache\n";
526                 my $size = @$id_array;
527                 my @ids = @$id_array[ $offset..($offset+$limit) ];
528                 return { count => $size, ids => \@ids };
529         }
530
531         my $method = $self->method_lookup("open-ils.search.biblio.marc");
532         if(!$method) {
533                 throw OpenSRF::EX::PANIC 
534                         ("Can't lookup method 'open-ils.search.biblio.marc'");
535         }
536
537         my ($records) = $method->run( $cat_search_hash->{$class}, $string );
538
539         my @cache_ids;
540
541         for my $i (@$records) { 
542                 if(defined($i->[0])) {
543                         push @cache_ids, $i->[0]; 
544                 }
545         }
546
547         my @ids = @cache_ids[ $offset..($offset+$limit) ];
548         my $size = @$records;
549
550         OpenILS::Application::SearchCache->put_cache( 
551                         $cache_key, \@cache_ids, $size );
552
553         return { count =>$size, ids => \@ids };
554
555 }
556
557
558 __PACKAGE__->register_method(
559         method  => "biblio_search_class",
560         api_name        => "open-ils.search.biblio.class",
561         argc            => 3, 
562         note            => "Searches biblio information by search class and returns the IDs",
563 );
564
565 sub biblio_search_class {
566
567         my( $self, $client, $class, $string, 
568                         $org_id, $org_type, $limit, $offset ) = @_;
569
570         warn "org: $org_id : depth: $org_type : limit: $limit :  offset: $offset\n";
571
572         $offset         ||= 0;
573         $limit          = 100 unless defined($limit and $limit > 0 );
574         $org_id         = "1" unless defined($org_id); # xxx
575         $org_type       = 0     unless defined($org_type);
576
577         warn "Searching biblio.class.id\n" . 
578                 "string: $string "              . 
579                 "\noffset: $offset\n"   .
580                 "limit: $limit\n"                       .
581                 "org_id: $org_id\n"             .
582                 "depth: $org_type\n" ;
583
584         $string = OpenILS::Application::Search->filter_search($string);
585         if(!$string) { return undef; }
586
587         if( !defined($org_id) or !$class or !$string ) {
588                 warn "not enbough args to metarecord search\n";
589                 throw OpenSRF::EX::InvalidArg 
590                         ("Not enough args to open-ils.search.cat.biblio.class")
591         }
592
593         $class =~ s/\s+//g;
594
595         if( ($class ne "title") and ($class ne "author") and 
596                 ($class ne "subject") and ($class ne "keyword") ) {
597                 warn "Invalid search class: $class\n";
598                 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
599         }
600
601         # grab the mr id's from storage
602
603         my $method = "open-ils.storage.metabib.$class.search_fts.metarecord_count";
604         warn "Performing count method $method\n";
605         my $session = OpenSRF::AppSession->create('open-ils.storage');
606
607         my $request = $session->request( $method, 
608                         term => $string, 
609                         org_unit => $org_id, 
610                         depth =>$org_type );
611
612         my $count = $request->gather(1);
613         warn "Received count $count\n";
614         # XXX check count size and respond accordingly
615
616         $request = $session->request(   
617                 "open-ils.storage.metabib.$class.search_fts.metarecord.atomic",
618                 #"open-ils.storage.cachable.metabib.$class.search_fts.metarecord.atomic",
619                 term            => $string, 
620                 org_unit => $org_id, 
621                 depth           => $org_type, 
622                 limit           => $limit,
623                 offset  => $offset,
624                 );
625
626         my $records = $request->gather(1);
627         my @all_ids;
628
629         use Data::Dumper;
630         warn "Received from class search " . Dumper($records);
631
632         # if we just get one, it won't be wrapped in an array
633         if(!ref($records->[0])) {
634                 $records = [$records];
635         }
636
637         for my $i (@$records) { 
638                 if(defined($i)) {
639                         push @all_ids, $i; 
640                 }
641         }
642
643         #my @ids = @all_ids[ $offset..($offset+$limit) ];
644         my @ids = @all_ids;
645         @ids = grep { defined($_->[0]) } @ids;
646
647         $session->finish();
648         $session->disconnect();
649
650         return { count =>$count, ids => \@ids };
651
652 }
653
654
655
656
657 __PACKAGE__->register_method(
658         method  => "biblio_mrid_to_modsbatch",
659         api_name        => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
660 );
661
662 sub biblio_mrid_to_modsbatch {
663         my( $self, $client, $mrid ) = @_;
664
665         throw OpenSRF::EX::InvalidArg 
666                 ("search.biblio.metarecord_to_mods requires mr id")
667                         unless defined( $mrid );
668
669
670         my $metarecord = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
671                         "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
672
673         if(!$metarecord) {
674                 throw OpenSRF::EX::ERROR ("No metarecord exists with the given id: $mrid");
675         }
676
677         my $master_id = $metarecord->master_record();
678
679
680         # check for existing mods
681         if($metarecord->mods()){
682                 warn "We already have mods for " . $metarecord->id . "\n";
683                 my $perl = JSON->JSON2perl($metarecord->mods());
684                 return Fieldmapper::metabib::virtual_record->new($perl);
685         }
686
687
688
689         warn "Creating mods batch for metarecord $mrid\n";
690         my $id_hash = biblio_mrid_to_record_ids( undef, undef,  $mrid );
691         my @ids = @{$id_hash->{ids}};
692
693         if(@ids < 1) { return undef; }
694
695         warn "Master ID is $master_id\n";
696         # grab the master record to start the mods batch 
697
698         my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
699                         "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
700
701         if(!$record) {
702                 throw OpenSRF::EX::ERROR 
703                         ("No record returned with id $master_id");
704         }
705
706         my $u = OpenILS::Utils::ModsParser->new();
707         use Data::Dumper;
708         $u->start_mods_batch( $record->marc );
709         my $main_doc_id = $record->id();
710
711         @ids = grep { $_ ne $master_id } @ids;
712
713         # now we have to collect all of the marc objects and push them into a mods batch
714         my $session = OpenSRF::AppSession->create("open-ils.storage");
715         my $request = $session->request(
716                 "open-ils.storage.direct.biblio.record_entry.batch.retrieve",  @ids );
717
718         while( my $response = $request->recv() ) {
719
720                 next unless $response;
721                 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
722                         throw $response ($response->stringify);
723                 }
724
725                 my $content = $response->content;
726
727                 if( $content ) {
728                         $u->push_mods_batch( $content->marc );
729                 }
730         }
731
732         my $mods = $u->finish_mods_batch();
733         $mods->doc_id($mrid);
734         $request->finish();
735
736         $client->respond_complete($mods);
737
738         my $mods_string = JSON->perl2JSON($mods->decast);
739
740         $metarecord->mods($mods_string);
741
742         my $req = $session->request( 
743                         "open-ils.storage.direct.metabib.metarecord.update", 
744                         $metarecord );
745
746
747         $req->gather(1);
748
749         $session->finish();
750         $session->disconnect();
751
752         return undef;
753
754 }
755
756
757
758 # converts a mr id into a list of record ids
759
760 __PACKAGE__->register_method(
761         method  => "biblio_mrid_to_record_ids",
762         api_name        => "open-ils.search.biblio.metarecord_to_records",
763 );
764
765 sub biblio_mrid_to_record_ids {
766         my( $self, $client, $mrid ) = @_;
767
768         throw OpenSRF::EX::InvalidArg 
769                 ("search.biblio.metarecord_to_record_ids requires mr id")
770                         unless defined( $mrid );
771
772         warn "Searching for record for MR $mrid\n";
773
774         my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage", 
775                         "open-ils.storage.direct.metabib.metarecord_source_map.search.metarecord", $mrid );
776
777         my @ids;
778         for my $map (@$mrmaps) { push @ids, $map->source(); }
779
780         warn "Recovered id's [@ids] for mr $mrid\n";
781
782         my $size = @ids;
783
784         return { count => $size, ids => \@ids };
785
786 }
787
788
789
790 __PACKAGE__->register_method(
791         method  => "biblio_record_to_marc_html",
792         api_name        => "open-ils.search.biblio.record.html" );
793
794 my $parser              = XML::LibXML->new();
795 my $xslt                        = XML::LibXSLT->new();
796 my $marc_sheet;
797
798 my $settings_client = OpenSRF::Utils::SettingsClient->new();
799 sub biblio_record_to_marc_html {
800         my( $self, $client, $recordid ) = @_;
801
802         if( !$marc_sheet ) {
803                 my $dir = $settings_client->config_value( "dirs", "xsl" );
804                 my $xsl = $settings_client->config_value(
805                         "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
806
807                 $xsl = $parser->parse_file("$dir/$xsl");
808                 $marc_sheet = $xslt->parse_stylesheet( $xsl );
809         }
810
811
812         my $record = $apputils->simple_scalar_request(
813                 "open-ils.storage", 
814                 "open-ils.storage.direct.biblio.record_entry.retrieve",
815                 $recordid );
816
817         my $xmldoc = $parser->parse_string($record->marc);
818         my $html = $marc_sheet->transform($xmldoc);
819         $html = $html->toString();
820         return $html;
821
822 }
823
824
825
826 __PACKAGE__->register_method(
827         method  => "retrieve_all_copy_locations",
828         api_name        => "open-ils.search.config.copy_location.retrieve.all" );
829
830 my $shelving_locations;
831 sub retrieve_all_copy_locations {
832         my( $self, $client ) = @_;
833         if(!$shelving_locations) {
834                 $shelving_locations = $apputils->simple_scalar_request(
835                         "open-ils.storage", 
836                         "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
837         }
838         return $shelving_locations;
839 }
840
841
842
843 __PACKAGE__->register_method(
844         method  => "retrieve_all_copy_statuses",
845         api_name        => "open-ils.search.config.copy_status.retrieve.all" );
846
847 my $copy_statuses;
848 sub retrieve_all_copy_statuses {
849         my( $self, $client ) = @_;
850         if(!$copy_statuses) {
851                 $copy_statuses = $apputils->simple_scalar_request(
852                         "open-ils.storage",
853                         "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
854         }
855         return $copy_statuses;
856 }
857
858
859
860
861
862 1;