From 8d6ee5c9f5f116ad25a1fcf0c47bc7b8147a385b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 24 Aug 2014 10:29:51 -0400 Subject: [PATCH] Some logical fixup to ILS->find_user_barcode. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS.pm | 28 +++++++++++++++++----------- lib/NCIP/ILS/Evergreen.pm | 6 +++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/NCIP/ILS.pm b/lib/NCIP/ILS.pm index a64414b..544baa8 100644 --- a/lib/NCIP/ILS.pm +++ b/lib/NCIP/ILS.pm @@ -310,6 +310,11 @@ LookupUser requests. It will return the barcode in scalar context, or the barcode and the tag of the field where the barcode was found in list context. +If multiple barcode fields are provided, it returns the first one that +it finds. This is not necessarily the first one given in the request +message. Maybe we should add a plural form of this method to find all +of the user barcodes provided? + =cut sub find_user_barcode { @@ -323,28 +328,29 @@ sub find_user_barcode { if ($message eq 'LookupUser') { my $authinput = $request->{$message}->{AuthenticationInput}; if ($authinput) { + $field = 'AuthenticationInputData'; # Convert to array ref if it isn't already. if (ref $authinput ne 'ARRAY') { $authinput = [$authinput]; } foreach my $input (@$authinput) { if ($input->{AuthenticationInputType} =~ /barcode/i) { - $barcode = $input->{AuthenticationInputData}; - $field = 'AuthenticationInputData'; + $barcode = $input->{$field}; last; } } } else { $authinput = $request->{$message}->{UserId}; - return unless($authinput); - if (ref $authinput ne 'ARRAY') { - $authinput = [$authinput]; - } - foreach my $input (@$authinput) { - if ($input->{UserIdentifierType} =~ /barcode/i) { - $barcode = $input->{UserIdentifierValue}; - $field = 'UserIdentifierValue'; - last; + $field = 'UserIdentifierValue'; + if ($authinput) { + if (ref $authinput ne 'ARRAY') { + $authinput = [$authinput]; + } + foreach my $input (@$authinput) { + if ($input->{UserIdentifierType} =~ /barcode/i) { + $barcode = $input->{$field}; + last; + } } } } diff --git a/lib/NCIP/ILS/Evergreen.pm b/lib/NCIP/ILS/Evergreen.pm index a0a772d..d351a4a 100644 --- a/lib/NCIP/ILS/Evergreen.pm +++ b/lib/NCIP/ILS/Evergreen.pm @@ -107,17 +107,17 @@ sub lookupuser { my $response = NCIP::Response->new({type => $message_type . "Response"}); $response->header($self->make_header($request)); - # Need to parse the request object to get the barcode and other - # data out. + # Need to parse the request object to get the user barcode. my ($barcode, $idfield) = $self->find_user_barcode($request); # If we can't find a barcode, report a problem. unless ($barcode) { + $idfield = 'AuthenticationInputType' unless ($idfield); # Fill in a problem object and stuff it in the response. my $problem = NCIP::Problem->new(); $problem->ProblemType('Needed Data Missing'); $problem->ProblemDetail('Cannot find user barcode in message.'); - $problem->ProblemElement('AuthenticationInputType'); + $problem->ProblemElement($idfield); $problem->ProblemValue('Barcode'); $response->problem($problem); return $response; -- 2.43.2