Skip to Content

Dear SCN Users,

Adding some more UDFs in addition to the mentioned UDFs in the below blog which can be reused.

USEFUL UDFs


1.UDF For Mapping Trace:

This UDF is to get the Values executed in the UDF . Very useful for debugging purpose.

Code:


MappingTrace trace=container.getTrace();

trace.addInfo(“Input Value —->”+strVal);

return strVal;


Untitled.png

2.UDF For removing duplicate/repeated values in Queue/Context:


Below UDF can be used to remove the duplicate or repeated values in queue/context. If execution type is selected as Queue, duplicate values in queue are removed. Same applies for context.


Code:


int k=0;

String b[]= new String[100];

for (int i=0;i<inputStr.length;i++)

{

char flag=0;

if(inputStr[i].equals(ResultList.CC))

{

result.addValue(ResultList.CC); 

  flag=1;

}

else

{

  for(int j=i+1;j<inputStr.length;j++)

   if(inputStr[i].equals(inputStr[j]))

      flag= 1;

}

if (flag==0)

{

b[k]=inputStr[i];

    result.addValue(b[k]);

k++;

}


Untitled.png


3.UDF For Generating Unique/Random Value(UUID):


Below UDF can be used to generate random unique value. This can be also used in Soap header in which particular fields might required UUID to be generated.No input is required for this UDF.


Code:


public String uniqueValueGeneration(Container container) throws StreamTransformationException{

  UUID uuid = UUID.randomUUID();                           // In Java UUID is a keyword.

  String randomUUIDString = uuid.toString();

   return randomUUIDString;

}


Untitled.png


4.UDF To convert Decimal to Integer Values:


Below UDF converts Decimal value to Integer value.


Code:


if(!decVal.equals(“”) && (decVal.length()>0))

{

    float floatVal = Float.parseFloat(decVal);

    int res = (int)floatVal;

    return String.valueOf(res);

}

else return decVal;


Untitled.png



5.Java Code to Add Time:


The below code was written to add a delay of 4 hours to the time field. We had this requirement to add a time difference in Soap header for authentication purpose. The same logic can be used  in UDF for time based functionalities.


Code:


import java.util.*;

import java.lang.*;

import java.text.*;

public class AddingTime {

public static Object AddTime(String TimeSent)
{
  SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss’Z'”);             
  Calendar cal = Calendar.getInstance();
  try
  {
    Date requiredDate = (Date)df.parse(TimeSent);
    cal.setTime(requiredDate);
    cal.add(Calendar.HOUR, Integer.parseInt(“4”));
  }
  catch(Exception e)
  {
  }
  return (df.format(cal.getTime()));

 
 
}

}

Input Example:2016-09-18 T 06:04:20’56         

Output Example:2016-09-18 T 10:04:20’56         


To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply