'open-ils.storage.direct.config.copy_status.retrieve.all.atomic' );
}
+sub fetch_copy_location {
+ my( $self, $id ) = @_;
+ my $evt;
+ my $cl = $self->storagereq(
+ 'open-ils.storage.direct.asset.copy_location.retrieve', $id );
+ $evt = OpenILS::Event->new('COPY_LOCATION_NOT_FOUND') unless $cl;
+ return ($cl, $evt);
+}
+
sub fetch_copy_locations {
my $self = shift;
return $self->simplereq(
'open-ils.storage.direct.asset.copy_location.retrieve.all.atomic');
}
+sub fetch_copy_location_by_name {
+ my( $self, $name, $org ) = @_;
+ my $evt;
+ my $cl = $self->storagereq(
+ 'open-ils.storage.direct.asset.copy_location.search_where',
+ { name => $name, owning_lib => $org } );
+ $evt = OpenILS::Event->new('COPY_LOCATION_NOT_FOUND') unless $cl;
+ return ($cl, $evt);
+}
+
sub fetch_callnumber {
my( $self, $id ) = @_;
my $evt = undef;
return ($obj, $evt);
}
+sub storagereq {
+ my( $self, $method, @params ) = @_;
+ return $self->simplereq(
+ 'open-ils.storage', $method, @params );
+}
+
1;
--- /dev/null
+package OpenILS::Application::Circ::CopyLocations;
+use base 'OpenSRF::Application';
+use strict; use warnings;
+use Data::Dumper;
+$Data::Dumper::Indent = 0;
+use OpenSRF::EX qw(:try);
+use OpenSRF::Utils::Logger qw(:logger);
+use OpenILS::Application::AppUtils;
+use OpenILS::Utils::Fieldmapper;
+my $U = "OpenILS::Application::AppUtils";
+
+
+__PACKAGE__->register_method(
+ api_name => "open-ils.circ.copy_location.retrieve.all",
+ method => 'cl_retrieve_all',
+ argc => 1,
+ signature => q/
+ Retrieves the ranged set of copy locations for the requested org.
+ If no org is provided, the home org of the requestor is used.
+ @param authtoken The login session key
+ @param orgId The org location id
+ @return An array of copy location objects
+ /);
+
+sub cl_retrieve_all {
+ my( $self, $client, $authtoken, $orgId ) = @_;
+ my( $requestor, $evt ) = $U->checkses($authtoken);
+ return $evt if $evt;
+ $orgId = defined($orgId) ? $orgId : $requestor->home_ou;
+ $logger->debug("Fetching ranged copy location set for org $orgId");
+ return $U->storagereq(
+ 'open-ils.storage.ranged.asset.copy_location.retrieve.atomic', $orgId);
+}
+
+__PACKAGE__->register_method(
+ api_name => 'open-ils.circ.copy_location.create',
+ method => 'cl_create',
+ argc => 2,
+ signature => q/
+ Creates a new copy location. Requestor must have the CREATE_COPY_LOCATION
+ permission at the location specified on the new location object
+ @param authtoken The login session key
+ @param copyLoc The new copy location object
+ @return The if of the new location object on success, event on error
+ /);
+
+sub cl_create {
+ my( $self, $client, $authtoken, $copyLoc ) = @_;
+ my( $requestor, $evt ) = $U->checkses($authtoken);
+ return $evt if $evt;
+ $evt = $U->check_perms($requestor->id,
+ $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
+ return $evt if $evt;
+
+ my $cl;
+ ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
+ return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
+
+ my $id = $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
+
+ return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
+ return $id;
+}
+
+__PACKAGE__->register_method (
+ api_name => 'open-ils.circ.copy_location.delete',
+ method => 'cl_delete',
+ argc => 2,
+ signature => q/
+ Deletes a copy location. Requestor must have the
+ DELETE_COPY_LOCATION permission.
+ @param authtoken The login session key
+ @param id The copy location object id
+ @return 1 on success, event on error
+ /);
+
+sub cl_delete {
+ my( $self, $client, $authtoken, $id ) = @_;
+ my( $requestor, $evt ) = $U->checkses($authtoken);
+ return $evt if $evt;
+
+ my $cl;
+ ($cl, $evt) = $U->fetch_copy_location($id);
+ return $evt if $evt;
+
+ $evt = $U->check_perms($requestor->id,
+ $cl->owning_lib, 'DELETE_COPY_LOCATION');
+ return $evt if $evt;
+
+ my $resp = $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_location.delete', $id );
+
+ return $U->DB_UPDATE_FAILED unless $resp;
+ return 1;
+}
+
+__PACKAGE__->register_method (
+ api_name => 'open-ils.circ.copy_location.update',
+ method => 'cl_update',
+ argc => 2,
+ signature => q/
+ Updates a copy location object. Requestor must have
+ the UPDATE_COPY_LOCATION permission
+ @param authtoken The login session key
+ @param copyLoc The copy location object
+ @return 1 on success, event on error
+ /);
+
+sub cl_update {
+ my( $self, $client, $authtoken, $copyLoc ) = @_;
+
+ my( $requestor, $evt ) = $U->checkses($authtoken);
+ return $evt if $evt;
+
+ my $cl;
+ ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
+ return $evt if $evt;
+
+ $evt = $U->check_perms($requestor->id,
+ $cl->owning_lib, 'UPDATE_COPY_LOCATION');
+ return $evt if $evt;
+
+ $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
+
+ my $resp = $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
+
+ return 1; # if there was no exception thrown, then the update was a success
+}
+
+
+
+666;
--- /dev/null
+#!/usr/bin/perl
+
+#----------------------------------------------------------------
+# Code for testing the container API
+#----------------------------------------------------------------
+
+require '../oils_header.pl';
+use vars qw/ $apputils $memcache $user $authtoken $authtime /;
+use strict; use warnings;
+
+#----------------------------------------------------------------
+err("\nusage: $0 <config> <oils_login_username> ".
+ " <oils_login_password> <name> <org>\n".
+ "Where <name> is the copy location name and <org> is the \n".
+ "org that houses the new location object\n") unless $ARGV[4];
+#----------------------------------------------------------------
+
+my $config = shift;
+my $username = shift;
+my $password = shift;
+my $name = shift;
+my $org = shift;
+
+sub go {
+ osrf_connect($config);
+ oils_login($username, $password);
+ my $cl =create_cl($name, $org);
+ update_cl($cl);
+# print_cl($org);
+ delete_cl($cl);
+}
+
+go();
+
+#----------------------------------------------------------------
+
+sub create_cl {
+ my( $name, $org ) = @_;
+
+ my $cl = Fieldmapper::asset::copy_location->new;
+ $cl->owning_lib($org);
+ $cl->name($name);
+ $cl->circulate(0);
+ $cl->opac_visible(0);
+ $cl->holdable(0);
+
+ my $resp = simplereq(
+ CIRC(), 'open-ils.circ.copy_location.create', $authtoken, $cl );
+
+ oils_event_die($resp);
+ printl("Copy location $name successfully created");
+ $cl->id($resp);
+ return $cl;
+}
+
+sub print_cl {
+ my( $org ) = @_;
+ debug( simplereq(
+ CIRC(), 'open-ils.circ.copy_location.retrieve.all', $authtoken, $org ) );
+}
+
+sub update_cl {
+ my $cl = shift;
+ $cl->name( 'test_' . $cl->name );
+ my $resp = simplereq(
+ CIRC(), 'open-ils.circ.copy_location.update', $authtoken, $cl );
+ oils_event_die($resp);
+ printl("Successfully set copy location name to ".$cl->name);
+}
+
+sub delete_cl {
+ my $cl = shift;
+ my $resp = simplereq(
+ CIRC(), 'open-ils.circ.copy_location.delete', $authtoken, $cl->id );
+ oils_event_die($resp);
+ printl("Copy location successfully deleted");
+}
+
+