cancel
Showing results for 
Search instead for 
Did you mean: 

nested-table to flat structure mapping -- take first entry from source

Former Member
0 Kudos

Hello XI gurus,

I need help with the following mapping.

I have the following source structure.

Root (1..1)
    Source_MT (1/unbounded)
        Name (1..1)
        Location (0..1)
            Region (0..unbounded)
        Position (1..unbounded)
            Start (1..1)

And, the target structure.

Target_MT (0..unbounded) <-- one of this for each Source_MT/Position
    Name (0..1)
    Region (0..1) <-- take the first Root/Source_MT/Location/Region from above
    Start (0..1)

The is my mapping so far.

Target_MT = Position <i>[context Root]</i>

Target_MT/Name = SplitByValue<i>[Each value]</i>( useOneAsMany( Root/Source_MT/Name, Position, Position) )

I need help on mapping the element ‘Region’. Can someone help? Thanks in advance.

Points will be awarded.

-mhd

Accepted Solutions (1)

Accepted Solutions (1)

henrique_pinto
Active Contributor
0 Kudos

This way it works for me:


Target_MT = RemoveContext(Root/Source_MT/Position);
Target_MT/Name = SplitByValue[Each value](useOneAsMany(Root/Source_MT/Name, Root/Source_MT/Position, Root/Source_MT/Position);
Target_MT/Region = SplitByValue[Each value](useOneAsMany(UDF1(Root/Source_MT/Location/Region), Root/Source_MT/Position, Root/Source_MT/Position);
Target_MT/Start = Root/Source_MT/Position/Start

where UDF1 is of Context type (not Queue) with the simple code below:


public void UDF1(String[] a,ResultList result,Container container){
result.addValue(a[0]);
}

Regards,

Henrique.

Former Member
0 Kudos

Henrique,

You're absolutely fabulous !!

It works. Thank you very much for your help.

-Michelle

justin_santhanam
Active Contributor

Michelle,

Great work Henrique!!

I think u've solved the issue.Consider the below logic and see whether it suits ur reqmt.

Mapping logic for EmployerOrg[Target]

http://www.flickr.com/photo_zoom.gne?id=810536210&size=o

Mapping logic for EmployerOrgName[Target]

http://www.flickr.com/photo_zoom.gne?id=810536230&size=o

Mapping logic for Municipality[Target]

http://www.flickr.com/photo_zoom.gne?id=810536244&size=o

Mapping logic for Region[Target]

http://www.flickr.com/photo_zoom.gne?id=810536274&size=o

Mapping logic for StartDate[Target]

http://www.flickr.com/photo_zoom.gne?id=810536290&size=o

Final-Results

http://www.flickr.com/photo_zoom.gne?id=810536436&size=o

Hope it helps!!!!

Best regards,

raj.

Former Member
0 Kudos

Raj,

You are wonderful. Thank you so much for all your effort!!

By the way, could you explain what happen when I did CopyValue to Region[]? What exactly does the queue look like after CopyValue?

-mhd

justin_santhanam
Active Contributor
0 Kudos

Michelle,

Thats fine!! Good to know u solved the issue. Michelle , how u used CopyValue function, I mean from source to target whats the flow u applied.

Best regards,

raj.

Former Member
0 Kudos

Hi Raj,

The original problem is solved but I'm now trying to educate myself. We can take it off-line or start a new thread, if you prefer.

The flow is :

Region 
= SplitByValue( useOneAsMany( CopyValue(Region[context EmployerOrg], position, position ] ) ).

Essentially, what I did was trying to apply CopyValue to Region, instead of using Henrique's UDF1. This is my original NAIVE attempt, which causes an error below.

The error is 'Too few values in first queue in function useOneAsMany. It must have the same number of contexts as second queue.'.

My question now is what does the queues to useOneAsMany look like that causes this error??

Best regards,

-Michelle

henrique_pinto
Active Contributor
0 Kudos

Hey Michelle,

glad to know it helped.

It is strange that you gave 10 points but the thread isn't marked as answered.

Would you check it and close the thread, please?

Regards,

Henrique.

Former Member
0 Kudos

Henrique,

Everytime I added something to a thread, the marked will turn to unmarked.

I will make sure it's closed.

Best regards,

-Michelle

henrique_pinto
Active Contributor
0 Kudos

Michelle,

no problems then.

Regards,

Henrique.

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Michelle,

Could you populate some data and reply us the structure u needed?

Best regards,

raj.

Former Member
0 Kudos

Hi Raj,

Thank you for your reply.

The source and result below have more fields than the outline I gave above. But they should give you some idea of what I'm trying to do. The problem is I'm not getting the 'Region' element right.

This is the source.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Resume xmlns:ns0="http://ns.hr-xml.org/2007-04-15">
   <ns0:StructuredXMLResume>
      <ns0:EmploymentHistory>

         <ns0:EmployerOrg>

            <ns0:EmployerOrgName>First ER</ns0:EmployerOrgName>
            <ns0:EmployerContactInfo>
               <ns0:LocationSummary>
                  <ns0:Municipality>  city 1     </ns0:Municipality>
                  <ns0:Region>dd1</ns0:Region>
                  <ns0:Region>dd2</ns0:Region>
                  <ns0:Region>dd3</ns0:Region>
               </ns0:LocationSummary>
            </ns0:EmployerContactInfo>

            <ns0:PositionHistory>
               <ns0:StartDate>20011231</ns0:StartDate>
            </ns0:PositionHistory>

             <ns0:PositionHistory>
               <ns0:StartDate>20021231</ns0:StartDate>
            </ns0:PositionHistory>

         </ns0:EmployerOrg>


         <ns0:EmployerOrg>

            <ns0:EmployerOrgName>Second ER</ns0:EmployerOrgName>
            <ns0:EmployerContactInfo>
               <ns0:LocationSummary>
                  <ns0:Municipality>  city 2     </ns0:Municipality>
                  <ns0:Region>dd4</ns0:Region>
                  <ns0:Region>dd5</ns0:Region>
                  <ns0:Region>dd6</ns0:Region>
               </ns0:LocationSummary>
            </ns0:EmployerContactInfo>

            <ns0:PositionHistory>
               <ns0:StartDate>20031231</ns0:StartDate>
            </ns0:PositionHistory>

             <ns0:PositionHistory>
               <ns0:StartDate>20041231</ns0:StartDate>
            </ns0:PositionHistory>
         </ns0:EmployerOrg>



      </ns0:EmploymentHistory>
   </ns0:StructuredXMLResume>
</ns0:Resume>

Below is the desired result. I added the nodes for Region in manually to show how I want it to be.

<?xml version="1.0" encoding="UTF-8"?>
<ns1:MainResume_MT xmlns:ns1="http://xiExercise.com/gry">
   <ResumeBody>

      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
         <Region>  dd1     </Region>
         <StartDate>20011231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
        <Region>  dd1     </Region>
         <StartDate>20021231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
        <Region>  dd4     </Region>
         <StartDate>20031231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
        <Region>  dd4     </Region>
         <StartDate>20041231</StartDate>
      </EmployerOrg>

   </ResumeBody>
</ns1:MainResume_MT>

-mhd

Message was edited by:

Michelle Harin-Dirac

Former Member
0 Kudos

Michelle,

You are making more complicated nested structures. I would suggest to remove <ns0:StructuredXMLResume> <ns0:EmploymentHistory> in your source structure. Then you will get rid of two unwanted structures. Then we will give a shot. Is this feasible for you?

Regards,

---Satish

justin_santhanam
Active Contributor
0 Kudos

Michelle,

If I understood ur problem correctly, the issue u are facing is . For the first tw0 employer u are getting correct Region and not for the second two employer since there is context change happened. U want always the first occurrence of Region from the whole source payload am I right? If yes try the below

Region[Change Context to <b>EmployerContactInfo</b>]-->RemoveContext--> Region[target]

I'm sure it will work.

Michelle, the above stuff will work. But use either change context <b>or</b> Remove Context, it will solve the issue.

Best regards,

raj.

Former Member
0 Kudos

Hi Satish,

Thanks for your reply.

Unfortunately, the source is a standard and we cannot change it.

Best regards,

-mhd

Former Member
0 Kudos

Hi Raj,

I'm sorry...not the first occurrence of Region of the WHOLE souce payload.

The regions dd1, dd2, dd3 and the first two positions go with the first EmployerOrg.

The regions dd4, dd5, dd6 and the last two positions go with the second EmployerOrg.

For each position in the source, there should be one EmployerOrg in the result.

In the result, the first two EmployerOrg should get dd1 region.

And, the second two EmployerOrg should get dd4 region.

Both dd1 and dd4 are the first occurrence within its own EmployerOrg in the source.

Should I still try your solution?

Best regards,

-mhd

justin_santhanam
Active Contributor
0 Kudos

Michelle,

Sorry for the late reply. Did u tried Mapping Region to Region Directly? Can u try this and let us know the results. I think it will work.

Consider the below case

dd1

dd2

dd3

<b>[Context Change]</b>

dd4

dd5

dd6

So if u mapped directly, after context change it will take only the first value, if i'm not wrong!!

Best regards,

raj.

Former Member
0 Kudos

Hello Raj,

I tried your method and this is the result.

<?xml version="1.0" encoding="UTF-8"?>
<ns1:MainResume_MT xmlns:ns1="http://xiExercise.com/gry">
   <ResumeBody>

      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
         <Region>dd1</Region>
         <StartDate>20011231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
         <Region>dd4</Region>
         <StartDate>20021231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
         <StartDate>20031231</StartDate>
      </EmployerOrg>

      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
         <StartDate>20041231</StartDate>
      </EmployerOrg>

   </ResumeBody>
</ns1:MainResume_MT>

The last two EmployerOrg do not get the Region and the second EmployerOrg gets the wrong Region, i.e. dd4 instead of dd1.

Do you think changing the context of Region might help?

Best regards,

-mhd

justin_santhanam
Active Contributor
0 Kudos

Michelle,

I'm really sorry , since I don't have system right now I cudn't able to check and tell u the soln.If u don't mind could u please try my previous suggestion and let me know the results.

Best regards,

raj.

Former Member
0 Kudos

Raj,

I truely appreciate your help.

I tried the following mapping.

Region = removeContexts( Region<i>[context EmployerContactInfo]</i> )

This is the result. Only the firsts get a Region.

<?xml version="1.0" encoding="UTF-8"?>
<ns1:MainResume_MT xmlns:ns1="http://xiExercise.com/gry">
   <ResumeBody>
      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
         <Region>dd1</Region>
         <StartDate>20011231</StartDate>
      </EmployerOrg>
      <EmployerOrg>
         <EmployerOrgName>First ER</EmployerOrgName>
         <Municipality>  city 1     </Municipality>
         <StartDate>20021231</StartDate>
      </EmployerOrg>
      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
         <StartDate>20031231</StartDate>
      </EmployerOrg>
      <EmployerOrg>
         <EmployerOrgName>Second ER</EmployerOrgName>
         <Municipality>  city 2     </Municipality>
         <StartDate>20041231</StartDate>
      </EmployerOrg>
   </ResumeBody>
</ns1:MainResume_MT>

Best regards,

-mhd

Former Member
0 Kudos

Raj,

I also tried this.

Region 
= SplitByValue( useOneAsMany( CopyValue(Region[context EmployerOrg], position, position ] ) ).

So, I CopyValue Region first and put it in useOneAsMany along with Positions and then do SplitByValue.

But it has an error 'Too few values in first queue in function useOneAsMany. It must have the same number of contexts as second queue.'

I guess after CopyValue, there is no contexts left. Is there a way to put the contexts back?

-mhd

Former Member
0 Kudos

Any other ideas? Anyone?

Best regards,

-mhd