Skip to content

Add the EDI purchase order processing sample - #161

Draft
niveathika wants to merge 2 commits into
wso2:mainfrom
niveathika:samples/edi-order-processing
Draft

Add the EDI purchase order processing sample#161
niveathika wants to merge 2 commits into
wso2:mainfrom
niveathika:samples/edi-order-processing

Conversation

@niveathika

Copy link
Copy Markdown
Member

Purpose

The finished code for a new how-to guide, Process Inbound EDI Purchase Orders from Trading Partners, which documents the envelope-aware ballerina/edi API (ballerina-spec#1441). The docs PR follows in wso2/docs-integrator and links here.

There is no EDI sample in this repository today.

The sample

integrator-default-profile/samples/edi-purchase-order-processing — a workspace with the integration and the generated EDI library:

  1. Identify the partner without a schema. edi:edifactHeadersFromEdiFile reads the UNB envelope — only the first 512 characters of the file — and the integration stops there if the sender is not the expected partner.
  2. Parse the orders with the generated library. interchangeFromEdiString reads the whole envelope hierarchy. Envelope segments are fail-fast; transaction bodies are fail-safe, so the message that cannot be read is quarantined with its parse error while the other two orders are processed.

The bundled orders.edi holds two valid orders and a third message missing its mandatory BGM segment, so both paths are exercised on every run.

Verified with bal run:

level=INFO  message="Order file from SUPERMART, reference REF2"
level=INFO  message="Order PO20001 received from SUPERMART"
level=INFO  message="Order PO20002 received from SUPERMART"
level=ERROR message="Quarantined message" reference="0003" error="Mandatory unit is missing in the EDI. Unit: Segment BGM ..."

Notes

  • The schema in schema/ORDERS.json was generated from the free UN/EDIFACT D03A directory and then adjusted for the partner: the line-item QTY segment, optional in the standard, is required here because this partner always sends it. That edit is the point of shipping the schema alongside the generated library — it is the record of what the partner actually sends, and README.md documents how to regenerate both.
  • No X12 sample: X12 specifications are licensed from ASC X12, so there is nothing publicly redistributable to build one from. The flow is identical for X12 given a licensed schema.

Reads an inbound EDIFACT interchange, identifies the trading partner from
the envelope without a schema, then parses the orders with the generated
library. A message the schema cannot read is quarantined with its parse
error and the rest of the interchange is still processed.

The schema comes from the free UN/EDIFACT D03A directory, adjusted for a
partner that always sends a line-item quantity the standard leaves
optional.
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ddbd1822-6c46-4e77-8e6a-74270634cfce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Explain that the sample generates a library because the schema is adjusted
for this partner, and that an unmodified standard ORDERS message can use
ballerinax/edifact.d03a.supplychain directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant