1 package OpenILS::Application::Actor;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
6 use Digest::MD5 qw(md5_hex);
8 use OpenSRF::EX qw(:try);
11 use OpenILS::Application::AppUtils;
12 use OpenILS::Utils::Fieldmapper;
13 use OpenILS::Application::Search::Actor;
14 use OpenILS::Utils::ModsParser;
16 my $apputils = "OpenILS::Application::AppUtils";
17 sub _d { warn "Patron:\n" . Dumper(shift()); }
18 my $cache_client = OpenSRF::Utils::Cache->new("global", 0);
21 __PACKAGE__->register_method(
22 method => "update_patron",
23 api_name => "open-ils.actor.patron.update",);
26 my( $self, $client, $user_session, $patron ) = @_;
28 my $session = $apputils->start_db_session();
31 warn $user_session . " " . $patron . "\n";
35 OpenILS::Application::AppUtils->check_user_session(
36 $user_session ); #throws EX on error
38 # XXX does this user have permission to add/create users. Granularity?
40 # $new_patron is the patron in progress. $patron is the original patron
41 # passed in with the method. new_patron will change as the components
42 # of patron are added/updated.
46 # create/update the patron first so we can use his id
47 if($patron->isnew()) {
49 $new_patron = _add_patron($session, _clone_patron($patron), $user_obj);
51 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
52 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
53 $client->respond_complete($new_patron->ex);
57 } else { $new_patron = $patron; }
59 $new_patron = _add_update_addresses($session, $patron, $new_patron, $user_obj);
61 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
62 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
63 $client->respond_complete($new_patron->ex);
67 $new_patron = _add_update_cards($session, $patron, $new_patron, $user_obj);
69 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
70 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
71 $client->respond_complete($new_patron->ex);
75 $new_patron = _add_survey_responses($session, $patron, $new_patron, $user_obj);
76 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
77 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
78 $client->respond_complete($new_patron->ex);
82 $new_patron = _create_stat_maps($session, $user_session, $patron, $new_patron, $user_obj);
83 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
84 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
85 $client->respond_complete($new_patron->ex);
90 # re-update the patron if anything has happened to him during this process
91 if($new_patron->ischanged()) {
92 $new_patron = _update_patron($session, $new_patron, $user_obj);
94 if(UNIVERSAL::isa($new_patron, "OpenILS::EX") ||
95 UNIVERSAL::isa($new_patron, "OpenILS::Perm")) {
96 $client->respond_complete($new_patron->ex);
100 $apputils->commit_db_session($session);
102 warn "Patron Update/Create complete\n";
103 return flesh_user($new_patron->id());
109 __PACKAGE__->register_method(
110 method => "user_retrieve_fleshed_by_id",
111 api_name => "open-ils.actor.user.fleshed.retrieve",);
113 sub user_retrieve_fleshed_by_id {
114 my( $self, $client, $user_session, $user_id ) = @_;
115 my $user_obj = $apputils->check_user_session( $user_session );
116 return flesh_user($user_id);
127 $session = OpenSRF::AppSession->create("open-ils.storage");
131 # grab the user with the given id
132 my $ureq = $session->request(
133 "open-ils.storage.direct.actor.user.retrieve", $id);
134 my $user = $ureq->gather(1);
136 if(!$user) { return undef; }
139 my $cards_req = $session->request(
140 "open-ils.storage.direct.actor.card.search.usr.atomic",
142 $user->cards( $cards_req->gather(1) );
144 for my $c(@{$user->cards}) {
145 if($c->id == $user->card || $c->id eq $user->card ) {
146 warn "Setting my card to " . $c->id . "\n";
151 my $add_req = $session->request(
152 "open-ils.storage.direct.actor.user_address.search.usr.atomic",
154 $user->addresses( $add_req->gather(1) );
156 for my $c(@{$user->addresses}) {
157 if($c->id == $user->billing_address || $c->id eq $user->billing_address ) {
158 warn "Setting my address to " . $c->id . "\n";
159 $user->billing_address($c);
163 for my $c(@{$user->addresses}) {
164 if($c->id == $user->mailing_address || $c->id eq $user->mailing_address ) {
165 warn "Setting my address to " . $c->id . "\n";
166 $user->mailing_address($c);
170 my $stat_req = $session->request(
171 "open-ils.storage.direct.actor.stat_cat_entry_user_map.search.target_usr.atomic",
173 $user->stat_cat_entries($stat_req->gather(1));
175 if($kill) { $session->disconnect(); }
176 $user->clear_passwd();
184 # clone and clear stuff that would break the database
188 my $new_patron = Fieldmapper::actor::user->new();
190 my $fmap = $Fieldmapper::fieldmap;
191 no strict; # shallow clone, may be useful in the fieldmapper
193 (keys %{$fmap->{"Fieldmapper::actor::user"}->{'fields'}}) {
194 $new_patron->$field( $patron->$field() );
199 $new_patron->clear_billing_address();
200 $new_patron->clear_mailing_address();
201 $new_patron->clear_addresses();
202 $new_patron->clear_card();
203 $new_patron->clear_cards();
204 $new_patron->clear_id();
205 $new_patron->clear_isnew();
206 $new_patron->clear_changed();
207 $new_patron->clear_deleted();
208 $new_patron->clear_stat_cat_entries();
217 my $user_obj = shift;
220 if($apputils->check_user_perms(
221 $user_obj->id, $user_obj->home_ou, "CREATE_USER")) {
222 return OpenILS::Perm->new("CREATE_USER");
225 warn "Creating new patron\n";
228 my $req = $session->request(
229 "open-ils.storage.direct.actor.user.create",$patron);
230 my $id = $req->gather(1);
232 return OpenILS::EX->new("DUPLICATE_USER_USERNAME");
235 # retrieve the patron from the db to collect defaults
236 my $ureq = $session->request(
237 "open-ils.storage.direct.actor.user.retrieve",
240 warn "Created new patron with id $id\n";
242 return $ureq->gather(1);
247 my( $session, $patron, $user_obj) = @_;
250 if($apputils->check_user_perms(
251 $user_obj->id, $user_obj->home_ou, "UPDATE_USER")) {
252 return OpenILS::Perm->new("UPDATE_USER");
255 warn "updating patron " . Dumper($patron) . "\n";
257 my $req = $session->request(
258 "open-ils.storage.direct.actor.user.update",$patron );
259 my $status = $req->gather(1);
260 if(!defined($status)) {
261 throw OpenSRF::EX::ERROR
262 ("Unknown error updating patron");
268 sub _add_update_addresses {
271 my $new_patron = shift;
273 my $current_id; # id of the address before creation
275 for my $address (@{$patron->addresses()}) {
277 $address->usr($new_patron->id());
279 if(ref($address) and $address->isnew()) {
280 warn "Adding new address at street " . $address->street1() . "\n";
282 $current_id = $address->id();
283 $address = _add_address($session,$address);
285 if( $patron->billing_address() and
286 $patron->billing_address() == $current_id ) {
287 $new_patron->billing_address($address->id());
288 $new_patron->ischanged(1);
291 if( $patron->mailing_address() and
292 $patron->mailing_address() == $current_id ) {
293 $new_patron->mailing_address($address->id());
294 $new_patron->ischanged(1);
297 } elsif( ref($address) and $address->ischanged() ) {
298 warn "Updating address at street " . $address->street1();
299 $address->usr($new_patron->id());
300 _update_address($session,$address);
302 } elsif( ref($address) and $address->isdeleted() ) {
303 warn "Deleting address at street " . $address->street1();
305 if( $address->id() == $new_patron->mailing_address() ) {
306 $new_patron->clear_mailing_address();
307 _update_patron($session, $new_patron);
310 if( $address->id() == $new_patron->billing_address() ) {
311 $new_patron->clear_billing_address();
312 _update_patron($session, $new_patron);
315 _delete_address($session,$address);
323 # adds an address to the db and returns the address with new id
325 my($session, $address) = @_;
326 $address->clear_id();
328 # put the address into the database
329 my $req = $session->request(
330 "open-ils.storage.direct.actor.user_address.create",
334 my $id = $req->gather(1);
336 throw OpenSRF::EX::ERROR
337 ("Unable to create new user address");
340 warn "Created address with id $id\n";
342 # update all the necessary id's
348 sub _update_address {
349 my( $session, $address ) = @_;
350 my $req = $session->request(
351 "open-ils.storage.direct.actor.user_address.update",
353 my $status = $req->gather(1);
354 if(!defined($status)) {
355 throw OpenSRF::EX::ERROR
356 ("Unknown error updating address");
363 sub _add_update_cards {
367 my $new_patron = shift;
369 my $virtual_id; #id of the card before creation
370 for my $card (@{$patron->cards()}) {
372 $card->usr($new_patron->id());
374 if(ref($card) and $card->isnew()) {
376 $virtual_id = $card->id();
377 $card = _add_card($session,$card);
378 if(UNIVERSAL::isa($card,"OpenILS::EX")) {
382 if($patron->card() == $virtual_id) {
383 $new_patron->card($card->id());
384 $new_patron->ischanged(1);
387 } elsif( ref($card) and $card->ischanged() ) {
388 $card->usr($new_patron->id());
389 _update_card($session, $card);
396 # adds an card to the db and returns the card with new id
398 my( $session, $card ) = @_;
401 warn "Adding card with barcode " . $card->barcode() . "\n";
402 my $req = $session->request(
403 "open-ils.storage.direct.actor.card.create",
406 my $id = $req->gather(1);
408 return OpenILS::EX->new("DUPLICATE_INVALID_USER_BARCODE");
412 warn "Created patron card with id $id\n";
418 my( $session, $card ) = @_;
421 my $req = $session->request(
422 "open-ils.storage.direct.actor.card.update",
424 my $status = $req->gather(1);
425 if(!defined($status)) {
426 throw OpenSRF::EX::ERROR
427 ("Unknown error updating card");
435 sub _delete_address {
436 my( $session, $address ) = @_;
438 warn "Deleting address " . $address->street1() . "\n";
440 my $req = $session->request(
441 "open-ils.storage.direct.actor.user_address.delete",
443 my $status = $req->gather(1);
444 if(!defined($status)) {
445 throw OpenSRF::EX::ERROR
446 ("Unknown error updating address");
448 warn "Delete address status is $status\n";
453 sub _add_survey_responses {
454 my ($session, $patron, $new_patron) = @_;
456 warn "updating responses for user " . $new_patron->id . "\n";
458 my $responses = $patron->survey_responses;
459 for my $resp( @$responses ) {
460 $resp->usr($new_patron->id);
463 my $status = $apputils->simple_scalar_request(
465 "open-ils.circ.survey.submit.user_id",
472 sub _create_stat_maps {
474 my($session, $user_session, $patron, $new_patron) = @_;
476 my $maps = $patron->stat_cat_entries();
478 for my $map (@$maps) {
480 next unless($map->isnew() || $map->ischanged());
482 my $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.update";
484 $method = "open-ils.storage.direct.actor.stat_cat_entry_user_map.create";
487 $map->target_usr($new_patron->id);
489 warn "Updating stat entry with method $method and session $user_session and map $map\n";
491 my $req = $session->request($method, $map);
492 my $status = $req->gather(1);
497 throw OpenSRF::EX::ERROR
498 ("Error updating stat map with method $method");
507 __PACKAGE__->register_method(
508 method => "search_username",
509 api_name => "open-ils.actor.user.search.username",
512 sub search_username {
513 my($self, $client, $username) = @_;
514 my $users = OpenILS::Application::AppUtils->simple_scalar_request(
516 "open-ils.storage.direct.actor.user.search.usrname.atomic",
524 __PACKAGE__->register_method(
525 method => "user_retrieve_by_barcode",
526 api_name => "open-ils.actor.user.fleshed.retrieve_by_barcode",);
528 sub user_retrieve_by_barcode {
529 my($self, $client, $user_session, $barcode) = @_;
530 warn "Searching for user with barcode $barcode\n";
531 my $user_obj = $apputils->check_user_session( $user_session );
533 my $session = OpenSRF::AppSession->create("open-ils.storage");
535 # find the card with the given barcode
536 my $creq = $session->request(
537 "open-ils.storage.direct.actor.card.search.barcode.atomic",
539 my $card = $creq->gather(1);
541 if(!$card || !$card->[0]) {
542 $session->disconnect();
547 my $user = flesh_user($card->usr(), $session);
548 $session->disconnect();
555 __PACKAGE__->register_method(
556 method => "get_user_by_id",
557 api_name => "open-ils.actor.user.retrieve",);
560 my ($self, $client, $user_session, $id) = @_;
562 my $user_obj = $apputils->check_user_session( $user_session );
564 return $apputils->simple_scalar_request(
566 "open-ils.storage.direct.actor.user.retrieve",
572 __PACKAGE__->register_method(
573 method => "get_org_types",
574 api_name => "open-ils.actor.org_types.retrieve",);
578 my($self, $client) = @_;
580 return $org_types if $org_types;
582 $apputils->simple_scalar_request(
584 "open-ils.storage.direct.actor.org_unit_type.retrieve.all.atomic" );
589 __PACKAGE__->register_method(
590 method => "get_user_profiles",
591 api_name => "open-ils.actor.user.profiles.retrieve",
595 sub get_user_profiles {
596 return $user_profiles if $user_profiles;
598 return $user_profiles =
599 $apputils->simple_scalar_request(
601 "open-ils.storage.direct.actor.profile.retrieve.all.atomic");
606 __PACKAGE__->register_method(
607 method => "get_user_ident_types",
608 api_name => "open-ils.actor.user.ident_types.retrieve",
611 sub get_user_ident_types {
612 return $ident_types if $ident_types;
613 return $ident_types =
614 $apputils->simple_scalar_request(
616 "open-ils.storage.direct.config.identification_type.retrieve.all.atomic" );
622 __PACKAGE__->register_method(
623 method => "get_org_unit",
624 api_name => "open-ils.actor.org_unit.retrieve",
629 my( $self, $client, $user_session, $org_id ) = @_;
631 if(defined($user_session) && !defined($org_id)) {
633 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
634 if(!defined($org_id)) {
635 $org_id = $user_obj->home_ou;
640 my $home_ou = OpenILS::Application::AppUtils->simple_scalar_request(
642 "open-ils.storage.direct.actor.org_unit.retrieve",
651 __PACKAGE__->register_method(
652 method => "get_org_tree",
653 api_name => "open-ils.actor.org_tree.retrieve",
655 note => "Returns the entire org tree structure",
659 my( $self, $client) = @_;
661 # see if it's in the cache
662 warn "Getting ORG Tree\n";
663 my $tree = $cache_client->get_cache('orgtree');
665 warn "Found orgtree in cache. returning...\n";
669 my $orglist = $apputils->simple_scalar_request(
671 "open-ils.storage.direct.actor.org_unit.retrieve.all.atomic" );
674 warn "found org list\n";
677 $tree = $self->build_org_tree($orglist);
678 $cache_client->put_cache('orgtree', $tree);
684 # turns an org list into an org tree
687 my( $self, $orglist) = @_;
689 return $orglist unless (
690 ref($orglist) and @$orglist > 1 );
693 $a->ou_type <=> $b->ou_type ||
694 $a->name cmp $b->name } @$orglist;
696 for my $org (@list) {
698 next unless ($org and defined($org->parent_ou));
699 my ($parent) = grep { $_->id == $org->parent_ou } @list;
702 $parent->children([]) unless defined($parent->children);
703 push( @{$parent->children}, $org );
711 __PACKAGE__->register_method(
712 method => "get_org_descendants",
713 api_name => "open-ils.actor.org_tree.descendants.retrieve"
716 # depth is optional. org_unit is the id
717 sub get_org_descendants {
718 my( $self, $client, $org_unit, $depth ) = @_;
719 my $orglist = $apputils->simple_scalar_request(
721 "open-ils.storage.actor.org_unit.descendants.atomic",
723 return $self->build_org_tree($orglist);
727 __PACKAGE__->register_method(
728 method => "get_org_ancestors",
729 api_name => "open-ils.actor.org_tree.ancestors.retrieve"
732 # depth is optional. org_unit is the id
733 sub get_org_ancestors {
734 my( $self, $client, $org_unit, $depth ) = @_;
735 my $orglist = $apputils->simple_scalar_request(
737 "open-ils.storage.actor.org_unit.ancestors.atomic",
739 return $self->build_org_tree($orglist);
743 __PACKAGE__->register_method(
744 method => "get_standings",
745 api_name => "open-ils.actor.standings.retrieve"
750 return $user_standings if $user_standings;
751 return $user_standings =
752 $apputils->simple_scalar_request(
754 "open-ils.storage.direct.config.standing.retrieve.all.atomic" );
759 __PACKAGE__->register_method(
760 method => "get_my_org_path",
761 api_name => "open-ils.actor.org_unit.full_path.retrieve"
764 sub get_my_org_path {
765 my( $self, $client, $user_session, $org_id ) = @_;
766 my $user_obj = $apputils->check_user_session($user_session);
767 if(!defined($org_id)) { $org_id = $user_obj->home_ou; }
769 return $apputils->simple_scalar_request(
771 "open-ils.storage.actor.org_unit.full_path.atomic",
776 __PACKAGE__->register_method(
777 method => "patron_adv_search",
778 api_name => "open-ils.actor.patron.search.advanced" );
780 sub patron_adv_search {
781 my( $self, $client, $staff_login, $search_hash ) = @_;
784 warn "patron adv with $staff_login and search " .
785 Dumper($search_hash) . "\n";
787 my $session = OpenSRF::AppSession->create("open-ils.storage");
788 my $req = $session->request(
789 "open-ils.storage.actor.user.crazy_search", $search_hash);
791 my $ans = $req->gather(1);
793 my %hash = map { ($_ =>1) } @$ans;
794 $ans = [ keys %hash ];
796 warn "Returning @$ans\n";
798 $session->disconnect();
805 sub _verify_password {
806 my($user_session, $password) = @_;
807 my $user_obj = $apputils->check_user_session($user_session);
809 #grab the user with password
810 $user_obj = $apputils->simple_scalar_request(
812 "open-ils.storage.direct.actor.user.retrieve",
815 if($user_obj->passwd eq $password) {
823 __PACKAGE__->register_method(
824 method => "update_password",
825 api_name => "open-ils.actor.user.password.update");
827 __PACKAGE__->register_method(
828 method => "update_password",
829 api_name => "open-ils.actor.user.username.update");
831 __PACKAGE__->register_method(
832 method => "update_password",
833 api_name => "open-ils.actor.user.email.update");
835 sub update_password {
836 my( $self, $client, $user_session, $new_value, $current_password ) = @_;
838 warn "Updating user with method " .$self->api_name . "\n";
839 my $user_obj = $apputils->check_user_session($user_session);
841 if($self->api_name =~ /password/) {
843 #make sure they know the current password
844 if(!_verify_password($user_session, md5_hex($current_password))) {
845 return OpenILS::EX->new("USER_WRONG_PASSWORD")->ex;
848 $user_obj->passwd($new_value);
850 elsif($self->api_name =~ /username/) {
851 $user_obj->usrname($new_value);
854 elsif($self->api_name =~ /email/) {
855 warn "Updating email to $new_value\n";
856 $user_obj->email($new_value);
859 my $session = $apputils->start_db_session();
860 $user_obj = _update_patron($session, $user_obj);
861 $apputils->commit_db_session($session);
863 if($user_obj) { return 1; }
868 __PACKAGE__->register_method(
869 method => "check_user_perms",
870 api_name => "open-ils.actor.user.perm.check",
872 Takes a user id, an org id, and an array of perm type strings. For each
873 perm type, if the user does *not* have the given permission it is added
874 to a list which is returned from the method. If all permissions
875 are allowed, an empty list is returned
879 sub check_user_perms {
880 my( $self, $client, $user_id, $org_id, $perm_types ) = @_;
883 for my $perm (@$perm_types) {
884 if($apputils->check_user_perms($user_id, $org_id, $perm)) {
885 push @not_allowed, $perm;
894 __PACKAGE__->register_method(
895 method => "user_fines_summary",
896 api_name => "open-ils.actor.user.fines.summary",
898 Returns a short summary of the users total open fines, excluding voided fines
899 Params are login_session, user_id
900 Returns a 'mus' object.
904 sub user_fines_summary {
905 my( $self, $client, $login_session, $user_id ) = @_;
907 my $user_obj = $apputils->check_user_session($login_session);
908 if($user_obj->id ne $user_id) {
909 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_FINES_SUMMARY")) {
910 return OpenILS::Perm->new("VIEW_USER_FINES_SUMMARY");
914 return $apputils->simple_scalar_request(
916 "open-ils.storage.direct.money.user_summary.search.usr",
924 __PACKAGE__->register_method(
925 method => "user_transactions",
926 api_name => "open-ils.actor.user.transactions",
927 notes => <<" NOTES");
928 Returns a list of open user transactions (mbts objects);
929 Params are login_session, user_id
930 Optional third parameter is the transactions type. defaults to all
933 __PACKAGE__->register_method(
934 method => "user_transactions",
935 api_name => "open-ils.actor.user.transactions.have_charge",
936 notes => <<" NOTES");
937 Returns a list of all open user transactions (mbts objects) that have an initial charge
938 Params are login_session, user_id
939 Optional third parameter is the transactions type. defaults to all
942 __PACKAGE__->register_method(
943 method => "user_transactions",
944 api_name => "open-ils.actor.user.transactions.have_balance",
945 notes => <<" NOTES");
946 Returns a list of all open user transactions (mbts objects) that have a balance
947 Params are login_session, user_id
948 Optional third parameter is the transactions type. defaults to all
951 __PACKAGE__->register_method(
952 method => "user_transactions",
953 api_name => "open-ils.actor.user.transactions.fleshed",
954 notes => <<" NOTES");
955 Returns an object/hash of transaction, circ, title where transaction = an open
956 user transactions (mbts objects), circ is the attached circluation, and title
957 is the title the circ points to
958 Params are login_session, user_id
959 Optional third parameter is the transactions type. defaults to all
962 __PACKAGE__->register_method(
963 method => "user_transactions",
964 api_name => "open-ils.actor.user.transactions.have_charge.fleshed",
965 notes => <<" NOTES");
966 Returns an object/hash of transaction, circ, title where transaction = an open
967 user transactions that has an initial charge (mbts objects), circ is the
968 attached circluation, and title is the title the circ points to
969 Params are login_session, user_id
970 Optional third parameter is the transactions type. defaults to all
973 __PACKAGE__->register_method(
974 method => "user_transactions",
975 api_name => "open-ils.actor.user.transactions.have_balance.fleshed",
976 notes => <<" NOTES");
977 Returns an object/hash of transaction, circ, title where transaction = an open
978 user transaction that has a balance (mbts objects), circ is the attached
979 circluation, and title is the title the circ points to
980 Params are login_session, user_id
981 Optional third parameter is the transaction type. defaults to all
986 sub user_transactions {
987 my( $self, $client, $login_session, $user_id, $type ) = @_;
989 my $user_obj = $apputils->check_user_session($login_session);
990 if($user_obj->id ne $user_id) {
991 if($apputils->check_user_perms($user_obj->id, $user_obj->home_ou, "VIEW_USER_TRANSACTIONS")) {
992 return OpenILS::Perm->new("VIEW_USER_TRANSACTIONS");
996 my $api = $self->api_name();
999 if(defined($type)) { @xact = (xact_type => $type);
1000 } else { @xact = (); }
1002 if($api =~ /have_charge/) {
1004 $trans = $apputils->simple_scalar_request(
1006 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1007 { usr => $user_id, total_owed => { ">" => 0 }, @xact });
1009 } elsif($api =~ /have_balance/) {
1011 $trans = $apputils->simple_scalar_request(
1013 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1014 { usr => $user_id, balance_owed => { ">" => 0 }, @xact });
1018 $trans = $apputils->simple_scalar_request(
1020 "open-ils.storage.direct.money.billable_transaction_summary.search_where.atomic",
1021 { usr => $user_id, @xact });
1024 if($api !~ /fleshed/) { return $trans; }
1029 for my $t (@$trans) {
1033 my $circ = $apputils->simple_scalar_request(
1035 "open-ils.storage.direct.action.circulation.retrieve",
1038 my $title = $apputils->simple_scalar_request(
1040 "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
1041 $circ->target_copy );
1043 my $u = OpenILS::Utils::ModsParser->new();
1044 $u->start_mods_batch($title->marc());
1045 my $mods = $u->finish_mods_batch();
1047 push @resp, {transaction => $t, circ => $circ, record => $mods };
1057 __PACKAGE__->register_method(
1058 method => "retrieve_groups",
1059 api_name => "open-ils.actor.groups.retrieve",
1060 notes => <<" NOTES");
1061 Returns a list of user groups
1063 sub retrieve_groups {
1064 my( $self, $client ) = @_;
1065 return $apputils->simple_scalar_request(
1067 "open-ils.storage.direct.permission.grp_tree.retrieve.all.atomic");
1121 some old methods that may be good to keep around for now
1124 my( $session, $card ) = @_;
1126 warn "Deleting card with barcode " . $card->barcode() . "\n";
1127 my $req = $session->request(
1128 "open-ils.storage.direct.actor.card.delete",
1130 my $status = $req->gather(1);
1131 if(!defined($status)) {
1132 throw OpenSRF::EX::ERROR
1133 ("Unknown error updating card");
1139 # deletes the patron and any attached addresses and cards
1140 __PACKAGE__->register_method(
1141 method => "delete_patron",
1142 api_name => "open-ils.actor.patron.delete",
1147 my( $self, $client, $patron ) = @_;
1148 my $session = $apputils->start_db_session();
1153 $patron->clear_mailing_address();
1154 $patron->clear_billing_address();
1155 $patron->ischanged(1);
1157 _update_patron($session, $patron);
1158 _delete_address($session,$_) for (@{$patron->addresses()});
1159 _delete_card($session,$_) for (@{$patron->cards()});
1160 _delete_patron($session,$patron);
1161 $apputils->commit_db_session($session);
1163 } catch Error with {
1165 $err = "-*- Failure deleting user: $e";
1166 $apputils->rollback_db_session($session);
1170 if($err) { throw OpenSRF::EX::ERROR ($err); }
1171 warn "Patron Delete complete\n";
1175 sub _delete_patron {
1176 my( $session, $patron ) = @_;
1178 warn "Deleting patron " . $patron->usrname() . "\n";
1180 my $req = $session->request(
1181 "open-ils.storage.direct.actor.user.delete",
1183 my $status = $req->gather(1);
1184 if(!defined($status)) {
1185 throw OpenSRF::EX::ERROR
1186 ("Unknown error updating patron");