patch for edi4r to make invoice parsing possible
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 17 Jul 2012 21:59:23 +0000 (17:59 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 30 Jul 2012 16:45:28 +0000 (12:45 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/edi_translator/misc/edi4r-break-on-nil-seg.patch [new file with mode: 0644]
Open-ILS/src/edi_translator/new-test.pl [new file with mode: 0644]
Open-ILS/src/edi_translator/test_edi_translator.pl [new file with mode: 0644]

diff --git a/Open-ILS/src/edi_translator/misc/edi4r-break-on-nil-seg.patch b/Open-ILS/src/edi_translator/misc/edi4r-break-on-nil-seg.patch
new file mode 100644 (file)
index 0000000..06a6294
--- /dev/null
@@ -0,0 +1,10 @@
+--- a/lib/edi4r.rb     2012-07-17 17:57:27.000000000 -0400
++++ b/lib/edi4r.rb     2012-07-17 17:51:48.000000000 -0400
+@@ -758,6 +758,7 @@
+       loop do
+         index += 1
+         seg = msg[index]
++        break if seg.nil?
+         next  if child_mode and seg.level > level+1 # other descendants
+         break if seg.level <= level
+         results << seg
diff --git a/Open-ILS/src/edi_translator/new-test.pl b/Open-ILS/src/edi_translator/new-test.pl
new file mode 100644 (file)
index 0000000..d5065d3
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use XML::Edifact;
+use XML::LibXML;
+
+XML::Edifact::open_dbm();
+XML::Edifact::read_edi_message($ARGV[0]);
+my $xmlstr = &XML::Edifact::make_xml_message();
+XML::Edifact::close_dbm();
+
+my $dom = load_xml XML::LibXML(string => $xmlstr);
+
+print $dom->toString(),"\n";
+0;
+
diff --git a/Open-ILS/src/edi_translator/test_edi_translator.pl b/Open-ILS/src/edi_translator/test_edi_translator.pl
new file mode 100644 (file)
index 0000000..b7c90cc
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+use vars qw/$debug/;
+
+use OpenILS::Utils::Cronscript;
+use OpenILS::Utils::Fieldmapper;
+use OpenILS::Application::AppUtils;
+use OpenILS::Application::Acq::EDI;
+use OpenSRF::Utils::Logger q/$logger/;
+
+INIT {
+    $debug = 1;
+}
+
+my %defaults = (
+    'quiet' => 0,
+    'test'  => 0,
+);
+
+print "loading OpenILS environment... " if $debug;
+
+my $cs = OpenILS::Utils::Cronscript->new(\%defaults);
+
+my $opts = $cs->MyGetOptions;
+my $e    = $cs->editor or die "Failed to get new CStoreEditor";
+
+print "creating acq.edi_message object from stdin\n" if $debug;
+my $message = new Fieldmapper::acq::edi_message;
+$message->message_type("ORDERS");
+
+my $input_field = $ENV{INPUT_IS_EDI} ? 'edi' : 'jedi';
+my $output_field = $ENV{INPUT_IS_EDI} ? 'jedi' : 'edi';
+{
+    local $/;
+    undef $/;
+    $message->$input_field(<STDIN>);
+
+}
+
+print "calling out to edi translator... \n" if $debug;
+
+my $r = attempt_translation OpenILS::Application::Acq::EDI($message, !$ENV{INPUT_IS_EDI});
+
+if (!$r) {
+    print STDERR "attempt_translation failed; see opensrf ERR logs\n";
+} else {
+    print $r->$output_field,"\n";
+}
+
+print "done.\n" if $debug;
+