From f9633641e1392db336da6acc55f02c7da3708553 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 24 Aug 2014 10:02:56 -0400 Subject: [PATCH] Remove NCIP/Handler.pm and family. Signed-off-by: Jason Stephenson --- lib/NCIP/Handler.pm | 139 -------------------------- lib/NCIP/Handler/AcceptItem.pm | 111 -------------------- lib/NCIP/Handler/CancelRequestItem.pm | 47 --------- lib/NCIP/Handler/CheckInItem.pm | 57 ----------- lib/NCIP/Handler/CheckOutItem.pm | 59 ----------- lib/NCIP/Handler/LookupItem.pm | 49 --------- lib/NCIP/Handler/LookupUser.pm | 97 ------------------ lib/NCIP/Handler/LookupVersion.pm | 51 ---------- lib/NCIP/Handler/RenewItem.pm | 53 ---------- lib/NCIP/Handler/RequestItem.pm | 62 ------------ 10 files changed, 725 deletions(-) delete mode 100644 lib/NCIP/Handler.pm delete mode 100644 lib/NCIP/Handler/AcceptItem.pm delete mode 100644 lib/NCIP/Handler/CancelRequestItem.pm delete mode 100644 lib/NCIP/Handler/CheckInItem.pm delete mode 100644 lib/NCIP/Handler/CheckOutItem.pm delete mode 100644 lib/NCIP/Handler/LookupItem.pm delete mode 100644 lib/NCIP/Handler/LookupUser.pm delete mode 100644 lib/NCIP/Handler/LookupVersion.pm delete mode 100644 lib/NCIP/Handler/RenewItem.pm delete mode 100644 lib/NCIP/Handler/RequestItem.pm diff --git a/lib/NCIP/Handler.pm b/lib/NCIP/Handler.pm deleted file mode 100644 index 7f58b1b..0000000 --- a/lib/NCIP/Handler.pm +++ /dev/null @@ -1,139 +0,0 @@ -package NCIP::Handler; -# -#=============================================================================== -# -# FILE: Hander.pm -# -# DESCRIPTION: -# -# FILES: --- -# BUGS: --- -# NOTES: --- -# AUTHOR: Chris Cormack (rangi), chrisc@catalyst.net.nz -# ORGANIZATION: Koha Development Team -# VERSION: 1.0 -# CREATED: 19/09/13 10:43:14 -# REVISION: --- -#=============================================================================== - -# Copyright 2014 Catalyst IT - -# This file is part of NCIPServer -# -# NCIPServer is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# NCIPServer is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with NCIPServer; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -=head1 NAME - - NCIP::Handler - -=head1 SYNOPSIS - - use NCIP::Handler; - my $handler = NCIP::Handler->new( { namespace => $namespace, - type => $request_type, - ils => $ils, - template_dir => $templates - } ); - -=head1 FUNCTIONS -=cut - -use Modern::Perl; -use Object::Tiny qw{ type namespace ils templates }; -use Module::Load; -use Template; - -=head2 new() - - Set up a new handler object, this will actually create one of the request type - eg NCIP::Handler::LookupUser - -=cut - -sub new { - my $class = shift; - my $params = shift; - my $subclass = __PACKAGE__ . "::" . $params->{type}; - load $subclass || die "Can't load module $subclass"; - my $self = bless { - type => $params->{type}, - namespace => $params->{namespace}, - ils => $params->{ils}, - templates => $params->{template_dir} - }, $subclass; - return $self; -} - -=head2 xpc() - - Give back an XPathContext Object, registered to the correct namespace - -=cut - -sub xpc { - my $self = shift; - my $xpc = XML::LibXML::XPathContext->new; - $xpc->registerNs( 'ns', $self->namespace() ); - return $xpc; -} - -=head2 get_user_elements($xml) - - When passed an xml dom, this will find the user elements and pass convert them into an arrayref - -=cut - -sub get_user_elements { - my $self = shift; - my $xmldoc = shift; - my $xpc = $self->xpc(); - - my $root = $xmldoc->documentElement(); - my @elements = - $xpc->findnodes( '//ns:LookupUser/UserElementType/Value', $root ); - unless ( $elements[0] ) { - @elements = $xpc->findnodes( '//ns:UserElementType', $root ); - } - return \@elements; -} - -sub get_agencies { - my $self = shift; - my $xmldoc = shift; - my $xpc = XML::LibXML::XPathContext->new; - $xpc->registerNs( 'ns', $self->namespace() ); - - my $root = $xmldoc->documentElement(); - - my $from = $xpc->find( '//ns:FromAgencyId', $root ); - my $to = $xpc->find( '//ns:ToAgencyId', $root ); - return ( $from, $to ); -} - -sub render_output { - my $self = shift; - my $templatename = shift; - - my $vars = shift; - my $template = Template->new( - { - INCLUDE_PATH => $self->templates, - POST_CHOMP => 1 - } - ); - my $output; - $template->process( $templatename, $vars, \$output ); - return $output; -} -1; diff --git a/lib/NCIP/Handler/AcceptItem.pm b/lib/NCIP/Handler/AcceptItem.pm deleted file mode 100644 index b739fb5..0000000 --- a/lib/NCIP/Handler/AcceptItem.pm +++ /dev/null @@ -1,111 +0,0 @@ -package NCIP::Handler::AcceptItem; - -=head1 - - NCIP::Handler::AcceptItem - -=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 $xpc = $self->xpc(); - my $itemid = $xpc->find( '//ns:ItemIdentifierValue', $root ); - my ($action) = $xpc->findnodes( '//ns:RequestedActionType', $root ); - my ($request) = $xpc->findnodes( '//ns:RequestId', $root ); - my $requestagency = $xpc->find( 'ns:AgencyId', $request ); - my $requestid = $xpc->find( '//ns:RequestIdentifierValue', $request ); - my $borrowerid = $xpc->find( '//ns:UserIdentifierValue', $root ); - - if ($action) { - $action = $action->textContent(); - } - - my $iteminfo = $xpc->find( '//ns:ItemOptionalFields', $root ); - my $itemdata = {}; - - if ( $iteminfo->[0] ) { - -# populate a hashref with bibliographic data, we need this to create an item -# (this could be moved up to Handler.pm eventually as CreateItem will need this also) - my $bibliographic = - $xpc->find( '//ns:BibliographicDescription', $iteminfo->[0] ); - my $title = $xpc->find( '//ns:Title', $bibliographic->[0] ); - if ( $title->[0] ) { - $itemdata->{title} = $title->[0]->textContent(); - } - my $author = $xpc->find( '//ns:Author', $bibliographic->[0] ); - if ( $author->[0] ) { - $itemdata->{author} = $author->[0]->textContent(); - } - my $date = - $xpc->find( '//ns:PublicationDate', $bibliographic->[0] ); - if ( $date->[0] ) { - $itemdata->{publicationdate} = $date->[0]->textContent(); - } - my $publisher = $xpc->find( '//ns:Publisher', $bibliographic->[0] ); - if ( $publisher->[0] ) { - $itemdata->{publisher} = $publisher->[0]->textContent(); - } - my $medium = $xpc->find( '//ns:Mediumtype', $bibliographic->[0] ); - if ( $medium->[0] ) { - $itemdata->{mediumtype} = $medium->[0]->textContent(); - } - } - - # accept the item - my $create = 0; - my ( $from, $to ) = $self->get_agencies($xmldoc); - -# Autographics workflow is for an accept item to create the item then do what is in $action - if ( $from->[0]->textContent() =~ /CPomAG/ ) { - $create = 1; - } - my $accepted = - $self->ils->acceptitem( $itemid, $borrowerid, $action, $create, - $itemdata ); - my $output; - my $vars; - - # we switch these for the templates - # because we are responding, to becomes from, from becomes to - $vars->{'fromagency'} = $to; - $vars->{'toagency'} = $from; - - $vars->{'messagetype'} = 'AcceptItemResponse'; - $vars->{'barcode'} = $itemid; - if ( !$accepted->{success} ) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $accepted->{'messages'}; - $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - my $elements = $self->get_user_elements($xmldoc); - $vars->{'requestagency'} = $requestagency; - $vars->{'requestid'} = $requestid; - $vars->{'newbarcode'} = $accepted->{'newbarcode'} || $itemid; - $vars->{'elements'} = $elements; - $vars->{'accept'} = $accepted; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/CancelRequestItem.pm b/lib/NCIP/Handler/CancelRequestItem.pm deleted file mode 100644 index 8cce605..0000000 --- a/lib/NCIP/Handler/CancelRequestItem.pm +++ /dev/null @@ -1,47 +0,0 @@ -package NCIP::Handler::CancelRequestItem; - -=head1 - - NCIP::Handler::CancelRequestItem - -=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; -use NCIP::User; - -our @ISA = qw(NCIP::Handler); - -sub handle { - my $self = shift; - my $xmldoc = shift; - if ($xmldoc) { - my $root = $xmldoc->documentElement(); - my $xpc = $self->xpc(); - my $userid = $xpc->findnodes( '//ns:UserIdentifierValue', $root ); - my $requestid = $xpc->findnodes( '//ns:RequestIdentifierValue', $root ); - my ( $error, $messages ) = $self->ils->cancelrequest($requestid); - if ($error) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $messages; - $vars->{'processingerrorelement'} = 'UniqueRequestIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - my $elements = $self->get_user_elements($xmldoc); - $vars->{'elements'} = $elements; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/CheckInItem.pm b/lib/NCIP/Handler/CheckInItem.pm deleted file mode 100644 index b03b403..0000000 --- a/lib/NCIP/Handler/CheckInItem.pm +++ /dev/null @@ -1,57 +0,0 @@ -package NCIP::Handler::CheckInItem; - -=head1 - - NCIP::Handler::CheckInItem - -=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 $xpc = $self->xpc(); - my $itemid = $xpc->findnodes( '//ns:ItemIdentifierValue', $root ); - - # checkin the item - my $branch = undef; # where the hell do we get this from??? - my $checkin = $self->ils->checkin( $itemid, $branch ); - my $output; - my $vars; - $vars->{'messagetype'} = 'CheckInItemResponse'; - $vars->{'barcode'} = $itemid; - my ( $from, $to ) = $self->get_agencies($xmldoc); - $vars->{'fromagency'} = $to; - $vars->{'toagency'} = $from; - - if ( !$checkin->{success} ) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $checkin->{'messages'}; - $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - - $vars->{'elements'} = $self->get_user_elements($xmldoc); - $vars->{'checkin'} = $checkin; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/CheckOutItem.pm b/lib/NCIP/Handler/CheckOutItem.pm deleted file mode 100644 index e6e9e34..0000000 --- a/lib/NCIP/Handler/CheckOutItem.pm +++ /dev/null @@ -1,59 +0,0 @@ -package NCIP::Handler::CheckOutItem; - -=head1 - - NCIP::Handler::CheckOutItem - -=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 $xpc = $self->xpc(); - - my $userid = - $xpc->findnodes( '//ns:UserIdentifierValue', - $root ); - my $itemid = - $xpc->findnodes( '//ns:ItemIdentifierValue', - $root ); - - # checkout the item - my ( $error, $messages, $datedue ) = - $self->ils->checkout( $userid, $itemid ); - my $vars; - my $output; - $vars->{'barcode'} = $itemid; - $vars->{'messagetype'} = 'CheckOutItemResponse'; - if ($error) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $messages; - $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - my $elements = $self->get_user_elements($xmldoc); - $vars->{'elements'} = $elements; - $vars->{'datedue'} = $datedue; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/LookupItem.pm b/lib/NCIP/Handler/LookupItem.pm deleted file mode 100644 index 3dc3c0f..0000000 --- a/lib/NCIP/Handler/LookupItem.pm +++ /dev/null @@ -1,49 +0,0 @@ -package NCIP::Handler::LookupItem; - -=head1 - - NCIP::Handler::LookupItem - -=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; -use NCIP::Item; - -our @ISA = qw(NCIP::Handler); - -sub handle { - my $self = shift; - my $xmldoc = shift; - my $item; - if ($xmldoc) { - - # Given our xml document, lets find the itemid - my ($item_id) = - $xmldoc->getElementsByTagNameNS( $self->namespace(), - 'ItemIdentifierValue' ); - $item = NCIP::Item->new( - { itemid => $item_id->textContent(), ils => $self->ils } ); - my ( $itemdata, $error ) = $item->itemdata(); - if ($error) { - - # handle error here - } - warn $item->itemid(); - } - my $vars; - $vars->{'messagetype'} = 'LookupItemResponse'; - $vars->{'item'} = $item; - my $output = $self->render_output( 'response.tt', $vars ); - return $output; -} - -1; diff --git a/lib/NCIP/Handler/LookupUser.pm b/lib/NCIP/Handler/LookupUser.pm deleted file mode 100644 index 94440fe..0000000 --- a/lib/NCIP/Handler/LookupUser.pm +++ /dev/null @@ -1,97 +0,0 @@ -package NCIP::Handler::LookupUser; - -=head1 - - NCIP::Handler::LookupUser - -=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; -use NCIP::User; - -our @ISA = qw(NCIP::Handler); - -sub handle { - my $self = shift; - my $xmldoc = shift; - if ($xmldoc) { - - # Given our xml document, lets find our userid - my ($user_id) = - $xmldoc->getElementsByTagNameNS( $self->namespace(), - 'UserIdentifierValue' ); - my $xpc = $self->xpc(); - unless ($user_id) { - - # We may get a password, username combo instead of userid - # Need to deal with that also - my $root = $xmldoc->documentElement(); - my @authtypes = - $xpc->findnodes( '//ns:AuthenticationInput', $root ); - my $barcode; - my $pin; - foreach my $node (@authtypes) { - my $class = - $xpc->findnodes( './ns:AuthenticationInputType', $node ); - my $value = - $xpc->findnodes( './ns:AuthenticationInputData', $node ); - if ( $class->[0]->textContent eq 'Barcode Id' ) { - $barcode = $value->[0]->textContent; - } - elsif ( $class->[0]->textContent eq 'PIN' ) { - $pin = $value->[0]->textContent; - } - - } - $user_id = $barcode; - } - else { - $user_id = $user_id->textContent(); - } - - # We may get a password, username combo instead of userid - # Need to deal with that also - - my $user = NCIP::User->new( { userid => $user_id, ils => $self->ils } ); - $user->initialise(); - my $vars; - -# this bit should be at a lower level - - my ($from,$to) = $self->get_agencies($xmldoc); - - # we switch these for the templates - # because we are responding, to becomes from, from becomes to - $vars->{'fromagency'} = $to; - $vars->{'toagency'} = $from; - - # if we have blank user, we need to return that - # and can skip looking for elementtypes - if ( $user->userdata->{'borrowernumber'} eq '' ) { - $vars->{'messagetype'} = 'LookupUserResponse'; - $vars->{'error_detail'} = "Borrower not found"; - my $output = $self->render_output( 'problem.tt', $vars ); - return $output; - } - my $elements = $self->get_user_elements($xmldoc); - - #set up the variables for our template - $vars->{'messagetype'} = 'LookupUserResponse'; - $vars->{'elements'} = $elements; - $vars->{'user'} = $user; - my $output = $self->render_output( 'response.tt', $vars ); - return $output; - - } -} - -1; diff --git a/lib/NCIP/Handler/LookupVersion.pm b/lib/NCIP/Handler/LookupVersion.pm deleted file mode 100644 index 4fa63e7..0000000 --- a/lib/NCIP/Handler/LookupVersion.pm +++ /dev/null @@ -1,51 +0,0 @@ -# --------------------------------------------------------------- -# Copyright © 2014 Jason J.A. Stephenson -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# --------------------------------------------------------------- -package NCIP::Handler::LookupVersion; - -=head1 - - NCIP::Handler::LookupVersion - -=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; -use NCIP::Const; - -our @ISA = qw(NCIP::Handler); - -sub handle { - my $self = shift; - my $xmldoc = shift; - if ($xmldoc) { - my $vars; - my ($from,$to) = $self->get_agencies($xmldoc); - $vars->{'fromagency'} = $to; - $vars->{'toagency'} = $from; - $vars->{'messagetype'} = 'LookupVersionResponse'; - $vars->{'versions'} = [ NCIP::Const::SUPPORTED_VERSIONS ]; - my $output = $self->render_output('response.tt', $vars); - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/RenewItem.pm b/lib/NCIP/Handler/RenewItem.pm deleted file mode 100644 index 8096676..0000000 --- a/lib/NCIP/Handler/RenewItem.pm +++ /dev/null @@ -1,53 +0,0 @@ -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 ( !$renewed->{success} ) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $renewed->{'messages'}; - $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - - $vars->{'elements'} = \@elements; - $vars->{'renewed'} = $renewed; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; diff --git a/lib/NCIP/Handler/RequestItem.pm b/lib/NCIP/Handler/RequestItem.pm deleted file mode 100644 index f98e70e..0000000 --- a/lib/NCIP/Handler/RequestItem.pm +++ /dev/null @@ -1,62 +0,0 @@ -package NCIP::Handler::RequestItem; - -=head1 - - NCIP::Handler::RequestItem - -=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 $xpc = XML::LibXML::XPathContext->new; - $xpc->registerNs( 'ns', $self->namespace() ); - - my ($userid) = $xpc->findnodes( '//ns:UserIdentifierValue', $root ); - $userid = $userid->textContent() if $userid; - - my ($itemid) = $xpc->findnodes( '//ns:ItemIdentifierValue', $root ); - $itemid = $itemid->textContent() if $itemid; - my ($biblionumber) = - $xpc->findnodes( '//ns:BibliographicRecordIdentifier', $root ); - $biblionumber = $biblionumber->textContent() if $biblionumber; - - # request the item - my $result = $self->ils->request( $userid, $itemid, $biblionumber ); - my $vars; - my $output; - $vars->{'barcode'} = $itemid; - $vars->{'messagetype'} = 'RequestItemResponse'; - if ( !$result->{'success'} ) { - $vars->{'processingerror'} = 1; - $vars->{'processingerrortype'} = $result->{messages}; - $vars->{'processingerrorelement'} = 'UniqueItemIdentifier'; - $output = $self->render_output( 'problem.tt', $vars ); - } - else { - my $elements = $self->get_user_elements($xmldoc); - $vars->{'elements'} = $elements; - - $vars->{'messages'} = $result->{messages}; - $output = $self->render_output( 'response.tt', $vars ); - } - return $output; - } -} - -1; -- 2.43.2