[open-ils-commits] r16681 - in trunk/Open-ILS/src: sql/Pg sql/Pg/upgrade support-scripts (atz)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jun 11 13:10:36 EDT 2010
Author: atz
Date: 2010-06-11 13:10:32 -0400 (Fri, 11 Jun 2010)
New Revision: 16681
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0306.data.acq.jedi_template.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
trunk/Open-ILS/src/support-scripts/edi_pusher.pl
Log:
0306: Update JEDI template, edi_pusher logic tweaked
Old pusher was excluding valid target with "not in"
subquery. Broke that out and added debugging so
that situation should be more obvious (if verbose).
Signed-off-by: Joe Atzberger <atz at esilibrary.com>
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-11 16:18:35 UTC (rev 16680)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-11 17:10:32 UTC (rev 16681)
@@ -68,7 +68,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0305'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0306'); -- atz
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-06-11 16:18:35 UTC (rev 16680)
+++ trunk/Open-ILS/src/sql/Pg/950.data.seed-values.sql 2010-06-11 17:10:32 UTC (rev 16681)
@@ -4840,24 +4840,33 @@
$$[%- USE date -%]
[%# start JEDI document -%]
[%- BLOCK big_block -%]
-["order", {
- "po_number":[% target.id %],
- "date":"[% date.format(date.now, '%Y%m%d') %]",
- "buyer":[
- {"id":"[% target.ordering_agency.mailing_address.san %]",
- "reference":{"API":"[% target.ordering_agency.mailing_address.san %]"}}
- ],
- "vendor":[
- "[% target.provider.san %]", // [% target.provider.name %] ([% target.provider.id %])
- {"id-qualifier":"91", "reference":{"IA":"[% target.provider.id %]"}, "id":"[% target.provider.san %]"}
- ],
- "currency":"[% target.provider.currency_type %]",
- "items":[
+{
+ "recipient":"[% target.provider.san %]",
+ "sender":"[% target.ordering_agency.mailing_address.san %]",
+ "body": [{
+ "ORDERS":[ "order", {
+ "po_number":[% target.id %],
+ "date":"[% date.format(date.now, '%Y%m%d') %]",
+ "buyer":[{
+ [%- IF target.provider.edi_default.vendcode -%]
+ "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]",
+ "id-qualifier": 91
+ [%- ELSE -%]
+ "id":"[% target.ordering_agency.mailing_address.san %]"
+ [%- END -%]
+ }],
+ "vendor":[
+ [%- # target.provider.name (target.provider.id) -%]
+ "[% target.provider.san %]",
+ {"id-qualifier": 92, "id":"[% target.provider.id %]"}
+ ],
+ "currency":"[% target.provider.currency_type %]",
+ "items":[
[% FOR li IN target.lineitems %]
{
"identifiers":[
{"id-qualifier":"SA","id":"[% li.id %]"},
- {"id-qualifier":"IB","id":"[% helpers.get_li_attr('isbn', li.attributes) %]"}
+ {"id-qualifier":"IB","id":"[% helpers.get_li_attr('isbn_13', li.attributes) || helpers.get_li_attr('isbn_10', li.attributes) %]"}
],
"price":[% li.estimated_unit_price || '0.00' %],
"desc":[
@@ -4867,12 +4876,14 @@
{"BPH":"[% helpers.get_li_attr('pagination','', li.attributes) %]"}
],
"quantity":[% li.lineitem_details.size %]
- [%-# TODO: lineitem details (later) -%]
- }[% UNLESS loop.last %],[% END -%]
- [%- END %]
- ],
- "line_items":[% target.lineitems.size %]
-}]
+ }[% UNLESS loop.last %],[% END %]
+ [%-# TODO: lineitem details (later) -%]
+ [% END %]
+ ],
+ "line_items":[% target.lineitems.size %]
+ }] [% # close ORDERS array %]
+ }] [% # close body array %]
+}
[% END %]
[% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
$$
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0306.data.acq.jedi_template.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0306.data.acq.jedi_template.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0306.data.acq.jedi_template.sql 2010-06-11 17:10:32 UTC (rev 16681)
@@ -0,0 +1,58 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0306'); --atz
+
+UPDATE action_trigger.event_definition SET template =
+$$[%- USE date -%]
+[%# start JEDI document -%]
+[%- BLOCK big_block -%]
+{
+ "recipient":"[% target.provider.san %]",
+ "sender":"[% target.ordering_agency.mailing_address.san %]",
+ "body": [{
+ "ORDERS":[ "order", {
+ "po_number":[% target.id %],
+ "date":"[% date.format(date.now, '%Y%m%d') %]",
+ "buyer":[{
+ [%- IF target.provider.edi_default.vendcode -%]
+ "id":"[% target.ordering_agency.mailing_address.san _ ' ' _ target.provider.edi_default.vendcode %]",
+ "id-qualifier": 91
+ [%- ELSE -%]
+ "id":"[% target.ordering_agency.mailing_address.san %]"
+ [%- END -%]
+ }],
+ "vendor":[
+ [%- # target.provider.name (target.provider.id) -%]
+ "[% target.provider.san %]",
+ {"id-qualifier": 92, "id":"[% target.provider.id %]"}
+ ],
+ "currency":"[% target.provider.currency_type %]",
+ "items":[
+ [% FOR li IN target.lineitems %]
+ {
+ "identifiers":[
+ {"id-qualifier":"SA","id":"[% li.id %]"},
+ {"id-qualifier":"IB","id":"[% helpers.get_li_attr('isbn_13', li.attributes) || helpers.get_li_attr('isbn_10', li.attributes) %]"}
+ ],
+ "price":[% li.estimated_unit_price || '0.00' %],
+ "desc":[
+ {"BTI":"[% helpers.get_li_attr('title', '', li.attributes) %]"},
+ {"BPU":"[% helpers.get_li_attr('publisher', '', li.attributes) %]"},
+ {"BPD":"[% helpers.get_li_attr('pubdate', '', li.attributes) %]"},
+ {"BPH":"[% helpers.get_li_attr('pagination','', li.attributes) %]"}
+ ],
+ "quantity":[% li.lineitem_details.size %]
+ }[% UNLESS loop.last %],[% END %]
+ [%-# TODO: lineitem details (later) -%]
+ [% END %]
+ ],
+ "line_items":[% target.lineitems.size %]
+ }] [% # close ORDERS array %]
+ }] [% # close body array %]
+}
+[% END %]
+[% tempo = PROCESS big_block; helpers.escape_json(tempo) %]
+$$
+WHERE id = 23;
+
+COMMIT;
Modified: trunk/Open-ILS/src/support-scripts/edi_pusher.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/edi_pusher.pl 2010-06-11 16:18:35 UTC (rev 16680)
+++ trunk/Open-ILS/src/support-scripts/edi_pusher.pl 2010-06-11 17:10:32 UTC (rev 16681)
@@ -20,7 +20,6 @@
use Data::Dumper;
use vars qw/$debug/;
-use OpenILS::Utils::CStoreEditor; # needs init() after IDL is loaded (by Cronscript session)
use OpenILS::Utils::Cronscript;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Application::AppUtils;
@@ -31,55 +30,56 @@
$debug = 1;
}
-my %opts = (
+my %defaults = (
'quiet' => 0,
'max-batch-size=i' => -1
);
-my $cs = OpenILS::Utils::Cronscript->new(\%opts);
-$cs->session('open-ils.acq') or die "No session created";
+my $cs = OpenILS::Utils::Cronscript->new(\%defaults);
-OpenILS::Utils::CStoreEditor::init();
-
-sub editor {
- my $ed = OpenILS::Utils::CStoreEditor->new(@_) or die "Failed to get new CStoreEditor";
- return $ed;
-}
-
-my $e = editor();
+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,
+ hook => $hook,
reactor => 'GeneratePurchaseOrderJEDI',
- active => 't'
+ active => 't'
});
+$opts->{verbose} = 0 if $opts->{quiet};
+
+
# print Dumper($defs);
print "\nHook '$hook' is used in ", scalar(@$defs), " event definition(s):\n";
$Data::Dumper::Indent = 1;
-my $remaining = $cs->first_defined('max-batch-size');
+my $remaining = $opts->{'max-batch-size'};
+
+my $subq = {
+ select => { acqedim => ['purchase_order'] },
+ from => 'acqedim',
+ where => {
+ message_type => 'ORDERS',
+ status => {'!=' => 'retry' },
+ purchase_order => {'!=' => undef }
+ }
+};
+
foreach my $def (@$defs) {
last if $remaining == 0;
printf "%3s - '%s'\n", $def->id, $def->name;
# give me all completed JEDI events that link to purchase_orders
# that have no delivery attempts or are in the retry state
+
my $query = {
select => {atev => ['id']},
- from => 'atev',
- where => {
+ from => 'atev',
+ where => {
event_def => $def->id,
- state => 'complete',
+ state => 'complete',
target => {
- 'not in' => {
- select => {acqedim => ['purchase_order']},
- from => 'acqedim',
- where => {
- message_type => 'ORDERS',
- status => {'!=' => 'retry'}
- }
- }
+ 'not in' => $subq
}
},
order_by => {atev => ['add_time']}
@@ -87,6 +87,11 @@
$query->{limit} = $remaining if $remaining > 0;
+ if ($opts->{verbose}) {
+ my $excluded = $e->json_query($subq);
+ print "Excluded: ", scalar(@$excluded), " purchase order(s): ", join("\n", map {Dumper $_} @$excluded), "\n";
+ }
+
my $events = $e->json_query($query);
if(!$events) {
@@ -138,32 +143,33 @@
$message->jedi($event->template_output()->data);
print "\ntarget->provider->edi_default->id: ", $target->provider->edi_default->id, "\n";
- print "\nNow calling attempt_translation\n\n";
+ my $logstr2 = sprintf "event %s, PO %s, template_output %s", $_->{id}, $message->purchase_order, $event->template_output->id;
+ printf "\nNow calling attempt_translation for $logstr2\n\n";
unless (OpenILS::Application::Acq::EDI->attempt_translation($message, 1)) {
- print STDERR "ERROR: attempt_translation failed, skipping message\n";
+ 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 "Writing new message + translation to DB\n";
+ print "Writing new message + translation to DB for $logstr2\n";
$e->xact_begin;
if($message->isnew) {
unless($e->create_acq_edi_message($message)) {
- $logger->error("Error creating acq.edi_message for PO ".$target->id.' : '.$e->die_event);
+ $logger->error("Error creating acq.edi_message for $logstr2: ".$e->die_event);
next;
}
} else {
unless($e->update_acq_edi_message($message)) {
- $logger->error("Error updating acq.edi_message for PO ".$target->id.' : '.$e->die_event);
+ $logger->error("Error updating acq.edi_message for $logstr2: ".$e->die_event);
next;
}
}
$e->xact_commit;
- print "Calling send_core(...)\n";
+ 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) {
my $message_out = shift @$res;
More information about the open-ils-commits
mailing list