Monday, February 8, 2010

I Want My Custom Java Function for Siebel!

Have you ever wanted to create a new customized function and call that from your RTF templates so that you don’t have to implement a same condition or calculation logic again and again with many different reports ?

I talked about this yesterday a little bit, but I had this problem when I was developing the Siebel reports and had to implement a date formatting or do some date related calculations. As I discussed yesterday that the Siebel  Integration Object generates the date data in its own format like ‘08/15/2008 09:20:11’ unlike the ‘Canonical’ format that BI Publisher expects, which is something like ‘2008-08-15T09:20:11’. Please check the previous post for the detail.

At the previous post, I have suggested two options to workaround this and talked about the first option with ‘totext()’ function. Today, I’m going to talk about the second option, which is to develop a Java custom function and use it in the RTF template.

Develop Custom Extended Java Function

BI Publisher supports the Java custom function that the users can develop their own functions with Java and call it from the RTF template. This will allow the users to hide tedious or complex calculation/business logic and centralize them in a single place, which not only improves the development productivity but also reduce the maintenance headache.

So, how to develop the Java custom function ? Luckily, Mr. BIP, Tim Dexter, has already talked about how to develop the custom Java function at his blog. Please check his post for the detail. At this post I’m going to talk about how to create one to convert the Siebel’s date data to BI Publisher’s ‘Canonical’ date format.

Here is the example of the function does the conversion.

package oracle.bip.extensions;

public class BIPExtensions {
    public BIPExtensions() {
    }
  
    public static final String convertDate(String cdate){
        String conv_date = "";

        if(cdate.length() == 11){
            conv_date = cdate.substring(6,10)+"-"+cdate.substring(0,2)+"-"+cdate.substring(3,5);
        }else if(cdate.length() == 19){
            conv_date = cdate.substring(6,10)+"-"+cdate.substring(0,2)+"-"+cdate.substring(3,5)+"T"+cdate.substring(11,19);
        }else{
            conv_date = cdate;
        }
        return(conv_date);
    }

}

The example above is a pretty simple one for a demo. It gets the Siebel given date, convert it to the ‘Canonical’ date formatted string, and returns. If the given date contains only the ‘MM/DD/YYYY’ portion then it returns only the date in ‘YYYY-MM-DD’ format. If it contains the time data also then it returns ‘YYY-MM-DDTHH:MI:SS’.

This is just an example. So of course you can develop anything you want and develop as many functions as you want in the same class. Once you completed the development you can compile it and deploy it to a JAR file.

At this point, the next thing you want to do is to test the function with your RTF template. There are three steps to follow.

Setup Your MS-Word Add-in Template Builder Environment

I have talked about how to setup the MS-Word Template Builder environment so that we can use the Siebel’s extended functions at this post, ‘Siebel’s Extended Function for RTF Template’.

Basically we need to do the same thing in order to use the above custom function. So what we need to do is to add one more JAR file location in the ‘_JAVA_OPTIONS’ variable in the MS-Word launch batch script file. Here is the example assuming that the JAR file is called ‘BIP_Extension.jar’ and located under ‘C:\JDeveloper\mywork\Local\Project1\deploy\’.

echo %1

set _JAVA_OPTIONS=-Xbootclasspath/a:D:\811DQSSIA\client\classes\SiebelXMLP.jar;D:\811DQSSIA\client\classes\XMLP.jar;D:\811DQSSIA\client\classes\siebel.jar;D:\811DQSSIA\client\classes\XSLFunctions.jar;D:\811DQSSIA\client\classes\SiebelCustomXMLP.jar;D:\811DQSSIA\client\classes\SiebelCustomXMLP_SIA.jar;C:\JDeveloper\mywork\Local\Project1\deploy\BIP_Extension.jar

"C:\Program Files\microsoft office\Office12\Winword.exe" %1

Now you can double click this .bat file to open your RTF template.

Declare a Name Space for the Extended Function

As mentioned in the ‘Siebel’s Extended Function for RTF Template’ post, you need to first specifying the custom class file by declaring its name space with the class path.


<?namespace:bipext=http://www.oracle.com/XSL/Transform/java/oracle.bip.extensions.BIPExtensions?>

Use it!

Once the name space is declared then you can use it as the same way you use the ‘xdoxslt’ or ‘xdofx’ functions. Type the name space first then type the function. Here is an example.


<?bipext:convertDate(ssCreatedDate)?>

My convertDate function takes an input parameter value of date string so I set a XML element name that holds the date data.

And after you ensure that the functions works appropriately then you can deploy it to the server side following the steps at ‘Siebel’s Extended Function for RTF Template’.

Conclusion

So now you got this whole freedom of developing and adding your functions to the BI Publisher’s reports development realm. However, note that as I suggested before you should review the existing BI Publisher’s native functions and the Siebel’s extended functions first to see if they can be used to meet your requirements. Developing your own new functions means you will be responsible for the maintenance. And it’s not uncommon that one developer develops something and leave after a project is completed, then the other members left alone have no idea how to fix it when a problem occurred with the custom functions. As long as you use the functions provided by Oracle then Oracle will be responsible for the fix. That’s the difference you want to consider for the long term.

Keep that in your mind have fun with the custom Java function !

1 comment:

  1. Hi Kanichiro ,

    One thing i missed in above explaination , how did you relate the namespace and jar you have created .

    I mean , in namespace , you have mentioned `http://www.oracle.com/XSL/Transform/java/oracle.bip.extensions` .

    Did you keep the at actual that location on server . I amm developing on my local desktop .

    warm regards
    shekhar

    ReplyDelete