LP#1373690 edi_pusher get --from-edi and --defs options for skipping translation...
authorBill Erickson <berickxx@gmail.com>
Thu, 25 Sep 2014 21:50:56 +0000 (17:50 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 13 May 2015 22:41:47 +0000 (18:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/support-scripts/edi_pusher.pl

index e94abb8..99cc469 100755 (executable)
@@ -34,6 +34,8 @@ my %defaults = (
     'quiet' => 0,
     'test'  => 0,   # TODO
     'max-batch-size=i' => -1,
+    'from-edi' => 0,
+    'def=s' => 0,
 
     # if true, print final EDI to STDOUT, send nothign to the vendor, write nothing to the DB
     'debug-only' => 0
@@ -44,11 +46,16 @@ my $cs = OpenILS::Utils::Cronscript->new(\%defaults);
 my $opts = $cs->MyGetOptions();
 my $e    = $cs->editor() or die "Failed to get new CStoreEditor";
 my $hook = 'acqpo.activated';
-my $defs = $e->search_action_trigger_event_definition({
-    hook    => $hook,
-    reactor => 'GeneratePurchaseOrderJEDI',
-    active  => 't'
-});
+my $defs;
+if ($opts->{def}) {
+    $defs = [$e->retrieve_action_trigger_event_definition($opts->{def})];
+} else {
+    $defs = $e->search_action_trigger_event_definition({
+        hook    => $hook,
+        reactor => 'GeneratePurchaseOrderJEDI',
+        active  => 't'
+    });
+}
 
 $opts->{verbose} = 0 if $opts->{quiet};
 
@@ -167,22 +174,30 @@ foreach my $def (@$defs) {
             next;
         }
 
-        printf "\nNow calling attempt_translation for $logstr2\n\n";
+        if ($opts->{'from-edi'}) {
 
-        unless (OpenILS::Application::Acq::EDI->attempt_translation($message, 1)) {
-            print STDERR "ERROR: attempt_translation failed for $logstr2\n";
-            next;
-            # The premise here is that if the translator failed, it is better to try again later from a "fresh" fetched file
-            # than to add a cascade of failing inscrutable copies of the same message(s) to our DB.  
-        }
+            print "Skipping JEDI translation on raw EDI definition\n";
+            $message->edi($message->jedi);
 
-        if ($opts->{'debug-only'}) {
-            print OpenILS::Application::Acq::EDI->attempt_translation($message, 1)->edi . "\n";
-            print "\ndebug-only => skipping FTP\n";
-            next;
+        } else {
+            printf "\nNow calling attempt_translation for $logstr2\n\n";
+
+            unless (OpenILS::Application::Acq::EDI->attempt_translation($message, 1)) {
+                print STDERR "ERROR: attempt_translation failed for $logstr2\n";
+                next;
+                # The premise here is that if the translator failed, it is better to try again later from a "fresh" fetched file
+                # than to add a cascade of failing inscrutable copies of the same message(s) to our DB.  
+            }
+
+            if ($opts->{'debug-only'}) {
+                print OpenILS::Application::Acq::EDI->attempt_translation($message, 1)->edi . "\n";
+                print "\ndebug-only => skipping FTP\n";
+                next;
+            }
+
+            print "Writing new message + translation to DB for $logstr2\n";
         }
 
-        print "Writing new message + translation to DB for $logstr2\n";
 
         $e->xact_begin;
         if($message->isnew) {
@@ -198,6 +213,9 @@ foreach my $def (@$defs) {
         }
         $e->xact_commit;
 
+        # XXX TESTING
+        exit;
+
         print "Calling send_core(...) for message (", $message->id, ")\n";
         my $res = OpenILS::Application::Acq::EDI->send_core($target->provider->edi_default, [$message->id]);
         if (@$res) {