From 9312ce8c3d365d99b348cca71822147943c1e7b8 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 16 Dec 2013 09:40:21 +1300 Subject: [PATCH] Trying to get this working a bit more robustly --- lib/NCIP.pm | 34 ++++++++++---------- t/config_sample/NCIP.xml | 2 +- t/sample_data/LookUpUser.xml | 44 -------------------------- t/sample_data/LookupUser.xml | 60 ++++++++++++++++++++++++++---------- 4 files changed, 63 insertions(+), 77 deletions(-) delete mode 100644 t/sample_data/LookUpUser.xml diff --git a/lib/NCIP.pm b/lib/NCIP.pm index 239cf1a..47e4461 100644 --- a/lib/NCIP.pm +++ b/lib/NCIP.pm @@ -9,7 +9,7 @@ use Module::Load; use Object::Tiny qw{xmldoc config namespace ils}; our $VERSION = '0.01'; -our $nsURI = 'http://www.niso.org/2008/ncip'; +our $strict_validation = 0; # move to config file =head1 NAME @@ -31,7 +31,7 @@ sub new { my $self = {}; my $config = NCIP::Configuration->new($config_dir); $self->{config} = $config; - $self->{namespace} = $nsURI; + $self->{namespace} = $config->('NCIP.namespace.value'); # load the ILS dependent module my $module = 'NCIP::ILS::' . $config->('NCIP.ils.value'); @@ -57,6 +57,7 @@ sub process_request { # We have invalid xml, or we can't figure out what kind of request this is # Handle error here + warn "We can't find request type"; return; #bail out for now @@ -86,25 +87,26 @@ sub handle_initiation { warn "Invalid xml, caught error: $_"; }; if ($dom) { - # should check validity with validate at this point - if ( $self->validate($dom) ) { - my $request_type = $self->parse_request($dom); - - # do whatever we should do to initiate, then hand back request_type - if ($request_type) { - $self->{xmldoc} = $dom; - return $request_type; - } - } - else { - warn "Not valid xml"; + if ( $strict_validation && !$self->validate($dom) ) { + + # we want strict validation, bail out if dom doesnt validate + warn " Not valid xml"; - # not valid throw error + # throw/log error return; } + my $request_type = $self->parse_request($dom); + + # do whatever we should do to initiate, then hand back request_type + if ($request_type) { + $self->{xmldoc} = $dom; + return $request_type; + } } else { + warn "We have no DOM"; + return; } } @@ -132,7 +134,7 @@ sub validate { sub parse_request { my $self = shift; my $dom = shift; - my $nodes = $dom->getElementsByTagNameNS( $nsURI, 'NCIPMessage' ); + my $nodes = $dom->getElementsByTagNameNS( $self->namespace(), 'NCIPMessage' ); if ($nodes) { my @childnodes = $nodes->[0]->childNodes(); if ( $childnodes[1] ) { diff --git a/t/config_sample/NCIP.xml b/t/config_sample/NCIP.xml index 64caccd..96d0988 100644 --- a/t/config_sample/NCIP.xml +++ b/t/config_sample/NCIP.xml @@ -34,5 +34,5 @@ - + diff --git a/t/sample_data/LookUpUser.xml b/t/sample_data/LookUpUser.xml deleted file mode 100644 index 04024ce..0000000 --- a/t/sample_data/LookUpUser.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - http://www.auto-graphics.com/ncip/schemes/uniqueagencyid/agencynames.scm - CPomAG:massvc:FLO-WENTWORTH - - - - - HTTP://schema.flo.org/ncip/ag - FLO-WENTWORTH - - - - - - HTTP://schema.flo.org/ncip/ag - FLO-WENTWORTH - - FLO-WHEELOCK - - - http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm - Name Information - - - http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm - User Address Information - - - http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm - User Privilege - - - http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm - Block Or Trap - - - - - diff --git a/t/sample_data/LookupUser.xml b/t/sample_data/LookupUser.xml index 84e9940..04024ce 100644 --- a/t/sample_data/LookupUser.xml +++ b/t/sample_data/LookupUser.xml @@ -1,16 +1,44 @@ - - - - - - - 381 - - - - - - - - - + + + + + + + http://www.auto-graphics.com/ncip/schemes/uniqueagencyid/agencynames.scm + CPomAG:massvc:FLO-WENTWORTH + + + + + HTTP://schema.flo.org/ncip/ag + FLO-WENTWORTH + + + + + + HTTP://schema.flo.org/ncip/ag + FLO-WENTWORTH + + FLO-WHEELOCK + + + http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm + Name Information + + + http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm + User Address Information + + + http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm + User Privilege + + + http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm + Block Or Trap + + + + + -- 2.43.2