From f9fbcce551bc9c969737fc3d962844297398eea7 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 13 Jan 2014 09:59:06 +1300 Subject: [PATCH] Extending the handlers --- lib/NCIP/Handler/CheckInItem.pm | 6 ++--- lib/NCIP/Handler/CheckOutItem.pm | 18 +++++++++++--- lib/NCIP/Handler/RenewItem.pm | 53 ++++++++++++++++++++++++++++++++++++++++ lib/NCIP/ILS/Koha.pm | 14 +++++++++++ 4 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 lib/NCIP/Handler/RenewItem.pm diff --git a/lib/NCIP/Handler/CheckInItem.pm b/lib/NCIP/Handler/CheckInItem.pm index 2656f68..ab8b255 100644 --- a/lib/NCIP/Handler/CheckInItem.pm +++ b/lib/NCIP/Handler/CheckInItem.pm @@ -35,9 +35,9 @@ sub handle { $vars->{'messagetype'} = 'CheckInItemResponse'; $vars->{'barcode'} = $itemid; if ( !$checkin->{success} ) { - $var->{'processingerror'} = 1; - $var->{'processingerrortype'} = $checkin->{'messages'}; - $var->{'processingerrorelement'} = 'UniqueItemIdentifier'; + $vars->{'processingerror'} = 1; + $vars->{'processingerrortype'} = $checkin->{'messages'}; + $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; $output = $self->render_output( 'problem.tt', $vars ); } else { diff --git a/lib/NCIP/Handler/CheckOutItem.pm b/lib/NCIP/Handler/CheckOutItem.pm index d92e579..4c40a9f 100644 --- a/lib/NCIP/Handler/CheckOutItem.pm +++ b/lib/NCIP/Handler/CheckOutItem.pm @@ -31,12 +31,22 @@ sub handle { my @elements = $root->findnodes('CheckOutItem/ItemElementType/Value'); # checkout the item - my $checkout = $self->ils->checkout( $userid, $itemid ); + my ( $error, $messages ) = $self->ils->checkout( $userid, $itemid ); my $vars; + my $output; + my $vars->{'barcode'}=$itemid; $vars->{'messagetype'} = 'CheckOutItemResponse'; - $vars->{'elements'} = \@elements; - $vars->{'checkout'} = $checkout; - my $output = $self->render_output( 'response.tt', $vars ); + if ($error) { + $vars->{'processingerror'} = 1; + $vars->{'processingerrortype'} = $messages; + $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; + $output = $self->render_output( 'problem.tt', $vars ); + } + else { + $vars->{'elements'} = \@elements; + + $output = $self->render_output( 'response.tt', $vars ); + } return $output; } } diff --git a/lib/NCIP/Handler/RenewItem.pm b/lib/NCIP/Handler/RenewItem.pm new file mode 100644 index 0000000..91a9c8a --- /dev/null +++ b/lib/NCIP/Handler/RenewItem.pm @@ -0,0 +1,53 @@ +package NCIP::Handler::RenewItem; + +=head1 + + NCIP::Handler::RenewItem + +=head1 SYNOPSIS + + Not to be called directly, NCIP::Handler will pick the appropriate Handler + object, given a message type + +=head1 FUNCTIONS + +=cut + +use Modern::Perl; + +use NCIP::Handler; + +our @ISA = qw(NCIP::Handler); + +sub handle { + my $self = shift; + my $xmldoc = shift; + if ($xmldoc) { + my $root = $xmldoc->documentElement(); + my $itemid = + $root->findnodes('RenewItem/UniqueItemId/ItemIdentifierValue'); + my @elements = $root->findnodes('RenewItem/ItemElementType/Value'); + + # checkin the item + my $renewed = $self->ils->renew( $itemid ); + my $output; + my $vars; + $vars->{'messagetype'} = 'RenewItemResponse'; + $vars->{'barcode'} = $itemid; + if ( !$checkin->{success} ) { + $vars->{'processingerror'} = 1; + $vars->{'processingerrortype'} = $checkin->{'messages'}; + $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; + $output = $self->render_output( 'problem.tt', $vars ); + } + else { + + $vars->{'elements'} = \@elements; + $vars->{'checkin'} = $checkin; + $output = $self->render_output( 'response.tt', $vars ); + } + return $output; + } +} + +1; diff --git a/lib/NCIP/ILS/Koha.pm b/lib/NCIP/ILS/Koha.pm index 38a4342..c6bc05a 100644 --- a/lib/NCIP/ILS/Koha.pm +++ b/lib/NCIP/ILS/Koha.pm @@ -43,6 +43,20 @@ sub checkin { } sub checkout { + my $self = shift; + my $userid = shift; + my $barcode = shift; + my ($error, $confirm) = CanBookBeIssued ( $userid, $barcode ); + #( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, + # $barcode, $duedatespec, $inprocess, $ignore_reserves ); + if ($error) { # plus the confirmation? +# Can't issue item, return error hash + return ( 1, $error); + } + else { + AddIssue($userid,$barcode); + return ( 0 ); + } } 1; -- 2.11.0