Oracle Policy Automation – Commentary Plugin

Many consultants have been spending quality time with Oracle Policy Automation either as part of a Siebel project or for their own benefit to broaden their vision of CRM in general. One of the most commonly needed features in Oracle Policy Automation, just like in all CRM or IT projects, is help. I mean of course Help, as in Assistance. Web Determinations are complex beasts in many cases, and the end user may be faced with the challenge of understanding what they being asked, and should be asking, as well as understanding how it all fits together into the interview.

Let’s face it, if I asked you to enter item PA124 on a tax assessment form, you might need some help too.  Many Oracle Policy Automation Web Determination rulebases use the Commentary feature which automatically generates a set of HTML pages for editing, and displaying in the Web Determination session, based on key pages and attributes of your rulebase.

Generate Commentary Files

And the result can be seen below.

Commentary Standard

However the number of potential files that could be generated (and therefore that have to be managed), might mean quite another headache especially if you intend to release this with multiple translation files attached.

So it is good to note that the Oracle Policy Automation Web Determination Engine offers developers, (after a careful assessment of the business requirement and using all the standard options to try and reach a solution without customizing) , the ability to create a custom Commentary Plugin to replace the standard one.

The format of this plugin is documented online, although it is not entirely up-to-date. Here is a small example of what your Plugin might do:-

Get Commentary Data from an MS SQL Server Database

Storing Commentary in a database has many advantages. Make sure that the relevant JDBC libraries are available to your project. You can download them from Microsoft. Of course your platform might not be the same as mine but they generally can be found here.

Without going into unnecessary detail, I have a database with three columns that are of interest for this demonstration :-

COMMENTLOCATION, COMMENTCONTENT and COMMENTLOCALE

  • Comment Location will be the page identifier in the Web Determination session (so screen/summary is a location)
  • Comment Content will be the HTML we will send the Web Determination session (just some valid HTML for our Assistance text)
  • Comment Locale is the code of the session “en-US” or “fr-FR” for example.

So our table will support any number of items in any number of locales.

Table of Commentary

Coding the Plugin

Our Commentary Plugin will use three key methods to get the job done:- hasCommentary, getCommentaryContent, and RegisterInterviewPlugin. The first will identify if the current location has some Commentary text available in our table, and the second will return the Commentary HTML.

The final RegisterInterviewPlugin will ensure that our code is only used in the case of our special rulebase. All other rulebases will continue to use the standard Commentary system.

Some example Code

package com.oracle.determinations.interview.engine.plugins.commentary;
/* your imports go here
/**
 * Tutorials and Examples - Plugins - Commentary - Sample
 * Code(RedirectCommentary)
 * Adapted from the web example with corrections and adaptations for SQL Server
 * On Demand Education Ltd 2013
 */
public class ODECommentary implements CommentaryProviderPlugin {
private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
 private Connection connection = null;
 private Statement statement;
 public ODECommentary() {
 try {
 Class.forName(driver);
 System.out.println(driver + "loaded.");
 } catch (ClassNotFoundException e) {
 System.err.print("Class not found: " + e.getMessage());
 }
 }
 /**
 * Connects to the database and creates a statement
 * Uses MS SQL JDBC driver 
 * @throws SQLException
 */
 private void connectDBObjects() throws SQLException {
 connection =DriverManager.getConnection("jdbc:sqlserver://XXX.XXX.XXX.XXX:1433;databaseName=XXXX;user=ODED;password=XXXX");
 /** Output lots of things - just here for debugging
 * remember you can see them using the View > Embedded Web Server Output
 */ 
 System.out.println("Connected to database");
 statement = connection.createStatement();
 }
/**
 * Closes database objects and terminates the connection
 *
 * @throws SQLException
 */
 private void closeDBObjects() throws SQLException {
 statement.close();
 connection.close();
 System.out.println("Closed connection");
 }
 private TypedInputStream executeSQL(String sql, String filter, String field)
 throws RuntimeException {
 TypedInputStream content = null;
 try {
 connectDBObjects();
 if (statement.execute(String.format(sql, filter))) {
 ResultSet result = statement.getResultSet();
 if (result.next()) {
 content = new TypedInputStream(
 "text/html",
 new StringBufferInputStream(new String(result.getString(field))));
 }
 result.close();
 }
 } catch (Exception e) {
 throw new RuntimeException(e.getMessage());
 } finally {
 try {
 closeDBObjects();
 } catch (SQLException e) {
 throw new RuntimeException(e.getMessage());
 }
 }
 return content;
 }
 /** ******************************** */
 /* Web-determinations method calls */
 /** ******************************** */
/**
 * Returns the commentary content for the target if hasCommentary(session,
 * target) is satisfied
 */
 public TypedInputStream getCommentaryContent(InterviewSession session,
 String target) {
 TypedInputStream commentContent = null;
 try {
 /**
 * use the target and separate the locale for multilingual Web Determinations
 * with Commentary in our table
* retrieve Commentary Content for whatever page has Commentary when the user looks at it
 */

 commentContent = executeSQL(
 "select COMMENT_CONTENT from OPACOMMENTS where COMMENT_LOCATION='%s'AND COMMENTLOCALE ='" + session.getLocale() + "'",
 target,
 "COMMENT_CONTENT"
 );
 } catch (RuntimeException e) {
 throw e;
 }
 return commentContent;
 }
 /**
 * Should not be called at all because we are returning false in
 * isCommentaryRedirect(session, target)
 */
 public String getCommentaryURL(InterviewSession session, String target) {
 throw new UnsupportedException(
 "Should not call getCommentaryURL when is isCommentaryRedirect returns false.");
 }
/**
 * Returns true if the commentary for the target is available
 */
 public boolean hasCommentary(InterviewSession session, String target) {
 TypedInputStream commentLocation = null;
 /**
 * use the target and separate the locale for multilingual Web Determinations
 * with Commentary in our table
 */
 try {
 commentLocation = executeSQL(
 "select COMMENT_LOCATION from OPACOMMENTS where COMMENT_LOCATION='%s' AND COMMENTLOCALE='" + session.getLocale() + "'",
 target,
 "COMMENT_LOCATION"
 );
 } catch (RuntimeException e) {
 throw e;
 }
 return (commentLocation != null);
 }
/**
 * Returns true if the commentary for this Web Determinations Interview is
 * available
 */
 public boolean isCommentaryEnabled(InterviewSession session) {
 // check database connection
 try {
 connectDBObjects();
 closeDBObjects();
 return true;
 } catch (Exception e) {
 return false;
 }
 }
/**
 * The example always returns false because the plugin doesn't redirect to
 * another URL to fetch commentary content.
 */
 public boolean isCommentaryRedirect(InterviewSession session, String target) {
 return false;
 }
/**
 * Registers the plugin if and only if the rulebase is
 * 'WHATEVERYOURRULEBASENAMEIS'
 */
 public InterviewSessionPlugin getInstance(InterviewSessionRegisterArgs args) {
 System.out.println("Rulebase identifier is " + args.getSession().getRulebase().getIdentifier());
 if (args.getSession().getRulebase().getIdentifier().equals("WHATEVERYOURRULEBASENAMEIS")) {
 return new ODECommentary();
 }
 return null;
 }
}

Setting it Up

Of course this is not professionally coded and should not be used for anything beyond a learning exercise. After compiling your JAR file, drop it into the

Release\web-determinations\WEB-INF\classes\plugins

folder of your rulebase to test it. Don’t forget that the rulebase name is in the code, to only use our custom Plugin when a certain rulebase is loaded.

Make sure that you have placed edited the section of the code that mentions your server, database and the SQL query.Move any SQL Server drivers into the relevant classpath for your Server (again, for this demonstration we will not deploy on a live server, we will use the embedded one that comes with Oracle Policy Automation) so it might be that your sqljdbc4.jar or similar needs to go in a folder  like

C:Program Files\OraclePolicy Modeling\EmbeddedTomcat\lib

Running the Plugin

Enter at least two lines into your Database Table, preferably using the example (the Summary Screen) for simplicity. Make sure each of the lines has a Locale. Ensure that your rulebase provides either base content or translation files to cover your two Locales.

Run the Web Determination Session from Oracle Policy Modelling with Ctrl + F5. Of course you will need least one question ready to  be asked in your Web Determination session.

ODE Commentary Plugin

In our case as you saw above we are ready to run our session. In the english version we see the text from the appropriate table in our Determination Window.

And the same for the French version, but with the appropriate Commentary of course. For multi-lingual projects particularly this might open up a more manageable, ongoing and interactive approach to Commentary content.

There is a very short video on the web to see what the example looks like here. Happy Commentarying!


Note: The attached files have been removed. If you are interested in them contact the author