1 package OpenILS::Application::Circ::CopyLocations;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
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";
13 __PACKAGE__->register_method(
14 api_name => "open-ils.circ.copy_location.retrieve.all",
15 method => 'cl_retrieve_all',
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
26 my( $self, $client, $authtoken, $orgId ) = @_;
27 my( $requestor, $evt ) = $U->checkses($authtoken);
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);
35 __PACKAGE__->register_method(
36 api_name => 'open-ils.circ.copy_location.create',
37 method => 'cl_create',
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
48 my( $self, $client, $authtoken, $copyLoc ) = @_;
49 my( $requestor, $evt ) = $U->checkses($authtoken);
51 $evt = $U->check_perms($requestor->id,
52 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
56 ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
57 return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
59 my $id = $U->storagereq(
60 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
62 return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
66 __PACKAGE__->register_method (
67 api_name => 'open-ils.circ.copy_location.delete',
68 method => 'cl_delete',
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
79 my( $self, $client, $authtoken, $id ) = @_;
80 my( $requestor, $evt ) = $U->checkses($authtoken);
84 ($cl, $evt) = $U->fetch_copy_location($id);
87 $evt = $U->check_perms($requestor->id,
88 $cl->owning_lib, 'DELETE_COPY_LOCATION');
91 my $resp = $U->storagereq(
92 'open-ils.storage.direct.asset.copy_location.delete', $id );
94 return $U->DB_UPDATE_FAILED unless $resp;
98 __PACKAGE__->register_method (
99 api_name => 'open-ils.circ.copy_location.update',
100 method => 'cl_update',
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
111 my( $self, $client, $authtoken, $copyLoc ) = @_;
113 my( $requestor, $evt ) = $U->checkses($authtoken);
117 ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
120 $evt = $U->check_perms($requestor->id,
121 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
124 $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
126 my $resp = $U->storagereq(
127 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
129 return 1; # if there was no exception thrown, then the update was a success