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);
9 my $apputils = "OpenILS::Application::AppUtils";
10 my $logger = "OpenSRF::Utils::Logger";
12 sub initialize { return 1; }
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";
21 __PACKAGE__->register_method(
22 method => "bucket_retrieve_all",
23 api_name => "open-ils.actor.container.bucket.all.retrieve_by_user",
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.
31 sub bucket_retrieve_all {
32 my($self, $client, $authtoken, $userid) = @_;
34 my ($staff, $user, $evt) =
35 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
38 $logger->debug("User " . $staff->id .
39 " retrieving all buckets for user $user");
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 );
51 __PACKAGE__->register_method(
52 method => "bucket_flesh",
53 api_name => "open-ils.actor.container.bucket.flesh",
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.
65 my($self, $client, $authtoken, $bucket, $type) = @_;
67 my( $staff, $evt ) = $apputils->check_ses($authtoken);
70 $logger->debug("User " . $staff->id . " retrieving bucket $bucket");
73 $meth = $cnmeth if $type eq "callnumber";
74 $meth = $copymeth if $type eq "copy";
75 $meth = $usermeth if $type eq "user";
77 my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket );
78 if(!$bkt) {return undef};
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;
87 $bkt->items( $apputils->simplereq( $svc,
88 "$meth"."_item.search.bucket.atomic", $bucket ) );
94 __PACKAGE__->register_method(
95 method => "bucket_retrieve_class",
96 api_name => "open-ils.actor.container.bucket.retrieve_by_class",
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
103 If bucketOwnerId is not defined, the authtoken is used as the
105 If requestor ID is different than bucketOwnerId, requestor must have
106 VIEW_CONTAINER permissions.
109 sub bucket_retrieve_class {
110 my( $self, $client, $authtoken, $userid, $class, $type ) = @_;
112 my ($staff, $user, $evt) =
113 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
116 $logger->debug("User " . $staff->id .
117 " retrieving buckets for $user [class=$class, type=$type]");
120 $meth = $cnmeth if $class eq "callnumber";
121 $meth = $copymeth if $class eq "copy";
122 $meth = $usermeth if $class eq "user";
127 $buckets = $apputils->simplereq( $svc,
128 "$meth.search_where.atomic", { owner => $user, btype => $type } );
130 $buckets = $apputils->simplereq( $svc,
131 "$meth.search_where.atomic", { owner => $user } );