Skip to content

Latest commit

 

History

History
205 lines (173 loc) · 11.3 KB

README.md

File metadata and controls

205 lines (173 loc) · 11.3 KB

Apache Camel F2F tooling hackathon (go back)

Lab 2: Perform a data transformation

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>

Prerequisites

Instructions

  1. Ensure that the opened folder in VS Code is lab2 (and not a parent one). This is critical to successfully follow this tutorial.

  2. Open CreateOrder-template.yaml file

  3. Run the Camel route before making a change and see Cart XML is printed in the terminal

    • Click quick editor action Run with JBang ... button Click Run with JBang button
    • Notice the Cart XML is printed in the terminal. Without adding a DataMapper step, The Camel Message Body delivers Cart XML alone. Cart XML is printed
  4. Append a Kaoto Data Mapper step between the last direct and the log

    • Right-click on the last direct
    • Select Append Append a DataMapper step
    • Type datamapper in search field and pick the Kaoto data mapper Select a DataMapper step in the catalog
    • Notice the added Kaoto data mapper step Click added DataMapper step
  5. Select the Kaoto data mapper step to open the Configuration panel

  6. Click Configure button in the config panel Click DataMapper configure button

  7. Notice the Data mapper interface DataMapper canvas

  8. Attach schema for Target body

    • In Target part (at the right), click on the button to Attach a schema Click "Attach a schema" button for Target Body Document
    • Select xsd/ShipOrder.xsd Select "xsd/ShipOrder.xsd"
    • Notice the schema displayed as a Tree ShipOrder schema is attached to the Target Body Document
  9. Attach schema for source body

    • In Source part (at the left), click on the button to Attach a schema Click "Attach a schema" button for Source Body Document
    • Select xsd/Card.xsd Select "xsd/Card.xsd"
    • Notice the schema displayed as a Tree Cart schema is attached to the Source Body Document
  10. Add account parameter to consume Account XML stored in the account Camel Variable

  • In Source part, click on the + icon to add a parameter Click "Add a parameter" button
  • Provide parameter name account Add a parameter "account" Parameter "account" is added
  1. Attach schema to the account parameter
  • Click attach a schema button next to the account parameter Click "Attach a schema" button for the parameter "account"
  • Select xsd/Account.xsd Select "xsd/Account.xsd"
  • Notice the schema displayed as a Tree Account schema is attached to the parameter "account"
  1. Add orderSequence parameter to consume an order sequence number stored in the orderSequence Camel Variable
  • In Source part, click on the + icon to add a parameter Click "Add a parameter" button
  • Provide parameter name orderSequence Add a parameter "orderSequence" Parameter "orderSequence" added
  1. Drag /Account/Name property of account parameter and Drop to Target /ShipOrder/ShipTo/Name Drag "/Account/Name" property of account parameter and Drop to Target "/ShipOrder/ShipTo/Name"

  2. Repeat Drag and Drop for Address, City and Country Repeat Drag and Drop for "Address", "City" and "Country"

  3. Configure OrderPerson by concatenating Name and AccountId

  • Drag /Account/@AccountId of account parameter and Drop to Target /ShipOrder/OrderPerson Drag "/Account/@AccountId" of account parameter and Drop to Target "/ShipOrder/OrderPerson"
  • Drag /Account/Name 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 a pencil button of Target "/ShipOrder/OrderPerson" to open XPath Editor
  • Click Function tab Click "Function" tab
  • Drag and Drop Concatenate function onto the text editor area on the right Drag "Concatenate" and Drop onto right text editor
  • The concat() function is applied in the XPath expression The "concat()" function is applied in the XPath expression
  • Edit the XPath expression and add colon : in between 2 fields Edit the XPath expression and add colon ":" in between 2 fields
  • Close the XPath editor Close XPath Editor
  1. Configure OrderId by concatenating AccountId and orderSequence
  • Drag /Account/@AccountId of account parameter and Drop to Target /ShipOrder/@OrderId Drag "/Account/@AccountId" of account parameter and Drop to Target "/ShipOrder/@OrderId"
  • Drag orderSequence 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 a pencil button of Target "/ShipOrder/@OrderId"
  • Click Function tab Click "Function" tab
  • Drag and Drop Concatenate function onto the text editor area on the right Drap "Concatenate" and Drop onto right text editor
  • The concat() function is applied in the XPath expression The "concat()" function is applied in the XPath expression
  • Edit the XPath expression and add ORDER- as prefix Add "ORDER-" prefix as a string literal
  • Edit the XPath expression and add dash - between the 2 fields Add "-" separator in between "AccountId" and "orderSequence"
  • Close the XPath editor Close XPath Editor
  1. Configure Item, elements of a list
  • Click 3-dot context menu of Target /ShipOrder/Item Click 3-dot context menu of Target "/ShipOrder/Item"
  • Select Wrap with for-each Select "Wrap with for-each"
  • Drag /Cart/Item of Source Body and Drop to Target for-each Drag "/Cart/Item" of Source Body and Drop to Target "for-each"
  • Drag and Drop all children of Item Drag and Drop all children of "Item"
  1. Click Design tab to go back to Kaoto route editor Click "Design" tab and go back to the Kaoto Canvas

  2. Click quick editor action Run with JBang ... button to run the Camel route Click Run with JBang

  3. Check the output

  • Notice the ShipOrder XML is successfully printed in the terminal ShipOrder XML printed in the console
  1. Congratulations you configured by point and click a data transformation including direct mapping but also data transformation.