1 package OpenILS::Application::Circ::CopyLocations;
2 use base 'OpenILS::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, $org_id ) = @_;
30 my $otree = $U->get_org_tree();
34 return new_editor()->search_asset_copy_location({
35 owning_lib => $U->get_org_full_path($org_id)
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
53 my( $self, $conn, $auth, $location ) = @_;
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);
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;
65 $e->create_asset_copy_location($location) or return $e->die_event;
72 __PACKAGE__->register_method (
73 api_name => 'open-ils.circ.copy_location.delete',
74 method => 'cl_delete',
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
86 my( $self, $conn, $auth, $id ) = @_;
88 my $e = new_editor(authtoken=>$auth, xact=>1);
89 return $e->die_event unless $e->checkauth;
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);
96 $e->delete_asset_copy_location($cloc) or return $e->die_event;
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
116 my( $self, $conn, $auth, $location ) = @_;
118 my $e = new_editor(authtoken=>$auth, xact=>1);
119 return $e->die_event unless $e->checkauth;
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;
125 return $e->die_event unless
126 $e->allowed('UPDATE_COPY_LOCATION', $orig_loc->owning_lib);
128 # disallow hijacking of the location
129 $location->owning_lib($orig_loc->owning_lib);
131 $e->update_asset_copy_location($location)
132 or return $e->die_event;
140 __PACKAGE__->register_method(
141 method => 'fetch_loc',
143 api_name => 'open-ils.circ.copy_location.retrieve',
147 my( $self, $con, $id ) = @_;
148 my $e = new_editor();
149 my $cl = $e->retrieve_asset_copy_location($id)