1 package OpenILS::Application::Actor::Container;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
7 use OpenSRF::EX qw(:try);
8 use OpenILS::Utils::Fieldmapper;
10 my $apputils = "OpenILS::Application::AppUtils";
11 my $logger = "OpenSRF::Utils::Logger";
13 sub initialize { return 1; }
15 my $svc = 'open-ils.storage';
16 my $meth = 'open-ils.storage.direct.container';
18 $types{'biblio'} = "$meth.biblio_record_entry_bucket";
19 $types{'callnumber'} = "$meth.call_number_bucket";
20 $types{'copy'} = "$meth.copy_bucket";
21 $types{'user'} = "$meth.user_bucket";
24 __PACKAGE__->register_method(
25 method => "bucket_retrieve_all",
26 api_name => "open-ils.actor.container.bucket.all.retrieve_by_user",
28 Retrieves all un-fleshed buckets assigned to given user
29 PARAMS(authtoken, bucketOwnerId)
30 If requestor ID is different than bucketOwnerId, requestor must have
31 VIEW_CONTAINER permissions.
34 sub bucket_retrieve_all {
35 my($self, $client, $authtoken, $userid) = @_;
37 my( $staff, $evt ) = $apputils->checkses($authtoken);
40 my( $user, $e ) = $apputils->checkrequestor( $staff, $userid, 'VIEW_CONTAINER');
43 $logger->debug("User " . $staff->id .
44 " retrieving all buckets for user $userid");
48 $buckets{$_} = $apputils->simplereq(
49 $svc, $types{$_} . ".search.owner.atomic", $userid ) for keys %types;
54 __PACKAGE__->register_method(
55 method => "bucket_flesh",
56 api_name => "open-ils.actor.container.bucket.flesh",
59 Fleshes a bucket by id
60 PARAMS(authtoken, bucketClass, bucketId)
61 bucketclasss include biblio, callnumber, copy, and user.
62 bucketclass defaults to biblio.
63 If requestor ID is different than bucketOwnerId, requestor must have
64 VIEW_CONTAINER permissions.
69 my($self, $client, $authtoken, $class, $bucket) = @_;
71 my( $staff, $evt ) = $apputils->checkses($authtoken);
74 $logger->debug("User " . $staff->id . " retrieving bucket $bucket");
76 my $meth = $types{$class};
78 my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket );
79 if(!$bkt) {return undef};
81 my( $user, $e ) = $apputils->checkrequestor( $staff, $bkt->owner, 'VIEW_CONTAINER' );
84 $bkt->items( $apputils->simplereq( $svc,
85 "$meth"."_item.search.bucket.atomic", $bucket ) );
91 __PACKAGE__->register_method(
92 method => "bucket_retrieve_class",
93 api_name => "open-ils.actor.container.bucket.retrieve_by_class",
96 Retrieves all un-fleshed buckets by class assigned to given user
97 PARAMS(authtoken, bucketOwnerId, class [, type])
98 class can be one of "biblio", "callnumber", "copy", "user"
99 The optional "type" parameter allows you to limit the search by
101 If bucketOwnerId is not defined, the authtoken is used as the
103 If requestor ID is different than bucketOwnerId, requestor must have
104 VIEW_CONTAINER permissions.
107 sub bucket_retrieve_class {
108 my( $self, $client, $authtoken, $userid, $class, $type ) = @_;
110 my( $staff, $user, $evt );
111 ($staff, $evt) = $apputils->checkses($authtoken);
114 ($user, $evt) = $apputils->checkrequestor($staff, $userid, 'VIEW_CONTAINER');
117 $logger->debug("User " . $staff->id .
118 " retrieving buckets for user $userid [class=$class, type=$type]");
120 my $meth = $types{$class} . ".search_where.atomic";
124 $buckets = $apputils->simplereq( $svc,
125 $meth, { owner => $userid, btype => $type } );
127 $logger->debug("Grabbing buckets by class $class: $svc : $meth : {owner => $userid}");
128 $buckets = $apputils->simplereq( $svc, $meth, { owner => $userid } );
134 __PACKAGE__->register_method(
135 method => "bucket_create",
136 api_name => "open-ils.actor.container.bucket.create",
137 notes => <<" NOTES");
138 Creates a new bucket object. If requestor is different from
139 bucketOwner, requestor needs CREATE_CONTAINER permissions
140 PARAMS(authtoken, bucketObject);
141 Returns the new bucket object
145 my( $self, $client, $authtoken, $class, $bucket ) = @_;
147 my( $staff, $target, $evt ) =
148 $apputils->checkses_requestor(
149 $authtoken, $bucket->owner, 'CREATE_CONTAINER' );
152 $logger->activity( "User " . $staff->id .
153 " creating a new continer for user " . $bucket->owner );
155 $logger->debug("Creating new container object: " . Dumper($bucket));
157 my $method = $types{$class} . ".create";
158 my $id = $apputils->simplereq( $svc, $method, $bucket );
160 $logger->debug("Creatined new container with id $id");
162 if(!$id) { throw OpenSRF::EX
163 ("Unable to create new bucket object"); }
169 __PACKAGE__->register_method(
170 method => "bucket_delete",
171 api_name => "open-ils.actor.container.bucket.delete",
172 notes => <<" NOTES");
173 Deletes a bucket object. If requestor is different from
174 bucketOwner, requestor needs DELETE_CONTAINER permissions
175 PARAMS(authtoken, class, bucketId);
176 Returns the new bucket object
180 my( $self, $client, $authtoken, $class, $bucketid ) = @_;
182 my( $bucket, $staff, $target, $evt );
184 ( $bucket, $evt ) = $apputils->fetch_container($bucketid, $class);
187 ( $staff, $target, $evt ) = $apputils->checkses_requestor(
188 $authtoken, $bucket->owner, 'DELETE_CONTAINER' );
191 $logger->activity( "User " . $staff->id .
192 " deleting continer $bucketid for user " . $bucket->owner );
194 my $method = $types{$class} . ".delete";
195 my $resp = $apputils->simplereq( $svc, $method, $bucketid );
197 throw OpenSRF::EX ("Unable to create new bucket object") unless $resp;
202 __PACKAGE__->register_method(
203 method => "item_create",
204 api_name => "open-ils.actor.container.bucket.item.create",
205 notes => <<" NOTES");
206 PARAMS(authtoken, class, item)
210 my( $self, $client, $authtoken, $class, $item ) = @_;
211 my( $bucket, $staff, $target, $evt);
213 ( $bucket, $evt ) = $apputils->fetch_container($item->bucket, $class);
216 ( $staff, $target, $evt ) = $apputils->checkses_requestor(
217 $authtoken, $bucket->owner, 'CREATE_CONTAINER_ITEM' );
220 $logger->activity( "User " . $staff->id .
221 " creating continer item " . Dumper($item) . " for user " . $bucket->owner );
223 my $method = $types{$class} . "_item.create";
224 my $resp = $apputils->simplreq( $svc, $method, $item );
226 throw OpenSRF::EX ("Unable to delete container item") unless $resp;
232 __PACKAGE__->register_method(
233 method => "item_create",
234 api_name => "open-ils.actor.container.bucket.item.delete",
235 notes => <<" NOTES");
236 PARAMS(authtoken, class, itemId)
240 my( $self, $client, $authtoken, $class, $itemid ) = @_;
241 my( $bucket, $item, $staff, $target, $evt);
244 ( $item, $evt ) = $apputils->fetch_container_item( $itemid, $class );
246 ( $bucket, $evt ) = $apputils->fetch_container($item->bucket, $class);
249 ( $staff, $target, $evt ) = $apputils->checkses_requestor(
250 $authtoken, $bucket->owner, 'DELETE_CONTAINER_ITEM' );
253 $logger->activity( "User " . $staff->id .
254 " deleting continer item $itemid for user " . $bucket->owner );
256 my $method = $types{$class} . "_item.delete";
257 my $resp = $apputils->simplreq( $svc, $method, $itemid );
259 throw OpenSRF::EX ("Unable to delete container item") unless $resp;