From 59dc4f8ad3a982ef2d2a7e5ff2c9f7ff8c0a850e Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 31 Aug 2014 09:56:03 -0400 Subject: [PATCH] Edit find_user_barcode in NCIP::ILS to be more universal. It now works with messages other than just LookupUser. Signed-off-by: Jason Stephenson --- lib/NCIP/ILS.pm | 62 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/NCIP/ILS.pm b/lib/NCIP/ILS.pm index 65309ea..a32442f 100644 --- a/lib/NCIP/ILS.pm +++ b/lib/NCIP/ILS.pm @@ -299,13 +299,12 @@ sub parse_request_type { return $type; } -=head2 find_barcode +=head2 find_user_barcode Cfind_user_barcode($request);> If you have a request type that includes a user barcode identifier -value, this routine will find it. It presently works only on -LookupUser requests. +value, this routine will find it. 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. @@ -325,33 +324,38 @@ sub find_user_barcode { my $field; my $message = $self->parse_request_type($request); return unless($message); - 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->{$field}; - last; - } + + # Check for UserId first because it is more common and still valid + # in LookupUser. + my $authinput = $request->{$message}->{UserId}; + if ($authinput) { + $field = 'UserIdentifierValue'; + if (ref $authinput ne 'ARRAY') { + $authinput = [$authinput]; + } + foreach my $input (@$authinput) { + # UserIdentifierType is optional, so we check if it is + # there. If it is, we skip this entry unless the + # identifier type contains the string barcode + if ($input->{UserIdentifierType}) { + next unless ($input->{UserIdentifierType} =~ /barcode/i); } - } else { - $authinput = $request->{$message}->{UserId}; - if ($authinput) { - $field = 'UserIdentifierValue'; - if (ref $authinput ne 'ARRAY') { - $authinput = [$authinput]; - } - foreach my $input (@$authinput) { - if ($input->{UserIdentifierType} =~ /barcode/i) { - $barcode = $input->{$field}; - last; - } - } + # We take the first field we find, unless the + # identifier type says it is not a barcode. + $barcode = $input->{$field}; + last; + } + } elsif ($message eq 'LookupUser') { + $field = 'AuthenticationInputData'; + $authinput = $request->{$message}->{AuthenticationInput}; + # 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->{$field}; + last; } } } -- 2.43.2