I need to map a groovy code into dataweave. The existing groovy code is similar to the pseudo example as-
if(condition) {
payload.each { data -> {
function1(data.attributes)
function2(data.attributes)
if(condition) {set flag}
}
if(flag is set) {return payload}
else {return errorMessage}
}
}
function1(data) {if(condition) {return errorMessage} else {return data}}
function2(data) {if(condition) {return errorMessage} else {return data}}
Consider the input payload as-
[
{
"attribute1": "value1",
"attribute2": "value2",
"attribute3": "value3",
"attribute4": "value4",
},
{
"attribute1": "value5",
"attribute2": "value6",
"attribute3": "value7",
"attribute4": "value8",
}
]
The output is an JSON array, which is dependent on the flag variable. If the flag is set, output JSON array will be about the errorMessages else pass the original payload. Is there a way in which this can be converted into a dataweave without using much additional mule processes?
Thanks in advance