]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Actor/Container.pm
added fleshed versions of the existing methods
[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 __PACKAGE__->register_method(
16         method  => "bucket_retrieve",
17         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name",
18         notes           => <<"  NOTES");
19                 Retrieves a BREB by name.  PARAMS(authtoken, bucketOwnerId, bucketName)
20                 If requestor ID is different than bucketOwnerId, requestor must have
21                 VIEW_CONTAINER permissions.
22         NOTES
23
24 __PACKAGE__->register_method(
25         method  => "bucket_retrieve",
26         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_name",
27         notes           => <<"  NOTES");
28                 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_name
29                 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
30         NOTES
31
32 __PACKAGE__->register_method(
33         method  => "bucket_retrieve",
34         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user",
35         notes           => <<"  NOTES");
36                 Returns all BRE Buckets that belong to the given user. 
37                 PARAMS( authtoken, bucketOwnerId )
38                 If requestor ID is different than bucketOwnerId, requestor must have
39                 VIEW_CONTAINER permissions.
40         NOTES
41
42 __PACKAGE__->register_method(
43         method  => "bucket_retrieve",
44         api_name        => "open-ils.actor.container.biblio_record_entry_bucket.fleshed.retrieve_by_user",
45         notes           => <<"  NOTES");
46                 see: open-ils.actor.container.biblio_record_entry_bucket.retrieve_by_user
47                 Returns an array of { bucket : <bucketObj>, items : [ <I1>, <I2>, ...] } objects
48         NOTES
49
50
51
52 sub bucket_retrieve {
53         my($self, $client, $authtoken, $userid, $name) = @_;
54
55         my ($staff, $user, $perm) = 
56                 $apputils->handle_requestor( $authtoken, $userid, 'VIEW_CONTAINER');
57         return $perm if $perm;
58
59         $logger->activity("User " . $staff->id . " retrieving buckets for user $user");
60
61         my $svc = 'open-ils.storage';
62         my $meth = 'open-ils.storage.direct.container';
63         my $bibmeth = "$meth.biblio_record_entry_bucket";
64         my $cnmeth = "$meth.biblio_record_entry_bucket";
65         my $copymeth = "$meth.biblio_record_entry_bucket";
66         my $usermeth = "$meth.biblio_record_entry_bucket";
67
68         my $buckets;
69         my $items;
70         my $resp = [];
71
72         if( $self->api_name =~ /biblio/ ) {
73
74                 if( $self->api_name =~ /retrieve_by_user/ ) {
75                         $buckets =  $apputils->simplereq( $svc, 
76                                 "$bibmeth.search.owner.atomic", $user ); }
77         
78                 if( $self->api_name =~ /retrieve_by_name/ ) {
79                         $buckets = $apputils->simplereq( $svc, 
80                                 "$bibmeth.search_where.atomic", { name => $name, owner => $user } ); }
81
82                 if( $self->api_name =~ /fleshed/ ) {
83                         for my $b (@$buckets) {
84                                 next unless $b;
85                                 $items = $apputils->simplereq( $svc,
86                                         "$bibmeth"."_item.search.bucket.atomic", $b->id );
87                                 push( @$resp, { bucket => $b , items => $items });
88                         }
89                 }
90         }
91
92         return $resp if ($self->api_name =~ /fleshed/);
93         return $buckets;
94 }
95
96
97
98 1;
99
100