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;
7 my $log = 'OpenSRF::Utils::Logger';
14 return undef unless @barcodes;
16 for my $card ( actor::card->search( { barcode => @barcodes } ) ) {
19 return $card->usr->to_fieldmapper;
21 $client->respond( $card->usr->to_fieldmapper);
25 __PACKAGE__->register_method(
26 api_name => 'open-ils.storage.direct.actor.user.search.barcode',
28 method => 'user_by_barcode',
33 =comment not gonna use it...
40 return undef unless (defined $searches);
42 for my $usr ( actor::user->search( $searches ) ) {
44 $client->respond( flesh_user( $usr ) );
48 __PACKAGE__->register_method(
49 api_name => 'open-ils.storage.fleshed.actor.user.search',
51 method => 'fleshed_search',
56 sub fleshed_search_like {
61 return undef unless (defined $searches);
63 for my $usr ( actor::user->search_like( $searches ) ) {
65 $client->respond( flesh_user( $usr ) );
69 __PACKAGE__->register_method(
70 api_name => 'open-ils.storage.fleshed.actor.user.search_like',
72 method => 'user_by_barcode',
77 sub retrieve_fleshed_user {
82 return undef unless @ids;
84 @ids = ($ids[0]) unless ($self->api_name =~ /batch/o);
86 $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
90 __PACKAGE__->register_method(
91 api_name => 'open-ils.storage.fleshed.actor.user.retrieve',
93 method => 'retrieve_fleshed_user',
96 __PACKAGE__->register_method(
97 api_name => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
99 method => 'retrieve_fleshed_user',
108 my $standing = $usr->standing;
109 my $profile = $usr->profile;
110 my $ident_type = $usr->ident_type;
112 my $maddress = $usr->mailing_address;
113 my $baddress = $usr->billing_address;
114 my $card = $usr->card;
116 my @addresses = $usr->addresses;
117 my @cards = $usr->cards;
119 my $usr_fm = $usr->to_fieldmapper;
120 $usr_fm->standing( $standing->to_fieldmapper );
121 $usr_fm->profile( $profile->to_fieldmapper );
122 $usr_fm->ident_type( $ident_type->to_fieldmapper );
124 $usr_fm->card( $card->to_fieldmapper );
125 $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
126 $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
128 $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
129 $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
140 my $select =<<" SQL";
143 ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
146 my $sth = actor::org_unit->db_Main->prepare_cached($select);
149 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
153 __PACKAGE__->register_method(
154 api_name => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
157 method => 'org_unit_list',
160 sub org_unit_type_list {
164 my $select =<<" SQL";
166 FROM actor.org_unit_type
167 ORDER BY depth, name;
170 my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
173 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
177 __PACKAGE__->register_method(
178 api_name => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
181 method => 'org_unit_type_list',
184 sub org_unit_full_path {
189 return undef unless ($id);
191 my $func = 'actor.org_unit_full_path(?)';
193 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
194 $sth->execute(''.$id);
196 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
200 __PACKAGE__->register_method(
201 api_name => 'open-ils.storage.actor.org_unit.full_path',
204 method => 'org_unit_full_path',
207 sub org_unit_ancestors {
212 return undef unless ($id);
214 my $func = 'actor.org_unit_ancestors(?)';
216 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
217 $sth->execute(''.$id);
219 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
223 __PACKAGE__->register_method(
224 api_name => 'open-ils.storage.actor.org_unit.ancestors',
227 method => 'org_unit_ancestors',
230 sub org_unit_descendants {
236 return undef unless ($id);
238 my $func = 'actor.org_unit_descendants(?)';
239 if (defined $depth) {
240 $func = 'actor.org_unit_descendants(?,?)';
243 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
244 $sth->execute(''.$id, ''.$depth) if (defined $depth);
245 $sth->execute(''.$id) unless (defined $depth);
247 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
251 __PACKAGE__->register_method(
252 api_name => 'open-ils.storage.actor.org_unit.descendants',
255 method => 'org_unit_descendants',
262 for my $rec ( actor::profile->retrieve_all ) {
263 $client->respond( $rec->to_fieldmapper );
268 __PACKAGE__->register_method(
269 method => 'profile_all',
270 api_name => 'open-ils.storage.direct.actor.profile.retrieve.all',