From 438cc7e52dfb4634c9be65c82e5030dbe2032923 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 6 Aug 2014 21:14:50 -0400 Subject: [PATCH] Add some the Header and Response objects. Also modify some existing objects to camel case the fields so that they match what is in Z39.83-1-2012. Add a make_header method to the base ILS class. Signed-off-by: Jason Stephenson --- lib/NCIP/Header.pm | 32 ++++++++++++++++++++++++++++++ lib/NCIP/ILS.pm | 24 ++++++++++++++++++++++ lib/NCIP/Problem.pm | 9 ++++++++- lib/NCIP/Response.pm | 46 +++++++++++++++++++++++++++++++++++++++++++ lib/NCIP/StructuredAddress.pm | 4 ++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 lib/NCIP/Header.pm create mode 100644 lib/NCIP/Response.pm diff --git a/lib/NCIP/Header.pm b/lib/NCIP/Header.pm new file mode 100644 index 0000000..0ae1960 --- /dev/null +++ b/lib/NCIP/Header.pm @@ -0,0 +1,32 @@ +# --------------------------------------------------------------- +# Copyright © 2014 Jason J.A. Stephenson +# +# 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, see . +# --------------------------------------------------------------- +package NCIP::Header; +use parent qw(Class::Accessor); + +# This is a NCIP ResponseHeader object. We do not implement an +# initator, so we do not implement the InitiationHeader and we do not +# attempt to make this object generic enough to handle that field. +# The fields are as defined in Z39.83-1-2012. Ext is provided but is +# not used by the current iteration of NCIPServer. + +NCIP::Problem->mk_accessors(qw(FromSystemId FromSystemAuthentication + FromAgencyId FromAgencyAuthentication + ToSystemId ToAgencyId Ext)); + +1; diff --git a/lib/NCIP/ILS.pm b/lib/NCIP/ILS.pm index 1523922..34f8f91 100644 --- a/lib/NCIP/ILS.pm +++ b/lib/NCIP/ILS.pm @@ -53,4 +53,28 @@ sub requestitem { sub lookupversion { } +# A few helper methods: + +# All subclasses will possibly want to create a ResponseHeader and the +# code for that would be highly redundant. We supply a default +# implementation here that can retrieve the agency information from +# the InitiationHeader of the message, swap their values, and return a +# NCIP::Header. +sub make_header { + my $self = shift; + my $initheader = shfit; + + my $header; + + if ($initheader && $initheader->{FromAgencyId} + && $initheader->{ToAgencyId}) { + $header = NCIP::Header->new( + FromAgencyId => $initheader->{ToAgencyId}, + ToAgencyId => $initheader->{FromAgencyId} + ); + } + + return $header; +} + 1; diff --git a/lib/NCIP/Problem.pm b/lib/NCIP/Problem.pm index 088a526..fc8fa06 100644 --- a/lib/NCIP/Problem.pm +++ b/lib/NCIP/Problem.pm @@ -19,6 +19,13 @@ package NCIP::Problem; use parent qw(Class::Accessor); -NCIP::Problem->mk_accessors(qw(type scheme detail element value ext)); +# NCIP::Problem is the object used to report that a problem occurred +# during message processing. The fields are as defined in +# Z39.83-1-2012. Ext is avaialable for future use, but it is not +# presently used by the problem template. The obsolete +# ProcessingError fields have been excluded. + +NCIP::Problem->mk_accessors(qw(ProblemType Scheme ProblemDetail ProblemElement + ProblemValue Ext)); 1; diff --git a/lib/NCIP/Response.pm b/lib/NCIP/Response.pm new file mode 100644 index 0000000..e702d10 --- /dev/null +++ b/lib/NCIP/Response.pm @@ -0,0 +1,46 @@ +# --------------------------------------------------------------- +# Copyright © 2014 Jason J.A. Stephenson +# +# 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, see . +# --------------------------------------------------------------- +package NCIP::Response; +use parent qw(Class::Accessor); + +# This is the Response object to be returned by the ILS' handlers. +# The fields are: +# +# type: A string representing the name of the response this is usually +# the initiation message name with Response tacked on, i.e. +# LookupUserResponse, etc. This value is used to lookup the +# appropriate template include for formatting the response message to +# the initiator. +# +# data: This is an object or struct with the response data for a +# successful result. It's value and needs vary by message type. +# +# problem: If the response is reporting a problem, this should point +# to a NCIP::Problem object to be used in the problem template. +# +# header: A NCIP::Header object for the optional ResponseHeader in the +# response template. + +# Presently, only one data or problem object is supported. If one is +# supplied the other must be left undefined/unset. Only 1 header is +# supported, but it is entirely optional according to the standard. + +NCIP::Problem->mk_accessors(qw(type data problem header)); + +1; diff --git a/lib/NCIP/StructuredAddress.pm b/lib/NCIP/StructuredAddress.pm index ce971f6..cbcc363 100644 --- a/lib/NCIP/StructuredAddress.pm +++ b/lib/NCIP/StructuredAddress.pm @@ -19,6 +19,10 @@ package NCIP::StructuredAddress; use parent qw(Class::Accessor); +# This a "StructuredAddress" as defined by Z39.83-1-2012. It is used +# for returning user address information when requested. The fields +# are as defined in the standard. + NCIP::StructuredAddress->mk_accessors(qw(line1 line2 locality region postalcode country)); -- 2.11.0