]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm
adding copy_location related code ... module plus test script and related events
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ / CopyLocations.pm
1 package OpenILS::Application::Circ::CopyLocations;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use Data::Dumper;
5 $Data::Dumper::Indent = 0;
6 use OpenSRF::EX qw(:try);
7 use OpenSRF::Utils::Logger qw(:logger);
8 use OpenILS::Application::AppUtils;
9 use OpenILS::Utils::Fieldmapper;
10 my $U = "OpenILS::Application::AppUtils";
11
12
13 __PACKAGE__->register_method(
14         api_name                => "open-ils.circ.copy_location.retrieve.all",
15         method          => 'cl_retrieve_all',
16         argc                    =>      1,
17         signature       => q/
18                 Retrieves the ranged set of copy locations for the requested org.
19                 If no org is provided, the home org of the requestor is used.
20                 @param authtoken The login session key
21                 @param orgId The org location id
22                 @return An array of copy location objects
23                 /);
24
25 sub cl_retrieve_all {
26         my( $self, $client, $authtoken, $orgId ) = @_;
27         my( $requestor, $evt ) = $U->checkses($authtoken);
28         return $evt if $evt;
29         $orgId = defined($orgId) ? $orgId : $requestor->home_ou;
30         $logger->debug("Fetching ranged copy location set for org $orgId");
31         return $U->storagereq(
32                 'open-ils.storage.ranged.asset.copy_location.retrieve.atomic', $orgId);
33 }
34
35 __PACKAGE__->register_method(
36         api_name                => 'open-ils.circ.copy_location.create',
37         method          => 'cl_create',
38         argc                    => 2,
39         signature       => q/
40                 Creates a new copy location.  Requestor must have the CREATE_COPY_LOCATION
41                 permission at the location specified on the new location object
42                 @param authtoken The login session key
43                 @param copyLoc The new copy location object
44                 @return The if of the new location object on success, event on error
45         /);
46
47 sub cl_create {
48         my( $self, $client, $authtoken, $copyLoc ) = @_;
49         my( $requestor, $evt ) = $U->checkses($authtoken);
50         return $evt if $evt;
51         $evt = $U->check_perms($requestor->id, 
52                 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
53         return $evt if $evt;
54
55         my $cl;
56         ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
57         return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
58
59         my $id = $U->storagereq(
60                 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
61
62         return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
63         return $id;
64 }
65
66 __PACKAGE__->register_method (
67         api_name                => 'open-ils.circ.copy_location.delete',
68         method          => 'cl_delete',
69         argc                    => 2,
70         signature       => q/
71                 Deletes a copy location. Requestor must have the 
72                 DELETE_COPY_LOCATION permission.
73                 @param authtoken The login session key
74                 @param id The copy location object id
75                 @return 1 on success, event on error
76         /);
77
78 sub cl_delete {
79         my( $self, $client, $authtoken, $id ) = @_;
80         my( $requestor, $evt ) = $U->checkses($authtoken);
81         return $evt if $evt;
82
83         my $cl;
84         ($cl, $evt) = $U->fetch_copy_location($id);
85         return $evt if $evt;
86
87         $evt = $U->check_perms($requestor->id, 
88                 $cl->owning_lib, 'DELETE_COPY_LOCATION');
89         return $evt if $evt;
90
91         my $resp = $U->storagereq(
92                 'open-ils.storage.direct.asset.copy_location.delete', $id );
93         
94         return $U->DB_UPDATE_FAILED unless $resp;
95         return 1;
96 }
97
98 __PACKAGE__->register_method (
99         api_name                => 'open-ils.circ.copy_location.update',
100         method          => 'cl_update',
101         argc                    => 2,
102         signature       => q/
103                 Updates a copy location object.  Requestor must have 
104                 the UPDATE_COPY_LOCATION permission
105                 @param authtoken The login session key
106                 @param copyLoc  The copy location object
107                 @return 1 on success, event on error
108         /);
109
110 sub cl_update {
111         my( $self, $client, $authtoken, $copyLoc ) = @_;
112
113         my( $requestor, $evt ) = $U->checkses($authtoken);
114         return $evt if $evt;
115
116         my $cl; 
117         ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
118         return $evt if $evt;
119
120         $evt = $U->check_perms($requestor->id, 
121                 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
122         return $evt if $evt;
123
124         $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
125
126         my $resp = $U->storagereq(
127                 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
128         
129         return 1; # if there was no exception thrown, then the update was a success
130 }
131
132
133
134 666;