cancel
Showing results for 
Search instead for 
Did you mean: 

Context handling to achieve the target structure

Former Member
0 Kudos

Hi All,

Please check the below requirement and let me know how to achieve it.

Source:

A1

|------INVITEM1

|------INVIPART1

|------INVIMATER1

|------INVITEM11

|------INVIPART11

|------INVIMATER11

A2

|------INVITEM2

|------INVIPART2

|------INVIMATER2

Target:

A1

|------INVITEM1

             |------INVIPART1

             |------INVIMATER1

|------INVITEM11

             |------INVIPART11

             |------INVIMATER11

A2

|------INVITEM2

             |------INVIPART2

             |------INVIMATER2

No fields are common in the parent and child nodes. I need to achieve this through graphical mapping.Please help.

Regards,

Nutan

Accepted Solutions (0)

Answers (1)

Answers (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Nutan,

Paste your source and Traget structure defined in PI based on that someone can help you.

use split value function with value change option .

Regards,

Raj

former_member190624
Active Contributor
0 Kudos

Hi Nutan,

Please use Java mapping (SAX parser) for your requirement .

Regards

Hari.

Former Member
0 Kudos

Hi Hari,

Is it not possible with graphical mapping?

Regards,

Nutan

Former Member
0 Kudos

Hi Raj,

By SplitbyValue the Target structure is coming as below:

Source:

A1

|------INVITEM1

|------INVIPART1

|------INVIMATER1

|------INVITEM11

|------INVIPART11

|------INVIMATER11

|------INVIMATER12

A2

|------INVITEM2

|------INVIPART2

Target:

A1

|----INVITEM1

      |-------INVIPART1

      |-------INVIMATER1

|-----INVITEM11

      |-------INVIPART11

      |-------INVIMATER11

A2

|-----INVITEM2

      |-------INVIPART2

      |-------INVIMATER12

In the source Under A1 after INVITEM11 there are two INVIMATER11 and INVIMATER12, so in the target both the INVIMATER11 and INVIMATER12 should have come under INVITEM11, but as you can see it's just splitting by value and moving into next node of A2--INVITEM2, which is incorrect.

My aim is achieve this:

whenever INVITEM is coming in source a new node should be created in target and the below INVIPART and INVIMATER should be added under the INVITEM node as in the source.

If INVITEM is twice in source under one context then it should be created twice in target under one context and INVIMATER and INVIPART should follow the context of INVITEM as in the target.

     

Regards,

Nutan

former_member190624
Active Contributor
0 Kudos

Hi Nutan,

I doubt that your requirement will be achieved by Graphical mapping .With following java code you can get your output.

Call below class from transform() method .  Hope this code will help you

mport java.io.OutputStream;

import org.xml.sax.Attributes;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

public class Nutan extends DefaultHandler {

    private OutputStream out;

    String chars;

    Nutan (OutputStream out)

    {this.out= out;}

    public void print(String str) throws SAXException

    {

        try{

            out.write(str.getBytes());

            out.flush();

           

        }

        catch(Exception e){

            e.printStackTrace();

        }

    }

   

    public void characters(char[] ch, int start, int length)

            throws SAXException {

        chars = new String(ch,start, length);

       

            print(chars);

            //System.out.println(chars);

                // TODO Auto-generated method stub

       

    }

    public void endDocument() throws SAXException {

        print("</nutan>");

        // TODO Auto-generated method stub

       

    }

    public void endElement(String uri, String localName, String name1)

            throws SAXException{

        //super.endElement(uri, localName, name);

        if(name1.equals("A1"))

        {}

        if(name1.equalsIgnoreCase("INVIPART1"))

        {

           

            print("</INVIPART1>");

        }

        if(name1.equalsIgnoreCase("INVIMATER1"))

        {

           

            print("</INVIMATER1>");

            print("</INVITEM1>");

        }

        if(name1.equalsIgnoreCase("INVIPART11"))

        {

           

            print("</INVIPART11>");

        }

        if(name1.equalsIgnoreCase("INVIMATER11"))

        {

           

            print("</INVIMATER11>");

            print("</INVITEM11>");

            print("</A1>");

        }

       

    }

    public void startDocument() throws SAXException {

        // TODO Auto-generated method stub

        print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

        print("<nutan>");

        //System.out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

   

       

    }

    public void startElement(String uri, String localName, String name,

            Attributes atts) throws SAXException {

        //System.out.println(uri);

        //System.out.println(localName);

        System.out.println(name);

        if(name.equals("A1"))

        {

           

            print("<A1>");

        }

               

        if(name.equalsIgnoreCase("INVITEM1"))

        {

           

            print("<INVITEM1>");

        }

        if(name.equalsIgnoreCase("INVIPART1"))

       

        {

           

            print("<INVIPART1>");

        }

        if(name.equalsIgnoreCase("INVIMATER1"))

           

        {

           

            print("<INVIMATER1>");

        }

        if(name.equalsIgnoreCase("INVITEM11"))

        {

           

            print("<INVITEM11>");

        }

        if(name.equalsIgnoreCase("INVIPART11"))

       

        {

           

            print("<INVIPART11>");

        }

        if(name.equalsIgnoreCase("INVIMATER11"))

           

        {

           

            print("<INVIMATER11>");

        }

    }

}

Regards

Hari.

Former Member
0 Kudos

Hi Hari,

The nodes can repeat many times. I check the source data, it's having sequence number along with each node as below:

Source:

A1

|------INVITEM1        (sequence no 1)

|------INVIPART1       (2)

|------INVIMATER1    (3)

|------INVITEM11       (4)

|------INVIPART11      (5)

|------INVIMATER11   (6)

|------INVIMATER12   (7)

A2

|------INVITEM2     (1)

|------INVIPART2   (2)

so I hope to achieve target the sequence no can be used. I can compare INVITEM and INVIPART sequence no.

please check the below code:

here var1 = sequence no of INVITEM and var2 = sequence no of INVIPART.

for(int i =0;i<2;)

{

  int x = i; i++;

    for(int j =0; j<3;j++)

     {

        if((var1[x]<var2[j]) && (var1[i]>var2[j]))

          {

            result.addValue(var2[j]);

             i --;

           }

         else

           {

             result.addContextChange();

             result.addValue(var2[j]);

                } 

       }

}

vk_k3
Participant
0 Kudos

HI Nutan,

Is your issue resolved?

let me know I will try to check ur requirement.

Regards,

VK