From 415945711f0888eff19750df18dc0953dc012a01 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 29 Jun 2011 11:34:29 -0400 Subject: [PATCH] Use open-ils.circ.checkout.full in SIP2. Change the SIP2 checkout code to use a single call to open-ils. circ.checkout.full instead of doing the whole checkout.permit checkout dance. Further simplify the checkout logic in O::SIP::Transaction::Checkout. Signed-off-by: Jason Stephenson Signed-off-by: Bill Erickson --- .../lib/OpenILS/SIP/Transaction/Checkout.pm | 108 +++++++----------- 1 file changed, 43 insertions(+), 65 deletions(-) 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 bede75dcc7..bb751b262e 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm @@ -77,76 +77,54 @@ sub do_checkout { my $override = 0; + if ($is_renew) { + $method = 'open-ils.circ.renew'; + } else { + $method = 'open-ils.circ.checkout.full'; + } + 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; - } + $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])) { + # 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"); + # This looks potentially dangerous, but we shouldn't + # end up here if the loop iterated with $override = 1; + next if ($override && $method !~ /override$/); + } else { + # We appear to have success. + # De-arrayify the response. + $resp = $$resp[0]; - my $circ = $resp->{payload}->{circ}; - $self->{'due'} = OpenILS::SIP->format_date($circ->due_date, 'due'); - $self->ok(1); - last; - } + 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$/); -- 2.43.2