From e603b31b72a4971c03636d9ef8f72ca075df5c8e Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 14 Dec 2005 15:43:23 +0000 Subject: [PATCH] added some NOT_FOUND events for record, copy, and circ (more to come) moved over some of the circ code to using the events and utility methods defined by apputils added some utility methods to apputils now exporting $logger var from the logger code git-svn-id: svn://svn.open-ils.org/ILS/trunk@2371 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/ils_events.xml | 24 +++++ .../perlmods/OpenILS/Application/AppUtils.pm | 54 +++++++++++ .../src/perlmods/OpenILS/Application/Circ.pm | 91 ++++++++----------- OpenSRF/src/perlmods/OpenSRF/Utils/Logger.pm | 5 +- 4 files changed, 122 insertions(+), 52 deletions(-) diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index 7c16b13067..a8a901a11c 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -32,6 +32,30 @@ + + + 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. + + + + + + Invalid parameters were encountered in a method diff --git a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm index 4f998acf3c..0449bc8650 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm @@ -5,6 +5,7 @@ use OpenSRF::Utils::Cache; use OpenSRF::EX qw(:try); use OpenILS::Perm; use OpenSRF::Utils::Logger; +use OpenILS::Utils::ModsParser; my $logger = "OpenSRF::Utils::Logger"; @@ -355,7 +356,60 @@ sub checkses_requestor { return( $requestor, $target, $evt); } +sub fetch_copy { + my( $self, $copyid ) = @_; + my( $copy, $evt ); + $copy = $self->simplereq( + 'open-ils.storage', + 'open-ils.storage.direct.asset.copy.retrieve', $copyid ); + + if(!$copy) { $evt = OpenILS::Event->new('COPY_NOT_FOUND'); } + + return( $copy, $evt ); +} + + +# retrieves a circ object by id +sub fetch_circulation { + my( $self, $circid ) = @_; + my $circ; my $evt; + + $circ = $self->simplereq( + 'open-ils.storage', + "open-ils.storage.direct.action.circulation.retrieve", $circid ); + + if(!$circ) { + $evt = OpenILS::Event->new('CIRCULATION_NOT_FOUND', circid => $circid ); + } + + return ( $circ, $evt ); +} + +sub fetch_record_by_copy { + my( $self, $copyid ) = @_; + my( $record, $evt ); + + $record = $self->simplereq( + 'open-ils.storage', + 'open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy', $copyid ); + + if(!$record) { + $evt = OpenILS::Event->new('BIBLIO_RECORD_NOT_FOUND'); + } + + return ($record, $evt); +} + +# turns a record object into an mvr (mods) object +sub record_to_mvr { + my( $self, $record ) = @_; + my $u = OpenILS::Utils::ModsParser->new(); + $u->start_mods_batch( $record->marc ); + my $mods = $u->finish_mods_batch(); + $mods->doc_id($record->id); + return $mods; +} diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 2bb25cb565..88eb3d6648 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -12,6 +12,10 @@ use OpenILS::Application::AppUtils; my $apputils = "OpenILS::Application::AppUtils"; use OpenSRF::Utils; use OpenILS::Utils::ModsParser; +use OpenILS::Event; +use OpenSRF::EX qw(:try); +use OpenSRF::Utils::Logger qw(:logger); +#my $logger = "OpenSRF::Utils::Logger"; # ------------------------------------------------------------------------ @@ -39,38 +43,29 @@ __PACKAGE__->register_method( sub checkouts_by_user { my( $self, $client, $user_session, $user_id ) = @_; - my $session = OpenSRF::AppSession->create("open-ils.storage"); - my $user_obj = $apputils->check_user_session($user_session); + my( $requestor, $target, $copy, $record, $evt ); - if(!$user_id) { $user_id = $user_obj->id(); } + ( $requestor, $target, $evt ) = + $apputils->checkses_requestor( $user_session, $user_id, 'VIEW_CIRCULATIONS'); + return $evt if $evt; - my $circs = $session->request( + my $circs = $apputils->simplereq( + 'open-ils.storage', "open-ils.storage.direct.action.open_circulation.search.atomic", - { usr => $user_id } ); - $circs = $circs->gather(1); + { usr => $target->id } ); my @results; for my $circ (@$circs) { - my $copy = $session->request( - "open-ils.storage.direct.asset.copy.retrieve", - $circ->target_copy ); + ( $copy, $evt ) = $apputils->fetch_copy($circ->target_copy); + return $evt if $evt; - warn "Retrieving record for copy " . $circ->target_copy . "\n"; + $logger->debug("Retrieving record for copy " . $circ->target_copy); - my $record = $session->request( - "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy", - $circ->target_copy ); + ($record, $evt) = $apputils->fetch_record_by_copy( $circ->target_copy ); + return $evt if $evt; - $copy = $copy->gather(1); - $record = $record->gather(1); - - use Data::Dumper; - warn Dumper $circ; - my $u = OpenILS::Utils::ModsParser->new(); - $u->start_mods_batch( $record->marc() ); - my $mods = $u->finish_mods_batch(); - $mods->doc_id($record->id()); + my $mods = $apputils->record_to_mvr($record); push( @results, { copy => $copy, circ => $circ, record => $mods } ); } @@ -89,27 +84,20 @@ __PACKAGE__->register_method( NOTES sub title_from_transaction { - my( $self, $client, $login_session, $transactionid ) = @_; - my $user = $apputils->check_user_session($login_session); - my $session = OpenSRF::AppSession->create('open-ils.storage'); - my $circ = $session->request( - "open-ils.storage.direct.action.circulation.retrieve", $transactionid )->gather(1); + my( $user, $circ, $title, $evt ); - if($circ) { - my $title = $session->request( - "open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy", - $circ->target_copy )->gather(1); + ( $user, $evt ) = $apputils->checkses( $login_session ); + return $evt if $evt; - if($title) { - my $u = OpenILS::Utils::ModsParser->new(); - $u->start_mods_batch( $title->marc ); - return $u->finish_mods_batch(); - } - } + ( $circ, $evt ) = $apputils->fetch_circulation($transactionid); + return $evt if $evt; + + ($title, $evt) = $apputils->fetch_record_by_copy($circ->target_copy); + return $evt if $evt; - return undef; + return $apputils->record_to_mvr($title); } @@ -133,34 +121,35 @@ __PACKAGE__->register_method( sub set_circ_lost { my( $self, $client, $login, $circid ) = @_; + my( $user, $circ, $evt ); - my $user = $apputils->check_user_session($login); - my $session = OpenSRF::AppSession->create('open-ils.storage'); - my $circ = $session->request( - "open-ils.storage.direct.action.circulation.retrieve", $circid )->gather(1); + ( $user, $evt ) = $apputils->checkses($login); + return $evt if $evt; - if(!$circ) { throw OpenSRF::EX::ERROR ("No circulation exists with id $circid"); } + ( $circ, $evt ) = $apputils->fetch_circulation( $circid ); + return $evt if $evt; if($self->api_name =~ /lost/) { - if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_LOST")) { - return OpenILS::Perm->new("SET_CIRC_LOST"); + if($evt = $apputils->checkperms( + $user->id, $circ->circ_lib, "SET_CIRC_LOST")) { + return $evt; } $circ->stop_fines("LOST"); } if($self->api_name =~ /claims_returned/) { - if($apputils->check_user_perms($user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) { - return OpenILS::Perm->new("SET_CIRC_CLAIMS_RETURNED"); + if($evt = $apputils->checkperms( + $user->id, $circ->circ_lib, "SET_CIRC_CLAIMS_RETURNED")) { + return $evt; } $circ->stop_fines("CLAIMSRETURNED"); } - - my $s = $session->request( - "open-ils.storage.direct.action.circulation.update", $circ )->gather(1); + my $s = $apputils->simplereq( + 'open-ils.storage', + "open-ils.storage.direct.action.circulation.update", $circ ); if(!$s) { throw OpenSRF::EX::ERROR ("Error updating circulation with id $circid"); } - } diff --git a/OpenSRF/src/perlmods/OpenSRF/Utils/Logger.pm b/OpenSRF/src/perlmods/OpenSRF/Utils/Logger.pm index f2a3ab7a75..dcc0c580a3 100644 --- a/OpenSRF/src/perlmods/OpenSRF/Utils/Logger.pm +++ b/OpenSRF/src/perlmods/OpenSRF/Utils/Logger.pm @@ -24,8 +24,9 @@ i.e. $logger->error( $msg, WARN ); # logs at log level WARN =cut @EXPORT_OK = qw/ NONE ERROR WARN INFO DEBUG INTERNAL /; +push @EXPORT_OK, '$logger'; -%EXPORT_TAGS = ( level => [ qw/ NONE ERROR WARN INFO DEBUG INTERNAL / ] ); +%EXPORT_TAGS = ( level => [ qw/ NONE ERROR WARN INFO DEBUG INTERNAL / ], logger => [ '$logger' ] ); my $config; # config handle my $loglevel; # global log level @@ -40,6 +41,8 @@ my $logfile_enabled = 1; # are we logging to a file? my $act_logfile_enabled = 1; # are we logging to a file? my $logdir; # log file directory +our $logger = "OpenSRF::Utils::Logger"; + # log levels sub ACTIVITY { return -1; } sub NONE { return 0; } -- 2.43.2