on 09-23-2009 2:44 PM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Could somebody help me with the code of UDF ? I know nothing about java programing
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.