[open-ils-commits] [GIT] Evergreen ILS branch master updated. f0b408bc6822b9b8be150c9af5947748edba06f2

Evergreen Git git at git.evergreen-ils.org
Fri Jun 24 13:24:36 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  f0b408bc6822b9b8be150c9af5947748edba06f2 (commit)
      from  ad0bbbb835fb6185a8b76cc5ae38dd0ec7209cc3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f0b408bc6822b9b8be150c9af5947748edba06f2
Author: Jason Stephenson <jstephenson at mvlc.org>
Date:   Mon Jun 20 14:07:54 2011 -0400

    Add checkout override to SIP2 checkout & renew.
    
    OpenILS::SIP::Transaction::Checkout was modified to allow for
    the override of certain, configurable events much in the same
    way that checkin currently does overrides.
    
    Signed-off-by: Jason Stephenson <jstephenson at mvlc.org>
    Signed-off-by: Bill Erickson <berick at esilibrary.com>

diff --git a/Open-ILS/examples/oils_sip.xml.example b/Open-ILS/examples/oils_sip.xml.example
index 3111626..8adecf8 100644
--- a/Open-ILS/examples/oils_sip.xml.example
+++ b/Open-ILS/examples/oils_sip.xml.example
@@ -114,6 +114,10 @@
                     -->
                 </checkin_override>
 
+                <checkout_override>
+                    <event>COPY_ALERT_MESSAGE</event>
+                </checkout_override>
+
                 <!-- If uncommented, overrides the legacy_script_support value in opensrf.xml for SIP. -->
                 <!--
                 <legacy_script_support>false</legacy_script_support>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm
index 1b94492..bede75d 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm
@@ -25,122 +25,135 @@ my %fields = (
 	      security_inhibit => 0,
 	      due              => undef,
 	      renew_ok         => 0,
-	      );
+             );
 
 sub new {
-	 my $class = shift;
+    my $class = shift;
 
     my $self = $class->SUPER::new(@_);
 
     my $element;
 
-	foreach $element (keys %fields) {
-		$self->{_permitted}->{$element} = $fields{$element};
-	}
+    foreach $element (keys %fields) {
+        $self->{_permitted}->{$element} = $fields{$element};
+    }
 
     @{$self}{keys %fields} = values %fields;
-	 
+
+    $self->load_override_events;
+
     return bless $self, $class;
 }
 
+# Lifted from Checkin.pm to load the list of events that we'll try to
+# override if they occur during checkout or renewal.
+my %override_events;
+sub load_override_events {
+    return if %override_events;
+    my $override = OpenILS::SIP->config->{implementation_config}->{checkout_override};
+    return unless $override;
+    my $events = $override->{event};
+    $events = [$events] unless ref $events eq 'ARRAY';
+    $override_events{$_} = 1 for @$events;
+}
 
 # if this item is already checked out to the requested patron,
-# renew the item and set $self->renew_ok to true.  
-# XXX if it's a renewal and the renewal is not permitted, set 
+# renew the item and set $self->renew_ok to true.
+# XXX if it's a renewal and the renewal is not permitted, set
 # $self->screen_msg("Item on Hold for Another User"); (or somesuch)
 # XXX Set $self->ok(0) on any errors
 sub do_checkout {
-	my $self = shift;
-	my $is_renew = shift || 0;
+    my $self = shift;
+    my $is_renew = shift || 0;
 
-	$self->ok(0); 
+    $self->ok(0);
 
-	my $args = { 
-		barcode => $self->{item}->id, 
+    my $args = {
+		barcode => $self->{item}->id,
 		patron_barcode => $self->{patron}->id
-	};
-
-	my $resp;
-
-	if ($is_renew) {
-		$resp = $U->simplereq(
-			'open-ils.circ',
-			'open-ils.circ.renew', $self->{authtoken},
-			{ barcode => $self->item->id, patron_barcode => $self->patron->id });
-	} else {
-		$resp = $U->simplereq(
-			'open-ils.circ',
-			'open-ils.circ.checkout.permit', 
-			$self->{authtoken}, $args );
-
-		$resp = [$resp] unless ref $resp eq 'ARRAY';
-
-		my $key;
-
-		syslog('LOG_DEBUG', "OILS: Checkout permit returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
-
-		if( @$resp == 1 and ! $U->event_code($$resp[0]) ) {
-			$key = $$resp[0]->{payload};
-			syslog('LOG_INFO', "OILS: circ permit key => $key");
-
-		} else {
-
-			# 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, 
-			patron_barcode => $self->{patron}->id, 
-			barcode			=> $self->{item}->id
-		};
-
-		$resp = $U->simplereq(
-			'open-ils.circ',
-			'open-ils.circ.checkout', $self->{authtoken}, $args );
-	}
-
-	syslog('LOG_INFO', "OILS: Checkout returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
-
-	# XXX Check for events
-	if( $resp ) {
-
-		if( my $code = $U->event_code($resp) ) {
-			my $txt = $resp->{textcode};
-			syslog('LOG_INFO', "OILS: Checkout failed with event $code : $txt");
-			$self->screen_msg('Checkout failed.  Please contact a librarian');
-			return 0; 
-		}
-
-		syslog('LOG_INFO', "OILS: Checkout succeeded");
-
-		my $circ = $resp->{payload}->{circ};
-		$self->{'due'} = OpenILS::SIP->format_date($circ->due_date, 'due');
-		$self->ok(1);
-
-		return 1;
-	}
-
-	return 0;
+               };
+
+    my ($resp, $method);
+
+    my $override = 0;
+
+    while (1) {
+        if ($is_renew) {
+            $method = 'open-ils.circ.renew';
+            $method .= '.override' if ($override);
+            $resp = $U->simplereq('open-ils.circ', $method, $self->{authtoken}, $args);
+        } else {
+            $method = 'open-ils.circ.checkout.permit';
+            $method .= '.override' if ($override);
+            $resp = $U->simplereq('open-ils.circ', $method, $self->{authtoken}, $args);
+
+            $resp = [$resp] unless ref $resp eq 'ARRAY';
+
+            syslog('LOG_DEBUG', "OILS: $method returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
+
+            if (@$resp == 1 && !$U->event_code($$resp[0])) {
+                my $key = $$resp[0]->{payload};
+                syslog('LOG_INFO', "OILS: circ permit key => $key");
+                # --------------------------------------------------------------------
+                # Now do the actual checkout
+                # --------------------------------------------------------------------
+                my $cko_args = $args;
+                $cko_args->{permit_key} = $key;
+                $method = 'open-ils.circ.checkout';
+                $resp = $U->simplereq('open-ils.circ', $method, $self->{authtoken}, $cko_args);
+            } else {
+                # We got one or more non-success events
+                $self->screen_msg('');
+                for my $r (@$resp) {
+                    if ( my $code = $U->event_code($r) ) {
+                        my $txt = $r->{textcode};
+                        syslog('LOG_INFO', "OILS: $method failed with event $code : $txt");
+
+                        if ($override_events{$txt} && $method !~ /override$/) {
+                            # Found an event we've been configured to override.
+                            $override = 1;
+                        } elsif ( $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;
+                        }
+                    }
+                }
+                # This looks potentially dangerous, but we shouldn't
+                # end up here if the loop iterated with $override = 1;
+                next if ($override && $method !~ /override$/);
+            }
+        }
+        syslog('LOG_INFO', "OILS: $method returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
+        # XXX Check for events
+        if ( $resp ) {
+
+            if ( my $code = $U->event_code($resp) ) {
+                my $txt = $resp->{textcode};
+                if ($override_events{$txt} && $method !~ /override$/) {
+                    $override = 1;
+                } else {
+                    syslog('LOG_INFO', "OILS: $method failed with event $code : $txt");
+                    $self->screen_msg('Checkout failed.  Please contact a librarian');
+                    last;
+                }
+            } else {
+                syslog('LOG_INFO', "OILS: $method succeeded");
+
+                my $circ = $resp->{payload}->{circ};
+                $self->{'due'} = OpenILS::SIP->format_date($circ->due_date, 'due');
+                $self->ok(1);
+                last;
+            }
+
+        }
+        last if ($method =~ /override$/);
+    }
+
+
+    return $self->ok;
 }
 
 

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/oils_sip.xml.example             |    4 +
 .../lib/OpenILS/SIP/Transaction/Checkout.pm        |  205 +++++++++++---------
 2 files changed, 113 insertions(+), 96 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list