cancel
Showing results for 
Search instead for 
Did you mean: 

Help wuth mapping - the task is complicated

Former Member
0 Kudos

Hello!

I have some structure:

<mt>

<element>

<priority>1</priority>

<usage>home</usage>

<key>aaa</key>

</element>

<element>

<priority>10</priority>

<usage>home</usage>

<key>bbb</key>

</element>

<element>

<priority>2</priority>

<usage>work</usage>

<key>ccc</key>

</element>

<element>

<priority>3</priority>

<usage>work</usage>

<key>ddd</key>

</element>

<element>

<priority>5</priority>

<usage>work</usage>

<key>eee</key>

</element>

</mt>

The element occurence is ounbounded. I need to have two elements in target: one with usage "work" and one with usage "home", each with the highest priority. For example, for the first I take all elements with usage "work". I need to select one element with the highest priority. For the second, I take all element with usage "home" and I need to select one element with the highest priority.

In my example above, I need to have something like this:

<mt>

<element>

<priority>10</priority>

<usage>home</usage>

<key>bbb</key>

</element>

<element>

<priority>5</priority>

<usage>work</usage>

<key>eee</key>

</element>

</mt>

How can I do this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

right click on Element and select duplicate subtree and map as follows

                             priority--->then
usage---->removeContext--->equalS---->ifWithoutelse--->sort(Ascending)---->collapseContext-->Element(first coccurence)
                  constant[home]/
                                                                                priority--->then
usage---->removeContext--->equalS---->ifWithoutelse--->sort(Ascending)---->collapseContext---->Element[1]     
              constant[work]/


Do the same for the Priority 
                       priority--->then
usage---->removeContext--->equalS---->ifWithoutelse--->sort(Ascending)---->collapseContext--->Priority(first coccurence)
           constant[home]/
                                                                                priority--->then
usage---->removeContext--->equalS---->ifWithoutelse--->sort(Ascending)---->collapseContext-->Priority[1]     
         constant[work]/
 


                                   priority--->then
usage---->removeContext--->equalS---->ifWithoutelse---> sortByKey---->collapseContext--->usage
                  constant[home]/
                                                                                usage--->then
usage---->removeContext--->equalS---->ifWithoutelse--->map to above sortByKey
              constant[home]/

Do the same for other second occurence of usage but change the constant value to work

Do the mapping of key as you map for usage

Answers (5)

Answers (5)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

This can be done without using UDF.. Please see mapping below:


For the node element:

element --> removeContext --> sort:Lexicographical (case insensitive) ascending --> splitByValue:value changed --> collapseContext --> element


For the priority:

usage --> removeContext --> sortByKey: Lexicographical (case insensitive) ascending --> formatByExample -->sort: numerical descending --> priority
priority --> removeContext --> /

usage --> removeContext --> sort:Lexicographical (case insensitive) ascending --> splitByValue: value changed -->/


For the usage:

usage --> removeContext --> sort:Lexicographical (case insensitive) ascending --> splitByValue:value changed --> collapseContext --> splitByValue:each value --> usage


For the key:

usage --> removeContext --> sortByKey: Lexicographical (case insensitive) ascending --> formatByExample -->sort: numerical descending --> priority
key --> removeContext --> /

usage --> removeContext --> sort:Lexicographical (case insensitive) ascending --> splitByValue: value changed -->/

Apologies, it seems that the preview button is missing

Former Member
0 Kudos

Hi

Try this.


//for your node

Priority(change context to node).........|
Usage(change context to node)........... |-->.SortbyKey(comparator numeric and order descending)----UDF-----Target(element)

Usage(change context to node)............|
Priority(change context to node)..........|-->.SortbyKey(comparator Lexicographical and order descending)----sort(comparator numerica and order descending)------->UDF-----Splitby Value-->Target(priority)

Priority(change context to node)........|
Usage(change context to node)...........|-->SortbyKey(comparator numeric and order descending)----UDF-----Splitby Value-->Target(usage)

//UDF in Queue


 for (int i = 0 ; i < list.length ; i++){
   if (i > 1)
      break;
  result.addValue(list<i>);
}

if you have any comments let me know.

Edited by: Luis Ortiz on Sep 23, 2009 11:42 AM

Former Member
0 Kudos

Dear Luis! Thanks for your help!

Priority in my case is unique.

How should I sort all other elements in my mapping? I mean "key" ?

Former Member
0 Kudos

Dear Luis, I think it doesn't works properly

If I need to use removeContext function before sortByKey ?

former_member187339
Active Contributor
0 Kudos

Hi Andrey,

Indeed it is complex.

Do these steps.

1. In message mapping, right click the subtree element and select duplicate subtree. Hence the target structure (in message mapping) will look like

>><mt><element><priority></priority><usage></usage><key></key></element><element><priority></priority><usage>work</usage><key></key></element><mt>

2. do the following mapping in first subtree


Constant --> element
constant ('H')..........................|    UDF1 .......sort(descending)....collapseContext--> priority
Usage(change context to node).........|
priority(change context to node).........|

constant('home') --> usage

constant ('H')..........................|    UDF2 ....... key
Usage(change context to node).........|
priority(change context to node).........|
key(change context to node).........|

3. and this mapping in second subtree

 
Constant --> element
constant ('W')..........................|    UDF1 .......sort(descending)....collapseContext--> priority
Usage(change context to node).........|
priority(change context to node).........|

constant('work') --> usage

constant ('W')..........................|    UDF2 ....... key
Usage(change context to node).........|
priority(change context to node).........|
key(change context to node).........|

4. The UDF1 : Type will be Queue and input will be usage, priority and Constant 'H' or 'W' (as per points 2 and 3)


if (const.equalIgnoreCase('H')) {
 for (int i=0;i<usage.length;i++) {
   if (usage<i>.equalIgnoreCase("HOME")) {
      result.addValue(priority<i>);
   }
 }
}
else { 
 for (int i=0;i<usage.length;i++) {
   if (usage<i>.equalIgnoreCase("WORK")) {
      result.addValue(priority<i>);
   }
 }  
}

5. The UDF2 : Type will be Queue and input will be usage, priority, key, and Constant 'H' or 'W' (as per points 2 and 3)


int outputPriority = 0;
int outputKey = 0;

if (const.equalIgnoreCase('H')) {
 for (int i=0;i<usage.length;i++) {
   if (usage<i>.equalIgnoreCase("HOME")) {
      if (outputPriority == 0) {
         outputPriority = Integer.parseInt(priority<i>);
      }
      if (outputPriority > Integer.parseInt(priority<i>)) 
          outputKey = key<i>;
      else {
          outputPriority = Integer.parseInt(priority<i>)
          outputKey = key<i>;
      }
   }
 }
 result.addValue(outputKey); 
 outputPriority = 0;
 outputKey = 0;
}
else { 
  for (int i=0;i<usage.length;i++) {
   if (usage<i>.equalIgnoreCase("WORK")) {
      if (outputPriority == 0) {
         outputPriority = Integer.parseInt(priority<i>);
      }
      if (outputPriority > Integer.parseInt(priority<i>)) 
          outputKey = key<i>;
      else {
          outputPriority = Integer.parseInt(priority<i>)
          outputKey = key<i>;
      }
   }
 }
 result.addValue(outputKey); 
 outputPriority = 0;
 outputKey = 0;
}

This shoudl surely work

Regards

Suraj

Edited by: S.R.Suraj on Sep 24, 2009 6:59 AM

SORRY I AM UNABLE TO CORRECT THE FORMATTING. HOPE SOME ADMINISTRATOR WILL SEE THIS AND HELP ME BY CORRECTING IT

Former Member
0 Kudos

Yeah you can use remove context. before sortbykey but it works with change node too.

Try again and let me know

Former Member
0 Kudos

How can I change context to node?

Former Member
0 Kudos

only rigth click on your source element and in the contextual menu choose the node root.

Former Member
0 Kudos

Could somebody help me with the code of UDF ? I know nothing about java programing

Former Member
0 Kudos

you need to get only two node per each element? only one home and work. and what happend if you file have two elements "work" with the same priority.?

Former Member
0 Kudos

Hi!

I think with pure Graphical Mapping this won't work. Despite from the recommendation UDF you might also create a java or abap mapping program. There you'll have "the freedom to do what you want" ... because you have control over the complete payload.

Regards,

Volker

VijayKonam
Active Contributor
0 Kudos

Write a UDF with Usage and Priority as inputs. With in the function find the maximum priority number for work/home. Then using the same index copy the value of your usage to the target. Should solve the problem.

VJ