From 8ab14d9de6f69c3a86b21ebc860c9cb447ab9c1c Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 6 Mar 2006 17:41:11 +0000 Subject: [PATCH] added retrieval methods for title, call_number, and copy notes added create and delete methods for copy notes git-svn-id: svn://svn.open-ils.org/ILS/trunk@3268 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/ils_events.xml | 44 ++---- .../perlmods/OpenILS/Application/AppUtils.pm | 25 +++ .../src/perlmods/OpenILS/Application/Circ.pm | 143 ++++++++++++++++++ .../test-scripts/copy_notes.pl | 72 +++++++++ 4 files changed, 249 insertions(+), 35 deletions(-) create mode 100755 Open-ILS/src/support-scripts/test-scripts/copy_notes.pl diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index f30d43b4ab..18cb9e22d6 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -13,66 +13,53 @@ No errors or unexpected events occurred - Placeholder event. Used for development only - The called method didn't actually do anything - - - User login failed. Why the login failed is not specified. - User login session has either timed out or does not exist. - Someone attempted to retrieve a user from the system and the user was not found. - The Z search did not succeed - The given username exists in the database - A checkout was attempted without a valid checkout permit key - The requested item is not cataloged in the database - The given copy is not in a standard circulation status - The given circulation is not in a standard status or @@ -83,121 +70,108 @@ - - Someone attempted to retrieve a circulation object from the system and the object was not found. - Someone attempted to retrieve a biblio record entry object from the system and the object was not found. - Someone attempted to retrieve a copy object from the system and the object was not found. - Someone attempted to retrieve a hold object from the system and the object was not found. - Someone attempted to retrieve a transit object from the system and the object was not found. - Someone attempted to retrieve a transit object from the system and the object was not found. - Someone attempted to retrieve a container object from the system and the object was not found. - Someone attempted to retrieve a container item object from the system and the object was not found. - Someone attempted to retrieve a volume object from the system and the object was not found. - Someone attempted to retrieve an org unit object from the system and the object was not found. - Stat cat object does not exist - Stat cat entry object does not exist - Stat cat entry map object does not exist - The non cataloged type object does not exist - The circ duration object does not exist - The recurring fines object does not exist - The max fines object does not exist - The copy location object does not exist - The hold transit object does not exist - Requested transaction object does not exist - Requested workstation object does not exist + + Requested copy note does not exist + + + Requested copy note does not exist + + + Requested copy note does not exist + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index b739b65c2e..e41a533316 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -901,5 +901,30 @@ sub fetch_fleshed_copy { 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; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index b28f72b69b..479705c948 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -285,4 +285,147 @@ sub view_circ_patrons { } + +__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; diff --git a/Open-ILS/src/support-scripts/test-scripts/copy_notes.pl b/Open-ILS/src/support-scripts/test-scripts/copy_notes.pl new file mode 100755 index 0000000000..c02691e20f --- /dev/null +++ b/Open-ILS/src/support-scripts/test-scripts/copy_notes.pl @@ -0,0 +1,72 @@ +#!/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"); + } +} + + + -- 2.43.2