From 0c348ecd81851438f6d773bbe97323b189979f0a Mon Sep 17 00:00:00 2001 From: atz Date: Fri, 18 Jun 2010 15:56:57 +0000 Subject: [PATCH] 0312 - JEDI template support for multiple ISBNs of same or different types. The first ISBN-13 is treated as primary, if there is one. Otherwise the first ISBN-10 is used. Signed-off-by: Joe Atzberger git-svn-id: svn://svn.open-ils.org/ILS/trunk@16759 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Trigger/Reactor.pm | 20 ++++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 12 +++- .../upgrade/0312.data.acq.jedi_template.sql | 64 +++++++++++++++++++ 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0312.data.acq.jedi_template.sql diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm index 0673409392..ad14e0bff2 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm @@ -93,6 +93,26 @@ my $_TT_helpers = { return $U->ou_ancestor_setting_value($org_id, $setting); }, + # This basically greps/maps out ths isbn string values, but also promotes the first isbn-13 to the + # front of the line (so that the EDI translator takes it as primary) if there is one. + get_li_isbns => sub { + my $attrs = shift; + my @isbns; + my $primary; + foreach (@$attrs) { + $_->attr_name eq 'isbn' or next; + my $val = $_->attr_value; + if (! $primary and length($val) == 13) { + $primary = $val; + } else { + push @isbns, $val; + } + } + $primary and unshift @isbns, $primary; + $logger->error("get_li_isbns returning isbns: " . join(', ', @isbns)); + return @isbns; + }, + # helpers.get_li_attr('isbn_13', li.attributes) # returns matching line item attribute, or undef get_li_attr => sub { diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 67f2292de7..f1121d4c32 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0311'); -- Scott McKellar +INSERT INTO config.upgrade_log (version) VALUES ('0312'); -- atz CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 262633c839..3e917c8cba 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -4864,9 +4864,15 @@ $$[%- USE date -%] "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) %]"} + "identifiers":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %] + [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%] + [% IF isbn.length == 13 -%] + {"id-qualifier":"EN","id":"[% isbn %]"}, + [% ELSE -%] + {"id-qualifier":"IB","id":"[% isbn %]"}, + [%- END %] + [% END %] + {"id-qualifier":"SA","id":"[% li.id %]"} ], "price":[% li.estimated_unit_price || '0.00' %], "desc":[ diff --git a/Open-ILS/src/sql/Pg/upgrade/0312.data.acq.jedi_template.sql b/Open-ILS/src/sql/Pg/upgrade/0312.data.acq.jedi_template.sql new file mode 100644 index 0000000000..9d230b417d --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0312.data.acq.jedi_template.sql @@ -0,0 +1,64 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0312'); --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":[ [%-# li.isbns = helpers.get_li_isbns(li.attributes) %] + [% FOR isbn IN helpers.get_li_isbns(li.attributes) -%] + [% IF isbn.length == 13 -%] + {"id-qualifier":"EN","id":"[% isbn %]"}, + [% ELSE -%] + {"id-qualifier":"IB","id":"[% isbn %]"}, + [%- END %] + [% END %] + {"id-qualifier":"SA","id":"[% li.id %]"} + ], + "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; -- 2.43.2