From 1484f469760e0e06af8b5cbffbd52c45c025d4c1 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Tue, 25 Feb 2014 11:51:58 +1300 Subject: [PATCH] Bug fixing LookupUser --- lib/NCIP.pm | 8 +++---- lib/NCIP/Handler/LookupUser.pm | 40 +++++++++++++++++++++++++++++++--- lib/NCIP/ILS/Koha.pm | 19 +++++++++------- t/config_sample/NCIP.xml | 2 +- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/lib/NCIP.pm b/lib/NCIP.pm index 8bbdd1a..a267a30 100644 --- a/lib/NCIP.pm +++ b/lib/NCIP.pm @@ -57,7 +57,7 @@ sub process_request { # We have invalid xml, or we can't figure out what kind of request this is # Handle error here - warn "We can't find request type"; +# warn "We can't find request type"; my $output = $self->_error("We can't find request type"); return $output; } @@ -90,7 +90,7 @@ sub handle_initiation { if ( $strict_validation && !$self->validate($dom) ) { # we want strict validation, bail out if dom doesnt validate - warn " Not valid xml"; +# warn " Not valid xml"; # throw/log error return; @@ -137,8 +137,8 @@ sub parse_request { $dom->getElementsByTagNameNS( $self->namespace(), 'NCIPMessage' ); if ($nodes) { my @childnodes = $nodes->[0]->childNodes(); - if ( $childnodes[0] ) { - return $childnodes[0]->localname(); + if ( $childnodes[1] ) { + return $childnodes[1]->localname(); } else { warn "Got a node, but no child node"; diff --git a/lib/NCIP/Handler/LookupUser.pm b/lib/NCIP/Handler/LookupUser.pm index 891eedb..bfa3993 100644 --- a/lib/NCIP/Handler/LookupUser.pm +++ b/lib/NCIP/Handler/LookupUser.pm @@ -29,6 +29,32 @@ sub handle { my ($user_id) = $xmldoc->getElementsByTagNameNS( $self->namespace(), 'UserIdentifierValue' ); + my $xpc = XML::LibXML::XPathContext->new; + $xpc->registerNs( 'ns', $self->namespace() ); + unless ($user_id) { + + # We may get a password, username combo instead of userid + # Need to deal with that also + my $root = $xmldoc->documentElement(); + my @authtypes = + $xpc->findnodes( '//ns:AuthenticationInput', $root ); + my $barcode; + my $pin; + foreach my $node (@authtypes) { + my $class = + $xpc->findnodes( './ns:AuthenticationInputType', $node ); + my $value = + $xpc->findnodes( './ns:AuthenticationInputData', $node ); + if ( $class->[0]->textContent eq 'Barcode Id' ) { + $barcode = $value->[0]->textContent; + } + elsif ( $class->[0]->textContent eq 'PIN' ) { + $pin = $value->[0]->textContent; + } + + } + $user_id = $barcode; + } # We may get a password, username combo instead of userid # Need to deal with that also @@ -39,9 +65,17 @@ sub handle { # if we have blank user, we need to return that # and can skip looking for elementtypes - - my $root = $xmldoc->documentElement(); - my @elements = $root->findnodes('LookupUser/UserElementType/Value'); + if ( $user->userdata->{'borrowernumber'} eq '' ) { + my $vars; + $vars->{'messagetype'} = 'LookupUser'; + $vars->{'error_detail'} = "Borrower not found"; + my $output = $self->render_output( 'problem.tt', $vars ); + return $output; + } + + my $root = $xmldoc->documentElement(); + my @elements = + $xpc->findnodes( 'ns:LookupUser/UserElementType/Value', $root ); #set up the variables for our template my $vars; diff --git a/lib/NCIP/ILS/Koha.pm b/lib/NCIP/ILS/Koha.pm index 2595ddd..a3f8afa 100644 --- a/lib/NCIP/ILS/Koha.pm +++ b/lib/NCIP/ILS/Koha.pm @@ -22,10 +22,18 @@ use Object::Tiny qw{ name }; use C4::Members qw{ GetMemberDetails }; use C4::Circulation qw { AddReturn CanBookBeIssued AddIssue }; use C4::Context; +use C4::Items qw { GetItem }; sub itemdata { - my $self = shift; - return ( { barcode => '123', title => 'fish' }, undef ); + my $self = shift; + my $barcode = shift; + my $itemdata = GetItem( undef, $barcode ); + if ($itemdata) { + return ( $itemdata, undef ); + } + else { + return ( undef, 1 ); # item not found error + } } sub userdata { @@ -59,11 +67,6 @@ sub checkout { my $borrower = GetMemberDetails( undef, $userid ); my $error; my $confirm; - my ( - $usernum, $userid, $usercnum, $userfirstname, - $usersurname, $userbranch, $branchname, $userflags, - $emailaddress, $branchprinter, $persona - ) = @_; my @USERENV = ( 1, 'test', @@ -118,7 +121,7 @@ sub renew { } else { -#handle stuff here + #handle stuff here } } 1; diff --git a/t/config_sample/NCIP.xml b/t/config_sample/NCIP.xml index 756f8c5..75ff303 100644 --- a/t/config_sample/NCIP.xml +++ b/t/config_sample/NCIP.xml @@ -34,6 +34,6 @@ - + -- 2.43.2