Commentary - Sample Code (DerbyCommentary)

This sample Commentary plugin returns HTML content. It retrieves the HTML content from a DERBY database, using the target.

The Commentary plugin in this example does the following:

 

The sample code will cover the following:

Setup

This sample code needs the following to run:

About the DERBY SQL database

The 'COMMENT_LOCATION' column contains the ID of the 'target' to match.

The 'COMMENT_CONTENT" column contains the HTML commentary content for the 'target'.

 

Commentary
COMMENT_ID
COMMENT_LOCATION
COMMENT_CONTENT

About the DerbyCommentary plugin

To setup this scenario:

  1. Create the SQL Database. It doesn't have to be DERBY, but that is what the source code is set up for
  2. Create the Rulebase in Oracle Policy Modeling, and run Build
  3. Copy the rulebase .zip file from the project output directory (for example, C:\projects\ExtFrameworkDataAdaptor\Development\output) to the rulebase folder in the Web Determinations (for example, <webroot>\WEB-INF\classes\rulebase)
  4. Copy the code for the DerbyCommentary plugin (you may need to modify the database connection details)
  5. Compile and JAR the DerbyCommentary (you may need class files for your specific database implementation)
  6. Install the JAR file on the Web Determinations. More info in article: Create a Plugin
  7. Run a Web Determinations Interview

How the DerbyCommentary plugin works

Note:

In the example that follows, the DerbyCommentary will only register itself if the rulebase is 'ExtFrameworkCommentary'. In practice however, you will need to locate the rulebase name "ExtFrameworkCommentary" and change it to the name of the rulebase you will be using.

Once registered, the Web Determinations will call the DerbyCommentary.isCommentaryEnabled() when a screen is to be displayed. DerbyCommentary always returns true.

When a screen is to be displayed, Web Determinations calls DerbyCommentary.hasCommentary() method for the screen itself, to check if commentary information exists for the screen. The same method is also called for each attribute control to be displayed in the screen. DerbyCommentary.hasCommentary() uses the target to query DERBY database and check if commentary data is available for the target screen/attribute.

If DerbyCommentary.hasCommentary() returns true for a target, its label is rendered as a link.

When the user clicks on the label link, Web Determinations calls DerbyCommentary.isCommentaryRedirect() to check if the commentary for the target (the clicked label link) returns URL or HTML content. DerbyCommentary plugin always returns false, since it can only provide commentary in HTML content. 

Web Determinations then calls DerbyCommentary.getCommentaryContent() to get the HTML commentary content for the target. DerbyCommentary queries the DERBY database and retrieves the commentary for the target. As mentioned before, the DERBY database has stored the commentary in pure HTML format, so DerbyCommentary does not need to process the data from DERBY database into HTML. DerbyCommentary encapsulates the HTML string in a TypedInputStream, and returns it to Web Determinations for display.

A similar sequence of the above can be seen in Commentary Plugin

Source Code

Note the inline comments

DerbyCommentary.java