Last active
August 29, 2015 14:23
-
-
Save felipebizz/c1c3f7ae5409e6d110a6 to your computer and use it in GitHub Desktop.
[Mule] Create JSON with Groovy from a payload Mule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<scripting:component doc:name="Groovy"> | |
<scripting:script engine="Groovy"><![CDATA[ | |
def list = []; | |
def issue = [:]; | |
for(i = 0 ; i < payload.size(); i++){ | |
issue.id = 'arizona.jobdone.processo.' + payload[i].JOB_ID + '-' + payload[i].PROCESS_ID; | |
issue.key = 'arizona.jobdone.processo.' + payload[i].JOB_ID + '-' + payload[i].PROCESS_ID; | |
issue.fields = [:]; | |
issue.fields.summary = payload[i].JOB_ID + '|' + payload[i].PROCESS_ID + '| Desd.3 |' + payload[i].CLIENTE + '|' + payload[i].AGENCIA + '| capas | PRINT |' + payload[i].PROCESS_NAME | |
issue.fields.project = [:]; | |
issue.fields.project.id = '1'; | |
issue.fields.project.key = 'VSTC'; | |
issue.fields.project.name = 'Time Central - JobDone'; | |
list.add(issue); | |
} | |
def root = [:]; | |
root.expand = 'schema,names'; | |
root.startAt = 0; | |
root.maxResults = 500 | |
root.total= 7 | |
root.issues =[:]; | |
root.issues = list | |
def jsonContent = new groovy.json.JsonBuilder(root); | |
println 'JSON COMPLETE : ' +jsonContent.toString() | |
return jsonContent.toPrettyString(); | |
]]></scripting:script> | |
</scripting:component> | |
<!-- RESULT --> | |
{ | |
expand: "schema,names", | |
startAt: 0, | |
maxResults: 500, | |
total: 7, | |
issues: | |
[ | |
{ | |
id: "arizona.jobdone.processo.34076-19", | |
key: "arizona.jobdone.processo.34076-19", | |
fields: { | |
summary: "34076|19| Desd.3 |BOTICARIO|ALMAP| capas | PRINT |Expedição", | |
project: { | |
id: "1", | |
key: "VSTC", | |
name: "Time Central - JobDone" | |
} | |
} | |
}, | |
{ | |
id: "arizona.jobdone.processo.34076-19", | |
key: "arizona.jobdone.processo.34076-19", | |
fields: { | |
summary: "34076|19| Desd.3 |BOTICARIO|ALMAP| capas | PRINT |Expedição", | |
project: { | |
id: "1", | |
key: "VSTC", | |
name: "Time Central - JobDone" | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment