]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Actor.pm
53672c65469c849fd2502c71f82ffdfdcaad3833
[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
6
7
8 __PACKAGE__->register_method(
9         method  => "actor_user_search_username",
10         api_name        => "open-ils.search.actor.user.search.username",
11 );
12
13 sub actor_user_search_username {
14
15         my($self, $client, $username) = @_;
16
17         my $users = OpenILS::Application::AppUtils->simple_scalar_request(
18                         "open-ils.storage", 
19                         "open-ils.storage.direct.actor.user.search.usrname",
20                         $username );
21
22         return $users;
23 }
24
25
26 __PACKAGE__->register_method(
27         method  => "actor_user_retrieve_by_barcode",
28         api_name        => "open-ils.search.actor.user.barcode",
29 );
30
31 sub actor_user_retrieve_by_barcode {
32         my($self, $client, $barcode) = @_;
33         warn "Searching for user with barcode $barcode\n";
34
35         my $session = OpenSRF::AppSession->create("open-ils.storage");
36
37         # find the card with the given barcode
38         my $creq        = $session->request(
39                         "open-ils.storage.direct.actor.card.search.barcode",
40                         $barcode );
41         my $card = $creq->gather(1);
42         $card = $card->[0];
43
44         # grab the user with the given card
45         my $ureq = $session->request(
46                         "open-ils.storage.direct.actor.user.retrieve",
47                         $card->usr());
48         my $user = $ureq->gather(1);
49
50         # grab the cards
51         my $cards_req = $session->request(
52                         "open-ils.storage.direct.actor.card.search.usr",
53                         $user->id() );
54         $user->cards( $cards_req->gather(1) );
55
56         my $add_req = $session->request(
57                         "open-ils.storage.direct.actor.user_address.search.usr",
58                         $user->id() );
59         $user->addresses( $add_req->gather(1) );
60
61         return $user;
62
63 }
64
65
66 __PACKAGE__->register_method(
67         method  => "get_org_tree",
68         api_name        => "open-ils.search.actor.org_tree.retrieve",
69         argc            => 1, 
70         note            => "Returns the entire org tree structure",
71 );
72
73 sub get_org_tree {
74
75         my( $self, $client, $user_session ) = @_;
76
77         if( $user_session ) { # keep for now for backwards compatibility
78
79                 my $user_obj = 
80                         OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
81                 
82                 my $session = OpenSRF::AppSession->create("open-ils.storage");
83                 my $request = $session->request( 
84                                 "open-ils.storage.direct.actor.org_unit.retrieve", $user_obj->home_ou );
85                 my $response = $request->recv();
86
87                 if(!$response) { 
88                         throw OpenSRF::EX::ERROR (
89                                         "No response from storage for org_unit retrieve");
90                 }
91                 if(UNIVERSAL::isa($response,"Error")) {
92                         throw $response ($response->stringify);
93                 }
94
95                 my $home_ou = $response->content;
96                 $request->finish();
97                 $session->disconnect();
98
99                 return $home_ou;
100         }
101
102         warn "Getting ORG Tree\n";
103         my $org_tree = OpenILS::Application::AppUtils->get_org_tree();
104         warn "Returning Org Tree\n";
105
106         return $org_tree;
107 }
108
109
110 __PACKAGE__->register_method(
111         method  => "get_org_tree_slim",
112         api_name        => "open-ils.search.actor.org_tree.slim.retrieve",
113         argc            => 1, 
114         note            => "Returns the entire org tree structure",
115 );
116
117 sub get_org_tree_slim {
118
119         my( $self, $client, $user_session ) = @_;
120
121         warn "Getting ORG Tree\n";
122         my $org_tree = OpenILS::Application::AppUtils->get_slim_org_tree();
123         warn "Returning Org Tree\n";
124
125         return $org_tree;
126 }
127
128
129
130
131
132
133 __PACKAGE__->register_method(
134         method  => "get_org_types",
135         api_name        => "open-ils.search.actor.org_types.retrieve",
136 );
137
138 sub get_org_types {
139         my($self, $client) = @_;
140
141          my $org_typelist = OpenILS::Application::AppUtils->simple_scalar_request(
142                 "open-ils.storage",
143                 "open-ils.storage.direct.actor.org_unit_type.retrieve.all" );
144
145          return $org_typelist;
146 }
147
148
149 __PACKAGE__->register_method(
150         method  => "get_user_profiles",
151         api_name        => "open-ils.search.actor.user.profiles",
152 );
153
154 sub get_user_profiles {
155         return OpenILS::Application::AppUtils->simple_scalar_request(
156                         "open-ils.storage",
157                         "open-ils.storage.direct.actor.profile.batch.retrieve.atomic",
158                         ( "1", "2", "3" ) );
159 }
160
161
162 1;