Untitled

mail@pastecode.io avatar
unknown
groovy
2 years ago
1.2 kB
2
Indexable
Never
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.XmlUtil;
import groovy.util.XmlSlurper;

def Message processData(Message message) {
    
    def messageLog = messageLogFactory.getMessageLog(message);

    map = message.getProperties();
	bp = map.get("foundBP") as String;
	
	def body = message.getBody() as String;
	def addressID = "do_nothing";
	
	if(body.contains(bp)){

        def xml = new XmlSlurper().parseText(body)
    
        def bpAddressData = xml.'**'.find { A_BusinessPartnerAddressType ->     
            A_BusinessPartnerAddressType.BusinessPartner.text() == bp
        }
    
        if(bpAddressData){
            def addressElements = bpAddressData.parent().children().list()
            def idx = addressElements.indexOf(bpAddressData)
            
            addressID = addressElements[idx].AddressID.text()
            message.setBody(XmlUtil.serialize(bpAddressData))
        }
	}
    
    if(messageLog != null) {
        messageLog.setStringProperty("Address Handling","Address Handling")
        messageLog.addAttachmentAsString("Address Handling",addressID,"text/plain");
    }
    
    message.setProperty("addressID", addressID);
    return message;

}