]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm
using org email as reply-to
[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 use OpenILS::Utils::CStoreEditor qw/:funcs/;
11 my $U = "OpenILS::Application::AppUtils";
12
13
14 __PACKAGE__->register_method(
15         api_name                => "open-ils.circ.copy_location.retrieve.all",
16         method          => 'cl_retrieve_all',
17         argc                    =>      1,
18         signature       => q/
19                 Retrieves the ranged set of copy locations for the requested org.
20                 If no org is provided, all copy locations are returned
21                 @param authtoken The login session key
22                 @param orgId The org location id
23                 @return An array of copy location objects
24                 /);
25
26 sub cl_retrieve_all {
27         my( $self, $client, $orgId ) = @_;
28
29         if(!$orgId) {
30                 my $otree = $U->get_org_tree();
31                 $orgId = $otree->id;
32         }
33
34         $logger->debug("Fetching ranged copy location set for org $orgId");
35         return $U->storagereq(
36                 'open-ils.storage.ranged.asset.copy_location.retrieve.atomic', $orgId);
37 }
38
39 __PACKAGE__->register_method(
40         api_name                => 'open-ils.circ.copy_location.create',
41         method          => 'cl_create',
42         argc                    => 2,
43         signature       => q/
44                 Creates a new copy location.  Requestor must have the CREATE_COPY_LOCATION
45                 permission at the location specified on the new location object
46                 @param authtoken The login session key
47                 @param copyLoc The new copy location object
48                 @return The if of the new location object on success, event on error
49         /);
50
51 sub cl_create {
52         my( $self, $client, $authtoken, $copyLoc ) = @_;
53         my( $requestor, $evt ) = $U->checkses($authtoken);
54         return $evt if $evt;
55         $evt = $U->check_perms($requestor->id, 
56                 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
57         return $evt if $evt;
58
59         my $cl;
60         ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
61         return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
62
63         my $id = $U->storagereq(
64                 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
65
66         return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
67         return $id;
68 }
69
70 __PACKAGE__->register_method (
71         api_name                => 'open-ils.circ.copy_location.delete',
72         method          => 'cl_delete',
73         argc                    => 2,
74         signature       => q/
75                 Deletes a copy location. Requestor must have the 
76                 DELETE_COPY_LOCATION permission.
77                 @param authtoken The login session key
78                 @param id The copy location object id
79                 @return 1 on success, event on error
80         /);
81
82 sub cl_delete {
83         my( $self, $client, $authtoken, $id ) = @_;
84         my( $requestor, $evt ) = $U->checkses($authtoken);
85         return $evt if $evt;
86
87         my $cl;
88         ($cl, $evt) = $U->fetch_copy_location($id);
89         return $evt if $evt;
90
91         $evt = $U->check_perms($requestor->id, 
92                 $cl->owning_lib, 'DELETE_COPY_LOCATION');
93         return $evt if $evt;
94
95         my $resp = $U->storagereq(
96                 'open-ils.storage.direct.asset.copy_location.delete', $id );
97         
98         return $U->DB_UPDATE_FAILED unless $resp;
99         return 1;
100 }
101
102 __PACKAGE__->register_method (
103         api_name                => 'open-ils.circ.copy_location.update',
104         method          => 'cl_update',
105         argc                    => 2,
106         signature       => q/
107                 Updates a copy location object.  Requestor must have 
108                 the UPDATE_COPY_LOCATION permission
109                 @param authtoken The login session key
110                 @param copyLoc  The copy location object
111                 @return 1 on success, event on error
112         /);
113
114 sub cl_update {
115         my( $self, $client, $authtoken, $copyLoc ) = @_;
116
117         my( $requestor, $evt ) = $U->checkses($authtoken);
118         return $evt if $evt;
119
120         my $cl; 
121         ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
122         return $evt if $evt;
123
124         $evt = $U->check_perms($requestor->id, 
125                 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
126         return $evt if $evt;
127
128         $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
129
130         my $resp = $U->storagereq(
131                 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
132         
133         return 1; # if there was no exception thrown, then the update was a success
134 }
135
136
137 __PACKAGE__->register_method(
138         method => 'fetch_loc',
139         api_name => 'open-ils.circ.copy_location.retrieve',
140 );
141
142 sub fetch_loc {
143         my( $self, $con, $id ) = @_;
144         my $e = new_editor();
145         my $cl = $e->retrieve_asset_copy_location($id)
146                 or return $e->event;
147         return $cl;
148 }
149
150
151
152
153 23;