Trying to get this working a bit more robustly
authorChris Cormack <chrisc@catalyst.net.nz>
Sun, 15 Dec 2013 20:40:21 +0000 (09:40 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Sun, 15 Dec 2013 20:40:21 +0000 (09:40 +1300)
lib/NCIP.pm
t/config_sample/NCIP.xml
t/sample_data/LookUpUser.xml [deleted file]
t/sample_data/LookupUser.xml

index 239cf1a..47e4461 100644 (file)
@@ -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] ) {
index 64caccd..96d0988 100644 (file)
@@ -34,5 +34,5 @@
   </version>
 
   <ils value='Koha' />
-
+  <namespace value= '' />
 </acsconfig>
diff --git a/t/sample_data/LookUpUser.xml b/t/sample_data/LookUpUser.xml
deleted file mode 100644 (file)
index 04024ce..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!DOCTYPE NCIPMessage PUBLIC "-//NISO//NCIP DTD Version 1//EN" "http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd">
-<NCIPMessage version="http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd">
-  <LookupUser>
-    <InitiationHeader>
-      <FromAgencyId>
-        <UniqueAgencyId>
-          <Scheme>http://www.auto-graphics.com/ncip/schemes/uniqueagencyid/agencynames.scm</Scheme>
-          <Value>CPomAG:massvc:FLO-WENTWORTH</Value>
-        </UniqueAgencyId>
-      </FromAgencyId>
-      <ToAgencyId>
-        <UniqueAgencyId>
-          <Scheme>HTTP://schema.flo.org/ncip/ag</Scheme>
-          <Value>FLO-WENTWORTH</Value>
-        </UniqueAgencyId>
-      </ToAgencyId>
-    </InitiationHeader>
-    <UniqueUserId>
-      <UniqueAgencyId>
-        <Scheme>HTTP://schema.flo.org/ncip/ag</Scheme>
-        <Value>FLO-WENTWORTH</Value>
-      </UniqueAgencyId>
-      <UserIdentifierValue>FLO-WHEELOCK</UserIdentifierValue>
-    </UniqueUserId>
-    <UserElementType>
-      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
-      <Value>Name Information</Value>
-    </UserElementType>
-    <UserElementType>
-      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
-      <Value>User Address Information</Value>
-    </UserElementType>
-    <UserElementType>
-      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
-      <Value>User Privilege</Value>
-    </UserElementType>
-    <UserElementType>
-      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
-      <Value>Block Or Trap</Value>
-    </UserElementType>
-  </LookupUser>
-</NCIPMessage>
-
-
index 84e9940..04024ce 100644 (file)
@@ -1,16 +1,44 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
-\r
-<ns1:NCIPMessage xmlns:ns1="http://www.niso.org/2008/ncip" ns1:version="http://www.niso.org/schemas/ncip/v2_01/ncip_v2_01.xsd">\r
-    <ns1:LookupUser>\r
-\r
-        <ns1:UserId>\r
-            <ns1:UserIdentifierValue>381</ns1:UserIdentifierValue>\r
-        </ns1:UserId>\r
-        \r
-        <ns1:LoanedItemsDesired/>\r
-        <ns1:RequestedItemsDesired/>\r
-        <ns1:UserFiscalAccountDesired/>\r
-\r
-    </ns1:LookupUser>\r
-</ns1:NCIPMessage>\r
-\r
+<?xml version="1.0" encoding="utf-8"?><!DOCTYPE NCIPMessage PUBLIC "-//NISO//NCIP DTD Version 1//EN" "http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd">
+<NCIPMessage version="http://www.niso.org/ncip/v1_0/imp1/dtd/ncip_v1_0.dtd">
+  <LookupUser>
+    <InitiationHeader>
+      <FromAgencyId>
+        <UniqueAgencyId>
+          <Scheme>http://www.auto-graphics.com/ncip/schemes/uniqueagencyid/agencynames.scm</Scheme>
+          <Value>CPomAG:massvc:FLO-WENTWORTH</Value>
+        </UniqueAgencyId>
+      </FromAgencyId>
+      <ToAgencyId>
+        <UniqueAgencyId>
+          <Scheme>HTTP://schema.flo.org/ncip/ag</Scheme>
+          <Value>FLO-WENTWORTH</Value>
+        </UniqueAgencyId>
+      </ToAgencyId>
+    </InitiationHeader>
+    <UniqueUserId>
+      <UniqueAgencyId>
+        <Scheme>HTTP://schema.flo.org/ncip/ag</Scheme>
+        <Value>FLO-WENTWORTH</Value>
+      </UniqueAgencyId>
+      <UserIdentifierValue>FLO-WHEELOCK</UserIdentifierValue>
+    </UniqueUserId>
+    <UserElementType>
+      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
+      <Value>Name Information</Value>
+    </UserElementType>
+    <UserElementType>
+      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
+      <Value>User Address Information</Value>
+    </UserElementType>
+    <UserElementType>
+      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
+      <Value>User Privilege</Value>
+    </UserElementType>
+    <UserElementType>
+      <Scheme>http://www.niso.org/ncip/v1_0/schemes/userelementtype/userelementtype.scm</Scheme>
+      <Value>Block Or Trap</Value>
+    </UserElementType>
+  </LookupUser>
+</NCIPMessage>
+
+