0
votes

I am using Mule 3.6.1 and have a flow that reads a CSV file and then splits the file and passes in each record to the datamapper. I can see that the record is present prior to data mapper but once the message leaves the datamapper, the payload is empty.

How can I fix this? Please note that the Choice will have 3 possible datamappers to select in the completed flow.

The flow is:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" 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" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.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/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/mongo http://www.mulesoft.org/schema/mule/mongo/current/mule-mongo.xsd">
    <context:property-placeholder location="mule-app.properties" />
    <configuration doc:name="Configuration">
        <expression-language autoResolveVariables="true">
            <import class="org.mule.util.StringUtils" />
            <import class="org.mule.util.ArrayUtils" />
        </expression-language>
    </configuration>
    <data-mapper:config name="test_mapper" transformationGraphPath="csv_to_json_1.grf" doc:name="test_mapper"/>
    <flow name="read-file" >
        <file:inbound-endpoint path="${file.unprocessed.location}" moveToPattern="#[message.inboundProperties['originalFilename']]" moveToDirectory="${file.processed.location}" responseTimeout="10000" doc:name="Files" mimeType="text/csv" >
            <file:filename-regex-filter pattern="test.csv" caseSensitive="true"/>
        </file:inbound-endpoint>
        <object-to-string-transformer doc:name="Object to String"/>
        <splitter expression="#[rows=StringUtils.split(message.payload,'\n\r'); ArrayUtils.subarray(rows,1,rows.size())]" doc:name="Splitter"/>
        <set-property propertyName="testFilename" value="#[flowVars.originalFilename]" doc:name="Set Filename"/>
        <choice doc:name="Choice">
            <when expression="#[message.outboundProperties.'testFilename'=='test.csv']">
                <data-mapper:transform config-ref="CSV_To_JSON" doc:name="CSV To JSON"/>
            </when>
            <otherwise>
                <logger level="INFO" doc:name="Logger"/>
            </otherwise>
        </choice>
        <object-to-string-transformer doc:name="Object to String"/>
        <logger level="INFO" doc:name="Logger"/>
    </flow>
</mule>

and CSV input file:

DeptID,Dept,Staff
5LL/A,Human Resources,4.00

and GRF file showing data mappings:

<?xml version="1.0" encoding="UTF-8"?><Graph __version="3.5.0" author="" created="Wed May 25 14:20:34 BST 2016" description="CSV To JSON" guiVersion="3.4.4.P" id="1464184235950" licenseCode="Unlicensed" licenseType="Unknown" modified="Wed May 25 14:20:34 BST 2016" modifiedBy="" name="CSV_To_JSON" preview-file="C:/test.csv" revision="1.0" showComponentDetails="false">
<Global>
<Metadata __referenceCounter="1" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _type="Input" id="f79c6373-b266-4a78-91c9-3a731304eef1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field containerType="SINGLE" label="DeptID" name="DeptID" size="10" type="string"/>
<Field containerType="SINGLE" label="Dept" name="Dept" size="10" type="string"/>
<Field containerType="SINGLE" eofAsDelimiter="true" label="Staff" name="Staff" size="10" type="string"/>
<Field __artificialType="_id" auto_filling="global_row_count" name="__id" type="long"/>
</Record>
</Metadata>
<Metadata __index="0" __referenceCounter="1" __sourcePath="{}/test" _dataStructure="SINGLE_DIMENSIONAL_COLLECTION" _id="__id" _type="Output" id="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1">
<Record fieldDelimiter="," name="test" recordDelimiter="\n\\|\r\n\\|\r" type="delimited">
<Field __artificialType="_id" __systemManaged="true" name="__id" type="string"/>
<Field __index="1" __sourcePath="{}/test/Dept" containerType="SINGLE" label="Dept" name="Dept" type="string"/>
<Field __index="0" __sourcePath="{}/test/DeptID" containerType="SINGLE" label="DeptID" name="DeptID" type="string"/>
<Field __index="2" __sourcePath="{}/test/Staff" containerType="SINGLE" label="Staff" name="Staff" type="string"/>
</Record>
</Metadata>
<Dictionary>
<Entry id="DictionaryEntry0" input="true" name="inputPayload" output="false" type="object"/>
<Entry id="DictionaryEntry1" input="false" name="outputPayload" output="true" type="object"/>
</Dictionary>
</Global>
<Phase number="0">
<Node charset="UTF-8" enabled="enabled" fileURL="dict:inputPayload" guiName="CSV READER" guiX="20" guiY="20" id="DATA_READER0" quoteCharacter="both" quotedStrings="true" skipRows="1" trim="true" type="DATA_READER">
<attr name="_data_format"><![CDATA[CSV]]></attr>
<attr name="__dataSourceDefinition"><![CDATA[C:/test.csv]]></attr>
</Node>
<Node enabled="enabled" guiName="Foreach 'test' -&gt; 'test'" guiX="460" guiY="20" id="FOREACH_TEST_TEST" transformClass="com.mulesoft.datamapper.transform.MelRecordTransform" type="REFORMAT">
<attr name="melScript"><![CDATA[//MEL
//START -> DO NOT REMOVE
output.__id = num2str(input.__id);
//END -> DO NOT REMOVE
output.DeptID = input.DeptID;
output.Dept = input.Dept;
output.Staff = input.Staff;
]]></attr>
</Node>
<Node cacheInMemory="true" charset="UTF-8" enabled="enabled" fileURL="dict:outputPayload" guiName="JSON WRITER" guiX="900" guiY="20" id="JSON_WRITER0" type="JSON_WRITER">
<attr name="mapping"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<clover:collection clover:name="test" xmlns:clover="http://www.cloveretl.com/ns/xmlmapping">
  <item clover:inPort="0">
    <DeptID>$0.DeptID</DeptID>
    <Dept>$0.Dept</Dept>
    <Staff>$0.Staff</Staff>
  </item>
</clover:collection>]]></attr>
<attr name="_data_format"><![CDATA[JSON]]></attr>
</Node>
<Edge debugMode="true" fromNode="DATA_READER0:0" guiBendpoints="" id="Edge0" inPort="Port 0 (in)" metadata="f79c6373-b266-4a78-91c9-3a731304eef1" outPort="Port 0 (output)" toNode="FOREACH_TEST_TEST:0"/>
<Edge debugMode="true" fromNode="FOREACH_TEST_TEST:0" guiBendpoints="" id="Edge1" inPort="Port 0 (in)" metadata="4b092da3-e786-4f90-8e22-d9d5e8d7a7b1" outPort="Port 0 (out)" toNode="JSON_WRITER0:0"/>
</Phase>
</Graph>
2
add a screenshot of the datamapper transformation, the only thing we see from your transformation is this "csv_to_json_1.grf"JoostD
Added grf file. Thanksuser3165854

2 Answers

1
votes

In the splitter your are already stripping of the header.

In DataMapper you have the option 'Rows to Ignore' set to "1".

Set that to "0", or change the expression in your splitter.

Because now you tell DataMapper to ignore your one and only row!

0
votes

You are ignoring the row coming into the datamapper and hence there is no mapping being done remove "rows to ignore".Then the mapper will work on the row coming inside