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);
10 my $apputils = "OpenILS::Application::AppUtils";
11 my $logger = "OpenSRF::Utils::Logger";
13 sub initialize { return 1; }
16 __PACKAGE__->register_method(
17 method => "bucket_retrieve",
18 api_name => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name",
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.
25 __PACKAGE__->register_method(
26 method => "bucket_retrieve",
27 api_name => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_name",
29 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name
30 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
33 __PACKAGE__->register_method(
34 method => "bucket_retrieve",
35 api_name => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user",
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.
43 __PACKAGE__->register_method(
44 method => "bucket_retrieve",
45 api_name => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_user",
47 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user
48 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
54 my($self, $client, $authtoken, $userid, $name) = @_;
56 my ($staff, $user, $perm) =
57 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
58 return $perm if $perm;
60 $logger->activity("User " . $staff->id . " retrieving buckets for user $user");
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";
73 if( $self->api_name =~ /biblio/ ) {
75 if( $self->api_name =~ /retrieve_by_user/ ) {
76 $buckets = $apputils->simplereq( $svc,
77 "$bibmeth.search.owner.atomic", $user ); }
79 if( $self->api_name =~ /retrieve_by_name/ ) {
80 $buckets = $apputils->simplereq( $svc,
81 "$bibmeth.search_where.atomic", { name => $name, owner => $user } ); }
83 if( $self->api_name =~ /fleshed/ ) {
84 for my $b (@$buckets) {
86 $items = $apputils->simplereq( $svc,
87 "$bibmeth"."_item.search.bucket.atomic", $b->id );
88 push( @$resp, { bucket => $b , items => $items });
93 return $resp if ($self->api_name =~ /fleshed/);
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";
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.
116 sub bucket_retrieve_all {
117 my($self, $client, $authtoken, $userid) = @_;
119 my ($staff, $user, $perm) =
120 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
121 return $perm if $perm;
123 $logger->activity("User " . $staff->id . " retrieving buckets for user $user");
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 );
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.
148 my($self, $client, $authtoken, $bucket, $type) = @_;
150 my( $staff, $evt ) = $apputils->check_ses($authtoken);
154 $meth = $cnmeth if $type eq "callnumber";
155 $meth = $copymeth if $type eq "copy";
156 $meth = $usermeth if $type eq "user";
158 my $bkt = $apputils->simplereq( $svc, "$meth.retrieve", $bucket );
159 if(!$bkt) {return undef};
161 $logger->debug("Fetching fleshed bucket $bucket");
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;
170 $bkt->items( $apputils->simplereq( $svc,
171 "$meth"."_item.search.bucket.atomic", $bucket ) );