]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
fleshed out "actor.usr" interface, and stream behavior adjustment
[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 $address = $usr->address;
111         my $card = $usr->card;
112
113         my @addresses = $usr->addresses;
114         my @cards = $usr->cards;
115
116         my $usr_fm = $usr->to_fieldmapper;
117         $usr_fm->standing( $standing->to_fieldmapper );
118         $usr_fm->profile( $profile->to_fieldmapper );
119         $usr_fm->ident_type( $ident_type->to_fieldmapper );
120
121         $usr_fm->card( $card->to_fieldmapper );
122         $usr_fm->address( $address->to_fieldmapper ) if ($address);
123
124         $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
125         $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
126
127         return $usr_fm;
128 }
129
130 sub org_unit_list {
131         my $self = shift;
132         my $client = shift;
133
134         my $select =<<" SQL";
135         SELECT  *
136           FROM  actor.org_unit
137           ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
138         SQL
139
140         my $sth = actor::org_unit->db_Main->prepare_cached($select);
141         $sth->execute;
142
143         my @fms;
144         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
145
146         return \@fms;
147 }
148 __PACKAGE__->register_method(
149         api_name        => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
150         api_level       => 1,
151         method          => 'org_unit_list',
152 );
153
154 sub org_unit_type_list {
155         my $self = shift;
156         my $client = shift;
157
158         my $select =<<" SQL";
159         SELECT  *
160           FROM  actor.org_unit_type
161           ORDER BY depth, name;
162         SQL
163
164         my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
165         $sth->execute;
166
167         my @fms;
168         push @fms, $_->to_fieldmapper for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
169
170         return \@fms;
171 }
172 __PACKAGE__->register_method(
173         api_name        => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
174         api_level       => 1,
175         method          => 'org_unit_type_list',
176 );
177
178 sub org_unit_descendants {
179         my $self = shift;
180         my $client = shift;
181         my $id = shift;
182
183         return undef unless ($id);
184
185         my $select =<<" SQL";
186         SELECT  a.*
187           FROM  connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
188                         as t(keyid text, parent_keyid text, level int, branch text,pos int),
189                 actor.org_unit a
190           WHERE t.keyid = a.id
191           ORDER BY t.pos;
192         SQL
193
194         my $sth = actor::org_unit->db_Main->prepare_cached($select);
195         $sth->execute($id);
196
197         my @fms;
198         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
199
200         return \@fms;
201 }
202 __PACKAGE__->register_method(
203         api_name        => 'open-ils.storage.actor.org_unit.descendants',
204         api_level       => 1,
205         method          => 'org_unit_descendants',
206 );
207
208
209 1;