]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/Handler/LookupUser.pm
94440feee0734a40d0d5ca3e0b9133ea8d65ede0
[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 = $self->xpc();
33         unless ($user_id) {
34
35             # We may get a password, username combo instead of userid
36             # Need to deal with that also
37             my $root = $xmldoc->documentElement();
38             my @authtypes =
39               $xpc->findnodes( '//ns:AuthenticationInput', $root );
40             my $barcode;
41             my $pin;
42             foreach my $node (@authtypes) {
43                 my $class =
44                   $xpc->findnodes( './ns:AuthenticationInputType', $node );
45                 my $value =
46                   $xpc->findnodes( './ns:AuthenticationInputData', $node );
47                 if ( $class->[0]->textContent eq 'Barcode Id' ) {
48                     $barcode = $value->[0]->textContent;
49                 }
50                 elsif ( $class->[0]->textContent eq 'PIN' ) {
51                     $pin = $value->[0]->textContent;
52                 }
53
54             }
55             $user_id = $barcode;
56         }
57         else {
58             $user_id = $user_id->textContent();
59         }
60
61         # We may get a password, username combo instead of userid
62         # Need to deal with that also
63
64         my $user = NCIP::User->new( { userid => $user_id, ils => $self->ils } );
65         $user->initialise();
66         my $vars;
67         
68 #  this bit should be at a lower level
69
70         my ($from,$to) = $self->get_agencies($xmldoc); 
71         
72         # we switch these for the templates
73         # because we are responding, to becomes from, from becomes to
74         $vars->{'fromagency'} = $to;
75         $vars->{'toagency'} = $from;
76
77         # if we have blank user, we need to return that
78         # and can skip looking for elementtypes
79         if ( $user->userdata->{'borrowernumber'} eq '' ) {
80             $vars->{'messagetype'}  = 'LookupUserResponse';
81             $vars->{'error_detail'} = "Borrower not found";
82             my $output = $self->render_output( 'problem.tt', $vars );
83             return $output;
84         }
85         my $elements = $self->get_user_elements($xmldoc);
86
87         #set up the variables for our template
88         $vars->{'messagetype'} = 'LookupUserResponse';
89         $vars->{'elements'}    = $elements;
90         $vars->{'user'}        = $user;
91         my $output = $self->render_output( 'response.tt', $vars );
92         return $output;
93
94     }
95 }
96
97 1;