Feed JEDI to the EDI translator to get EDI, and vice versa.
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 26 Jul 2012 14:17:06 +0000 (10:17 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 1 Aug 2012 19:15:24 +0000 (15:15 -0400)
Run this script as the opensrf user.

INPUT_IS_EDI=1 perl test_edi_translator.pl < blob.edi

-or-

perl test_edi_translator.pl < blob.jedi

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/edi_translator/test_edi_translator.pl [new file with mode: 0644]

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..a7149ad
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+# This assumes you have the translator (edi_webrick) running.
+
+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;
+