]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
3d5bc8a19efa54e59e7dfe8e1f7bb8129eeaebea
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / actor.pm
1 package OpenILS::Application::Storage::Publisher::actor;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenILS::Application::Storage::CDBI::actor;
4 use OpenSRF::Utils::Logger qw/:level/;
5 use OpenILS::Utils::Fieldmapper;
6
7 my $log = 'OpenSRF::Utils::Logger';
8
9 sub user_by_barcode {
10         my $self = shift;
11         my $client = shift;
12         my @barcodes = shift;
13
14         return undef unless @barcodes;
15
16         for my $card ( actor::card->search( { barcode => @barcodes } ) ) {
17
18                 next unless $card;
19
20                 my $usr_fm = flesh_user( $card->usr );
21                 $client->respond( $usr_fm );
22         }
23         return undef;
24 }
25 __PACKAGE__->register_method(
26         api_name        => 'open-ils.storage.fleshed.actor.user.search.barcode',
27         api_level       => 1,
28         method          => 'user_by_barcode',
29         stream          => 1,
30         cachable        => 1,
31 );
32
33 sub fleshed_search {
34         my $self = shift;
35         my $client = shift;
36         my $searches = shift;
37
38         return undef unless (defined $searches);
39
40         for my $usr ( actor::user->search( $searches ) ) {
41                 next unless $usr;
42                 $client->respond( flesh_user( $usr ) );
43         }
44         return undef;
45 }
46 __PACKAGE__->register_method(
47         api_name        => 'open-ils.storage.fleshed.actor.user.search',
48         api_level       => 1,
49         method          => 'fleshed_search',
50         stream          => 1,
51         cachable        => 1,
52 );
53
54 sub fleshed_search_like {
55         my $self = shift;
56         my $client = shift;
57         my $searches = shift;
58
59         return undef unless (defined $searches);
60
61         for my $usr ( actor::user->search_like( $searches ) ) {
62                 next unless $usr;
63                 $client->respond( flesh_user( $usr ) );
64         }
65         return undef;
66 }
67 __PACKAGE__->register_method(
68         api_name        => 'open-ils.storage.fleshed.actor.user.search_like',
69         api_level       => 1,
70         method          => 'user_by_barcode',
71         stream          => 1,
72         cachable        => 1,
73 );
74
75 sub retrieve_fleshed_user {
76         my $self = shift;
77         my $client = shift;
78         my @ids = shift;
79
80         return undef unless @ids;
81
82         @ids = ($ids[0]) unless ($self->api_name =~ /batch/o); 
83
84         $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
85
86         return undef;
87 }
88 __PACKAGE__->register_method(
89         api_name        => 'open-ils.storage.fleshed.actor.user.retrieve',
90         api_level       => 1,
91         method          => 'retrieve_fleshed_user',
92         cachable        => 1,
93 );
94 __PACKAGE__->register_method(
95         api_name        => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
96         api_level       => 1,
97         method          => 'retrieve_fleshed_user',
98         stream          => 1,
99         cachable        => 1,
100 );
101
102 sub flesh_user {
103         my $usr = shift;
104
105
106         my $standing = $usr->standing;
107         my $profile = $usr->profile;
108         my $ident_type = $usr->ident_type;
109                 
110         my $maddress = $usr->mailing_address;
111         my $baddress = $usr->billing_address;
112         my $card = $usr->card;
113
114         my @addresses = $usr->addresses;
115         my @cards = $usr->cards;
116
117         my $usr_fm = $usr->to_fieldmapper;
118         $usr_fm->standing( $standing->to_fieldmapper );
119         $usr_fm->profile( $profile->to_fieldmapper );
120         $usr_fm->ident_type( $ident_type->to_fieldmapper );
121
122         $usr_fm->card( $card->to_fieldmapper );
123         $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
124         $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
125
126         $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
127         $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
128
129         return $usr_fm;
130 }
131
132 sub org_unit_list {
133         my $self = shift;
134         my $client = shift;
135
136         my $select =<<" SQL";
137         SELECT  *
138           FROM  actor.org_unit
139           ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
140         SQL
141
142         my $sth = actor::org_unit->db_Main->prepare_cached($select);
143         $sth->execute;
144
145         my @fms;
146         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
147
148         return \@fms;
149 }
150 __PACKAGE__->register_method(
151         api_name        => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
152         api_level       => 1,
153         method          => 'org_unit_list',
154 );
155
156 sub org_unit_type_list {
157         my $self = shift;
158         my $client = shift;
159
160         my $select =<<" SQL";
161         SELECT  *
162           FROM  actor.org_unit_type
163           ORDER BY depth, name;
164         SQL
165
166         my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
167         $sth->execute;
168
169         my @fms;
170         push @fms, $_->to_fieldmapper for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
171
172         return \@fms;
173 }
174 __PACKAGE__->register_method(
175         api_name        => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
176         api_level       => 1,
177         method          => 'org_unit_type_list',
178 );
179
180 sub org_unit_descendants {
181         my $self = shift;
182         my $client = shift;
183         my $id = shift;
184
185         return undef unless ($id);
186
187         my $select =<<" SQL";
188         SELECT  a.*
189           FROM  connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
190                         as t(keyid text, parent_keyid text, level int, branch text,pos int),
191                 actor.org_unit a
192           WHERE t.keyid = a.id
193           ORDER BY t.pos;
194         SQL
195
196         my $sth = actor::org_unit->db_Main->prepare_cached($select);
197         $sth->execute($id);
198
199         my @fms;
200         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
201
202         return \@fms;
203 }
204 __PACKAGE__->register_method(
205         api_name        => 'open-ils.storage.actor.org_unit.descendants',
206         api_level       => 1,
207         method          => 'org_unit_descendants',
208 );
209
210
211 1;