/* https://sapintegrationsuitecourse.com */ import com.sap.gateway.ip.core.customdev.util.Message import groovy.xml.* def Message processData(Message message) { def body = message.getBody(String) def headers = message.getHeaders() def properties = message.getProperties() DoMapping(body, headers, properties) return message } //Need comment this TestRun() before upload to SAP CI. This TestRun() for local debug only TestRun() void TestRun() { def scriptDir = new File(getClass().protectionDomain.codeSource.location.toURI().path).parent def dataDir = scriptDir + "\\Data" Map headers = [:] Map props = [:] File inputFile = new File("$dataDir\\xml_orders_tree.txt") def inputBody = inputFile.getText("UTF-8") DoMapping(inputBody, headers, props) println "idoc_no = " + props.get("idoc_no") println "order_no = " + props.get("order_no") println "material_list = " + props.get("material_list") println "item_count = " + props.get("item_count") println "schedule_line_count = " + props.get("schedule_line_count") println "total_quantity = " + props.get("total_quantity") println "total_weight = " + props.get("total_weight") } def DoMapping(String body, Map headers, Map properties) { def InputPayload = new XmlParser().parseText(body) InputPayload.order.each { this_order -> //Get idoc_no, order_no def v_idoc_no = this_order.header.idoc_no.text() def v_order_no = this_order.header.order_no.text() //Get material_list, item_count, schedule_line_count, total_weight, total_quantity def v_material_list = [] def v_item_count = 0 def v_schedule_line_count = 0 def v_total_weight = 0 def v_total_quantity = 0 this_order.item.each { this_item -> v_item_count++ v_material_list.add(this_item.material.text()) def v_weight = this_item.weight.text().toDouble() v_total_weight += v_weight this_item.schedule.line.each { this_line -> v_schedule_line_count++ def v_schedule_qty = this_line.schedule_qty.text().toInteger() v_total_quantity += v_schedule_qty } } properties.put("idoc_no", v_idoc_no) properties.put("order_no", v_order_no) properties.put("material_list", v_material_list.join("|")) properties.put("item_count", v_item_count) properties.put("schedule_line_count", v_schedule_line_count) properties.put("total_quantity", v_total_quantity) properties.put("total_weight", v_total_weight) } }