]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/Handler/LookupUser.pm
Trying to get the headers set correctly
[working/NCIPServer.git] / lib / NCIP / Handler / LookupUser.pm
1 package NCIP::Handler::LookupUser;
2
3 =head1
4
5   NCIP::Handler::LookupUser
6
7 =head1 SYNOPSIS
8
9     Not to be called directly, NCIP::Handler will pick the appropriate Handler 
10     object, given a message type
11
12 =head1 FUNCTIONS
13
14 =cut
15
16 use Modern::Perl;
17
18 use NCIP::Handler;
19 use NCIP::User;
20
21 our @ISA = qw(NCIP::Handler);
22
23 sub handle {
24     my $self   = shift;
25     my $xmldoc = shift;
26     if ($xmldoc) {
27
28         # Given our xml document, lets find our userid
29         my ($user_id) =
30           $xmldoc->getElementsByTagNameNS( $self->namespace(),
31             'UserIdentifierValue' );
32         my $xpc = XML::LibXML::XPathContext->new;
33         $xpc->registerNs( 'ns', $self->namespace() );
34         unless ($user_id) {
35
36             # We may get a password, username combo instead of userid
37             # Need to deal with that also
38             my $root = $xmldoc->documentElement();
39             my @authtypes =
40               $xpc->findnodes( '//ns:AuthenticationInput', $root );
41             my $barcode;
42             my $pin;
43             foreach my $node (@authtypes) {
44                 my $class =
45                   $xpc->findnodes( './ns:AuthenticationInputType', $node );
46                 my $value =
47                   $xpc->findnodes( './ns:AuthenticationInputData', $node );
48                 if ( $class->[0]->textContent eq 'Barcode Id' ) {
49                     $barcode = $value->[0]->textContent;
50                 }
51                 elsif ( $class->[0]->textContent eq 'PIN' ) {
52                     $pin = $value->[0]->textContent;
53                 }
54
55             }
56             $user_id = $barcode;
57         }
58         else {
59             $user_id = $user_id->textContent();
60         }
61
62         # We may get a password, username combo instead of userid
63         # Need to deal with that also
64
65         my $user = NCIP::User->new( { userid => $user_id, ils => $self->ils } );
66         $user->initialise();
67         my $vars;
68         
69 #  this bit should be at a lower level
70
71         my ($from,$to) = $self->get_agencies($xmldoc); 
72         
73         # we switch these for the templates
74         # because we are responding, to becomes from, from becomes to
75         $vars->{'fromagency'} = $to;
76         $vars->{'toagency'} = $from;
77
78         # if we have blank user, we need to return that
79         # and can skip looking for elementtypes
80         if ( $user->userdata->{'borrowernumber'} eq '' ) {
81             $vars->{'messagetype'}  = 'LookupUserResponse';
82             $vars->{'error_detail'} = "Borrower not found";
83             my $output = $self->render_output( 'problem.tt', $vars );
84             return $output;
85         }
86         my $elements = $self->get_user_elements($xmldoc);
87
88         #set up the variables for our template
89         $vars->{'messagetype'} = 'LookupUserResponse';
90         $vars->{'elements'}    = $elements;
91         $vars->{'user'}        = $user;
92         my $output = $self->render_output( 'response.tt', $vars );
93         return $output;
94
95     }
96 }
97
98 1;