]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm
caceb1564e5e8be93199e5c6105dd7a8179f9a38
[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 use OpenILS::EX;
9
10 my $apputils = "OpenILS::Application::AppUtils";
11 my $logger = "OpenSRF::Utils::Logger";
12
13 sub initialize { return 1; }
14
15 =head comment
16 __PACKAGE__->register_method(
17         method  => "bucket_retrieve",
18         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name",
19         notes           => <<"  NOTES");
20                 Retrieves a BREB by name.  PARAMS(authtoken, bucketOwnerId, bucketName)
21                 If requestor ID is different than bucketOwnerId, requestor must have
22                 VIEW_CONTAINER permissions.
23         NOTES
24
25 __PACKAGE__->register_method(
26         method  => "bucket_retrieve",
27         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_name",
28         notes           => <<"  NOTES");
29                 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name
30                 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
31         NOTES
32
33 __PACKAGE__->register_method(
34         method  => "bucket_retrieve",
35         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user",
36         notes           => <<"  NOTES");
37                 Returns all BRE Buckets that belong to the given user. 
38                 PARAMS( authtoken, bucketOwnerId )
39                 If requestor ID is different than bucketOwnerId, requestor must have
40                 VIEW_CONTAINER permissions.
41         NOTES
42
43 __PACKAGE__->register_method(
44         method  => "bucket_retrieve",
45         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_user",
46         notes           => <<"  NOTES");
47                 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user
48                 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
49         NOTES
50
51
52
53 sub bucket_retrieve {
54         my($self, $client, $authtoken, $userid, $name) = @_;
55
56         my ($staff, $user, $perm) = 
57                 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
58         return $perm if $perm;
59
60         $logger->activity("User " . $staff->id . " retrieving buckets for user $user");
61
62         my $svc = 'open-ils.storage';
63         my $meth = 'open-ils.storage.direct.container';
64         my $bibmeth = "$meth.biblio_record_entry_bucket";
65         my $cnmeth = "$meth.biblio_record_entry_bucket";
66         my $copymeth = "$meth.biblio_record_entry_bucket";
67         my $usermeth = "$meth.biblio_record_entry_bucket";
68
69         my $buckets;
70         my $items;
71         my $resp = [];
72
73         if( $self->api_name =~ /biblio/ ) {
74
75                 if( $self->api_name =~ /retrieve_by_user/ ) {
76                         $buckets =  $apputils->simplereq( $svc, 
77                                 "$bibmeth.search.owner.atomic", $user ); }
78         
79                 if( $self->api_name =~ /retrieve_by_name/ ) {
80                         $buckets = $apputils->simplereq( $svc, 
81                                 "$bibmeth.search_where.atomic", { name => $name, owner => $user } ); }
82
83                 if( $self->api_name =~ /fleshed/ ) {
84                         for my $b (@$buckets) {
85                                 next unless $b;
86                                 $items = $apputils->simplereq( $svc,
87                                         "$bibmeth"."_item.search.bucket.atomic", $b->id );
88                                 push( @$resp, { bucket => $b , items => $items });
89                         }
90                 }
91         }
92
93         return $resp if ($self->api_name =~ /fleshed/);
94         return $buckets;
95 }
96 =cut
97
98
99 my $svc = 'open-ils.storage';
100 my $meth = 'open-ils.storage.direct.container';
101 my $bibmeth = "$meth.biblio_record_entry_bucket";
102 my $cnmeth = "$meth.call_number_bucket";
103 my $copymeth = "$meth.copy_bucket";
104 my $usermeth = "$meth.user_bucket";
105
106 __PACKAGE__->register_method(
107         method  => "bucket_retrieve_all",
108         api_name        => "open-ils.actor.container.bucket.all.retrieve_by_user",
109         notes           => <<"  NOTES");
110                 Retrieves all un-fleshed buckets assigned to given user 
111                 PARAMS(authtoken, bucketOwnerId)
112                 If requestor ID is different than bucketOwnerId, requestor must have
113                 VIEW_CONTAINER permissions.
114         NOTES
115
116 sub bucket_retrieve_all {
117         my($self, $client, $authtoken, $userid) = @_;
118
119         my ($staff, $user, $perm) = 
120                 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
121         return $perm if $perm;
122
123         $logger->activity("User " . $staff->id . " retrieving buckets for user $user");
124
125         my %buckets;
126
127         $buckets{biblio} = $apputils->simplereq( $svc, "$bibmeth.search.owner.atomic", $user ); 
128         $buckets{callnumber} = $apputils->simplereq( $svc, "$cnmeth.search.owner.atomic", $user ); 
129         $buckets{copy} = $apputils->simplereq( $svc, "$copymeth.search.owner.atomic", $user ); 
130         $buckets{user} = $apputils->simplereq( $svc, "$usermeth.search.owner.atomic", $user ); 
131
132         return \%buckets;
133 }
134
135 __PACKAGE__->register_method(
136         method  => "bucket_flesh",
137         api_name        => "open-ils.actor.container.bucket.flesh",
138         notes           => <<"  NOTES");
139                 Fleshes a bucket by id
140                 PARAMS(authtoken, bucketId, bucketype)
141                 Types include biblio, callnumber, copy, and user
142                 If requestor ID is different than bucketOwnerId, requestor must have
143                 VIEW_CONTAINER permissions.
144         NOTES
145
146 sub bucket_flesh {
147
148         my($self, $client, $authtoken, $bucket, $type) = @_;
149
150         my( $staff, $evt ) = $apputils->check_ses($authtoken);
151         return $evt if $evt;
152
153         my $meth = $bibmeth;
154         $meth = $cnmeth if $type eq "callnumber";
155         $meth = $copymeth if $type eq "copy";
156         $meth = $usermeth if $type eq "user";
157
158         my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket );
159         if(!$bkt) {return undef};
160
161         $logger->debug("Fetching fleshed bucket $bucket");
162
163         if( $bkt->owner ne $staff->id ) {
164                 my $userobj = $apputils->fetch_user($bkt->owner);
165                 my $perm = $apputils->check_perms( 
166                         $staff->id, $userobj->home_ou, 'VIEW_CONTAINER' );
167                 return $perm if $perm;
168         }
169
170         $bkt->items( $apputils->simplereq( $svc,
171                 "$meth"."_item.search.bucket.atomic", $bucket ) );
172
173         return $bkt;
174 }
175
176
177 1;
178
179