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 {
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;
+ }
}
}
}
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;