import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.xml.*;
def getRows(body) {
String[] lines = body.split("\\r?\\n")
lines[0].replace('\n', '')
// List<String[]> rows = lines.collect {it.tokenize(',')}
List<String[]> rows = lines.collect {it.split(',')}
println rows
return rows
}
def getListNodes(input) {
def listOfNodes = [];
for (int i = 0; i < input.size(); i++) {
//Identifier for the Purchase Order is “PO”
if (input[i][0] == 'PO') {
def obj = [
PurchaseOrders: input[i],
items : []
]
for (int j = i + 1; j < input.size(); j++) {
//All the “ITEM” will come under the “PO” structure.
if (input[j][0] != 'PO') {
obj.items.add(input[j])
} else {
i = j - 1;
break;
}
}
listOfNodes.add(obj)
}
}
return listOfNodes
}
def generateXML(xml, listNodes) {
// println listNodes
listNodes.each{it ->
def currHeader = it.get('PurchaseOrders')
def currNode = it.get('items')
xml.PurchaseOrders {
BELNR(currHeader[1])
RECIPNT_NO(currHeader[2])
CURCY(currHeader[3])
Item{
currNode.each { it1 ->
Items {
POSEX(it1[1])
MENGE(it1[2])
MENEE(it1[3])
PEINH(it1[4])
NETWR(it1[5])
}
}
}
}
}
}
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def rows = getRows(body)
def listNodes = getListNodes(rows)
generateXML(xml, listNodes)
message.setBody(writer.toString());
return message
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |