Bug fixing LookupUser
authorChris Cormack <chrisc@catalyst.net.nz>
Mon, 24 Feb 2014 22:51:58 +0000 (11:51 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 24 Feb 2014 22:51:58 +0000 (11:51 +1300)
lib/NCIP.pm
lib/NCIP/Handler/LookupUser.pm
lib/NCIP/ILS/Koha.pm
t/config_sample/NCIP.xml

index 8bbdd1a..a267a30 100644 (file)
@@ -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";
index 891eedb..bfa3993 100644 (file)
@@ -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;
index 2595ddd..a3f8afa 100644 (file)
@@ -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;
index 756f8c5..75ff303 100644 (file)
@@ -34,6 +34,6 @@
   </version>
 
   <ils value='Koha' />
-  <namespace value= '' />
+  <namespace value= 'http://www.niso.org/2008/ncip' />
   <templates value= 'templates/' />
 </acsconfig>