This IBM Integration Bus V10 Open Beta technology tutorial demonstrates how you can transform data from one format to another by using the Graphical Data Mapping editor. In this particular scenario, the Graphical Data Mapping editor is used to transform messages between the DFDL modelling language and the JSON data format.
An IBM Integration Bus message map is used to transform data from an input file that contains vCard records into multiple JSON messages. The content of the data is also validated. Depending on the information included in each record, the corresponding JSON message produced might be a reject message or a valid message.
Whether you are an experienced IBM Integration Bus developer or just starting to use the product, you can use this tutorial to learn how to achieve the following tasks:
Note: An IBM user ID is required. If you do not already have an IBM user ID, you can create one using a link on the IBM Integration Bus V10 Open Beta web page.
You can also watch an installation video. See IBM Integration Bus V10 Open Beta installation video.
You have imported the initial PI file.
The following screen capture shows IBM Integration Bus Toolkit after you import the tutorial PI file, with some of the elements expanded:
To complete the steps in this section, you must have IBM Integration Bus Toolkit open.
A message map is the IBM Integration Bus implementation of a graphical data map. It is based on XML schema and XPath 2.0 standards. But you can also transform JSON data.
For more information, see Message maps.
Outside of this tutorial, if you want to map messages between unlike domains, it might be necessary to set the MessageSet, the MessageType, and the MessageFormat elements within the Properties tree of the output message assembly.
The fields that need setting in such cases will depend on the target parser associated with the output message domain (JSON, SOAP, etc.). When you create a new map, the Graphical Data Mapping editor will add an Override group of transforms that includes a Move and an Assign transform, which are used to set default values for these elements in the output.
For more information, see the following documentation available in IBM Knowledge Center:
Complete the following steps to create a message map in the Application Development view of IBM Integration Bus Toolkit:
Note: Ensure that you select the vCard check box and not the vCards check box.
You have created your Transform_vCards_into_JSON_Mapping message map.
The map opens in the Graphical Data Mapping editor. The following screen capture shows the message map, with some of the elements expanded:
A user-defined element is an element that you can add directly into a message map to define the data of an extension point, shown as any or anyAttribute in the map. You can add user-defined elements to define extension points in any of the following message assembly components:
You can also use user-defined elements to define a JSON message, and a SOAP or XML message that has an xsd:any in a message map.
You can add any of the following types of user-defined elements:
For more information, see Defining user-defined elements.
A JSON message consists of name-value pairs, which are known as JSON objects, and ordered collections of values, which are known as JSON arrays.
For more information, see Creating or transforming a JSON output message by using a message map.
This tutorial demonstrates how you can transform data held in vCard records into the following JSON message output:
The JSON message includes the following elements:
Row | Element name | Graphical Data Mapping editor data type | JSON element data type | Cardinality |
---|---|---|---|---|
1 | Operation | string | JSON object | Mandatory (1..1) |
2 | ClientDetails | Anonymous | JSON array | Mandatory (1..1) |
The JSON array ClientDetails contains the following elements:
Row | Element name | Graphical Data Mapping editor data type | JSON element data type | Cardinality |
---|---|---|---|---|
1 | Title | string | JSON object | Mandatory (1..1) |
2 | Name | string | JSON object | Mandatory (1..1) |
3 | LastName | string | JSON object | Mandatory (1..1) |
4 | string | JSON object | Mandatory (1..1) | |
5 | WorkAddress | Anonymous | JSON array | Optional (0..1) |
6 | HomeAddress | Anonymous | JSON array | Mandatory (1..1) |
7 | OtherAddress | boolean | JSON object | Optional (0..1) |
The JSON array WorkAddress contains the following elements:
Row | Element name | Graphical Data Mapping editor data type | JSON element data type | Cardinality |
---|---|---|---|---|
1 | Street | string | JSON object | Mandatory (1..1) |
2 | Region | string | JSON object | Mandatory (1..1) |
3 | PostalCode | string | JSON object | Mandatory (1..1) |
4 | Country | string | JSON object | Mandatory (1..1) |
The JSON array HomeAddress contains the following elements:
Row | Element name | Graphical Data Mapping editor data type | JSON element data type | Cardinality |
---|---|---|---|---|
1 | Street | string | JSON object | Mandatory (1..1) |
2 | City | string | JSON object | Mandatory (1..1) |
3 | PostalCode | string | JSON object | Mandatory (1..1) |
4 | Country | string | JSON object | Mandatory (1..1) |
NOTE: By default, when you use the Add User-Defined function, each new element is created as a string element. However, in this tutorial, you need to edit the data type and cardinality of certain elements, as indicated in the section entitled "The JSON message output and data structure" above.
Note: Remember to edit the data type and cardinality of the child elements in accordance with the information provided in the section entitled "The JSON message output and data structure" above.
After you complete the previous steps, the JSON message that you define looks like the one in the following screen capture:
To implement the conditional expression that is used to determine whether the If transform is applied or not, you must configure the If transform properties. You define an XPath 2.0 expression expression within the Condition tab of the transform Properties.
Background information:
Background information:
Background information:
After you define and configure the transformations associated with the conditional transform, the If transform and the Else transform display warning symbols. These warnings indicate that there is a mismatch between the cardinality of elements in the vCard object and the JSON message.
The vCard elements can be repeating, that is, they have a cardinality of 0..*. The JSON messages are non-repeating elements. The Graphical Data Mapping editor requires clear configuration of the indexes that should be applied on each transformation.
By default, the Graphical Data Mapping editor uses the first index if none are specified.
In the Graphical Data Mapping editor, you can use transforms, cast functions, and XPath 2.0 functions to run different actions on input
data and move the result to the output element. You choose the appropriate mapping operation that is based on the result that you want
to achieve. For more information, see Transforms (Mapping operations).
You can map elements and attributes between the input and output objects.
You can apply a transform to the mapping that specifies the action to
be performed on the input data. The result of the transform is stored
in the output element. For more information on the standard mapping
transforms that are provided by the Graphical Data Mapping editor, see Transform types in the Graphical Data Mapping editor.
When you create a connection between two or more elements, a transform is assigned, based on the number and type of input elements. You can then change the transform by choosing from a list of available transforms. If a particular transform type is not shown in the list, that transform is not valid for your input and output elements.
Add a transform between an input element and an output element:
Change the default transform to an If transform:
NOTE: The If transform must have a condition defined.
By default, as soon as the If transform is defined in the map, an information message is displayed to alert you that a conditional expression must be configured.
Define the conditional expression of an If transform to remove the error:
Background informationNote: Always use the content assist tool (Ctrl+Space)to obtain the element name used by the Graphical Data Mapping editor. If you copy and paste the expression provided, the solution might not work as expected.
The following figure shows the entire conditional expression:
TIP: If you cannot see the Properties view for the transform, it might be that you have the message map maximized in your workspace. Complete the following steps to open the Properties view for the transform:
Add the Else transform associated with the If transform:
Background information:
When the Else transform is added, both the If transform and the Else transform are grouped within a container named Conditions.
Also, when the Else transform is added, a warning icon is displayed on the left side of the transform.
This warning exists to highlight the fact that you must define transformations within the nested map of the Else transform. You will define the required transforms, and therefore remove this warning, at a later stage in this tutorial.
Define the input connections to the Else transform:
Background informationDefine additional output connections to the If transform:
Background informationNOTE: The first connection to the Operation element is automatically defined when you add the If transform to the map.
Define the output connections to the Else transform:
Define the transformation logic that must be applied when the If condition evaluates to true:
NOTE: A For each transform is automatically defined. Because DeliveryAddress is a repeating element, the only transforms that are permitted are ones that transform repeating structures.
NOTE: Remember to use control assist (CTRL+Space) to select the element $DeliveryAddress/Parameter.
Background information:
To define transformations in the nested map, the Graphical Data Mapping editor provides you with a QuickFix
represented by a lightbulb icon in the transform. The suggestion allows you to invoke Automap.
For more information, see Mapping input to output elements automatically
Tip: To return to the main map, click the arrow on the right hand side until you are back on the main map view.
Define the transformation logic that must be applied for the Else transform:
Remove the warnings displayed in the If transform, and in the Else transform:
Background informationIn this tutorial, we only pass one instance of each element. To remove the warning of the If transform, you must complete the following steps:
You have added a conditional transform to your message map.
In IBM Integration Bus, you use the Mapping node to graphically construct one or more new messages and populate them with various types of information. A message map is the resource that you create to configure a Mapping node. For more information, see
Mapping node.
To assign a message map to a Mapping node, complete the following steps:
After you complete the steps to assign a map to a Mapping node, the Properties tab of the Mapping node looks as follows:
The Integration Nodes view of the IBM Integration Bus Toolkit displays the default integration node named TESTNODE_name_of_your_system and other integration nodes that you have defined. Integration nodes can be local or remote.
If you expand an integration node, all the integration servers in it are displayed, as well as deployed resources.
In IBM Integration Bus, after you develop your solution, you deploy your integration solution to one or more integration servers.
For more information, see Packaging and deploying.
There are different methods that you can use to deploy your solutions. For example, you can drag the application project and related library projects from the Application Development view onto the default integration server. Alternatively, you can right-click an integration server and click Deploy to select the library or application. This method is the one demonstrated in this tutorial.
Your IBM Integration Bus Toolkit should look like the following figure:
This tutorial includes three files to help you test the solution: