Skip to content

Commit

Permalink
Merge pull request #35 from RDPerera/version-bump
Browse files Browse the repository at this point in the history
Add updated documentation to module.md
  • Loading branch information
niveathika authored Mar 13, 2024
2 parents 1c93352 + 1283fd8 commit cccaee3
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 156 deletions.
156 changes: 78 additions & 78 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
## Module Overview
## Overview

EDI module provides functionality to convert EDI text to json and json to EDI text. Schema of EDI files have to be provided in json format.
Electronic Data Interchange (EDI) is a technology designed to facilitate the electronic transfer of business documents among various organizations. This system empowers businesses to seamlessly exchange standard business transactions like purchase orders, invoices, and shipping notices. These transactions are formatted in a structured, computer-readable manner, eliminating the reliance on paper-based processes and manual data entry. Consequently, EDI technology significantly boosts efficiency and minimizes errors in the business-to-business (B2B) communication landscape.

## Compatibility
The Ballerina EDI module offers robust functionality for the effortless conversion of EDI text to JSON, and inversely, JSON to EDI. Tailored to augment integration capabilities, this module is a key component in enhancing the handling of EDI data within Ballerina applications. It provides a more streamlined, efficient approach, ensuring seamless data management and integration in business processes.

| | Version |
|:---------------------------------:|:---------------------:|
| Ballerina Language | 2201.8.4 |
| Java Development Kit (JDK) | 17 |
## Define EDI Schema

## Example
Before utilizing the EDI parser, it is crucial to define the structure of the EDI data intended for import. Developers can refer the [Ballerina EDI Schema Specification](./docs/specs/SchemaSpecification.md) for guidance. This specification outlines the essential elements necessary to describe an EDI schema, covering attributes such as name, delimiters, segments, field definitions, components, sub-components, and additional configuration options.

A simple EDI schema is shown below (let's assume that this is saved in edi-schema1.json file):
As an illustrative example, consider the following EDI schema definition for a _simple order_, assumed to be stored as "schema.json":

````json
```json
{
"name": "SimpleOrder",
"delimiters" : {"segment" : "~", "field" : "*"},
"segments" : {
"HDR": {
"delimiters" : {"segment" : "~", "field" : "*", "component": ":", "repetition": "^"},
"segments" : [
{
"code": "HDR",
"tag" : "header",
"fields" : [{"tag" : "code"}, {"tag" : "orderId"}, {"tag" : "organization"}, {"tag" : "date"}]
"minOccurances": 1,
"fields" : [{"tag": "code"}, {"tag" : "orderId"}, {"tag" : "organization"}, {"tag" : "date"}]
},
"ITM": {
{
"code": "ITM",
"tag" : "items",
"maxOccurances" : -1,
"fields" : [{"tag" : "code"}, {"tag" : "item"}, {"tag" : "quantity", "dataType" : "int"}]
"fields" : [{"tag": "code"}, {"tag" : "item"}, {"tag" : "quantity", "dataType" : "int"}]
}
}
]
}
````
```

Above schema can be used to parse EDI documents with one HDR segment (mapped to "header") and any number of ITM segments (mapped to "items"). HDR segment contains three fields, which are mapped to "orderId", "organization" and "date". Each ITM segment contains two fields mapped to "item" and "quantity". Below is a sample EDI document that can be parsed using the above schema (let's assume that below EDI is saved in edi-sample1.edi file):
This schema can be used to parse EDI documents featuring one HDR segment, mapped to _header_, and any number of ITM segments, mapped to _items_. The HDR segment incorporates three _fields_, corresponding to _orderId_, _organization_, and _date_. Each ITM segment comprises two fields, mapped to _item_ and _quantity_.

````edi
Below is an example of an EDI document that can be parsed using the aforementioned schema. Let's assume that the following EDI information is saved in a file named 'sample.edi':

```
HDR*ORDER_1201*ABC_Store*2008-01-01~
ITM*A-250*12
ITM*A-45*100
ITM*D-10*58
ITM*K-80*250
ITM*T-46*28
````
ITM*A-250*12~
ITM*A-45*100~
ITM*D-10*58~
ITM*K-80*250~
ITM*T-46*28~
```

### Reading EDI files
## Reading EDI Files

Below code reads the edi-sample1.edi into a json variable named "orderData".
The utility functions in EDI package allows you to read Electronic Data Interchange (EDI) files and convert them into JSON data. Here's a quick example demonstrating how to read an EDI file, parse it using a defined schema, and print the resulting JSON data:

````ballerina
```ballerina
import ballerina/io;
import balarina/edi;
import ballerina/edi;
public function main() returns error? {
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/edi-schema1.json"));
string ediText = check io:fileReadString("resources/edi-sample1.edi");
// Step 1: Load EDI schema from a JSON file
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/schema.json"));
// Step 2: Read the EDI file as a string
string ediText = check io:fileReadString("resources/sample.edi");
// Step 3: Convert EDI string to JSON using the specified schema
json orderData = check edi:fromEdiString(ediText, schema);
// Step 4: Print the resulting JSON data
io:println(orderData.toJsonString());
}
````
"orderData" json variable value will be as follows (i.e. output of io:println(orderData.toJsonString())):
```

````json
{
"header": {
"code": "HDR",
"orderId": "ORDER_1201",
"organization": "ABC_Store",
"date": "2008-01-01"
},
"items": [
{
"code": "ITM",
"item": "A-250",
"quantity": 12
},
{
"code": "ITM",
"item": "A-45",
"quantity": 100
},
{
"code": "ITM",
"item": "D-10",
"quantity": 58
},
{
"code": "ITM",
"item": "K-80",
"quantity": 250
},
{
"code": "ITM",
"item": "T-46",
"quantity": 28
}
]
}
````
In this example, the EDI file (`sample.edi`) is read, and its content is converted into a JSON variable named `orderData`. The JSON variable structure corresponds to the expected output.

### Writing EDI files
## Writing EDI Files

Ballerina EDI module can also convert JSON data into EDI texts, based on a given schema. Below code demonstrates the conversion of a json data to EDI text based on the schema used in the above example:
Furthermore, edi module provides functionality to convert JSON data into EDI text using a specified schema. The following code snippet demonstrates how to create a JSON variable representing an order and convert it into an EDI string:

````ballerina
```ballerina
import ballerina/io;
import balarinax/edi;
import ballerina/edi;
public function main() returns error? {
json order2 = {...};
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/edi-schema1.json"));
// Step 1: Create a JSON variable representing an order
json order2 = {
"header": {
"code": "HDR",
"orderId": "ORDER_1201",
"organization": "ABC_Store",
"date": "2008-01-01"
},
"items": [
{
"code": "ITM",
"item": "A-250",
"quantity": 12
},
{
"code": "ITM",
"item": "B-250",
"quantity": 10
} // ... Additional items ...
]
};
// Step 2: Load the EDI schema from a JSON file
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/schema.json"));
// Step 3: Convert the JSON order data to EDI string using the schema
string orderEDI = check edi:toEdiString(order2, schema);
// Step 4: Print the resulting EDI string
io:println(orderEDI);
}
````
```

In this example, the `order2` JSON variable is converted into an EDI string using the specified schema, and the resulting EDI string is printed. This demonstrates the capability of the Ballerina EDI module to seamlessly convert JSON data into EDI format.
156 changes: 78 additions & 78 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,114 @@
## Module Overview
## Overview

EDI module provides functionality to convert EDI text to json and json to EDI text. Schema of EDI files have to be provided in json format.
Electronic Data Interchange (EDI) is a technology designed to facilitate the electronic transfer of business documents among various organizations. This system empowers businesses to seamlessly exchange standard business transactions like purchase orders, invoices, and shipping notices. These transactions are formatted in a structured, computer-readable manner, eliminating the reliance on paper-based processes and manual data entry. Consequently, EDI technology significantly boosts efficiency and minimizes errors in the business-to-business (B2B) communication landscape.

## Compatibility
The Ballerina EDI module offers robust functionality for the effortless conversion of EDI text to JSON, and inversely, JSON to EDI. Tailored to augment integration capabilities, this module is a key component in enhancing the handling of EDI data within Ballerina applications. It provides a more streamlined, efficient approach, ensuring seamless data management and integration in business processes.

| | Version |
|:---------------------------------:|:---------------------:|
| Ballerina Language | 2201.8.4 |
| Java Development Kit (JDK) | 17 |
## Define EDI Schema

## Example
Before utilizing the EDI parser, it is crucial to define the structure of the EDI data intended for import. Developers can refer the [Ballerina EDI Schema Specification](./docs/specs/SchemaSpecification.md) for guidance. This specification outlines the essential elements necessary to describe an EDI schema, covering attributes such as name, delimiters, segments, field definitions, components, sub-components, and additional configuration options.

A simple EDI schema is shown below (let's assume that this is saved in edi-schema1.json file):
As an illustrative example, consider the following EDI schema definition for a _simple order_, assumed to be stored as "schema.json":

````json
```json
{
"name": "SimpleOrder",
"delimiters" : {"segment" : "~", "field" : "*"},
"segments" : {
"HDR": {
"delimiters" : {"segment" : "~", "field" : "*", "component": ":", "repetition": "^"},
"segments" : [
{
"code": "HDR",
"tag" : "header",
"fields" : [{"tag" : "code"}, {"tag" : "orderId"}, {"tag" : "organization"}, {"tag" : "date"}]
"minOccurances": 1,
"fields" : [{"tag": "code"}, {"tag" : "orderId"}, {"tag" : "organization"}, {"tag" : "date"}]
},
"ITM": {
{
"code": "ITM",
"tag" : "items",
"maxOccurances" : -1,
"fields" : [{"tag" : "code"}, {"tag" : "item"}, {"tag" : "quantity", "dataType" : "int"}]
"fields" : [{"tag": "code"}, {"tag" : "item"}, {"tag" : "quantity", "dataType" : "int"}]
}
}
]
}
````
```

Above schema can be used to parse EDI documents with one HDR segment (mapped to "header") and any number of ITM segments (mapped to "items"). HDR segment contains three fields, which are mapped to "orderId", "organization" and "date". Each ITM segment contains two fields mapped to "item" and "quantity". Below is a sample EDI document that can be parsed using the above schema (let's assume that below EDI is saved in edi-sample1.edi file):
This schema can be used to parse EDI documents featuring one HDR segment, mapped to _header_, and any number of ITM segments, mapped to _items_. The HDR segment incorporates three _fields_, corresponding to _orderId_, _organization_, and _date_. Each ITM segment comprises two fields, mapped to _item_ and _quantity_.

````edi
Below is an example of an EDI document that can be parsed using the aforementioned schema. Let's assume that the following EDI information is saved in a file named 'sample.edi':

```
HDR*ORDER_1201*ABC_Store*2008-01-01~
ITM*A-250*12
ITM*A-45*100
ITM*D-10*58
ITM*K-80*250
ITM*T-46*28
````
ITM*A-250*12~
ITM*A-45*100~
ITM*D-10*58~
ITM*K-80*250~
ITM*T-46*28~
```

### Reading EDI files
## Reading EDI Files

Below code reads the edi-sample1.edi into a json variable named "orderData".
The utility functions in EDI package allows you to read Electronic Data Interchange (EDI) files and convert them into JSON data. Here's a quick example demonstrating how to read an EDI file, parse it using a defined schema, and print the resulting JSON data:

````ballerina
```ballerina
import ballerina/io;
import balarina/edi;
import ballerina/edi;
public function main() returns error? {
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/edi-schema1.json"));
string ediText = check io:fileReadString("resources/edi-sample1.edi");
// Step 1: Load EDI schema from a JSON file
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/schema.json"));
// Step 2: Read the EDI file as a string
string ediText = check io:fileReadString("resources/sample.edi");
// Step 3: Convert EDI string to JSON using the specified schema
json orderData = check edi:fromEdiString(ediText, schema);
// Step 4: Print the resulting JSON data
io:println(orderData.toJsonString());
}
````
"orderData" json variable value will be as follows (i.e. output of io:println(orderData.toJsonString())):
```

````json
{
"header": {
"code": "HDR",
"orderId": "ORDER_1201",
"organization": "ABC_Store",
"date": "2008-01-01"
},
"items": [
{
"code": "ITM",
"item": "A-250",
"quantity": 12
},
{
"code": "ITM",
"item": "A-45",
"quantity": 100
},
{
"code": "ITM",
"item": "D-10",
"quantity": 58
},
{
"code": "ITM",
"item": "K-80",
"quantity": 250
},
{
"code": "ITM",
"item": "T-46",
"quantity": 28
}
]
}
````
In this example, the EDI file (`sample.edi`) is read, and its content is converted into a JSON variable named `orderData`. The JSON variable structure corresponds to the expected output.

### Writing EDI files
## Writing EDI Files

Ballerina EDI module can also convert JSON data into EDI texts, based on a given schema. Below code demonstrates the conversion of a json data to EDI text based on the schema used in the above example:
Furthermore, edi module provides functionality to convert JSON data into EDI text using a specified schema. The following code snippet demonstrates how to create a JSON variable representing an order and convert it into an EDI string:

````ballerina
```ballerina
import ballerina/io;
import balarinax/edi;
import ballerina/edi;
public function main() returns error? {
json order2 = {...};
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/edi-schema1.json"));
// Step 1: Create a JSON variable representing an order
json order2 = {
"header": {
"code": "HDR",
"orderId": "ORDER_1201",
"organization": "ABC_Store",
"date": "2008-01-01"
},
"items": [
{
"code": "ITM",
"item": "A-250",
"quantity": 12
},
{
"code": "ITM",
"item": "B-250",
"quantity": 10
} // ... Additional items ...
]
};
// Step 2: Load the EDI schema from a JSON file
edi:EdiSchema schema = check edi:getSchema(check io:fileReadJson("resources/schema.json"));
// Step 3: Convert the JSON order data to EDI string using the schema
string orderEDI = check edi:toEdiString(order2, schema);
// Step 4: Print the resulting EDI string
io:println(orderEDI);
}
````
```

In this example, the `order2` JSON variable is converted into an EDI string using the specified schema, and the resulting EDI string is printed. This demonstrates the capability of the Ballerina EDI module to seamlessly convert JSON data into EDI format.

0 comments on commit cccaee3

Please sign in to comment.