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 use OpenILS::Utils::CStoreEditor qw/:funcs/;
11 my $U = "OpenILS::Application::AppUtils";
14 __PACKAGE__->register_method(
15 api_name => "open-ils.circ.copy_location.retrieve.all",
16 method => 'cl_retrieve_all',
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
27 my( $self, $client, $orgId ) = @_;
30 my $otree = $U->get_org_tree();
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);
39 __PACKAGE__->register_method(
40 api_name => 'open-ils.circ.copy_location.create',
41 method => 'cl_create',
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
52 my( $self, $client, $authtoken, $copyLoc ) = @_;
53 my( $requestor, $evt ) = $U->checkses($authtoken);
55 $evt = $U->check_perms($requestor->id,
56 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
60 ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
61 return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
63 my $id = $U->storagereq(
64 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
66 return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
70 __PACKAGE__->register_method (
71 api_name => 'open-ils.circ.copy_location.delete',
72 method => 'cl_delete',
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
83 my( $self, $client, $authtoken, $id ) = @_;
84 my( $requestor, $evt ) = $U->checkses($authtoken);
88 ($cl, $evt) = $U->fetch_copy_location($id);
91 $evt = $U->check_perms($requestor->id,
92 $cl->owning_lib, 'DELETE_COPY_LOCATION');
95 my $resp = $U->storagereq(
96 'open-ils.storage.direct.asset.copy_location.delete', $id );
98 return $U->DB_UPDATE_FAILED unless $resp;
102 __PACKAGE__->register_method (
103 api_name => 'open-ils.circ.copy_location.update',
104 method => 'cl_update',
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
115 my( $self, $client, $authtoken, $copyLoc ) = @_;
117 my( $requestor, $evt ) = $U->checkses($authtoken);
121 ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
124 $evt = $U->check_perms($requestor->id,
125 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
128 $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
130 my $resp = $U->storagereq(
131 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
133 return 1; # if there was no exception thrown, then the update was a success
137 __PACKAGE__->register_method(
138 method => 'fetch_loc',
139 api_name => 'open-ils.circ.copy_location.retrieve',
143 my( $self, $con, $id ) = @_;
144 my $e = new_editor();
145 my $cl = $e->retrieve_asset_copy_location($id)