33
UN/EDIFACT Interchange Processing with Smooks v1.4 Smooks Community Day - 14/Aug/2010 Tom Fennelly Wednesday 1 September 2010

UN/EDIFACT Interchange Processing with Smooks v1.4

Embed Size (px)

Citation preview

Page 1: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT Interchange Processing with Smooks v1.4

Smooks Community Day - 14/Aug/2010Tom Fennelly

Wednesday 1 September 2010

Page 2: UN/EDIFACT Interchange Processing  with Smooks v1.4

AGENDA• What is UN/EDIFACT?

• EDI Support in Smooks v1.3 (and before)

• EDI Conversion Tool (ECT)

• <unedifact: reader>

• UN/EDIFACT + Java

‣ EDI Java Compiler (EJC)

• Distribution

‣ Mapping Models (ECT), Java Bindings (EJC)

• Future

• Examples & Code Walk-thru...

Wednesday 1 September 2010

Page 3: UN/EDIFACT Interchange Processing  with Smooks v1.4

WHAT IS UN/EDIFACT?

Wednesday 1 September 2010

Page 4: UN/EDIFACT Interchange Processing  with Smooks v1.4

WHAT IS UN/EDIFACT?

• UN/EDIFACT

‣ “United Nations/Electronic Data Interchange For Administration, Commerce and Transport”

• UN/EDIFACT & X12

‣ Dominant B2B data exchange standards (>>> XML)

‣ X12 North America

‣ UN/EDIFACT Everywhere else

Wednesday 1 September 2010

Page 5: UN/EDIFACT Interchange Processing  with Smooks v1.4

WHAT IS UN/EDIFACT?

• A Message Interchange “Protocol"

UNBUNH

<message>UNTUNH

<message>UNTetc...

UNZ

Wednesday 1 September 2010

Page 6: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI SUPPORT IN 1.3

Wednesday 1 September 2010

Page 7: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI SUPPORT IN 1.3

<edi:reader mappingModel="../edi-mapping-models/order-mapping.xml" />

HDR*1*0*59.97*64.92*4.95*Wed Nov 15 13:45:28 EST 2006CUS*user1*Harry^Fletcher*SDORD*1*1*364*The 40-Year-Old Virgin*29.98ORD*2*1*299*Pulp Fiction*29.99

<Order> <header> <order-id>1</order-id> <status-code>0</status-code> <net-amount>59.97</net-amount> <total-amount>64.92</total-amount> <tax>4.95</tax> <date>Wed Nov 15 13:45:28 EST 2006</date> </header> <customer-details> <username>user1</username>

Input <message>

Smooks

Output

Wednesday 1 September 2010

Page 8: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI SUPPORT IN 1.3

• Single <message> instance

‣ No Interchange Support

• Generic EDI Reader

‣ No standards support “out-of-the-box”

‣ Hand coded “EDI Mapping Models”

• Reading - YES .... Writing - NO

Wednesday 1 September 2010

Page 9: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI SUPPORT IN 1.3• Each <message> defined by an “EDI Mapping Model”

‣ Schema for EDI <?xml version="1.0" encoding="UTF-8"?><medi:edimap xmlns:medi="http://www.milyn.org/schema/edi-message-mapping-1.3.xsd">

<medi:description name="DVD Order" version="1.0" />

<medi:delimiters segment="&#10;" field="*" component="^" sub-component="~" />

<medi:segments xmltag="Order">

<medi:segment segcode="HDR" xmltag="header"> <medi:field xmltag="order-id" /> <medi:field xmltag="status-code" /> <medi:field xmltag="net-amount" /> <medi:field xmltag="total-amount" /> <medi:field xmltag="tax" /> <medi:field xmltag="date" /> </medi:segment>

<medi:segment segcode="CUS" xmltag="customer-details"> <medi:field xmltag="username" /> <medi:field xmltag="name"> <medi:component xmltag="firstname" /> <medi:component xmltag="lastname" /> </medi:field> <medi:field xmltag="state" /> </medi:segment>

Wednesday 1 September 2010

Page 10: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT SUPPORT IN 1.4

Wednesday 1 September 2010

Page 11: UN/EDIFACT Interchange Processing  with Smooks v1.4

MORE... WHAT IS UN/EDIFACT?

• UN/EDIFACT Standard

‣ An Interchange Protocol

‣ A Directory of Interchange Message Definitions

- 20+ Directory Versions/Releases (d93a, d03b etc)

- ~ 200 Messages/Directory

- Defined in .zip files... downloadable

- Not very user friendly !!!

Wednesday 1 September 2010

Page 12: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI CONVERSION TOOL (ECT)

• Input: UN/DIFACT Directory .zip

• Output: Smooks EDI Mapping Model .jar

‣ “Zip Set”

Wednesday 1 September 2010

Page 13: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI CONVERSION TOOL (ECT)

• Maven & Ant Plugins

<plugins> <plugin> <groupId>org.milyn</groupId> <artifactId>maven-ect-plugin</artifactId> <version>1.4-SNAPSHOT</version> <configuration> <src>d03b.zip</src> <srcType>UNEDIFACT</srcType> </configuration> <executions> <execution><goals><goal>generate</goal></goals></execution> </executions> </plugin> </plugins>

Wednesday 1 September 2010

Page 14: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI CONVERSION TOOL (ECT)

• d03b-mapping-1.0-SNAPSHOT.jar

org.milyn.edi.unedifact:d03b-mapping:1.0-SNAPSHOT

#UN/EDIFACT Interchange Properties#Sun Aug 08 10:41:40 IST 2010interchangeType=UNEDIFACTinterchangeBindingConfig=/org/milyn/smooks/edi/unedifact/model/r41/bindings/unedifact-interchange.xmlmessageBindingConfig=/org/milyn/smooks/edi/unedifact/model/r41/bindings/unedifact-message.xml

Wednesday 1 September 2010

Page 15: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI CONVERSION TOOL (ECT)

• Future Additions

‣ X12

‣ HL7

‣ TRADACOMS

‣ etc...

Wednesday 1 September 2010

Page 16: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT READER

<unedifact:reader mappingModel="org.milyn.edi.unedifact:d03b-mapping:1.0-SNAPSHOT" />

InputInterchange

Smooks

Output

UNBUNH<message>UNTUNH<message>UNTetc...UNZ

<unEdifact> <UNB> <syntaxIdentifier> <id>UNOA</id> <versionNum>4</versionNum> </syntaxIdentifier> <sender> <id>LOCK</id> <codeQualifier>02</codeQualifier> </sender> </UNB> <interchangeMessage> <UNH> <messageRefNum>PAXLST16</messageRefNum> <messageIdentifier> <id>PAXLST</id> <versionNum>D</versionNum> <releaseNum>03B</releaseNum>

Wednesday 1 September 2010

Page 17: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT READER

UNBUNH

<message>UNTUNH

<message>UNTetc...

UNZ

One

• Nested Execution of the <edi:reader>

Two

Three

Wednesday 1 September 2010

Page 18: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT + JAVA

• Read: EDI Stream Java Objects

• Write: Java Objects EDI Stream

Wednesday 1 September 2010

Page 19: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT + JAVA

• Read: EDI Stream SAX Events Java Objects

• Write: Java Objects EDI Stream

Wednesday 1 September 2010

Page 20: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT + JAVA

• EDI Stream SAX Events

‣ EDI Mapping Models

• SAX Events Java Objects

‣ Smooks Java Binding (<jb:bean> etc)?

ECT

Wednesday 1 September 2010

Page 21: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI JAVA COMPILER (EJC)

• Input: EDI Mapping Model “Zip Set” (from ECT)

‣ e.g. d03b-mapping-1.0-SNAPSHOT.jar

• Output: Compiled Java Object Model

‣ Including <jb:bean> binding configurations

‣ Easy to use Factory Class

‣ e.g. d03b-binding-1.0-SNAPSHOT.jar

Wednesday 1 September 2010

Page 22: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI JAVA COMPILER (EJC)

• Maven & Ant Plugins<plugins> <plugin> <groupId>org.milyn</groupId> <artifactId>maven-ejc-plugin</artifactId> <version>1.4-SNAPSHOT</version> <configuration> <ediMappingModel>urn:org.milyn.edi.unedifact:d03b-mapping:1.0-SNAPSHOT</ediMappingModel> </configuration> <executions> <execution><goals><goal>generate</goal></goals></execution> </executions> <dependencies> <dependency> <groupId>org.milyn.edi.unedifact</groupId> <artifactId>d03b-mapping</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </plugin></plugins>

Wednesday 1 September 2010

Page 23: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI JAVA COMPILER (EJC)

• Read: EDI Stream Java Objects// Create an instance of the EJC generated factory class... cache this and reuse !!!D03BInterchangeFactory factory = D03BInterchangeFactory.getInstance();

// Deserialize the UN/EDIFACT interchange stream to Java...UNEdifactInterchange interchange = factory.fromUNEdifact(ediInStream);

// Need to test which interchange syntax version. Supports v4.1 at the moment...if(interchange instanceof UNEdifactInterchange41) { UNEdifactInterchange41 interchange41 = (UNEdifactInterchange41) interchange;

for(UNEdifactMessage41 message : interchange41.getMessages()) { // Process the messages...

Object messageObj = message.getMessage();

if(messageObj instanceof Invoic) { // It's an INVOIC message.... Invoic invoic = (Invoic) messageObj; ItemDescription itemDescription = invoic.getItemDescription(); // etc etc.... } else if(messageObj instanceof Cuscar) { // It's a CUSCAR message... } else if(etc etc etc...) { // etc etc etc... } }}

Wednesday 1 September 2010

Page 24: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI JAVA COMPILER (EJC)

• Write: Java Objects EDI Stream

factory.toUNEdifact(interchange, ediOutStream);

Wednesday 1 September 2010

Page 25: UN/EDIFACT Interchange Processing  with Smooks v1.4

EDI JAVA COMPILER (EJC)

• Interchange Object Model

public class UNEdifactInterchange41 implements UNEdifactInterchange {

private UNB41 interchangeHeader; private UNZ41 interchangeTrailer ; private List<UNEdifactMessage41> messages;}

public class UNEdifactMessage41 implements UNEdifactMessage {

private UNB41 interchangeHeader; private UNG41 groupHeader; private UNE41 groupTrailer ; private UNH41 messageHeader; private UNT41 messageTrailer ; private Object message;}

Wednesday 1 September 2010

Page 26: UN/EDIFACT Interchange Processing  with Smooks v1.4

DISTRIBUTION

• Maven Central Public Repo

‣ EDI Mapping Model “Zip Sets”

‣ Java Binding Models

<dependency> <groupId>org.milyn.edi.unedifact</groupId> <artifactId>d03b-mapping</artifactId> <version>1.0-SNAPSHOT</version></dependency>

<dependency> <groupId>org.milyn.edi.unedifact</groupId> <artifactId>d03b-binding</artifactId> <version>1.0-SNAPSHOT</version></dependency>

Wednesday 1 September 2010

Page 27: UN/EDIFACT Interchange Processing  with Smooks v1.4

DISTRIBUTION

• Build and distribute as many as possible

‣ Users avoid ECT and EJC steps

‣ Consume/Produce UN/EDIFACT in minutes !!!

‣ SVN Repo (edi/gen)

Wednesday 1 September 2010

Page 28: UN/EDIFACT Interchange Processing  with Smooks v1.4

FUTURE...

Wednesday 1 September 2010

Page 29: UN/EDIFACT Interchange Processing  with Smooks v1.4

WHAT’S NEXT?

• UN/EDIFACT

‣ Support for v3, v4 Interchange Syntax (currently v4.1)

• Make Interchange Splitting & Routing Easy

‣ Output: Java, XML, EDI Fragments

‣ Tight/Simple JBoss ESB, Camel etc Integration

‣ (Currently possible but requires know-how)

• XSD SupportWednesday 1 September 2010

Page 30: UN/EDIFACT Interchange Processing  with Smooks v1.4

WHAT’S NEXT?

• Bean Validation Annotations on EJC generated Models?

• WS, REST Support?

‣ XSD Support provides framework

• Extend Support to X12, HL7 etc

‣ UN/EDIFACT provides framework

Wednesday 1 September 2010

Page 31: UN/EDIFACT Interchange Processing  with Smooks v1.4

EXAMPLES & CODE WALK-THRU

Wednesday 1 September 2010

Page 32: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT TO XMLEXAMPLE

1. Add Mapping Model Dependencies (Zip Sets)

2. Create Smooks Configuration With <unedifact:reader>

3. Execute Smooks runtime on Smooks configuration

Wednesday 1 September 2010

Page 33: UN/EDIFACT Interchange Processing  with Smooks v1.4

UN/EDIFACT - READING & WRITING EXAMPLE

1. Add Mapping Model Dependencies (Java Bindings)

2. Read using Interchange Factory class

3. Write using Interchange Factory class

Wednesday 1 September 2010