cancel
Showing results for 
Search instead for 
Did you mean: 

Complex mapping

oscar_mller
Explorer
0 Kudos

People,

I have a source xml where the structures are independent. The link between them is via the id field. See the example below:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:mtOrigem xmlns:ns0="http://poc.wilson.sons:testejoinentreestruturas">

   <header>

      <id>1</id>

   </header>

   <header>

      <id>2</id>

   </header>

   <item>

      <id>2</id>

      <item>2A</item>

      <valor>2000.00</valor>

   </item>

</ns0:mtOrigem>

In this example I have two headers (id 1 and 2) and an item on the id 2.

The problem is that the target structure is linked (the item is below the header). How to make that link? Notice that, after mapping, the item was below the id 1, when the correct would be below the id 2 :

<?xml version="1.0" encoding="UTF-8"?>

<ns0:mtDestino xmlns:ns0="http://poc.wilson.sons:testejoinentreestruturas">

   <header>

      <id>1</id>

      <item>

         <item>2A</item>

         <valor>2000.00</valor>

      </item>

   </header>

   <header>

      <id>2</id>

   </header>

</ns0:mtDestino>

Can anyone help me solve this issue? In the attached image is the print of the mapping.

Thanks,

Oscar Möller

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Oscar,

Please write multiple input, multiple output UDF with execution type 'all values in queue'. Input fields, id from header and all fields under item. Output fields as item field and valor field

Below is sample code


for (int i = 0; i < id_header.length; i++) { 

            for (int j = 0; j < id_item.length; j++) { 

                if (id_header[i].equals(id_item[j])) { 

                    result1.addValue(item_field[j]);

      result2.addValue(valor[j]));

                } 

            } 

            result.addValue(ResultList.CC); 

        }

Please check

oscar_mller
Explorer
0 Kudos

Raghu,

Thanks for the reply.

This UDF must be created according to what parameters and arguments? Then how should I use it in the mapping?

Thank You,

RaghuVamseedhar
Active Contributor
0 Kudos

Oscar,

Attaching screenshot of an example. Please develop UDF, similar to it.

Note:- Remove context of input fields.

oscar_mller
Explorer
0 Kudos

Thanks for the reply.

Only I have a question. What is the "CC" field in the last line: ResultList.CC

Thanks,

oscar_mller
Explorer
0 Kudos

Raghu,

I researched and found that the CC is the "context Change". Ok, but have not worked. The "CC" should not be after creating fields of the item? I put there, but it is only creating the first item of the first id. I'm trying to understand how the logic applies in the creation of tags. I removed the contexts of all input parameters. Is that so?

Thaks

oscar_mller
Explorer
0 Kudos

To help you, here are the attachments that illustrate what is happening.

Thanks

Former Member
0 Kudos

Hi Oscar,

Please find the below screen shots.

Check the above logic and let me know if your requirment is fulfilled or not.

Regards,

Raju.

oscar_mller
Explorer
0 Kudos

Excelent Raju.

I had not put the ResultList.CC for items.

Thank you very much.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Oscar,

Please try this method on your mapping.

Quickly building the mapping on my side.

Regards,

Jannus Botha

oscar_mller
Explorer
0 Kudos

Jannus,

Thank's for your reply. In its mapping, ROID is a structure? PartID is in the header or item?

Thank you,

Oscar

Former Member
0 Kudos

Hi Oscar,

Think i got the mapping. Not sure if all the scenario you have will work but this one will with the following mapping. Please see screen shots below.

The objects with the blue marking are from ITEM level.

Regards,

Jannus Botha

oscar_mller
Explorer
0 Kudos

Jannus,

It worked. Many thanks for the help.

Oscar

oscar_mller
Explorer
0 Kudos

Jannus,

Really worked for the example, but if I put more than one item for the same header or another item in another header, gives error in useoneasmany function.

The reason is that the second parameter is not much the number of contexts corresponding to the number of items or contexts of the first parameter.

I understood the logic of your mapping, but I can not find something valid for the second parameter, which makes work for all cases.

Can you help me again?

Thank's,

Former Member
0 Kudos

Hi Oscar,

You will need to provide me with a list of scenarios to be able to come up with a solution. Because the problem you had posted initialy was resolved by my mapping design.

So technically should this thread by closed.

Please provide me with the test cases.

Regards,

Jannus Botha

oscar_mller
Explorer
0 Kudos

Jannus,

Note that, in the source layout, the two structures are unbounded. So I can have 0..n items for each header. Here are other examples:

<? xml version = "1.0" encoding = "UTF-8"?>

<ns0: mtOrigem xmlns: ns0 = "http: //poc.wilson.sons: testejoinentreestruturas">

    <header>

       <id> 1 </ id>

    </ header>

    <header>

       <id> 2 </ id>

    </ header>

    <item>

       <id> 2 </ id>

       <item> 2A </ item>

       <value> 2000.00 </ value>

    </ item>

    <item>

       <id> 1 </ id>

       <item> 1A </ item>

       <value> 1000.00 </ value>

    </ item>

</ ns0: mtOrigem>

<? xml version = "1.0" encoding = "UTF-8"?>

<ns0: mtOrigem xmlns: ns0 = "http: //poc.wilson.sons: testejoinentreestruturas">

    <header>

       <id> 1 </ id>

    </ header>

    <header>

       <id> 2 </ id>

    </ header>

    <header>

       <id> 3 </ id>

    </ header>

    <item>

       <id> 3 </ id>

       <item> 3A </ item>

       <value> 3000.00 </ value>

    </ item>

    <item>

       <id> 1 </ id>

       <item> 1A </ item>

       <value> 1000.00 </ value>

    </ item>

    <item>

       <id> 3 </ id>

       <item> 3B </ item>

       <value> 3300.00 </ value>

    </ item>

</ ns0: mtOrigem>

Thank´s