on 08-27-2015 11:57 AM
Dear Experts,
I am working on a mapping logic where i will get the input data in the string , i need to generate a new field for every 5 characters.
My source structure :
MT_Source:
<config>
<product>
<feature id="BAYAADWAA9IDBA9ABCD3"/>
</product>
</config>
Desired Target structure
MT_Target
<config>
<product>
<feature id="BAYAA"/>
<feature id="DWAA9"/>
<feature id="IDBA9"/>
<feature id="ABCD3"/>
</product>
</config>
Please provide your valuable inputs.
Thanks,
Pavan T
take input one field as "field" and one output as "result" udf type is all values of a context.
int len = field[0].length();
String str = field[0];
int number = (int)Math.ceil(len/5.0);
for(int i=0; i<number; i++)
{
if(i!=number-1)
result.addValue(str.substring(i*5,(i+1)5));
else
result.addValue(str.substring(i*5,str.length());
}
ex
ABCDE
FGHIJ
KLMNO
P 15-16
len 16
num = 4
ABCDEFGHIJKLMNOP
map the udf to target node featureID
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Viany,
I am getting below error while testing the mapping.
Source text of object Message Mapping: MM_Request | http://Gforce_POC_Retrive_Catalog_Codes has syntax errors: |
You should use code given by sahithi its better and faster
but just to correct the typing mistakes i have corrected the code
int len = field[0].length();
String str = field[0];
int number = (int)Math.ceil(len/5.0);
for(int i=0; i<number; i++)
{
if(i!=number-1)
result.addValue(str.substring(i*5,(i+1)*5));
else
result.addValue(str.substring(i*5,str.length()));
}
Hi Vinay,
I Removed split value for for feature. I am getting id values in feature also. i want values to be populate in "id" field only.
<?xml version="1.0" encoding="UTF-8" ?>
</ns2:Product>
</ns1:Config>
</ns2:ContentSet>
</ns1:ContentSets>
</ns1:DescribeConfigRequest>
Hi Pavan,
You can use the code given by Sahithi as it is looking optimized one if you ask me.
Just in the code replace input with input[0] and use the same exact code as it is.
Here, for target Feature node, give the output of the udf as it is.
For Id target attribute, use split by value after the udf and pass to the target.
@Sahithi: I assume you don't mind on this. I have just though of writing the code using if and else but saw the code given by you in the mean time, so just told the minor correction which you have forgotten..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Achieve using below UDF:
int size = 5;
for (int i = 0; i < input.length(); i += size){
int end = i + size > input.length() ? input.length() : i + size;
result.addValue(input.substring(i, end));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pavan,
I guess you cant use the same names for mutliple fields in XML.
if your requirement is to achieve something like below
<feature id="BAYAA"/>
<feature id1="DWAA9"/>
<feature id2="IDBA9"/>
<feature id3="ABCD3"/>
you can use Substring function in mapping function to achieve the requirment.
Feature Id = substring(0,5)
Feature Id 1 = substring(5,5)
Feature Id 2 = substring(10,5)
Feature Id 3 = substring ( 15.5)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.