0
votes

I have to do 1st level normalization from the input data coming from excel.[Input Excel][1].

Now the output shall be like[Output file][2]. I have tried using MEL(defining a method as global configuration) in combination of Dataweave. Inside dataweave I am trying to call the method defined above as global config. This approach is not working as the file generated is blank. Could anyone suggest a better approach or problem in this approach. Below is the code @Manik:

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

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:file="http://www.mulesoft.org/schema/mule/file" 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/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.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/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">

  <configuration doc:name="Configuration">
     <expression-language>
         <global-functions>
            def getCompanyName(name){
                 if (flowVars.companyList contains name) {
                    return "";
                 }  else {
                    flowVars.companyList.add(name);
                    return name;
                 }
            }
          </global-functions>
     </expression-language>
 </configuration>


  <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File" readFromDirectory="C:\Users\Desktop\Mule-Doc"/>
    <file:connector name="File1" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>


    <flow name="csvnormalizationFlow">
         <file:inbound-endpoint path="C:\Users\Desktop\Mule-Doc" connector-ref="File" responseTimeout="10000" doc:name="File"/>
        <set-variable value="#[[]]" variableName="companyList" doc:name="Variable" mimeType="application/csv"/>
        <logger message="The payload is-----------------------#[payload]" level="INFO" doc:name="Logger"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0

%output application/csv header=true
---
payload map {
    CompanyName: getCompanyName($.Company),
    location:$.Location
}]]></dw:set-payload>
        </dw:transform-message>

        <file:outbound-endpoint path="C:\Users\Desktop\Output" outputPattern="test.csv" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>
2
Could you please post your MEL function and dataweave scriptAnupamBhusari
The MEL function is <configuration doc:name="Configuration"> <expression-language> <global-functions> def getCompanyName(name){ if (flowVars.companyList contains name) { return ""; } else { flowVars.companyList.add(name); return name; } } </global-functions> </expression-language> </configuration>Mule_Agent
The dataweave code is <dw:transform-message doc:name="Transform Message"> <dw:set-payload><![CDATA[%dw 1.0 %output application/csv header=true --- payload map { CompanyName: getCompanyName($.Company), location:$.Location }]]></dw:set-payload> </dw:transform-message>Mule_Agent

2 Answers

0
votes

Complete answer is here -https://stackoverflow.com/a/37123291/5616671

Can you post your flow xml here? I ran that code and it is giving me expected output.

-1
votes

You can add a null handler un your Data weave expressions and the check if it is the payload that doesn't write anything. An example of null handle below.

 (payload.listAllFlightsResponse.*return default [])