]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Serial.pm
Basic support for returning MFHD for display purposes
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Serial.pm
1 package OpenILS::Application::Search::Serial;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
4
5
6 use OpenSRF::Utils::JSON;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::MFHDParser;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Utils::CStoreEditor q/:funcs/;
11 use OpenSRF::Utils::Cache;
12 use Encode;
13
14 use OpenSRF::Utils::Logger qw/:logger/;
15
16 use Data::Dumper;
17
18 use OpenSRF::Utils::JSON;
19
20 use Time::HiRes qw(time);
21 use OpenSRF::EX qw(:try);
22 use Digest::MD5 qw(md5_hex);
23
24 use XML::LibXML;
25 use XML::LibXSLT;
26
27 use OpenILS::Const qw/:const/;
28
29 use OpenILS::Application::AppUtils;
30 my $apputils = "OpenILS::Application::AppUtils";
31 my $U = $apputils;
32
33 my $pfx = "open-ils.search_";
34
35 =over
36
37 =item * mfhd_to_hash
38
39 =back
40
41 Takes an MFHD record ID and returns a hash of holdings statements
42
43 =cut
44
45 sub mfhd_to_hash {
46         my ($self, $client, $id) = @_;
47         
48         my $session = OpenSRF::AppSession->create("open-ils.cstore");
49         my $request = $session->request(
50                         "open-ils.cstore.direct.serial.record_entry.retrieve", $id )->gather(1);
51
52         my $u = OpenILS::Utils::MFHDParser->new();
53         my $mfhd_hash = $u->generate_svr( $request->marc );
54
55         $session->disconnect();
56         return $mfhd_hash;
57 }
58
59 __PACKAGE__->register_method(
60         method  => "mfhd_to_hash",
61         api_name        => "open-ils.search.serial.record.mfhd.retrieve",
62         argc            => 1, 
63         note            => "Given a serial record ID, return MFHD holdings"
64 );
65
66 =over
67
68 =item * bib_to_mfhd_hash 
69
70 =back
71
72 Given a bib record ID, returns a hash of holdings statements
73
74 =cut
75
76 sub bib_to_mfhd_hash {
77         my ($self, $client, $bib) = @_;
78         
79         my $mfhd_hash;
80
81         # miker suggested this way, but I'm too stupid to get it to work
82 #       my $e = OpenILS::Utils::CStoreEditor->new();
83 #       my $mfhd = $e->search_serial_record_entry({bib=>$bib});
84
85         my @mfhd = $U->cstorereq( "open-ils.cstore.json_query.atomic", {
86                 select  => { sre => 'marc' },
87                 from    => 'sre',
88                 where   => { record => $bib },
89                 distinct => 1
90         });
91         
92         if (!@mfhd or scalar(@mfhd) == 0) {
93                 return undef;
94         }
95
96         my $u = OpenILS::Utils::MFHDParser->new();
97         $mfhd_hash = $u->generate_svr( $mfhd[0][0]->{marc} );
98
99         return $mfhd_hash;
100 }
101
102 __PACKAGE__->register_method(
103         method  => "bib_to_mfhd_hash",
104         api_name        => "open-ils.search.serial.record.bib_to_mfhd.retrieve",
105         argc            => 1, 
106         note            => "Given a bibliographic record ID, return MFHD holdings"
107 );
108
109 1;