sub NOOP_False { return 0 }
+# To be used in two places within $_TT_helpers. Without putting the code out
+# here, we can't really reuse it within that structure.
+sub get_li_attr {
+ my $name = shift or return; # the first arg is always the name
+ my ($type, $attr) = (scalar(@_) == 1) ? (undef, $_[0]) : @_;
+ # if the next is the last, it's the attributes, otherwise type
+ # use Data::Dumper; $logger->warn("get_li_attr: " . Dumper($attr));
+ ($name and @$attr) or return;
+ my $length;
+ $name =~ s/^(\D+)_(\d+)$/$1/ and $length = $2;
+ foreach (@$attr) {
+ $_->attr_name eq $name or next;
+ next if $length and $length != length($_->attr_value);
+ return $_->attr_value if (! $type) or $type eq $_->attr_type;
+ }
+ return;
+}
# helper functions inserted into the TT environment
my $_TT_helpers = {
# helpers.get_li_attr('isbn_13', li.attributes)
# returns matching line item attribute, or undef
- get_li_attr => sub {
- my $name = shift or return; # the first arg is always the name
- my ($type, $attr) = (scalar(@_) == 1) ? (undef, $_[0]) : @_;
- # if the next is the last, it's the attributes, otherwise type
- # use Data::Dumper; $logger->warn("get_li_attr: " . Dumper($attr));
- ($name and @$attr) or return;
- my $length;
- $name =~ s/^(\D+)_(\d+)$/$1/ and $length = $2;
- foreach (@$attr) {
- $_->attr_name eq $name or next;
- next if $length and $length != length($_->attr_value);
- return $_->attr_value if (! $type) or $type eq $_->attr_type;
+ get_li_attr => \&get_li_attr,
+
+ get_li_attr_jedi => sub {
+ my $value = get_li_attr(@_);
+ if ($value) {
+ # Here we can add any number of special case transformations to
+ # avoid problems with the EDI translator (or bad JSON).
+
+ # The ? character, if in the final position of a string, breaks
+ # the translator. + or ' or : could be problematic, too.
+ if ($value =~ /[\?\+':]$/) {
+ chop $value;
+ }
+
+ # Make sure any double quotation marks are escaped.
+ $value =~ s/"/\\"/g;
+
+ # What the heck, get rid of [ ] too (although I couldn't get them
+ # to cause any problems for me.
+ $value =~ s/[\[\]]//g;
}
- return;
+
+ return $value;
},
get_queued_bib_attr => sub {
],
"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) %]"}
+ {"BTI":"[% helpers.get_li_attr_jedi('title', '', li.attributes) %]"},
+ {"BPU":"[% helpers.get_li_attr_jedi('publisher', '', li.attributes) %]"},
+ {"BPD":"[% helpers.get_li_attr_jedi('pubdate', '', li.attributes) %]"},
+ {"BPH":"[% helpers.get_li_attr_jedi('pagination','', li.attributes) %]"}
],
[%- ftx_vals = [];
FOR note IN li.lineitem_notes;
printf STDERR "ERROR: No edi_default account found for $logstr. File will not be sent!\n";
}
- $message->jedi($event->template_output()->data);
+ my $jedi = $event->template_output()->data;
+
+ # Crucial identifiers won't contain unicode characters, and EDIFACT
+ # (or at least our translator) generally can't handle them anyway.
+ $jedi =~ s/\\u[0-9a-f]{4}//g;
+
+ $message->jedi($jedi);
print "\ntarget->provider->edi_default->id: ", $target->provider->edi_default->id, "\n";
my $logstr2 = sprintf "event %s, PO %s, template_output %s", $_->{id}, $message->purchase_order, $event->template_output->id;