Apache Camel F2F tooling hackathon (go back)
The goal of this lab is to perform a data transformation. We will use the Kaoto Data mapper component to showcase how we can easily achieve it using an UI and leveraging the Apache Camel functionality.
We're gonna start from an existing Apache Camel Route (CreateOrder-template) that simulates fetching information from external systems, namely Account
from GetAccount
direct route and Cart
from GetCart
direct route, as well as an order sequence number fetching from GetOrderSequence
direct route. And then transforming and combining them into a new ShipOrder
format. For this purpose, appropriate XML schemas are provided in the xsd
folder.
While Cart
is stored in Camel Message Body, Account
and order sequence number are stored in Camel Variables. The variable names are account
and orderSequence
. In the DataMapper step we will configure later, These Camel Variables are consumed as Parameters
.
Here's an example of the Account
object:
<kaoto:Account AccountId="acc001" xmlns:kaoto="kaoto.datamapper.test">
<Name>Jane Doe</Name>
<Address>Purkyňova 111, 612 00</Address>
<City>Brno-Medlánky</City>
<Country>Česká republika</Country>
</kaoto:Account>
And the Cart
object:
<kaoto:Cart xmlns:kaoto="kaoto.datamapper.test">
<Item>
<Title>Shadowman T-shirts</Title>
<Note>XL</Note>
<Quantity>10</Quantity>
<Price>25.00</Price>
</Item>
<Item>
<Title>Kaoto T-shirts</Title>
<Note>L</Note>
<Quantity>5</Quantity>
<Price>24.50</Price>
</Item>
</kaoto:Cart>
The desired output is the ShipOrder
object:
<ShipOrder xmlns="io.kaoto.datamapper.poc.test"
xmlns:ns0="kaoto.datamapper.test"
OrderId="ORDER-acc001-nnnn">
<OrderPerson>acc001:Jane Doe</OrderPerson>
<ShipTo xmlns="">
<Name>Jane Doe</Name>
<Address>Purkyňova 111, 612 00</Address>
<City>Brno-Medlánky</City>
<Country>Česká republika</Country>
</ShipTo>
<Item xmlns="">
<Title>Shadowman T-shirts</Title>
<Note>XL</Note>
<Quantity>10</Quantity>
<Price>25.00</Price>
</Item>
<Item xmlns="">
<Title>Kaoto T-shirts</Title>
<Note>L</Note>
<Quantity>5</Quantity>
<Price>24.50</Price>
</Item>
</ShipOrder>
- Install VS code.
- Install the Extension pack for Apache Camel by Red Hat in VS Code.
- Install the Kaoto editor extension provided in the
vsix
folder (i.e.code --install-extension vsix/vscode-kaoto-2024-camel-F2F-hackathon-001.vsix
). - Install JBang CLI.
-
Ensure that the opened folder in VS Code is
lab2
(and not a parent one). This is critical to successfully follow this tutorial. -
Open CreateOrder-template.yaml file
-
Run the Camel route before making a change and see
Cart
XML is printed in the terminal -
Append a Kaoto Data Mapper step between the last direct and the log
-
Select the Kaoto data mapper step to open the Configuration panel
-
Attach schema for Target body
-
Attach schema for source body
-
Add
account
parameter to consumeAccount
XML stored in theaccount
Camel Variable
- Attach schema to the
account
parameter
- Click
attach a schema
button next to theaccount
parameter - Select
xsd/Account.xsd
- Notice the schema displayed as a Tree
- Add
orderSequence
parameter to consume an order sequence number stored in theorderSequence
Camel Variable
-
Drag
/Account/Name
property of account parameter and Drop to Target/ShipOrder/ShipTo/Name
-
Configure OrderPerson by concatenating Name and AccountId
- Drag
/Account/@AccountId
of account parameter and Drop to Target/ShipOrder/OrderPerson
- Drag
/Account/Name
of account parameter and Drop to Target/ShipOrder/OrderPerson
- Click the pencil button of Target
/ShipOrder/OrderPerson
to open the XPath Editor - Click
Function
tab - Drag and Drop
Concatenate
function onto the text editor area on the right - The
concat()
function is applied in the XPath expression - Edit the XPath expression and add colon
:
in between 2 fields - Close the XPath editor
- Configure OrderId by concatenating AccountId and orderSequence
- Drag
/Account/@AccountId
of account parameter and Drop to Target/ShipOrder/@OrderId
- Drag
orderSequence
parameter and Drop to Target/ShipOrder/@OrderId
- Click the pencil button of Target
/ShipOrder/@OrderId
to open the XPath Editor - Click
Function
tab - Drag and Drop
Concatenate
function onto the text editor area on the right - The
concat()
function is applied in the XPath expression - Edit the XPath expression and add
ORDER-
as prefix - Edit the XPath expression and add dash
-
between the 2 fields - Close the XPath editor
- Configure Item, elements of a list
- Click 3-dot context menu of Target
/ShipOrder/Item
- Select
Wrap with for-each
- Drag
/Cart/Item
of Source Body and Drop to Targetfor-each
- Drag and Drop all children of
Item
- Congratulations you configured by point and click a data transformation including direct mapping but also data transformation.