0
votes

enter image description here

I have two XML streams from Bigcommerce API. One XML stream contains the order information, the other stream contains the line items (products). I am attempting to combine the two XML streams with dataweave and get one xml document as the output. When I run the flow as attached I do not get all products, but only one set of products (the first set)

==================================================================

Here is the order.xml stream:

<?xml version="1.0"?>
<order>
<id>40144</id>
<date>2016-05-01</date>
</order>

Here is the products stream (notice we will have multiple products here):

<?xml version="1.0"?>
<products>
<product>
<id>1234</id>
<order_id>40144</order_id>
<product_id>12345</product_id>
<order_address_id>12</order_address_id>
<name>Widget</name>
</product>
<product>
<id>53245</id>
<order_id>40144</order_id>
<product_id>56435</product_id>
<order_address_id>12</order_address_id>
<name>Super Widget</name>
</product>
</products>

Here is the Mule flow config (system variables changed)

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps"
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" 
xmlns:imap="http://www.mulesoft.org/schema/mule/imap" 
xmlns="http://www.mulesoft.org/schema/mule/core" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/xml 
http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/imaps 
http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core 
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http 
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/imap 
http://www.mulesoft.org/schema/mule/imap/current/mule-imap.xsd
http://www.mulesoft.org/schema/mule/objectstore 
http://www.mulesoft.org/schema/mule/objectstore/current/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/ee/dw 
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<imaps:connector name="IMAP" backupFolder="backup" validateConnections="true" backupEnabled="true" checkFrequency="900" doc:name="IMAP"/>
<http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="myserver.net" port="443" doc:name="HTTP Request Configuration">
    <http:basic-authentication username="user" password="password"/>
</http:request-config>
<flow name="scattgathFlow">
    <imaps:inbound-endpoint host="192.168.1.1" port="993" responseTimeout="10000" user="user" password="password" doc:name="IMAP" connector-ref="IMAP"/> 
    <set-variable doc:name="Variable" value="#[message.inboundProperties.subject.replaceAll('[^0-9\\-]', '')]" variableName="email_subj"/>
    <http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]" method="GET" doc:name="HTTP" metadata:id="72233863-af08-4d0d-9a75-5b726b6d117e">
    </http:request> 
    <!--  Sub flow to retrieve products -->  
    <flow-ref name="payload1" doc:name="payload1" metadata:id="896da22a-11f4-4a80-9b38-85507261b002"/>
        <dw:transform-message metadata:id="8c4bb84a-74f8-4761-8f56-859dcf50473c" doc:name="Transform Message">
            <dw:input-payload doc:sample="products.xml"/>
            <dw:input-outbound-property propertyName="MULE_ENCODING"/>
            <dw:set-payload>
    <![CDATA[%dw 1.0
    %output application/xml
    %input payload application/xml
    ---
    {
    newxml: {
         billto: payload.order.customer_id as :string,
         shipping: payload.order.status,
    products: {
        productID: payload.products.product.product_id,
        sku: payload.products.product.sku,
        name: payload.products.product.name
    }
}
}]]></dw:set-payload>
</dw:transform-message>
<logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="payload1" >
    <http:request config-ref="HTTP_Request_Configuration" path="/api/v2/orders/#[email_subj]/products.xml" method="GET" doc:name="HTTP" metadata:id="4806e0ff-68f0-4295-baff-d65b07ae5190"/>
</sub-flow>
</mule>
1
some remarks on your question... it does not contain a actual question and your examples do not match the payload in your dataweave. Improving your question would facilitate other to work out a solution for your problem.Yevgeniy

1 Answers

0
votes

you have to iterate over payload.products.*product. this is what it might look like:

%dw 1.0
%output application/xml
%input payload application/xml
---
newxml: {
    products: {
        (payload.products.*product map {
            product: {
                productID: $.product_id,
                name: $.name
            }
        })
    }
}

when using <products>...</products> from your question the output will look like this:

<?xml version='1.0' encoding='UTF-8'?>
<newxml>
  <products>
    <product>
      <productID>12345</productID>
      <name>Widget</name>
    </product>
    <product>
      <productID>56435</productID>
      <name>Super Widget</name>
    </product>
  </products>
</newxml>

take a look here and you will find many example for transformation with dataweave including examples using map.