]> git.evergreen-ils.org Git - working/NCIPServer.git/blob - lib/NCIP/Handler/AcceptItem.pm
Fix lookupuser problem reporting in Evergreen driver.
[working/NCIPServer.git] / lib / NCIP / Handler / AcceptItem.pm
1 package NCIP::Handler::AcceptItem;
2
3 =head1
4
5   NCIP::Handler::AcceptItem
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
20 our @ISA = qw(NCIP::Handler);
21
22 sub handle {
23     my $self   = shift;
24     my $xmldoc = shift;
25     if ($xmldoc) {
26         my $root   = $xmldoc->documentElement();
27         my $xpc    = $self->xpc();
28         my $itemid = $xpc->find( '//ns:ItemIdentifierValue', $root );
29         my ($action)  = $xpc->findnodes( '//ns:RequestedActionType', $root );
30         my ($request) = $xpc->findnodes( '//ns:RequestId',           $root );
31         my $requestagency = $xpc->find( 'ns:AgencyId', $request );
32         my $requestid  = $xpc->find( '//ns:RequestIdentifierValue', $request );
33         my $borrowerid = $xpc->find( '//ns:UserIdentifierValue',    $root );
34         
35         if ($action) {
36             $action = $action->textContent();
37         }
38         
39         my $iteminfo = $xpc->find( '//ns:ItemOptionalFields', $root );
40         my $itemdata = {};
41
42         if ( $iteminfo->[0] ) {
43
44 # populate a hashref with bibliographic data, we need this to create an item
45 # (this could be moved up to Handler.pm eventually as CreateItem will need this also)
46             my $bibliographic =
47               $xpc->find( '//ns:BibliographicDescription', $iteminfo->[0] );
48             my $title = $xpc->find( '//ns:Title', $bibliographic->[0] );
49             if ( $title->[0] ) {
50                 $itemdata->{title} = $title->[0]->textContent();
51             }
52             my $author = $xpc->find( '//ns:Author', $bibliographic->[0] );
53             if ( $author->[0] ) {
54                 $itemdata->{author} = $author->[0]->textContent();
55             }
56             my $date =
57               $xpc->find( '//ns:PublicationDate', $bibliographic->[0] );
58             if ( $date->[0] ) {
59                 $itemdata->{publicationdate} = $date->[0]->textContent();
60             }
61             my $publisher = $xpc->find( '//ns:Publisher', $bibliographic->[0] );
62             if ( $publisher->[0] ) {
63                 $itemdata->{publisher} = $publisher->[0]->textContent();
64             }
65             my $medium = $xpc->find( '//ns:Mediumtype', $bibliographic->[0] );
66             if ( $medium->[0] ) {
67                 $itemdata->{mediumtype} = $medium->[0]->textContent();
68             }
69         }
70
71         # accept the item
72         my $create = 0;
73         my ( $from, $to ) = $self->get_agencies($xmldoc);
74
75 # Autographics workflow is for an accept item to create the item then do what is in $action
76         if ( $from->[0]->textContent() =~ /CPomAG/ ) {
77             $create = 1;
78         }
79         my $accepted =
80           $self->ils->acceptitem( $itemid, $borrowerid, $action, $create,
81             $itemdata );
82         my $output;
83         my $vars;
84
85         # we switch these for the templates
86         # because we are responding, to becomes from, from becomes to
87         $vars->{'fromagency'} = $to;
88         $vars->{'toagency'}   = $from;
89
90         $vars->{'messagetype'} = 'AcceptItemResponse';
91         $vars->{'barcode'}     = $itemid;
92         if ( !$accepted->{success} ) {
93             $vars->{'processingerror'}        = 1;
94             $vars->{'processingerrortype'}    = $accepted->{'messages'};
95             $vars->{'processingerrorelement'} = 'UniqueItemIdentifier';
96             $output = $self->render_output( 'problem.tt', $vars );
97         }
98         else {
99             my $elements = $self->get_user_elements($xmldoc);
100             $vars->{'requestagency'} = $requestagency;
101             $vars->{'requestid'}     = $requestid;
102             $vars->{'newbarcode'}   = $accepted->{'newbarcode'} || $itemid;
103             $vars->{'elements'} = $elements;
104             $vars->{'accept'}   = $accepted;
105             $output = $self->render_output( 'response.tt', $vars );
106         }
107         return $output;
108     }
109 }
110
111 1;