From b6974acaca18e8838ed0c234eb9bed040db217d0 Mon Sep 17 00:00:00 2001 From: erickson Date: Sat, 2 Sep 2006 16:02:22 +0000 Subject: [PATCH] Msg is just a message repository - will likely load strings from an external source at some point better checkout handling git-svn-id: svn://svn.open-ils.org/ILS/trunk@5859 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/SIP/Item.pm | 6 ---- Open-ILS/src/perlmods/OpenILS/SIP/Msg.pm | 31 +++++++++++++++++ Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm | 1 + .../perlmods/OpenILS/SIP/Transaction/Checkout.pm | 40 +++++++++++++--------- 4 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 Open-ILS/src/perlmods/OpenILS/SIP/Msg.pm diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm index 2c1a4fdb17..a24a716bd3 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Item.pm @@ -1,9 +1,3 @@ -# -# -# A Class for hiding the ILS's concept of the item from the OpenSIP -# system -# - package OpenILS::SIP::Item; use strict; use warnings; diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Msg.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Msg.pm new file mode 100644 index 0000000000..620a9ba9df --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Msg.pm @@ -0,0 +1,31 @@ +package OpenILS::SIP::Msg; +use strict; use warnings; +# ------------------------------------------------------- +# Defines the various screen messages +# Currently they are just constants.. they need to be +# moved to an external lang-specific source +# ------------------------------------------------------- +use vars qw(@EXPORT_OK %EXPORT_TAGS); +use Exporter; +use base qw/Exporter/; + + +# --------------------------------------------------------------------- +# Shoves defined constants into the export array +# so they don't have to be listed twice in the code +# --------------------------------------------------------------------- +sub econst { + my($name, $value) = @_; + my $caller = caller; + no strict; + *{$name} = sub () { $value }; + push @{$caller.'::EXPORT_OK'}, $name; +} + + +econst OILS_SIP_MSG_CIRC_EXISTS => 'This item is already checked out'; +econst OILS_SIP_MSG_CIRC_PERMIT_FAILED => 'Patron is not allowed to check out the selected item'; + +%EXPORT_TAGS = ( const => [ @EXPORT_OK ] ); + + diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm index 84b6101a29..3d91dd261c 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction.pm @@ -9,6 +9,7 @@ use strict; use warnings; use Sys::Syslog qw(syslog); use OpenILS::SIP; +use OpenILS::SIP::Msg qw/:const/; my %fields = ( diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm index 1ae77cac82..e2cc1abe91 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm @@ -11,6 +11,7 @@ use POSIX qw(strftime); use OpenILS::SIP; use OpenILS::SIP::Transaction; +use OpenILS::SIP::Msg qw/:const/; use Sys::Syslog qw(syslog); use OpenILS::Application::AppUtils; @@ -64,33 +65,38 @@ sub do_checkout { 'open-ils.circ.checkout.permit', $self->{authtoken}, $args ); - if( ref($resp) eq 'ARRAY' ) { - my @e; - push( @e, $_->{textcode} ) for @$resp; - syslog('LOG_INFO', "OILS: Checkout permit failed with events: @e"); - $self->screen_msg('Patron is not allowed to check out the selected item'); - return 0; - } - - if( my $code = $U->event_code($resp) ) { - my $txt = $resp->{textcode}; - syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt"); - $self->screen_msg('Patron is not allowed to check out the selected item'); - return 0; - } + $resp = [$resp] unless ref $resp eq 'ARRAY'; my $key; - if( $key = $resp->{payload} ) { + if( @$resp == 1 and ! $U->event_code($$resp[0]) ) { + $key = $$resp[0]->{payload}; syslog('LOG_INFO', "OILS: circ permit key => $key"); } else { - syslog('LOG_WARN', "OILS: Circ permit failed :\n" . Dumper($resp) ); - $self->screen_msg('Patron is not allowed to check out the selected item'); + + # We got one or more non-success events + $self->screen_msg(''); + for my $r (@$resp) { + + if( my $code = $U->event_code($resp) ) { + my $txt = $resp->{textcode}; + syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt"); + + if( $txt eq 'OPEN_CIRCULATION_EXISTS' ) { + $self->screen_msg(OILS_SIP_MSG_CIRC_EXISTS); + return 0; + } else { + $self->screen_msg(OILS_SIP_MSG_CIRC_PERMIT_FAILED); + } + } + } return 0; } + # -------------------------------------------------------------------- # Now do the actual checkout + # -------------------------------------------------------------------- $args = { permit_key => $key, -- 2.11.0