<event code='0' textcode='SUCCESS'>
<desc>No errors or unexpected events occurred</desc>
</event>
-
<event code='1' textcode='UNKNOWN'>
<desc>Placeholder event. Used for development only</desc>
</event>
-
<event code='3' textcode='NO_CHANGE'>
<desc>
The called method didn't actually do anything
</desc>
</event>
-
-
-
<event code='1000' textcode='LOGIN_FAILED'>
<desc>
User login failed. Why the login failed is not specified.
</desc>
</event>
-
<event code='1001' textcode='NO_SESSION'>
<desc>
User login session has either timed out or does not exist.
</desc>
</event>
-
<event code='1002' textcode='USER_NOT_FOUND'>
<desc>
Someone attempted to retrieve a user from the system and the user
was not found.
</desc>
</event>
-
<event code='1003' textcode='Z3950_SEARCH_FAILED'>
<desc>The Z search did not succeed</desc>
</event>
-
<event code='1200' textcode='USERNAME_EXISTS'>
<desc>
The given username exists in the database
</desc>
</event>
-
<event code='1201' textcode='CIRC_PERMIT_BAD_KEY'>
<desc>
A checkout was attempted without a valid checkout permit key
</desc>
</event>
-
<event code='1202' textcode='ITEM_NOT_CATALOGED'>
<desc>
The requested item is not cataloged in the database
</desc>
</event>
-
<event code='1203' textcode='COPY_BAD_STATUS'>
<desc>
The given copy is not in a standard circulation status
</desc>
</event>
-
<event code='1204' textcode='CIRC_BAD_STATUS'>
<desc>
The given circulation is not in a standard status or
-
-
<event code='1500' textcode='CIRCULATION_NOT_FOUND'>
<desc>
Someone attempted to retrieve a circulation object from the system and
the object was not found.
</desc>
</event>
-
<event code='1501' textcode='BIBLIO_RECORD_NOT_FOUND'>
<desc>
Someone attempted to retrieve a biblio record entry object from the
system and the object was not found.
</desc>
</event>
-
<event code='1502' textcode='COPY_NOT_FOUND'>
<desc>
Someone attempted to retrieve a copy object from the
system and the object was not found.
</desc>
</event>
-
<event code='1503' textcode='HOLD_NOT_FOUND'>
<desc>
Someone attempted to retrieve a hold object from the
system and the object was not found.
</desc>
</event>
-
<event code='1504' textcode='TRANSIT_NOT_FOUND'>
<desc>
Someone attempted to retrieve a transit object from the
system and the object was not found.
</desc>
</event>
-
<event code='1505' textcode='BILLING_NOT_FOUND'>
<desc>
Someone attempted to retrieve a transit object from the
system and the object was not found.
</desc>
</event>
-
<event code='1506' textcode='CONTAINER_NOT_FOUND'>
<desc>
Someone attempted to retrieve a container object from the
system and the object was not found.
</desc>
</event>
-
<event code='1507' textcode='CONTAINER_ITEM_NOT_FOUND'>
<desc>
Someone attempted to retrieve a container item object from the
system and the object was not found.
</desc>
</event>
-
<event code='1508' textcode='VOLUME_NOT_FOUND'>
<desc>
Someone attempted to retrieve a volume object from the
system and the object was not found.
</desc>
</event>
-
<event code='1509' textcode='ORG_UNIT_NOT_FOUND'>
<desc>
Someone attempted to retrieve an org unit object from the
system and the object was not found.
</desc>
</event>
-
<event code='1510' textcode='STAT_CAT_NOT_FOUND'>
<desc> Stat cat object does not exist </desc>
</event>
-
<event code='1511' textcode='STAT_CAT_ENTRY_NOT_FOUND'>
<desc> Stat cat entry object does not exist </desc>
</event>
-
<event code='1512' textcode='STAT_CAT_ENTRY_MAP_NOT_FOUND'>
<desc> Stat cat entry map object does not exist </desc>
</event>
-
<event code='1513' textcode='NON_CAT_TYPE_NOT_FOUND'>
<desc> The non cataloged type object does not exist </desc>
</event>
-
<event code='1514' textcode='CIRC_DURATION_NOT_FOUND'>
<desc> The circ duration object does not exist </desc>
</event>
-
<event code='1515' textcode='RECURRING_FINE_NOT_FOUND'>
<desc> The recurring fines object does not exist </desc>
</event>
-
<event code='1516' textcode='MAX_FINE_NOT_FOUND'>
<desc> The max fines object does not exist </desc>
</event>
-
<event code='1517' textcode='COPY_LOCATION_NOT_FOUND'>
<desc> The copy location object does not exist </desc>
</event>
-
<event code='1518' textcode='HOLD_TRANSIT_NOT_FOUND'>
<desc> The hold transit object does not exist </desc>
</event>
-
<event code='1519' textcode='TRANSACTION_NOT_FOUND'>
<desc> Requested transaction object does not exist </desc>
</event>
-
<event code='1520' textcode='WORKSTATION_NOT_FOUND'>
<desc> Requested workstation object does not exist </desc>
</event>
+ <event code='1521' textcode='COPY_NOTE_NOT_FOUND'>
+ <desc> Requested copy note does not exist </desc>
+ </event>
+ <event code='1522' textcode='VOLUME_NOTE_NOT_FOUND'>
+ <desc> Requested copy note does not exist </desc>
+ </event>
+ <event code='1523' textcode='TITLE_NOTE_NOT_FOUND'>
+ <desc> Requested copy note does not exist </desc>
+ </event>
return ($copy, $evt);
}
+
+# returns the org that owns the callnumber that the copy
+# is attached to
+sub fetch_copy_owner {
+ my( $self, $copyid ) = @_;
+ my( $copy, $cn, $evt );
+ $logger->debug("Fetching copy owner $copyid");
+ ($copy, $evt) = $self->fetch_copy($copyid);
+ return (undef,$evt) if $evt;
+ ($cn, $evt) = $self->fetch_callnumber($copy->call_number);
+ return (undef,$evt) if $evt;
+ return ($cn->owning_lib);
+}
+
+sub fetch_copy_note {
+ my( $self, $id ) = @_;
+ my( $note, $evt );
+ $logger->debug("Fetching copy note $id");
+ $note = $self->storagereq(
+ 'open-ils.storage.direct.asset.copy_note.retrieve', $id );
+ $evt = OpenILS::Event->new('COPY_NOTE_NOT_FOUND', id => $id ) unless $note;
+ return ($note, $evt);
+}
+
+
1;
}
+
+__PACKAGE__->register_method(
+ method => 'fetch_notes',
+ api_name => 'open-ils.circ.copy_note.retrieve.all',
+ signature => q/
+ Returns an array of copy note objects.
+ @param args A named hash of parameters including:
+ authtoken : Required if viewing non-public notes
+ itemid : The id of the item whose notes we want to retrieve
+ pub : True if all the caller wants are public notes
+ @return An array of note objects
+ /);
+
+__PACKAGE__->register_method(
+ method => 'fetch_notes',
+ api_name => 'open-ils.circ.call_number_note.retrieve.all',
+ signature => q/@see open-ils.circ.copy_note.retrieve.all/);
+
+__PACKAGE__->register_method(
+ method => 'fetch_notes',
+ api_name => 'open-ils.circ.title_note.retrieve.all',
+ signature => q/@see open-ils.circ.copy_note.retrieve.all/);
+
+# NOTE: VIEW_COPY/VOLUME/TITLE_NOTES perms should always be global
+sub fetch_notes {
+ my( $self, $connection, $args ) = @_;
+
+ my $id = $$args{itemid};
+ my $authtoken = $$args{authtoken};
+ my( $r, $evt);
+
+ if( $self->api_name =~ /copy/ ) {
+ if( $$args{pub} ) {
+ return $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_note.search_where.atomic',
+ { owning_copy => $id, pub => 't' } );
+ } else {
+ ( $r, $evt ) = $U->checksesperms($authtoken, 'VIEW_COPY_NOTES');
+ return $evt if $evt;
+ return $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_note.search.owning_copy.atomic', $id );
+ }
+
+ } elsif( $self->api_name =~ /call_number/ ) {
+ if( $$args{pub} ) {
+ return $U->storagereq(
+ 'open-ils.storage.direct.asset.call_number_note.search_where.atomic',
+ { call_number => $id, pub => 't' } );
+ } else {
+ ( $r, $evt ) = $U->checksesperms($authtoken, 'VIEW_VOLUME_NOTES');
+ return $evt if $evt;
+ return $U->storagereq(
+ 'open-ils.storage.direct.asset.call_number_note.search.call_number.atomic', $id );
+ }
+
+ } elsif( $self->api_name =~ /title/ ) {
+ if( $$args{pub} ) {
+ return $U->storagereq(
+ 'open-ils.storage.direct.bilbio.record_note.search_where.atomic',
+ { record => $id, pub => 't' } );
+ } else {
+ ( $r, $evt ) = $U->checksesperms($authtoken, 'VIEW_TITLE_NOTES');
+ return $evt if $evt;
+ return $U->storagereq(
+ 'open-ils.storage.direct.asset.call_number_note.search.call_number.atomic', $id );
+ }
+ }
+
+ return undef;
+}
+
+__PACKAGE__->register_method(
+ method => 'create_copy_note',
+ api_name => 'open-ils.circ.copy_note.create',
+ signature => q/
+ Creates a new copy note
+ @param authtoken The login session key
+ @param note The note object to create
+ @return The id of the new note object
+ /);
+
+sub create_copy_note {
+ my( $self, $connection, $authtoken, $note ) = @_;
+ my( $cnowner, $requestor, $evt );
+
+ ($cnowner, $evt) = $U->fetch_copy_owner($note->owning_copy);
+ return $evt if $evt;
+ ($requestor, $evt) = $U->checkses($authtoken);
+ return $evt if $evt;
+ $evt = $U->check_perms($requestor->id, $cnowner, 'CREATE_COPY_NOTE');
+ return $evt if $evt;
+
+ $note->create_date('now');
+ $note->pub( ($note->pub) ? 't' : 'f' );
+
+ my $id = $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_note.create', $note );
+ return $U->DB_UPDATE_FAILED($note) unless $id;
+
+ $logger->activity("User ".$requestor->id." created a new copy ".
+ "note [$id] for copy ".$note->owning_copy." with text ".$note->value);
+
+ return $id;
+}
+
+__PACKAGE__->register_method(
+ method => 'delete_copy_note',
+ api_name => 'open-ils.circ.copy_note.delete',
+ signature => q/
+ Deletes an existing copy note
+ @param authtoken The login session key
+ @param noteid The id of the note to delete
+ @return 1 on success - Event otherwise.
+ /);
+
+sub delete_copy_note {
+ my( $self, $conn, $authtoken, $noteid ) = @_;
+ my( $requestor, $note, $owner, $evt );
+
+ ($requestor, $evt) = $U->checkses($authtoken);
+ return $evt if $evt;
+
+ ($note, $evt) = $U->fetch_copy_note($noteid);
+ return $evt if $evt;
+
+ if( $note->creator ne $requestor->id ) {
+ ($owner, $evt) = $U->fetch_copy_onwer($note->owning_copy);
+ return $evt if $evt;
+ $evt = $U->check_perms($requestor->id, $owner, 'DELETE_COPY_NOTE');
+ return $evt if $evt;
+ }
+
+ my $stat = $U->storagereq(
+ 'open-ils.storage.direct.asset.copy_note.delete', $noteid );
+ return $U->DB_UPDATE_FAILED($noteid) unless $stat;
+
+ $logger->activity("User ".$requestor->id." deleted copy note $noteid");
+ return 1;
+}
+
+
+
+
1;
--- /dev/null
+#!/usr/bin/perl
+
+#----------------------------------------------------------------
+# Code for testing the container API
+#----------------------------------------------------------------
+
+require '../oils_header.pl';
+use vars qw/ $user $authtoken /;
+use strict; use warnings;
+
+my $config = shift;
+my $copyid = shift;
+#my $copyid = 1;
+my $username = shift || 'admin';
+my $password = shift || 'open-ils';
+
+my $create_method = 'open-ils.circ.copy_note.create';
+my $retrieve_method = 'open-ils.circ.copy_note.retrieve.all';
+my $delete_method = 'open-ils.circ.copy_note.delete';
+
+
+sub go {
+ osrf_connect($config);
+ oils_login($username, $password);
+ oils_fetch_session($authtoken);
+ create_notes();
+ retrieve_notes();
+ delete_notes();
+}
+go();
+
+#----------------------------------------------------------------
+
+my @ids_created;
+sub create_notes {
+
+ for(0..5) {
+ my $note = Fieldmapper::asset::copy_note->new;
+
+ $note->owning_copy($copyid);
+ $note->creator($user->id);
+ $note->title("Test Note 1");
+ $note->value("This copy needs to be fixed - $_");
+ $note->pub(1);
+
+ my $id = simplereq(
+ 'open-ils.circ', $create_method, $authtoken, $note );
+ oils_event_die($id);
+ push(@ids_created, $id);
+ printl("Created copy note $id");
+ }
+}
+
+sub retrieve_notes {
+ my $notes = simplereq(
+ 'open-ils.circ', $retrieve_method,
+ {authtoken => $authtoken, itemid => $copyid});
+ oils_event_die($notes);
+ printl("Retrieved: [".$_->id."] ".$_->value) for @$notes;
+}
+
+sub delete_notes() {
+ for my $id (@ids_created) {
+ my $stat = simplereq(
+ 'open-ils.circ', $delete_method, $authtoken, $id);
+ oils_event_die($stat);
+ printl("Deleted note $id");
+ }
+}
+
+
+