Use open-ils.circ.checkout.full in SIP2.
authorJason Stephenson <jstephenson@mvlc.org>
Wed, 29 Jun 2011 15:34:29 +0000 (11:34 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Jul 2011 13:48:47 +0000 (09:48 -0400)
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 <jstephenson@mvlc.org>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/SIP/Transaction/Checkout.pm

index bede75d..bb751b2 100644 (file)
@@ -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$/);