]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm
ab572bfa03bbe6eb4bf0e38a8a29cacd89cfb3b2
[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
52 sub cl_create {
53     my( $self, $conn, $auth, $location ) = @_;
54
55     my $e = new_editor(authtoken=>$auth, xact=>1);
56     return $e->die_event unless $e->checkauth;
57     return $e->die_event unless 
58         $e->allowed('CREATE_COPY_LOCATION', $location->owning_lib);
59
60     # make sure there is no copy_location with the same name in the same place
61     my $existing = $e->search_asset_copy_location(
62         {owning_lib => $location->owning_lib, name => $location->name}, {idlist=>1});
63     return OpenILS::Event->new('COPY_LOCATION_EXISTS') if @$existing;
64
65     $e->create_asset_copy_location($location) or return $e->die_event;
66     $e->commit;
67     return $location->id;
68 }
69
70
71
72 __PACKAGE__->register_method (
73         api_name                => 'open-ils.circ.copy_location.delete',
74         method          => 'cl_delete',
75         argc                    => 2,
76         signature       => q/
77                 Deletes a copy location. Requestor must have the 
78                 DELETE_COPY_LOCATION permission.
79                 @param authtoken The login session key
80                 @param id The copy location object id
81                 @return 1 on success, event on error
82         /);
83
84
85 sub cl_delete {
86     my( $self, $conn, $auth, $id ) = @_;
87
88     my $e = new_editor(authtoken=>$auth, xact=>1);
89     return $e->die_event unless $e->checkauth;
90
91     my $cloc = $e->retrieve_asset_copy_location($id) 
92         or return $e->die_event;
93     return $e->die_event unless 
94         $e->allowed('DELETE_COPY_LOCATION', $cloc->owning_lib);
95
96     $e->delete_asset_copy_location($cloc) or return $e->die_event;
97     $e->commit;
98     return 1;
99 }
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
115 sub cl_update {
116     my( $self, $conn, $auth, $location ) = @_;
117
118     my $e = new_editor(authtoken=>$auth, xact=>1);
119     return $e->die_event unless $e->checkauth;
120
121     # check permissions against the original copy location
122     my $orig_loc = $e->retrieve_asset_copy_location($location->id)
123         or return $e->die_event;
124
125     return $e->die_event unless 
126         $e->allowed('UPDATE_COPY_LOCATION', $orig_loc->owning_lib);
127
128     # disallow hijacking of the location
129     $location->owning_lib($orig_loc->owning_lib);  
130
131     $e->update_asset_copy_location($location)
132         or return $e->die_event;
133
134     $e->commit;
135     return 1;
136 }
137
138
139
140 __PACKAGE__->register_method(
141         method => 'fetch_loc',
142         api_name => 'open-ils.circ.copy_location.retrieve',
143 );
144
145 sub fetch_loc {
146         my( $self, $con, $id ) = @_;
147         my $e = new_editor();
148         my $cl = $e->retrieve_asset_copy_location($id)
149                 or return $e->event;
150         return $cl;
151 }
152
153
154
155
156 23;