]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Serial.pm
b7188e2bfe8120d8ca44107a5711e7f3665d166b
[working/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         # XXX perhaps this? --miker
82 #       my $e = OpenILS::Utils::CStoreEditor->new();
83 #       my $mfhd = $e->search_serial_record_entry({ record => $bib });
84 #       return $u->generate_svr( $mfhd->[0]->marc ) if (ref $mfhd);
85 #       return undef;
86
87         my @mfhd = $U->cstorereq( "open-ils.cstore.json_query.atomic", {
88                 select  => { sre => 'marc' },
89                 from    => 'sre',
90                 where   => { record => $bib },
91                 distinct => 1
92         });
93         
94         if (!@mfhd or scalar(@mfhd) == 0) {
95                 return undef;
96         }
97
98         my $u = OpenILS::Utils::MFHDParser->new();
99         $mfhd_hash = $u->generate_svr( $mfhd[0][0]->{marc} );
100
101         return $mfhd_hash;
102 }
103
104 __PACKAGE__->register_method(
105         method  => "bib_to_mfhd_hash",
106         api_name        => "open-ils.search.serial.record.bib_to_mfhd.retrieve",
107         argc            => 1, 
108         note            => "Given a bibliographic record ID, return MFHD holdings"
109 );
110
111 sub bib_to_mfhd {
112         my ($self, $client, $bib) = @_;
113         
114         my $mfhd;
115
116         my $e = OpenILS::Utils::CStoreEditor->new();
117         my $serials = $e->search_serial_record_entry({ record => $bib });
118         if (!ref $serials) {
119                 return undef;
120         }
121
122         my $u = OpenILS::Utils::MFHDParser->new();
123         foreach (@$serials) {
124                 push(@$mfhd, $u->generate_svr($_->marc));
125         }
126
127         return $mfhd;
128 }
129
130 __PACKAGE__->register_method(
131         method  => "bib_to_mfhd",
132         api_name        => "open-ils.search.serial.record.bib.retrieve",
133         argc            => 1, 
134         note            => "Given a bibliographic record ID, return MFHD holdings"
135 );
136
137 1;