+++ /dev/null
-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 <chrisc@catalyst.net.nz>
-
-# 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;
+++ /dev/null
-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;
+++ /dev/null
-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;
+++ /dev/null
-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;
+++ /dev/null
-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;
+++ /dev/null
-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;
+++ /dev/null
-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;
+++ /dev/null
-# ---------------------------------------------------------------
-# Copyright © 2014 Jason J.A. Stephenson <jason@sigio.com>
-#
-# 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;
+++ /dev/null
-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;
+++ /dev/null
-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;