[open-ils-commits] r808 - in acq_edi/trunk: . lib/openils (mbklein)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Mar 1 19:13:25 EST 2010


Author: mbklein
Date: 2010-03-01 19:13:24 -0500 (Mon, 01 Mar 2010)
New Revision: 808

Added:
   acq_edi/trunk/README.rdoc
   acq_edi/trunk/openils-mapper.gemspec
Modified:
   acq_edi/trunk/lib/openils/mapper.rb
Log:
Created gem

Added: acq_edi/trunk/README.rdoc
===================================================================
--- acq_edi/trunk/README.rdoc	                        (rev 0)
+++ acq_edi/trunk/README.rdoc	2010-03-02 00:13:24 UTC (rev 808)
@@ -0,0 +1,60 @@
+= Introduction
+
+This module adds methods to edi4r's EDI::E::Interchange class to map between EDIFACT, Ruby structures, and JSON strings. It takes JSON input and turns it into valid, well-formatted EDIFACT messages. In order to provide the greatest range of flexibility, the mapper can process two types of input interchangeably: low-level (or raw) and high-level.
+
+== Low-Level
+
+Low-level input describes the exact structure of the required EDIFACT segments and data elements, without having to worry about syntax or exact placement. Any segment, simple data element (DE), or composite data element (CDE) can be specified directly. The tradeoff, of course, is that the application sending the JSON message has to be intimately aware of the underlying EDIFACT message's structure, including all segment and DE/CDE order, data types, and code lists. For example, the following EDIFACT segments describe a vendor (SU) identified by its Standard Address Number (code 31B), and with an internal department code (1865, qualified by the code IA):
+
+  NAD+SU+1556150::31B'
+  RFF+IA:1865'
+
+The low-level JSON representation of those two segments looks like this:
+
+  [
+    'NAD', { '3035' : 'SU', 'C082' : { '3039' : '1556150', '3055' : '31B' }},
+    'RFF', { 'C506' : { '1153' : 'IA', '1154' : '1865' }}
+  ]
+
+In this case, the JSON is more verbose than the raw EDIFACT, but at least it insulates the caller from the details of element order, blank DEs, and character escaping.
+
+== High-Level
+
+The mapper's high-level mode defines a number of pseudo-segments that know how to translate themselves into their low-level counterparts. For example, to create a simple supplier segment with an ID and using the defaults for everything else:
+
+  ['vendor', '1556150']
+  => NAD+SU+1556150::91'
+
+But it's easy to override some of the defaults and add extra segment information as well:
+
+  ['vendor', { 'id' : '1556150', 'id-qual' : '31B', 'reference' : { 'IA' : '1865' }}]
+  => NAD+SU+1556150::31B'
+     RFF+IA:1865'
+
+Another example involves the descriptive metadata sent with each line item in a purchase order. Strings longer than 35 characters have to be split across multiple DEs, and strings longer than 70 characters require multiple iterations of the IMD segment:
+
+  IMD+F+BAU+:::Campbell, James'
+  IMD+F+BTI+:::The Ghost Mountain boys ?: their epi:c march and the terrifying battle f'
+  IMD+F+BTI+:::or New Guinea -- the forgotten war :of the South Pacific'
+  IMD+F+BPU+:::Crown Publishers'
+  IMD+F+BPD+:::2007'''
+
+Note the character escaping (?:) and segmentation (:), as well as the repetition of the IMD title (BTI) field to accommodate the long string. The high level version can look like this:
+
+  [
+  'desc', { 'BAU' : 'Campbell, James' },
+  'desc', { 'BTI' : "The Ghost Mountain boys : their epic march and the terrifying battle for New Guinea -- the forgotten war of the South Pacific" },
+  'desc', { 'BPU' : 'Crown Publishers' },
+  'desc', { 'BPD' : 2007 }
+  ]
+
+or even like this:
+
+  ['desc', [
+    'BAU', 'Campbell, James',
+    'BTI', "The Ghost Mountain boys : their epic march and the terrifying battle for New Guinea -- the forgotten war of the South Pacific",
+    'BPU', 'Crown Publishers',
+    'BPD', 2007
+  ]]
+  
+Since the mapper uses regular expressions and closures to define and evaluate the high-level pseudo-segments, the mapper can be extended very easily (in some cases, trivially), and with great flexibility.
\ No newline at end of file

Modified: acq_edi/trunk/lib/openils/mapper.rb
===================================================================
--- acq_edi/trunk/lib/openils/mapper.rb	2010-03-01 20:08:40 UTC (rev 807)
+++ acq_edi/trunk/lib/openils/mapper.rb	2010-03-02 00:13:24 UTC (rev 808)
@@ -3,6 +3,7 @@
 module OpenILS
   
   class Mapper < EDI::E::Mapper
+    VERSION = '0.8.2'
   end
   
 end

Added: acq_edi/trunk/openils-mapper.gemspec
===================================================================
--- acq_edi/trunk/openils-mapper.gemspec	                        (rev 0)
+++ acq_edi/trunk/openils-mapper.gemspec	2010-03-02 00:13:24 UTC (rev 808)
@@ -0,0 +1,24 @@
+require 'rake'
+begin
+  $: << File.join(File.dirname(__FILE__),'lib')
+  require 'openils/mapper'
+  Gem::Specification.new do |s|
+    s.name = "openils-mapper"
+    s.version = OpenILS::Mapper::VERSION
+    s.summary = "EDIFACT<->JSON middleware for the Evergreen Open Source ILS"
+    s.email = "mbklein at gmail.com"
+    s.description = "Middleware layer to provide translation between high-level JSON and raw EDIFACT messages"
+    s.authors = ["Michael B. Klein"]
+    s.files = FileList["[A-Z]*", "README.rdoc", "{bin,lib,test}/**/*"]
+    s.extra_rdoc_files = ['README.rdoc']
+    s.rdoc_options << '--main' << 'README.rdoc'
+    s.add_dependency 'edi4r', '>= 0.9.4'
+    s.add_dependency 'edi4r-tdid', '>= 0.6.5'
+    s.add_dependency 'json', '>= 1.1.3'
+    s.add_development_dependency 'rcov', '>= 0.8.1'
+    s.add_development_dependency 'rspec', '>= 1.2.2'
+    s.add_development_dependency 'rake', '>= 0.8.0'
+  end
+rescue LoadError
+  puts "Error loading OpenILS::Mapper module."
+end



More information about the open-ils-commits mailing list