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, $orgId ) = @_;
29 my $otree = $U->get_org_tree();
33 $logger->debug("Fetching ranged copy location set for org $orgId");
34 return $U->storagereq(
35 'open-ils.storage.ranged.asset.copy_location.retrieve.atomic', $orgId);
38 __PACKAGE__->register_method(
39 api_name => 'open-ils.circ.copy_location.create',
40 method => 'cl_create',
43 Creates a new copy location. Requestor must have the CREATE_COPY_LOCATION
44 permission at the location specified on the new location object
45 @param authtoken The login session key
46 @param copyLoc The new copy location object
47 @return The if of the new location object on success, event on error
51 my( $self, $client, $authtoken, $copyLoc ) = @_;
52 my( $requestor, $evt ) = $U->checkses($authtoken);
54 $evt = $U->check_perms($requestor->id,
55 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
59 ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
60 return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
62 my $id = $U->storagereq(
63 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
65 return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
69 __PACKAGE__->register_method (
70 api_name => 'open-ils.circ.copy_location.delete',
71 method => 'cl_delete',
74 Deletes a copy location. Requestor must have the
75 DELETE_COPY_LOCATION permission.
76 @param authtoken The login session key
77 @param id The copy location object id
78 @return 1 on success, event on error
82 my( $self, $client, $authtoken, $id ) = @_;
83 my( $requestor, $evt ) = $U->checkses($authtoken);
87 ($cl, $evt) = $U->fetch_copy_location($id);
90 $evt = $U->check_perms($requestor->id,
91 $cl->owning_lib, 'DELETE_COPY_LOCATION');
94 my $resp = $U->storagereq(
95 'open-ils.storage.direct.asset.copy_location.delete', $id );
97 return $U->DB_UPDATE_FAILED unless $resp;
101 __PACKAGE__->register_method (
102 api_name => 'open-ils.circ.copy_location.update',
103 method => 'cl_update',
106 Updates a copy location object. Requestor must have
107 the UPDATE_COPY_LOCATION permission
108 @param authtoken The login session key
109 @param copyLoc The copy location object
110 @return 1 on success, event on error
114 my( $self, $client, $authtoken, $copyLoc ) = @_;
116 my( $requestor, $evt ) = $U->checkses($authtoken);
120 ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
123 $evt = $U->check_perms($requestor->id,
124 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
127 $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
129 my $resp = $U->storagereq(
130 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
132 return 1; # if there was no exception thrown, then the update was a success