[open-ils-commits] r805 - in acq_edi/trunk: lib/edi lib/openils test (mbklein)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 1 13:46:55 EST 2010
Author: mbklein
Date: 2010-03-01 13:46:51 -0500 (Mon, 01 Mar 2010)
New Revision: 805
Modified:
acq_edi/trunk/lib/edi/mapper.rb
acq_edi/trunk/lib/openils/mapper.rb
acq_edi/trunk/test/map_spec.rb
Log:
Fixed sender/recipient initialization issues
Modified: acq_edi/trunk/lib/edi/mapper.rb
===================================================================
--- acq_edi/trunk/lib/edi/mapper.rb 2010-02-26 03:59:12 UTC (rev 804)
+++ acq_edi/trunk/lib/edi/mapper.rb 2010-03-01 18:46:51 UTC (rev 805)
@@ -92,7 +92,28 @@
end
def initialize(msg_type, msg_opts = {}, ic_opts = {})
- @ic = EDI::E::Interchange.new(ic_opts || {})
+ # Bug in edi4r 0.9 -- sometimes :recipient is used; sometimes :recip. It doesn't
+ # work. We'll override it.
+ local_ic_opts = ic_opts.reject { |k,v| [:sender,:recipient].include?(k) }
+ @ic = EDI::E::Interchange.new(local_ic_opts || {})
+ @ic.header.cS002.d0004 = ic_opts[:sender] unless ic_opts[:sender].nil?
+ @ic.header.cS003.d0010 = ic_opts[:recipient] unless ic_opts[:recipient].nil?
+
+ # Apply any envelope defaults.
+ ['UNA','UNB','UNZ'].each { |seg|
+ seg_defs = self.class.defaults[seg]
+ if seg_defs
+ seg_defs.each_pair { |cde,defs|
+ segment = @ic.header[cde].first
+ unless segment.nil?
+ defs.each_pair { |de,val|
+ segment[de][0].value = val
+ }
+ end
+ }
+ end
+ }
+
@message = @ic.new_message( { :msg_type => msg_type, :version => 'D', :release => '96A', :resp_agency => 'UN' }.merge(msg_opts || {}) )
@ic.add(@message,false)
end
Modified: acq_edi/trunk/lib/openils/mapper.rb
===================================================================
--- acq_edi/trunk/lib/openils/mapper.rb 2010-02-26 03:59:12 UTC (rev 804)
+++ acq_edi/trunk/lib/openils/mapper.rb 2010-03-01 18:46:51 UTC (rev 805)
@@ -8,6 +8,7 @@
end
OpenILS::Mapper.defaults = {
+ 'UNB' => { 'S002' => { '0007' => '31B' }, 'S003' => { '0007' => '31B' } },
'BGM' => { 'C002' => { '1001' => 220 }, '1225' => 9 },
'DTM' => { 'C507' => { '2005' => 137, '2379' => 102 } },
'NAD' => { 'C082' => { '3055' => '31B' } },
Modified: acq_edi/trunk/test/map_spec.rb
===================================================================
--- acq_edi/trunk/test/map_spec.rb 2010-02-26 03:59:12 UTC (rev 804)
+++ acq_edi/trunk/test/map_spec.rb 2010-03-01 18:46:51 UTC (rev 805)
@@ -41,6 +41,11 @@
}.should raise_error(TypeError)
end
+ it "should properly fill in interchange envelope defaults" do
+ map = EDI::E::Mapper.new('ORDERS', nil, {:sender => '123456', :recipient => '654321'})
+ map.to_s.should =~ /UNA:\+\.\? 'UNB\+UNOB:3\+123456\+654321\+[0-9]{6}:[0-9]{4}\+1'UNH\+1\+ORDERS:D:96A:UN'UNT\+2\+1'UNZ\+1\+1'/
+ end
+
it "should add multiple elements in tuple form" do
@map.add(
'BGM', { 'C002' => { '1001' => 220 }, '1004' => '12345678', '1225' => 9 },
More information about the open-ils-commits
mailing list