From 103c2ca99f7c126e98abffd41ae3a74cf838b828 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 7 Sep 2010 16:41:53 +0000 Subject: [PATCH] cache the SIP login session to determine 'where' a transaction is occuring in case the caller does not indicate the location; compare hold pickup lib to physical location to determine alert type; small logging and format tweaks git-svn-id: svn://svn.open-ils.org/ILS/trunk@17502 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/SIP.pm | 27 ++++++--- .../perlmods/OpenILS/SIP/Transaction/Checkin.pm | 64 +++++++++++++--------- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/SIP.pm b/Open-ILS/src/perlmods/OpenILS/SIP.pm index 4d749bd2f..e101e4be0 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP.pm @@ -62,14 +62,24 @@ sub new { return $self; } -sub verify_session { - my $self = shift; +sub fetch_session { + my $self = shift; + my $ses = $U->simplereq( 'open-ils.auth', - 'open-ils.auth.session.retrieve', $self->{authtoken} ); - return 1 unless $U->event_code($ses); - syslog('LOG_INFO', "OILS: Logging back after session timeout as user ".$self->{login}->{id}); - return $self->login( $self->{login}->{id}, $self->{login}->{password} ); + 'open-ils.auth.session.retrieve', $self->{authtoken}); + + return undef if $U->event_code($ses); # auth timed out + return $self->{login_session} = $ses; +} + +sub verify_session { + my $self = shift; + + return 1 if $self->fetch_session; + + syslog('LOG_INFO', "OILS: Logging back after session timeout as user ".$self->{login}->{id}); + return $self->login( $self->{login}->{id}, $self->{login}->{password} ); } sub editor { @@ -205,6 +215,9 @@ sub login { my $key = $response->{payload}->{authtoken}; syslog('LOG_INFO', "OILS: Login succeeded for $username : authkey = $key"); + + $self->fetch_session; # to cache the login + return $self->{authtoken} = $key; } @@ -365,7 +378,7 @@ sub checkin { return $xact; } - $xact->do_checkin( $inst_id, $trans_date, $return_date, $current_loc, $item_props ); + $xact->do_checkin( $self, $inst_id, $trans_date, $return_date, $current_loc, $item_props ); if ($xact->ok) { $xact->patron($self->find_patron($item->{patron})); diff --git a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm index 7a97b2f9a..4ea152777 100644 --- a/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm +++ b/Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm @@ -56,7 +56,7 @@ sub resensitize { my %org_sn_cache; sub do_checkin { my $self = shift; - my ($inst_id, $trans_date, $return_date, $current_loc, $item_props) = @_; # most unused + my ($sip_handler, $inst_id, $trans_date, $return_date, $current_loc, $item_props) = @_; # most unused unless($self->{item}) { $self->ok(0); @@ -65,13 +65,22 @@ sub do_checkin { $inst_id ||= ''; + # physical location defaults to ws ou of the logged in sip user, + # which currently defaults to home_ou, since ws's aren't used. + my $phys_location = $sip_handler->{login_session}->ws_ou; + my $args = {barcode => $self->{item}->id}; - if($current_loc) { + + if($current_loc) { # SIP client specified a physical location + my $org_id = (defined $org_sn_cache{$current_loc}) ? $org_sn_cache{$current_loc} : OpenILS::SIP->editor()->search_actor_org_unit({shortname => $current_loc}, {idlist => 1})->[0]; + $org_sn_cache{$current_loc} = $org_id; - $args->{circ_lib} = $org_id if defined $org_id; + + # if the caller specifies a physical location, use it as the checkin circ lib + $args->{circ_lib} = $phys_location = $org_id if defined $org_id; } my $resp = $U->simplereq( @@ -81,47 +90,53 @@ sub do_checkin { ); if ($debug) { - open (DUMP, ">/tmp/sip_do_checkin.dump"); - print DUMP Dumper($resp); - close DUMP; + my $s = Dumper($resp); + $s =~ s/\n//mog; + syslog('LOG_INFO', "OILS: Checkin response: $s"); } + # In oddball cases, we can receive an array of events. + # The first event received should be treated as the main result. + $resp = $$resp[0] if ref($resp) eq 'ARRAY'; + my $code = $U->event_code($resp); my $txt = (defined $code) ? $resp->{textcode} : ''; + syslog('LOG_INFO', "OILS: Checkin resulted in event: $txt"); + $resp->{org} &&= OpenILS::SIP::shortname_from_id($resp->{org}); # Convert id to shortname $self->destination_loc($resp->{org}) if $resp->{org}; - $debug and warn "Checkin textcode: $txt, org: " . ($resp->{org} || ''); - if ($txt eq 'ROUTE_ITEM') { - # $self->destination_loc($resp->{org}); # org value already converted and added (above) - $self->alert_type('04'); # send to other branch - } - elsif ($txt and $txt ne 'NO_CHANGE' and $txt ne 'SUCCESS') { - syslog('LOG_WARNING', "OILS: Checkin returned unrecognized event $code : $txt"); - # $self->ok(0); # maybe still ok? - $self->alert_type('00'); # unknown + # Note, this alert_type will be overridden below if this is a hold transit + $self->alert_type('04'); # send to other branch + + } elsif ($txt and $txt ne 'NO_CHANGE' and $txt ne 'SUCCESS') { + syslog('LOG_WARNING', "OILS: Checkin returned unexpected event $code : $txt"); + $self->alert_type('00'); # unknown } my $payload = $resp->{payload} || {}; # Two places to look for hold data. These are more important and more definitive than above. if ($payload->{remote_hold}) { - $self->item->hold($payload->{remote_hold}); # actually only used for checkin at non-owning branch w/ hold at same branch - } - elsif ($payload->{hold}) { + # actually only used for checkin at non-owning branch w/ hold at same branch + $self->item->hold($payload->{remote_hold}); + + } elsif ($payload->{hold}) { $self->item->hold($payload->{hold}); } if ($self->item->hold) { - my $holder = OpenILS::SIP->find_patron('usr' => $self->item->hold->usr) - or warn "OpenILS::SIP->find_patron cannot find hold usr => '" . $self->item->hold->usr . "'"; + my $holder = OpenILS::SIP->find_patron('usr' => $self->item->hold->usr) or + syslog('LOG_WARNING', "OpenILS::SIP->find_patron cannot find hold usr => '" . $self->item->hold->usr . "'"); + $self->item->hold_patron_bcode( $holder->id ); $self->item->hold_patron_name( $holder->name ); # Item already had the holder ID, we really just needed the name $self->item->destination_loc( OpenILS::SIP::shortname_from_id($self->item->hold->pickup_lib) ); # must use pickup_lib as method - my $atype = ($self->item->destination_loc eq $inst_id) ? '01' : '02'; + + my $atype = ($self->item->hold->pickup_lib == $phys_location) ? '01' : '02'; $self->alert_type($atype); } @@ -131,14 +146,13 @@ sub do_checkin { my $copy = $resp->{payload}->{copy} || ''; if ( $circ ) { - # $self->item->{patron} = OpenILS::SIP::patron_barcode_from_id($circ->usr); # Item.pm already does this for us! $self->ok(1); } elsif ($txt eq 'NO_CHANGE' or $txt eq 'SUCCESS' or $txt eq 'ROUTE_ITEM') { - $self->ok(1); # NO_CHANGE means it wasn't checked out anyway, no problem + $self->ok(1); # NO_CHANGE means it wasn't checked out anyway, no problem } else { $self->alert(1); - $self->alert_type('00') unless $self->alert_type; # wasn't checked out, but *something* changed - # $self->ok(0); # maybe still ok? + $self->alert_type('00') unless $self->alert_type; # wasn't checked out, but *something* changed + # $self->ok(0); # maybe still ok? } } -- 2.11.0