Summarization : Mapping Pattern in PI
Problem: One name can have multiple credit cards (as Source) and I want to generate summary of customer (as in Target) as well as total summary of all customer as report in summary tag.
Message Mapping:Example of source and traget structure.
First mape source NAME to target CUSTOMERANME.
target CARDCOUNT mapped to source CREDITCARD including the standard function count. Also change the context to records of CREDITCARD.
target CARDTOTALPAYMENT mapped with source PAYMENT including standard function sum.
Target TOTAL CARD mapped to source CREDIT CARD node with count function.
Target TOTAL PAYMENT mapped with source PAYMENT including standard function sum.
And here the output:










Thanks for the blog. It would have been great if you could have put some more explanation to it.
Chris
Looks like you put together a blog based on the requirement you were working. There is very little explaination to the the design patern.
To preserve the sanity of the blogs published, please take a little more effort in translating the content from a requirement to a pattern that the community can benefit from.
--Naveen
Problem: One name can have multiple credit cards (as Source) and I want to generate summary of customer (as in Target) as well as total summary of all customer as report in summary tag.<br/><br/><br/><br/>Apart from Graphical Message mapping(discussed in the earlier blog)this problem can be solved using Java Mapping also.<br/><br/><br/>The code for java mapping(implementing SAX parser)as follows:<br/><br/><br/>import java.io.;<br/>import java.util.Map;<br/>import javax.xml.parsers.SAXParser;<br/>import javax.xml.parsers.SAXParserFactory;<br/>import org.xml.sax.Attributes;<br/>import org.xml.sax.SAXException;<br/>import org.xml.sax.helpers.DefaultHandler;<br/>import com.sap.aii.mapping.api.StreamTransformation;<br/><br/>/*"tcust""tcard""tsum" tcust+;<br/> }<br/> if("Creditcard".equals(eName)) {<br/> count; tcard;<br/> }<br/> if("Payment".equals(eName)) {<br/> i=1;<br/> }<br/> }<br/><br/> public void endElement(String namespaceURI, String sName, // simple name<br/> String qName // qualified name<br/> ) throws SAXException {<br/> String eName = sName;<br/> if ("".equals(eName))<br/> eName = qName;<br/> if("name".equals(eName)) {<br/> try {<br/> Echo01.out.write("</CustomerName>".getBytes());<br/> } catch (Exception e) {<br/> e.printStackTrace();<br/> }<br/> }<br/> if ("records".equals(eName)) {<br/> try {<br/> Echo01.out.write(("<CardCount>"count"</CardCount>").getBytes());<br/> Echo01.out.write(("<CardTotalPayment>"sum"</CardTotalPayment></records>").getBytes());<br/> } catch (Exception e) {<br/> e.printStackTrace();<br/> }<br/> count=0; sum=0;<br/> }<br/> }<br/><br/> public void characters(char buf[], int offset, int len)<br/> throws SAXException {<br/> String s = new String(buf, offset, len);<br/> if(i==1) {<br/> sum=Integer.parseInt(s); tsum+=Integer.parseInt(s); i=0;<br/> }<br/> if(j==1) {<br/> try {<br/> Echo01.out.write(s.trim().getBytes());<br/> }<br/> catch(IOException e) {<br/> e.printStackTrace();<br/> }<br/> j=0;<br/> }<br/> }<br/> // Start a new line<br/> private void nl() throws SAXException {<br/> String lineEnd = System.getProperty("line.separator");<br/> try {<br/> Echo01.out.write(lineEnd.getBytes());<br/> } catch (IOException e) {<br/> throw new SAXException("I/O error", e);<br/> }<br/> }<br/>}<br/><br/><br/><br/>Regards:<br/>Sankar Choudhury
It’s really looking nice.
It’s always easy to play with context and make easier the effort in consolidation or making the summary of the data. I just show this graphical technique to avoid the large code.
Cheers,
Sunil