How to handle if else nested statment in dataweave in mulesoft - mule

OptIn: "Yes" when payload.country==true and payload.state==false otherwise "No" when payload.country==false and payload.state==true otherwise "NOT VALID" when payload.country==false and payload.state==false otherwise ""

This can be achieve through following example :-
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="DataweaveFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/poc" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[ %dw 1.0
%input payload application/json
%output application/json
---
{ value1: "Yes" } when payload.country==true and payload.state==false
otherwise (
{ value1: "No" } when payload.country==false and payload.state==true
otherwise (
{ value1: "NOT VALID" } when payload.country==false and payload.state==false
otherwise "your value"
))]]></dw:set-payload>
</dw:transform-message>
<logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger" />
</flow>
Where I tested this with following input :-
case 1:-
{
"country":true,
"state":false
}
case 2:-
{
"country":false,
"state":true
}
case 3:-
{
"country":false,
"state":false
}
case 4:-
{
"country":true,
"state":"default value"
}

Related

Add one more element to the object array inside for each loop in mule 3

I have Input as below
[{Name=ABC, ID=123},{Name=XYZ, ID=345}]
I would iterate over this collection in a for-each loop and add one more element Age to each object.
My expected output would be like
[{Name=ABC, ID=123, Age=23},{Name=XYZ, ID=345, Age=24}]
Any help would be highly appreciated. Thanks in advance.
HTH..
%dw 2.0
output application/json
var inp = [
{
"Name":"ABC",
"ID":"123"
},
{
"Name":"XYZ",
"ID":"345"
}
]
---
inp map {
($),
age: (23 + ($$)) // or your logic to derive age
}
It was not possible with DW as because payload inside for-each was modified. So I tried using Expression component. Below is my configuration XML.
<flow name="add-one-more-element-to-the-original-payload">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
<logger message="Pooling Started" level="INFO" doc:name="Log"/>
</poll>
<dw:transform-message doc:name="Transform Payload">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
%var collection = [{"Name":"ABC","ID":123},{"Name":"XYZ","ID":345}]
---
collection]]></dw:set-payload>
</dw:transform-message>
<set-variable variableName="outputList" value="#[new java.util.ArrayList()]"
doc:name="Set Variable"/>
<foreach doc:name="For Each" collection="#[payload]">
<dw:transform-message doc:name="CurrentPayload">
<dw:set-variable variableName="currentPayload"><![CDATA[%dw 1.0
%output application/java
---
payload]]></dw:set-variable>
</dw:transform-message>
<flow-ref name="get-age-subflow" doc:name="Get Age"/>
<expression-component doc:name="Expression"><!
[CDATA[flowVars.currentPayload.Age=payload.Age;]]></expression-component>
<expression-transformer expression="#
[flowVars.outputList.add(flowVars.currentPayload)]" doc:name="Expression"/>
</foreach>
<logger message="#[flowVars.outputList]" level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="get-age-subflow">
<dw:transform-message doc:name="Transform Age">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Age:24
}]]></dw:set-payload>
</dw:transform-message>
</sub-flow>

Mule Runtime 4.2.1 Anypoint 7.3.4: Cannot copy message with a stream payload

Facing below runtime error after upgrading from Mule Runtime 4.2.0 to 4.2.1.
Below detailed my codebase, and quick error message, and detailed error logs for review. Please suggest, if anyone faced the same problem?
I referred to other similar question and answer in StackOverflow Mule ESB : Cannot copy message with a stream payload, this doesn't solve mine below error.
Runitime Error on Mule 4.2.1:
Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider"
Detailed Error Log
INFO 2019-08-05 11:29:15,388 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_LITE #7ed56bee] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: BY status: <?xml version='1.0' encoding='UTF-8'?>
<DeliveryStatus>
<DeliveryID>46658</DeliveryID>
<Username>user_di_test</Username>
<StartDelivery>2019-08-05T05:24:34.886502+00:00</StartDelivery>
<LastProcessed>2019-08-05T05:46:16.508861+00:00</LastProcessed>
<Status>LOADED</Status>
<ParameterInfo>
<Category>Events</Category>
<Version>1.14.17</Version>
<File>Events.gz</File>
</ParameterInfo>
<Statistics>
<DeliveredRecords>323</DeliveredRecords>
<PendingRecords>323</PendingRecords>
<ProcessedRecords>0</ProcessedRecords>
<ErroneousRecords>0</ErroneousRecords>
</Statistics>
</DeliveryStatus>
INFO 2019-08-05 11:29:15,397 [[MuleRuntime].cpuIntensive.09: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_INTENSIVE #6b417a92] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: payload : {
"DeliveryStatus": {
"DeliveryID": "46658",
"Username": "user_di_test",
"StartDelivery": "2019-08-05T05:24:34.886502+00:00",
"LastProcessed": "2019-08-05T05:46:16.508861+00:00",
"Status": "LOADED",
"ParameterInfo": {
"Category": "Events",
"Version": "1.14.17",
"File": "Events.gz"
},
"Statistics": {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
}
}
INFO 2019-08-05 11:29:15,410 [[MuleRuntime].cpuIntensive.09: [jda-demand-adapter].Get_BY_Status_n_Update_Part_Flow.CPU_INTENSIVE #6b417a92] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Delivery Status summary: "46658","LOADED", {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
INFO 2019-08-05 11:29:17,030 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Final response for Job without Errors, jobDetails: null
INFO 2019-08-05 11:29:17,032 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Inside Aggregation complete - For loop payload:[org.mule.runtime.api.metadata.TypedValue#fc4ba33d]
INFO 2019-08-05 11:29:17,052 [[MuleRuntime].io.110: [jda-demand-adapter].Update_Part_Status_Recordcount_Flow.BLOCKING #502d3ddf] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: After Reporting Transformation: {
"Summary": {
"DataPostingStatus": "",
"DataPostingDetailedStatus": "",
"JobCreatedDate": "",
"JobRestartDate": "",
"JobLastModifiedTime": "",
"JobExecutionDuration": "",
"JobExecutionDuration_in_Secs": "",
"RecordsProcessed": "",
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErrorRecords": "0",
"Categories": [
"Events"
]
},
"CategorySummary": [
{
"Category": "Events",
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErrorRecords": "0",
"DeliveryId": [
"46658"
]
}
],
"Errors": {
},
"Details": [
{
"DeliveryStatus": {
"DeliveryID": "46658",
"Username": "user_di_test",
"StartDelivery": "2019-08-05T05:24:34.886502+00:00",
"LastProcessed": "2019-08-05T05:46:16.508861+00:00",
"Status": "LOADED",
"ParameterInfo": {
"Category": "Events",
"Version": "1.14.17",
"File": "Events.gz"
},
"Statistics": {
"DeliveredRecords": "323",
"PendingRecords": "323",
"ProcessedRecords": "0",
"ErroneousRecords": "0"
}
}
}
]
}
ERROR 2019-08-05 11:29:17,076 [[MuleRuntime].cpuLight.11: [jda-demand-adapter].Ingestion_Status_Main_Flow.CPU_LITE #7132a277] [event: 20e0d4f1-b746-11e9-afb2-0a0027000005] org.mule.runtime.core.internal.exception.OnErrorContinueHandler:
********************************************************************************
Message : Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider".
Element : Get_Job_Status_Details_Flow/processors/1 # jda-demand-adapter:com/jda/cd/common/flow/ingestion-status.xml:257 (Scatter-Gather)
Element XML : <scatter-gather doc:name="Scatter-Gather">
<route>
<logger level="INFO" doc:name="Logger" message="Calculating the Job Satus ..."></logger>
<flow-ref name="GetDetailedJobStatus_SubFlow" doc:name="GetDetailedJobStatus_SubFlow"></flow-ref>
<set-payload value="#[{
"detailedStatus": vars.detailedStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="5ea3c7bf-b1b1-4231-9af3-c8e39f241866"></set-payload>
</route>
<route>
<flow-ref name="Get_Job_Details_Flow_Enricher_0" doc:name="Get_Job_Details_Flow_Enricher_0"></flow-ref>
<set-payload value="#[{
"jobStatus": vars.jobStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="e0a78803-a93c-4523-9551-4cf9218f059b"></set-payload>
<logger level="INFO" doc:name="Logger Job Details" doc:id="8b31e869-5630-4e01-902d-3e259ba2734e" message="Scatter-Gather Get_Job_Details_Flow_Enricher_0 payload:#[payload], jobStatus:#[vars.jobStatus]"></logger>
<choice doc:name="CalcJobStatus_IfNeeded-Choice">
<when expression="#[vars.jobStatus == 'IN_PROGRESS']">
<async doc:name="Async">
<flow-ref name="CalcBatchStatus_Flow" doc:name="CalcBatchStatus_Flow"></flow-ref>
</async>
</when>
<otherwise>
<logger message="job status is final" level="INFO" doc:name="Logger"></logger>
</otherwise>
</choice>
</route>
<route>
<flow-ref name="Get_Records_By_Status_SubFlow_Enricher_1" doc:name="Get_Records_By_Status_SubFlow_Enricher_1"></flow-ref>
<set-payload value="#[{
"recordsByStatus": vars.recordsByStatus
}]" mimeType="application/java" doc:name="Set Payload"></set-payload>
</route>
<route>
<logger message="#["jobExecution Duration : "]" level="INFO" doc:name="Logger"></logger>
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_2" doc:name="Get_Job_Status_Details_Flow_Enricher_2"></flow-ref>
<logger message="payload last_mod_date #[vars] #[vars.lastModDate]" level="INFO" doc:name="Logger"></logger>
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_6" target="jobCreatedDate" targetValue="#[payload[0].CREATED_DATE]" doc:name="Get_Job_Status_Details_Flow_Enricher_6"></flow-ref>
<set-variable value="#[now()]" doc:name="Current time" doc:id="547a11d2-b9dc-479e-a0c4-36e5b367bcee" variableName="currentTime"></set-variable>
<set-variable value="#[%dw 2.0 import * from dw::util::Timer output application/java --- ((toMilliseconds(vars.lastModDate) - toMilliseconds(vars.jobCreatedDate))/1000) as Number as String {format: ".##"}]" doc:name="Set Variable jobExecutionDurationSeconds" doc:id="499b7eda-f565-4a7c-94bd-9aeaf7306941" variableName="jobExecutionDurationSeconds"></set-variable>
<set-variable value="#[%dw 2.0 import * from dw::util::Timer output application/java --- ((toMilliseconds(vars.currentTime) - toMilliseconds(vars.lastModDate))/1000) as Number as String {format: ".##"}]" doc:name="TimeSinceLastMod" doc:id="0f30996f-1c89-4d45-90e9-915f3d2440bb" variableName="timeSinceLastMod"></set-variable>
<set-variable value="#[%dw 2.0 output application/json --- (((vars.jobExecutionDurationSeconds / 3600) as Number) as String {format: ".##"}) ++ ":" ++ ((((vars.jobExecutionDurationSeconds mod 3600) as Number) / 60 as Number) as String)as String {format: ".##"} ++ ":" ++((((vars.jobExecutionDurationSeconds mod 60) as Number))as String) as String {format: ".##"}]" doc:name="Set Variable jobExecutionDuration" doc:id="eaa22fce-6085-4290-8a31-46fc0bdd90c0" variableName="jobExecutionDuration"></set-variable>
<set-variable value="#[%dw 2.0 output application/json --- (((vars.timeSinceLastMod / 3600) as Number) as String) as String {format: ".##"} ++ ":" ++ ((((vars.timeSinceLastMod mod 3600) as Number) / 60 as Number) as String) as String {format: ".##"} ++ ":" ++((((vars.timeSinceLastMod mod 60) as Number))as String) as String {format: ".##"}]" doc:name="Set Variable TimeSinceLastModString" doc:id="15942ccf-d219-40f1-a783-3e4466bdfbbf" variableName="timeSinceLastModString"></set-variable>
<logger message="job_create date #[vars]" level="INFO" doc:name="Logger"></logger>
<set-payload value="#[%dw 2.0 output application/json --- {"jobExecutionDuration": vars.jobExecutionDuration, "jobExecutionDurationSeconds": vars.jobExecutionDurationSeconds, "jobCreatedDate":vars.jobCreatedDate,"lastModDate": vars.lastModDate,"currentTime": vars.currentTime,"timeSinceLastMod": vars.timeSinceLastMod}]" doc:name="Set Payload" doc:id="a97e5020-9d64-411e-87bf-ab325f29cd7f" mimeType="application/json"></set-payload>
</route>
</scatter-gather>
Error type : MULE:UNKNOWN
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.runtime.api.exception.MuleRuntimeException: Cannot copy message with a stream payload. Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider"
********************************************************************************
Below Codebase works fine in Mule 4.2.0, after upgrading Mule runtime to 4.2.1 and trying to use Anypoint 7.3.4, getting above runtime error. I am not getting the clue to fix it.
Below same code works on Mule 4.2.0:
<flow name="Ingestion_Status_Main_Flow" doc:description="Ingestion_Status_Main_Flow will read BY_delivery_IDs and try to read the status of the delivery from BY. If BY service is not available, then it provides the status of the status tables. In addition to the BY response details, it shows the job's current status, Number of records as per the status. ">
<http:listener path="${secure::ingestion.status.resource}/{jobId}" allowedMethods="GET" doc:name="/status" config-ref="HTTP_Listener_Config">
<http:response statusCode="#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]"/>
<http:error-response statusCode="#[vars.statusCode default migration::HttpListener::httpListenerResponseErrorStatusCode(vars)]"/>
</http:listener>
<logger message='#[attributes.uriParams.jobId]' level="INFO" doc:name="Job ID from input" />
<set-variable variableName="jobId" value="#[attributes.uriParams.jobId]" doc:name="jobId" />
<set-variable value="#[attributes.queryParams.notify]" doc:name="notifyFlag" doc:id="c2c8a869-4941-4f72-9cd3-3c9ea7441e65" variableName="notify"/>
<flow-ref name="Validate_Input_JobID_Sub_Flow" doc:name="Validate_Input_JobID_Sub_Flow" />
<set-variable variableName="correlationId" value="#[vars.jobId]" doc:name="Session Variable"/>
<flow-ref name="Fetch_Parts_for_Job_SubFlow" doc:name="Fetch_Parts_for_Job_SubFlow" />
<set-variable value="#[sizeOf(payload)]" doc:name="sizeOfPayload" doc:id="0ab10eae-0b50-4b37-bd89-0ac614f548db" variableName="sizeOfPayload" />
<logger message='Delivery ID for Job: #[payload.BY_DELIVERY_ID]' level="INFO" doc:name="Deliver IDs" />
<choice doc:name="Choice">
<when expression="#[sizeOf(payload) > 0]">
<foreach doc:name="For Each" doc:id="742d1496-9be5-409a-a42c-e0da8a1a696d" >
<logger level="INFO" doc:name="Logger For Each" doc:id="e9aeff5c-e00c-4fd4-ada3-09b22f4161cd" message="inside for each #[payload] "/>
<flow-ref doc:name="Get_BY_Status_n_Update_Part_Flow" doc:id="6e00a6b0-8d83-4df6-b22a-ce6666fed36a" name="Get_BY_Status_n_Update_Part_Flow"/>
<aggregators:group-based-aggregator doc:name="groupByDeliveryId" doc:id="b4b76fac-3f35-4812-9c1d-81b23ddd1eb9" name="groupByDeliveryId" groupSize="#[vars.sizeOfPayload]" >
<aggregators:incremental-aggregation >
<logger level="INFO" doc:name="Logger" doc:id="f3e2bdd1-d660-4074-92b0-4c04ea421706" message="Incremental size #[sizeOf(payload)]" />
</aggregators:incremental-aggregation>
<aggregators:aggregation-complete >
<logger message="Final response for Job without Errors, jobDetails: #[vars.detailedStatus]" level="INFO" doc:name="Response without Errors included" />
<logger level="INFO" doc:name="Logger" doc:id="eb7c7626-7091-481a-939c-926f938d84ae" message="Inside Aggregation complete - For loop payload:#[payload]" />
<ee:transform doc:name="Reporting Transformation" doc:id="421fb819-c58f-4f46-8d6d-e5dfa43df133">
<ee:message>
<ee:set-payload resource="ingestion\ingestion-status-resp.dwl" />
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="f6acf89c-5b84-4cbc-9cab-bf4b9e48da4f" message="After Reporting Transformation: #[payload]"/>
<set-variable variableName="aggregatedPayload" value="#[payload]" doc:name="Set Variable" doc:id="eded53f3-18ac-4a84-8fcf-916e89d7a185"/>
</aggregators:aggregation-complete>
</aggregators:group-based-aggregator>
</foreach>
</when>
<otherwise>
<logger message="No Delivery IDs found." level="INFO" doc:name="Logger" />
<set-payload value="#[{
"Summary": {
"DataPostingStatus": '',
"DataPostingDetailedStatus": '',
"JobCreatedDate": '',
"JobRestartDate": '',
"JobLastModifiedTime": '',
"JobExecutionDuration": '',
"JobExecutionDuration_in_Secs": '',
"RecordsProcessed": ''
}
}]" mimeType="application/json" doc:name="Set Payload" doc:id="066c7871-dd4b-4bde-8663-e0558a5847df"/>
</otherwise>
</choice>
<set-payload value="#[vars.aggregatedPayload]" doc:name="Set Payload" doc:id="337a0771-458c-4511-920c-ca38fcb8c6d9" />
<logger message='getting db details #[payload]' level="INFO" doc:name="Logger"/>
<flow-ref name="Ingestion_Status_Main_Flow_Enricher_22" doc:name="Ingestion_Status_Main_Flow_Enricher_22"/>
<set-payload value="#[vars.aggregatedPayload]" doc:name="Set Payload" doc:id="7ef033ba-17d6-4597-9b4c-96fb73212e63" />
<ee:transform doc:name="Transform Message" doc:id="794cfad2-e368-4b44-9c7e-746e0e692338" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
Summary: {
DataPostingStatus: vars.jobStatus,
DataPostingDetailedStatus: vars.detailedStatus,
JobCreatedDate: vars.jobCreatedDate,
JobRestartDate: "",
JobLastModifiedTime: vars.lastModDate,
JobExecutionDuration: vars.jobExecutionDuration,
JobExecutionDuration_in_Secs: vars.jobExecutionDurationSeconds,
RecordsProcessed: "",
DeliveredRecords: payload.Summary.DeliveredRecords,
PendingRecords: payload.Summary.PendingRecords,
ProcessedRecords: payload.Summary.ProcessedRecords,
ErrorRecords: payload.Summary.ErrorRecords,
Categories: payload.Summary.Categories,
},
Errors:{},
CategorySummary: payload.CategorySummary,
Details: payload.Details
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger message='Getting errors details...' level="INFO" doc:name="Logger"/>
<flow-ref name="Add_Errors_to_Payload_Sub_Flow_Enricher_0" doc:name="Add_Errors_to_Payload_Sub_Flow_Enricher_0"/>
<ee:transform doc:name="Transform Message" doc:id="5b0518ac-139a-42f8-ae12-a42cce2449c1" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload
]]></ee:set-payload>
</ee:message>
</ee:transform>
<async doc:name="Async">
<choice doc:name="Choice">
<when expression="#[vars.notify == 'true']">
<flow-ref name="Send_Status_Mail_Flow" doc:name="Send_Status_Mail_Flow" />
</when>
<otherwise>
<logger message="Notification flag is not provided as query parameter." level="INFO" doc:name="Logger" />
</otherwise>
</choice>
</async>
<logger message='Final response: #[payload] jobId: #[vars.jobId]' level="DEBUG" doc:name="Response with Errors" />
<logger message="Ingestion status request done" level="INFO" doc:name="Status request completed" />
<error-handler ref="Global_Errorflow_Choice_Exception_Strategy" doc:name="Global Exception Strategy" />
</flow>
<sub-flow name="Ingestion_Status_Main_Flow_Enricher_22">
<flow-ref name="Get_Job_Status_Details_Flow" doc:description="Job status retrieved from status tables."/>
</sub-flow>
</flow>
<sub-flow name="Get_Job_Status_Details_Flow" doc:description="Job status retrieved from status tables.
For now, different stages of the job processing has been reported.
1. Batches not yet created.
2. Batches created, and parts are getting creating.
3. Parts are created, and processing.
4. Some part uploads are failed.
5. Some parts processing is failed i.e. payload is not created. ">
<scatter-gather doc:name="Scatter-Gather">
<route>
<logger level="INFO" doc:name="Logger" message="Calculating the Job Satus ..." />
<flow-ref name="GetDetailedJobStatus_SubFlow" doc:name="GetDetailedJobStatus_SubFlow" />
<set-payload value="#[{
"detailedStatus": vars.detailedStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="5ea3c7bf-b1b1-4231-9af3-c8e39f241866"/>
</route>
<route>
<flow-ref name="Get_Job_Details_Flow_Enricher_0" doc:name="Get_Job_Details_Flow_Enricher_0"/>
<set-payload value="#[{
"jobStatus": vars.jobStatus
}]" mimeType="application/java" doc:name="Set Payload" doc:id="e0a78803-a93c-4523-9551-4cf9218f059b"/>
<logger level="INFO" doc:name="Logger Job Details" doc:id="8b31e869-5630-4e01-902d-3e259ba2734e" message="Scatter-Gather Get_Job_Details_Flow_Enricher_0 payload:#[payload], jobStatus:#[vars.jobStatus]"/>
<choice doc:name="CalcJobStatus_IfNeeded-Choice">
<when expression="#[vars.jobStatus == 'IN_PROGRESS']">
<async doc:name="Async">
<flow-ref name="CalcBatchStatus_Flow" doc:name="CalcBatchStatus_Flow" />
</async>
</when>
<otherwise>
<logger message="job status is final" level="INFO" doc:name="Logger" />
</otherwise>
</choice>
</route>
<route>
<flow-ref name="Get_Records_By_Status_SubFlow_Enricher_1" doc:name="Get_Records_By_Status_SubFlow_Enricher_1"/>
<set-payload value="#[{
"recordsByStatus": vars.recordsByStatus
}]" mimeType="application/java" doc:name="Set Payload" />
</route>
<route>
<logger message='#["jobExecution Duration : "]' level="INFO" doc:name="Logger" />
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_2" doc:name="Get_Job_Status_Details_Flow_Enricher_2"/>
<logger message='payload last_mod_date #[vars] #[vars.lastModDate]' level="INFO" doc:name="Logger" />
<flow-ref name="Get_Job_Status_Details_Flow_Enricher_6" target="jobCreatedDate" targetValue="#[payload[0].CREATED_DATE]" doc:name="Get_Job_Status_Details_Flow_Enricher_6"/>
<set-variable value="#[now()]" doc:name="Current time" doc:id="547a11d2-b9dc-479e-a0c4-36e5b367bcee" variableName="currentTime"/>
<set-variable value='#[%dw 2.0
import * from dw::util::Timer
output application/java
---
((toMilliseconds(vars.lastModDate) - toMilliseconds(vars.jobCreatedDate))/1000) as Number as String {format: ".##"}]' doc:name="Set Variable jobExecutionDurationSeconds" doc:id="499b7eda-f565-4a7c-94bd-9aeaf7306941" variableName="jobExecutionDurationSeconds"/>
<set-variable value='#[%dw 2.0
import * from dw::util::Timer
output application/java
---
((toMilliseconds(vars.currentTime) - toMilliseconds(vars.lastModDate))/1000) as Number as String {format: ".##"}]' doc:name="TimeSinceLastMod" doc:id="0f30996f-1c89-4d45-90e9-915f3d2440bb" variableName="timeSinceLastMod"/>
<set-variable value='#[%dw 2.0
output application/json
---
(((vars.jobExecutionDurationSeconds / 3600) as Number) as String {format: ".##"}) ++ ":" ++ ((((vars.jobExecutionDurationSeconds mod 3600) as Number) / 60 as Number) as String)as String {format: ".##"} ++ ":" ++((((vars.jobExecutionDurationSeconds mod 60) as Number))as String) as String {format: ".##"}]' doc:name="Set Variable jobExecutionDuration" doc:id="eaa22fce-6085-4290-8a31-46fc0bdd90c0" variableName="jobExecutionDuration"/>
<set-variable value='#[%dw 2.0
output application/json
---
(((vars.timeSinceLastMod / 3600) as Number) as String) as String {format: ".##"} ++ ":" ++ ((((vars.timeSinceLastMod mod 3600) as Number) / 60 as Number) as String) as String {format: ".##"} ++ ":" ++((((vars.timeSinceLastMod mod 60) as Number))as String) as String {format: ".##"}]' doc:name="Set Variable TimeSinceLastModString" doc:id="15942ccf-d219-40f1-a783-3e4466bdfbbf" variableName="timeSinceLastModString"/>
<logger message='job_create date #[vars]' level="INFO" doc:name="Logger" />
<set-payload value='#[%dw 2.0 output application/json --- {"jobExecutionDuration": vars.jobExecutionDuration, "jobExecutionDurationSeconds": vars.jobExecutionDurationSeconds, "jobCreatedDate":vars.jobCreatedDate,"lastModDate": vars.lastModDate,"currentTime": vars.currentTime,"timeSinceLastMod": vars.timeSinceLastMod}]' doc:name="Set Payload" doc:id="a97e5020-9d64-411e-87bf-ab325f29cd7f" mimeType="application/json"/>
</route>
</scatter-gather>
<logger message="Flowvars used to invoke the restart-flows: payload: #[payload]" level="INFO" doc:name="RestartFlags - Logger" />
</sub-flow>

Mule - Type mismatch for 'map' operator

Requirement is to bring CXF service in mule.
As per my knowledge i tried creating the configuration in mule but getting an error as shown below.
Exception while executing:
(payload.ns0#ValidateVIN.*ns0#VIN map ((vIN , indexOfVIN) -> {
^
Type mismatch for 'map' operator
found :null, :function
required :array, :function.
Attaching the code below.
<?xml version="1.0" encoding="UTF-8"?>
<mule ... >
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="9009" basePath="Mule" doc:name="HTTP Listener Configuration"/>
<cxf:configuration name="Autoprefill_CXF_Configuration" enableMuleSoapHeaders="true" initializeStaticBusInstance="true" doc:name="CXF Configuration"/>
<flow name="autoprefillFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/VINService" allowedMethods="POST" doc:name="HTTP"/>
<logger message="#[message.payloadAs(String)]" level="INFO" doc:name="Logger"/>
<dw:transform-message doc:name="Transform Message" metadata:id="566ab616-f256-4763-af42-82d4cbbcc277">
<dw:input-payload mimeType="application/xml"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://www.pwc.com/vin
---
{
ns0#ValidateVIN: {
(payload.ns0#ValidateVIN.*ns0#VIN map ((vIN , indexOfVIN) -> {
ns0#VIN: vIN
}))
}
}]]></dw:set-payload>
</dw:transform-message>
<cxf:simple-client operation="validateVIN" serviceClass="autoprefill.VINPort" doc:name="CXF"/>
<logger message="#[message.payloadAs(String)]" level="INFO" doc:name="Logger"/>
</flow>
</mule>
I tried removing the message transform property, but that time i got the below error
java.lang.String cannot be cast to java.util.Collection. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor
The service is expecting a list of string. Im not sure how that can be done in mule. Any help will be much appreciated.
The problem is in the Transform Message component.
The map function is expecting an array of data (collection of data), but it did not receive any value.
I suggest to check the payload before Transform Message component. Perhaps payload is not in expected format. If you can share the payload (or full logs at least) here, I can help you with the transformation.

Invoke Component in message Enricher and how to define the target value for Message Enricher

I am practicing on salesforce to mulesoft connection. I am trying to query the account from salesforce, do some logic using Invoke Component and update the Account name in Salesforce. Please find the XML code below. I get the following error when i invoke..
Execution of the expression "Variable:Fname=__object_for_enrichment" failed. (org.mule.api.expression.ExpressionRuntimeException).
XML:
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8092" doc:name="HTTP Listener Configuration"/>
<sfdc:config name="Salesforce__Basic_Authentication" username="username" password="*******" securityToken="Token" doc:name="Salesforce: Basic Authentication" url="https://login.salesforce.com/services/Soap/u/38.0">
<reconnect-forever/>
</sfdc:config>
<spring:beans>
<spring:bean id="Bean" name="UpdateAcc" class="com.pack.salesforceconnect.SFJava"/>
</spring:beans>
<flow name="salesforceconnectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/salesforce" doc:name="HTTP"/>
<sfdc:query-single config-ref="Salesforce__Basic_Authentication" query="dsql:SELECT Id,Name,ShippingCity FROM Account ORDER BY Name DESC" doc:name="Salesforce"/>
<dw:transform-message doc:name="Transform Message">
<dw:input-payload doc:sample="sample_data\Account.dwl"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Id: payload.Id,
Name: payload.Name,
ShippingCity: payload.ShippingCity
}]]></dw:set-payload>
</dw:transform-message>
<enricher source="#[payload.Name]" target="#[Variable:Fname]" doc:name="Message Enricher">
<invoke name="Invoke" object-ref="UpdateAcc" method="ChangeSCity" methodArguments="#[payload.Name]" metadata:id="id"/>
</enricher>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
[{
Id: payload.Id,
Name: variable:FName,
ShippingCity: payload.ShippingCity
}]]]></dw:set-payload>
</dw:transform-message>
<set-payload value="#[payload]" doc:name="Set Payload"/>
</flow>
</mule>
Class:
package com.pack.salesforceconnect;
public class SFJava {
public String ChangeSCity(String Fname){
//String ShippingCity;
System.out.print("Account Name received : "+Fname);
if (Fname == null){
Fname = "New Account";
}else{
Fname = "Washington Industries Inc.,";
}
System.out.print("Account Name: "+Fname);
return Fname;
}
}
Syntax wrong .. it would be target="#[variable:Fname]" instead of target="#[Variable:Fname]"
Or simply you can use target="#[flowVars.Fname]"

aperak edi file in mule dataweaver

I am trying to create aperak-edifact file from mule data weaver component.
Here is my piece of code
<edifact-edi:config name="EDIFACT_EDI" delimiterUsage="USE_SPECIFIED_FOR_WRITES" doc:name="EDIFACT EDI" interchangeIdPartner="YYYY" interchangeIdSelf="XXXX">
<edifact-edi:schemas>
<edifact-edi:schema>/edifact/d98b/APERAK.esl</edifact-edi:schema>
</edifact-edi:schemas>
</edifact-edi:config>
<flow name="new1Flow">
<file:inbound-endpoint path="C:\Users\Desktop" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="aperak.xml" caseSensitive="true"/>
</file:inbound-endpoint>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Messages: {
D98B: {
APERAK: [{
Interchange: {
UNB0201: "XXX",
UNB0301: "YYYY"
},
MessageHeader: {
UNH01: "1"
},
Heading: {
"0020_BGM": {
BGM0101: "7"
}
}
}]
}
}
}]]></dw:set-payload>
</dw:transform-message>
<edifact-edi:write config-ref="EDIFACT_EDI" doc:name="EDIFACT EDI"/>
<file:outbound-endpoint path="C:\Users\Desktop" outputPattern="out.json" responseTimeout="10000" doc:name="File"/>
</flow>
Output
UNB+UNOB:4+XXX+YYY+05042016:0948+1'UNH+2+APERAK:D:98B:UN'BGM+7'UNT+3+2'UNZ+1+1'
But the output created is all in one line where I want it to be appeared line by line. So how can I introduce new line for edifact
Any help is appreciated
Expected Output
UNB+UNOB:4+XXX+YYY+05042016:0948+1'
UNH+2+APERAK:D:98B:UN'
BGM+7'
UNT+3+2'UNZ+1+1'
Set the lineEnding configuration attribute of edifact-edi:config to output a CRLF.