cancel
Showing results for 
Search instead for 
Did you mean: 

Tricky Java UDF

Former Member
0 Kudos

Hello Sdn

I have bit tricky problem to achieve through java udf in XI. We have to parse a tricky text in java.

Source has a text field : ST - 102RP34;RP - 234ST89;VT - 90789ST;

So the souce text field has a qualifier - value;

In target , I have 3 repeating segments

1) First segment to be created if qualifier is ST ,second segment for qualifier RP,third segment for qualifier VT.

2) There exists 1 field in each segment.

Target Field value for first segment : 10234RP34

Target Field for second sement : 234ST89

Target field for third segment :90789ST

So the problem and trick ,as i understand is : we have 3 qualifiers but in values for these qualifier also we have qualifier values ST,RP etc. So we cant just directly take index of qualifiers as values also have qualifier values.Eg : we have a value : 10234RP34 and RP is also the qualifier.

There will be 2 udfs : one for segment creation and other for the Target field value.

Basically with help of some do while or some loop we need to extract value after "-" and before " ;" and this shld be in some loop to get all the values.

Please help. I am not a java person.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

text to be parsed. ST - 102RP34;RP - 234ST89;VT - 90789ST;


function ( String text ) 
{
  StringTokenizer str = new StringTokenzier( text, ";");  //split the string with ; delimeter
  while (str.hasToken())  //will loop for 3 times,
  {
     String ele = str.nextToken(); 
     StringTokenizer qua = new StringTokenzier( ele, "-" );
     String qualifier = qua.nextToken();  // this will contain ST, RP, VT
     String value = qua.nextToken();      // this will contain 102RP34, 234ST89, 9789ST
    
   //add ur logic here for each element

  }

}

let me know if any issues.

Former Member
0 Kudos

Hello sdn

Frankly speaking ,I dont understand what will be the output of your code as you are not returning anything and do we need to use it at segment level or field level and what kind of function will it be : value or context or queue?

Since there are 3 segments and each segment has one value, so i guess we need 6 udfs : 3 + 3 ,If I could get one udf for segment level and other for field level ,i could manage myself by coping and changing the qualifier.

Eg : if source text field value is : ST - 102RP34;RP - 234ST89;VT - 90789ST;

Then in target side i want to create a sement for qualifier RP and its corresponding field should have a value : 234ST89

But point is, RP is also coming in the value for qualifier ST

I am not good in java, can you please help me out by giving a code, for segment and other for field mapping. If something is not clear ,I could tell. I am not proficient in java ,as i mentioned above also. Help would be appreciated from any one.

Thanks

Edited by: Guest1 guest on Oct 31, 2008 1:26 AM

Edited by: Guest1 guest on Oct 31, 2008 1:32 AM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Assuming that your target is having nodes like

 
qualifier
value
qualifier 
value 
qualifier
value

You need 2 UDF's one to generate qualifier and another to generate value from the input String of parameter cache context

For generating qualifier


public void qualifier(String[] input,ResultList result,Container container)
{
                           String element, qualifier ="";
 StringTokenizer token1 = new StringTokenizer( input, ";");
			  while (token1.hasMoreTokens())
			  {
				 element = token1.nextToken(); 
				 StringTokenizer token2 = new StringTokenizer( element, "-" );
				 qualifier = token2.nextToken();
				 result.addValue(qualifier);  	   		 
			  }
}
}

output returned will be

ST
RP
VT

Another UDF just and extension of the above can give values(type context)


public void values(String[] input,ResultList result,Container container)
{
String element, qualifier,value ="";
 StringTokenizer token1 = new StringTokenizer( input, ";");
			  while (token1.hasMoreTokens())
			  {
				 element = token1.nextToken(); 
				 StringTokenizer token2 = new StringTokenizer( element, "-" );
				 qualifier = token2.nextToken();
                                 value = token2.nextToken();
				 result.addValue(value);  	   		 
			  }
}
}

output returned will be

102RP34
234ST89
90789ST

Thanks

Gaurav

Former Member
0 Kudos

Hello Sdn

Assuming that above code works ,still we need to modify it as the req is that if qualifier = RP then create a segment ,and in that segment the field should have a value corresponding to that qualifier.

Eg : if source text field value is : ST - 102RP34;RP - 234ST89;VT - 90789ST;

Then in target side i want to create a segment for qualifier RP and its corresponding field should have a value : 234ST89

The target side segment is repeating , there r 3 segments on target side for these 3 qualifiers

How to modify the above code to achieve this functionality?

I dont hav a system right now and i will just have some hours tomorrow to implement this.

Thanks

Former Member
0 Kudos

Hello sdn

The code mentioned above gives some issues : class needs to be defined for String Tokenizer.

Can someone help in debugging ?

My requirement:

Eg : if source text field value is : ST - 102RP34;RP - 234ST89;VT - 90789ST;

Then in target side i want to create a sement for qualifier RP and its corresponding field should have a value : 234ST89

Thanks

Edited by: Guest1 guest on Oct 31, 2008 6:09 PM

Former Member
0 Kudos

>

> Hello sdn

>

> The code mentioned above gives some issues : class needs to be defined for String Tokenizer.

>

> Can someone help in debugging ?

>

>

> My requirement:

>

> Eg : if source text field value is : ST - 102RP34;RP - 234ST89;VT - 90789ST;

>

> Then in target side i want to create a sement for qualifier RP and its corresponding field should have a value : 234ST89

>

>

>

> Thanks

>

> Edited by: Guest1 guest on Oct 31, 2008 6:09 PM

you need to provide import statment and import java.util.StringTokenizer

create the udf with above logic provided..

input will the string & another parameter (RP/VT/ST) --> UDF (will return the value for the constant parameter that is passed ) --> map to the element (RP) or if need to create then use the node function.

Former Member
0 Kudos

Hello sdn

I do not understand , conteaxt function needs array as an input and output ,we r just returning qualifier.

a is my input which is the text field.

secondly i m getting error:

symbol : constructor StringTokenizer (java.lang.String[],java.lang.String) location: class java.util.StringTokenizer StringTokenizer token1 = new StringTokenizer( a, ";");

^ 1 error

Thanks

Former Member
0 Kudos

Hi Guest

Replied with answer in newer post from you.

Thanks

Gaurav

Former Member
0 Kudos

Hello Anand /Gaurav

Your code is also working ,since it was a context function so it was expecting an array in the below line

StringTokenizer token1 = new StringTokenizer( input, ";");

I just changed input to input[0] and it worked.

Thanks