]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Actor.pm
fixed debuging code ...
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Actor.pm
1 package OpenILS::Application::Search::Actor;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
5 my $apputils = "OpenILS::Application::AppUtils";
6
7
8
9 __PACKAGE__->register_method(
10         method  => "actor_user_search_username",
11         api_name        => "open-ils.search.actor.user.search.username",
12 );
13
14 sub actor_user_search_username {
15
16         my($self, $client, $username) = @_;
17
18         my $users = OpenILS::Application::AppUtils->simple_scalar_request(
19                         "open-ils.storage", 
20                         "open-ils.storage.direct.actor.user.search.usrname.atomic",
21                         $username );
22
23         return $users;
24 }
25
26
27 __PACKAGE__->register_method(
28         method  => "actor_user_retrieve_by_barcode",
29         api_name        => "open-ils.search.actor.user.barcode",
30 );
31
32 sub actor_user_retrieve_by_barcode {
33         my($self, $client, $barcode) = @_;
34         warn "Searching for user with barcode $barcode\n";
35
36         my $session = OpenSRF::AppSession->create("open-ils.storage");
37
38         # find the card with the given barcode
39         my $creq        = $session->request(
40                         "open-ils.storage.direct.actor.card.search.barcode.atomic",
41                         $barcode );
42         my $card = $creq->gather(1);
43         $card = $card->[0];
44         my $user = flesh_user($card->usr(), $session);
45         $session->disconnect();
46         return $user;
47
48 }
49
50
51 __PACKAGE__->register_method(
52         method  => "actor_user_retrieve_by_session",
53         api_name        => "open-ils.search.actor.user.session",
54 );
55
56 sub actor_user_retrieve_by_session {
57         my($self, $client, $user_session) = @_;
58         warn "Searching for user with user_session $user_session\n";
59         my $user_obj = $apputils->check_user_session($user_session);
60         my $session = OpenSRF::AppSession->create("open-ils.storage");
61         return flesh_user($user_obj->id);
62 }
63
64
65 sub flesh_user {
66         my $id = shift;
67         my $session = shift;
68         my $kill = 0;
69
70         if(!$session) {
71                 $session = OpenSRF::AppSession->create("open-ils.storage");
72                 $kill = 1;
73         }
74
75         # grab the user with the given card
76         my $ureq = $session->request(
77                         "open-ils.storage.direct.actor.user.retrieve",
78                         $id);
79         my $user = $ureq->gather(1);
80
81         # grab the cards
82         my $cards_req = $session->request(
83                         "open-ils.storage.direct.actor.card.search.usr.atomic",
84                         $user->id() );
85         $user->cards( $cards_req->gather(1) );
86
87         my $add_req = $session->request(
88                         "open-ils.storage.direct.actor.user_address.search.usr.atomic",
89                         $user->id() );
90         $user->addresses( $add_req->gather(1) );
91
92         if($kill) { $session->disconnect(); }
93
94         return $user;
95
96 }
97
98
99 __PACKAGE__->register_method(
100         method  => "get_org_tree",
101         api_name        => "open-ils.search.actor.org_tree.retrieve",
102         argc            => 1, 
103         note            => "Returns the entire org tree structure",
104 );
105
106 sub get_org_tree {
107
108         my( $self, $client, $user_session ) = @_;
109
110 =head
111         if( $user_session ) { # keep for now for backwards compatibility
112
113                 my $user_obj = 
114                         OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
115                 
116                 my $session = OpenSRF::AppSession->create("open-ils.storage");
117                 my $request = $session->request( 
118                                 "open-ils.storage.direct.actor.org_unit.retrieve", $user_obj->home_ou );
119                 my $response = $request->recv();
120
121                 if(!$response) { 
122                         throw OpenSRF::EX::ERROR (
123                                         "No response from storage for org_unit retrieve");
124                 }
125                 if(UNIVERSAL::isa($response,"Error")) {
126                         throw $response ($response->stringify);
127                 }
128
129                 my $home_ou = $response->content;
130                 $request->finish();
131                 $session->disconnect();
132
133                 return $home_ou;
134         }
135 =cut
136
137         warn "Getting ORG Tree\n";
138         my $org_tree = OpenILS::Application::AppUtils->get_org_tree();
139         warn "Returning Org Tree\n";
140
141         return $org_tree;
142 }
143
144
145 __PACKAGE__->register_method(
146         method  => "get_org_tree_slim",
147         api_name        => "open-ils.search.actor.org_tree.slim.retrieve",
148         argc            => 1, 
149         note            => "Returns the entire org tree structure",
150 );
151
152 sub get_org_tree_slim {
153         my( $self, $client, $user_session ) = @_;
154         warn "Getting ORG Tree\n";
155         warn "Call: " . $self->api_name() . "\n";
156         return OpenILS::Application::AppUtils->get_slim_org_tree();
157 }
158
159
160
161
162
163
164 __PACKAGE__->register_method(
165         method  => "get_org_types",
166         api_name        => "open-ils.search.actor.org_types.retrieve",
167 );
168
169 sub get_org_types {
170         my($self, $client) = @_;
171
172          my $org_typelist = OpenILS::Application::AppUtils->simple_scalar_request(
173                 "open-ils.storage",
174                 "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
175
176          return $org_typelist;
177 }
178
179
180 __PACKAGE__->register_method(
181         method  => "get_user_profiles",
182         api_name        => "open-ils.search.actor.user.profiles.retrieve",
183 );
184 sub get_user_profiles {
185         return OpenILS::Application::AppUtils->simple_scalar_request(
186                         "open-ils.storage",
187                         "open-ils.storage.direct.actor.profile.retrieve.all.atomic",
188                         ( "1", "2", "3" ) );
189 }
190
191
192
193 __PACKAGE__->register_method(
194         method  => "get_user_ident_types",
195         api_name        => "open-ils.search.actor.user.ident_types.retrieve",
196 );
197 sub get_user_ident_types {
198         return OpenILS::Application::AppUtils->simple_scalar_request(
199                         "open-ils.storage",
200                         "open-ils.storage.direct.config.identification_type.retrieve.all.atomic" );
201 }
202
203
204
205
206 __PACKAGE__->register_method(
207         method  => "get_org_unit",
208         api_name        => "open-ils.search.actor.org_unit.retrieve",
209         argc            => 1, 
210         note            => "Returns the entire org tree structure",
211 );
212
213 sub get_org_unit {
214
215         my( $self, $client, $user_session ) = @_;
216
217         my $user_obj = 
218                 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
219
220         my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request(
221                 "open-ils.storage",
222                 "open-ils.storage.direct.actor.org_unit.retrieve", 
223                 $user_obj->home_ou );
224
225         return $home_ou;
226 }
227
228
229
230
231 1;