]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm
d1ac1dd9e5656ffdad1cfe8ad0200534ac8a76a1
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Actor / Container.pm
1 package OpenILS::Application::Actor::Container;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
5 use OpenILS::Perm;
6 use Data::Dumper;
7 use OpenSRF::EX qw(:try);
8
9 my $apputils = "OpenILS::Application::AppUtils";
10 my $logger = "OpenSRF::Utils::Logger";
11
12 sub initialize { return 1; }
13
14 my $svc = 'open-ils.storage';
15 my $meth = 'open-ils.storage.direct.container';
16 my $bibmeth = "$meth.biblio_record_entry_bucket";
17 my $cnmeth = "$meth.call_number_bucket";
18 my $copymeth = "$meth.copy_bucket";
19 my $usermeth = "$meth.user_bucket";
20
21 __PACKAGE__->register_method(
22         method  => "bucket_retrieve_all",
23         api_name        => "open-ils.actor.container.bucket.all.retrieve_by_user",
24         notes           => <<"  NOTES");
25                 Retrieves all un-fleshed buckets assigned to given user 
26                 PARAMS(authtoken, bucketOwnerId)
27                 If requestor ID is different than bucketOwnerId, requestor must have
28                 VIEW_CONTAINER permissions.
29         NOTES
30
31 sub bucket_retrieve_all {
32         my($self, $client, $authtoken, $userid) = @_;
33
34         my ($staff, $user, $evt) = 
35                 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
36         return $evt if $evt;
37
38         $logger->debug("User " . $staff->id . 
39                 " retrieving all buckets for user $user");
40
41         my %buckets;
42
43         $buckets{biblio} = $apputils->simplereq( $svc, "$bibmeth.search.owner.atomic", $user ); 
44         $buckets{callnumber} = $apputils->simplereq( $svc, "$cnmeth.search.owner.atomic", $user ); 
45         $buckets{copy} = $apputils->simplereq( $svc, "$copymeth.search.owner.atomic", $user ); 
46         $buckets{user} = $apputils->simplereq( $svc, "$usermeth.search.owner.atomic", $user ); 
47
48         return \%buckets;
49 }
50
51 __PACKAGE__->register_method(
52         method  => "bucket_flesh",
53         api_name        => "open-ils.actor.container.bucket.flesh",
54         notes           => <<"  NOTES");
55                 Fleshes a bucket by id
56                 PARAMS(authtoken, bucketId, buckeclass)
57                 bucketclasss include biblio, callnumber, copy, and user.  
58                 bucketclass defaults to biblio.
59                 If requestor ID is different than bucketOwnerId, requestor must have
60                 VIEW_CONTAINER permissions.
61         NOTES
62
63 sub bucket_flesh {
64
65         my($self, $client, $authtoken, $bucket, $type) = @_;
66
67         my( $staff, $evt ) = $apputils->check_ses($authtoken);
68         return $evt if $evt;
69
70         $logger->debug("User " . $staff->id . " retrieving bucket $bucket");
71
72         my $meth = $bibmeth;
73         $meth = $cnmeth if $type eq "callnumber";
74         $meth = $copymeth if $type eq "copy";
75         $meth = $usermeth if $type eq "user";
76
77         my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket );
78         if(!$bkt) {return undef};
79
80         if( $bkt->owner ne $staff->id ) {
81                 my $userobj = $apputils->fetch_user($bkt->owner);
82                 my $perm = $apputils->check_perms( 
83                         $staff->id, $userobj->home_ou, 'VIEW_CONTAINER' );
84                 return $perm if $perm;
85         }
86
87         $bkt->items( $apputils->simplereq( $svc,
88                 "$meth"."_item.search.bucket.atomic", $bucket ) );
89
90         return $bkt;
91 }
92
93
94 __PACKAGE__->register_method(
95         method  => "bucket_retrieve_class",
96         api_name        => "open-ils.actor.container.bucket.retrieve_by_class",
97         notes           => <<"  NOTES");
98                 Retrieves all un-fleshed buckets by class assigned to given user 
99                 PARAMS(authtoken, bucketOwnerId, class [, type])
100                 class can be one of "biblio", "callnumber", "copy", "user"
101                 The optional "type" parameter allows you to limit the search by 
102                 bucket type.  
103                 If bucketOwnerId is not defined, the authtoken is used as the
104                 bucket owner.
105                 If requestor ID is different than bucketOwnerId, requestor must have
106                 VIEW_CONTAINER permissions.
107         NOTES
108
109 sub bucket_retrieve_class {
110         my( $self, $client, $authtoken, $userid, $class, $type ) = @_;
111
112         my ($staff, $user, $evt) = 
113                 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
114         return $evt if $evt;
115
116         $logger->debug("User " . $staff->id . 
117                 " retrieving buckets for $user [class=$class, type=$type]");
118
119         my $meth = $bibmeth;
120         $meth = $cnmeth if $class eq "callnumber";
121         $meth = $copymeth if $class eq "copy";
122         $meth = $usermeth if $class eq "user";
123
124         my $buckets;
125
126         if( $type ) {
127                 $buckets = $apputils->simplereq( $svc,
128                         "$meth.search_where.atomic", { owner => $user, btype => $type } );
129         } else {
130                 $buckets = $apputils->simplereq( $svc,
131                         "$meth.search_where.atomic", { owner => $user } );
132         }
133
134         return $buckets;
135 }
136
137
138 1;
139
140