Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

Helpful UDFs - 1

$
0
0

Dear Users,

 

Here are some UDFs that might me helpful in your business scenarios.

 

1. UDF for Date Conversion :

 

          This UDF is used to convert the given date into required time zone and date format, it takes actual date as first input, required time zone as second input and format as third input which is validated based upon the second input. it validates the format of the both inputs and if true, returns actual date otherwise throws an exception. To use this, we need to import the UTIL and TEXT pages.

 

 

        Untitled.png

Code :

 

                       DateFormat df1 =new SimpleDateFormat(DateFormat);

            

                       df1.setTimeZone(TimeZone.getDefault());

            

                        DateFormat df2 = new SimpleDateFormat(DateFormat);

 

                       df2.setTimeZone(TimeZone.getTimeZone(ReqTimeZone));

 

                       String target = " ";

 

                       try

 

                      {

  

                       Date d = df1.parse(CurrentDate);

    

                      target = df2.format(d);

 

                      }

 

                     catch( Exception e)

 

                    {}

 

                    Return target;

 

  Input :


                    1.png

Output :


                       2.png




2. Combining Array Elements:


             This is Queuetype UDF.It takes a string and delimiter value as arrays and combines all the array elements with a delimiter and sends as single value.


                      6.png


Code :

 

                  String res="",delimiter="";

 

                  res = StrArray[0]

 

                  delimiter = Separator[0];

 

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

 

                  res = res+delimiter+StrArray[i];

 

                  result.addValue(res);


Input and Output :


                  7.png


3 . Checking Mandatory Field

 

                      This is a simple type UDF. It takes a single value and checks if the node exists or not. If the node exists, it returns same value, Otherwise it throws an exception.


                 8.png


Code :

 

                  if (!var1.equals("")&&(Var1.length()>0))

 

                  return var1;

 

                  else

 

                  throw new RuntimeException("This field is mandatory : value is missing");


                 

Input   :


                 9.png


Output     :



                  10.png


4. Remove Domain Name


               This is simple type UDF. It takes a mail id as input and removes the domain name.


                11.png


Code :


                  String Pattern = "@xyz.com";

 

                  String StrippedString = str.replaceAll(pattern,"");

 

                  return strippedstring;

             

                                    Input :                                                                            Output                                                                                                        


                  1.png2.png

5. Checks for the end of the List

 

                      This is Queue type UDF. It takes a set of values as input and sends all the values to output until the end of the list field appears for the first time.

 

                   3.png

 

Code :

 

                 int i = 0;

            

                 int j = 0;

 

                 // check for the presence of EOD

                 while (!Var1[i].equals("EOD"))

            

                  {

            

                  // add the values till EOD is not present

                  result.addvalue(var1[i]);

 

                  i=i+1;

 

                  }

 

                                         Input :                                                             Output

 

                    5.png6.png


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>