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, $evt ) = $apputils->checkses($authtoken);
150 if( $bucket->owner ne $staff->id ) {
151 return $evt if ($evt = $apputils->check_perms('CREATE_CONTAINER'));
154 $logger->activity( "User " . $staff->id .
155 " creating a new continer for user " . $bucket->owner );
157 my $method = $types{$class} . ".create";
158 my $id = $apputils->simplreq( $svc, $method, $bucket );
160 if(!$id) { throw OpenSRF::EX
161 ("Unable to create new bucket object"); }