Skip to Content

In PART – I ,  we have seen as How to frame/create the GS1 XML Main schema .

In this blog we are going to see how to use in ESR to get the desired result/GS1 Output.

Steps to be performed in ESR

Step 1:  


Import the design schema which we have zipped as Architecture Schema” in earlier step.

Step 2:  


Create all the standard objects , like Source DT , MT , SI

Here the Source is Proxy so source DT is required and target is External definition so no Target DT.

Step 3:  


Create Message Mapping between Source Proxy structure and GS1 xml Structure (Architecture Schema).

Important Note :


  1. Architecture Schema: This can be linked to any business document. Here we are linking with Price Synchronization Document.
  2. Once you have completed your message mapping , the xml output which we are going to get won’t be directly usable in GS1.
  3. Hence we need to create Cascade java mapping to achieve this.
  4. Java code as follows

package com.sap.pi.gs1;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.util.HashMap;

import java.util.Map;

import java.io.*;

import java.util.Date;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import com.sap.aii.mapping.api.AbstractTrace;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationConstants;

import com.sap.aii.mapping.api.StreamTransformationException;

public class MultiTextReplaceGS1 implements StreamTransformation  {

                /**

                 * @param args

                 * This program to Convert/Clean the Mapping output to GS1 understandable format

                 * Here we have used HashMap

                 */

           

                private Map map = null;

                private AbstractTrace trace = null;

                public void setParameter(Map arg0) {

                map = arg0; // Store reference to the mapping parameters

                if (map == null) {

                this.map = new HashMap();

                }

                }

                public void execute(InputStream arg0, OutputStream arg1)

                throws StreamTransformationException {

                String line = null;

           

                BufferedReader reader = new BufferedReader(new InputStreamReader(arg0));

                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(arg1));

           

                StringBuffer buffer = new StringBuffer();

           

                // To set the Current date time for PriceSync Header URL

           

                DateFormat dateFormatDate = new SimpleDateFormat(“yyyy-MM-dd”);

           

                DateFormat dateFormatTime = new SimpleDateFormat(“HH:mm:ss”);

           

                Date date = new Date();

           

                // To set the Price Sync header create date and time stamp

           

                String PriceSyncHeaderDate = dateFormatDate.format(date)+”T”+ dateFormatTime.format(date);

            

                // Get reference to mapping trace

           

                trace = (AbstractTrace)map.get(StreamTransformationConstants.MAPPING_TRACE);

           

                trace.addInfo(“Processing message”);

           

                try {

                                trace.addWarning(“Read Started”);

                                while((line = reader.readLine()) != null) {

                                    buffer.append(line);

                                    buffer.append(“\r\n”);

                                }

                           

                                trace.addWarning(“Read Completed”);

                            

                                reader.close();

                                                             

                                trace.addWarning(“Replacement Going to start”);

                           

Map<String, String> ReplacementMap = new HashMap<String, String>();

                           

                                ReplacementMap.put(“<ns1:StandardBusinessDocument xmlns:ns1=\”http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader\”>”,  “<sh:StandardBusinessDocument xmlns:sh=\”http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader\” xmlns:eanucc=\”urn:ean.ucc:2\” xmlns:gdsn=\”urn:ean.ucc:gdsn:2\” xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” xsi:schemaLocation=\”http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader http://www.gdsregistry.org/2.8/schemas/sbdh/StandardBusinessDocumentHeader.xsd urn:ean.ucc:2 http://www.gdsregistry.org/2.8/schemas/PriceSynchronisationDocumentProxy.xsd\”>”);

                                trace.addWarning(“StandardBusinessDocument Header URL Set completed”);

                           

                                ReplacementMap.put(“ns2:message xmlns:ns2=\”urn:ean.ucc:2\””, “eanucc:message” );

   

ReplacementMap.put(“ns2:message”, “eanucc:message” );

        ReplacementMap.put(“ns1”, “sh”); 

              

ReplacementMap.put(“ns2:entityIdentification”,”entityIdentification”);

   

ReplacementMap.put(“ns2:documentCommand>”,”eanucc:documentCommand>”);

                           

                                ReplacementMap.put(“ns2:transaction”,”eanucc:transaction”);

                                           

                            

                               // Price tag change  along with header time stamp

                           

                                 ReplacementMap.put(“<ns3:priceSynchronisationDocument xmlns:ns3=\”urn:ean.ucc:gdsn:2\” lastUpdateDate=\”\” creationDateTime=\”\” documentStatus=\”\”>”, “<gdsn:priceSynchronisationDocument xsi:schemaLocation=\”urn:ean.ucc:2 http://www.gdsregistry.org/2.8/schemas/PriceSynchronisationDocumentProxy.xsd\” documentStatus=\”ORIGINAL\” creationDateTime=\”” + PriceSyncHeaderDate +”\”>”);

                           

                                 trace.addWarning(“priceSynchronisationDocument Header URL Set completed”);

                            

                                 ReplacementMap.put(“ns3:priceSynchronisationDocument>”,”gdsn:priceSynchronisationDocument>”);

                                                                                                           

                                String toWrite = buffer.toString();

                           

                                           

                                for (Map.Entry<String, String> entry : ReplacementMap.entrySet())

                                {

                                    toWrite = toWrite.replaceAll(entry.getKey(), entry.getValue());

                                }

                                                           

                                //Once we get the complete coverted output , we have to replace all  ns2: to empty

                           

                                String updateWrite = toWrite.replaceAll(“ns2:”,””);

                                                           

                                bw.write(updateWrite);

                           

                                trace.addWarning(“Replacement Completed Successfully”);

                           

                                  // Flush and close

                           

                                bw.flush();

                           

                                bw.close();

                           

                } catch (IOException ioe) {

                           

                trace.addWarning(“Could not process source message” + ioe.toString());

           

                throw new RuntimeException(ioe.getMessage());

           

                }              

                trace.addInfo(“Processing completed successfully”);

                }               

           

}

5. Crate Jar file

6. Create imported archive using the jar.


Step 5:    Create Operation Mapping and Use Java class after the Message Mapping

            Java_Mapping.jpg

All done!   🙂

Happy Learning.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply