By Andrew Higginbottom on Dec 09, 2013
Welcome to this TMT, today I will show you how to create a Web Determinations plugin. Plugins provide a mechanism to alter the default behavior throughout the Oracle Policy Automation web applications. You can use plugins to change the way pages and controls are rendered, the way sessions are loaded and saved, where rulebases are loaded from, and the way many other aspects of the applications work. Plugins are developed as Java or .NET classes and packaged and deployed as JARs or DLLs.
In this tutorial we will start from a completely empty workspace and have an event handler plugin up and running in under 10 minutes.
Before we get started there are two prerequisites to download:
- Eclipse IDE for Java EE Developers (I used Kepler SR1)
- Oracle Policy Automation runtime components for Java (I used v10.4.4.21.0)
Expand the downloads to a convenient location and launch eclipse.exe within the eclipse folder. Create a workspace folder (or accept the default) to hold the eclipse project files and continue to the eclipse IDE. Close the Welcome tab to see the normal eclipse view.
Now we are ready to import the out of the box Web Determinations application via the menu. File > Import, choose Web > WAR file.
On the next screen Browse... to the location where you expanded the OPA runtime download, and navigate to \web-determinations\web-determinations.war. Leave the rest of the field defaults and click Finish.
Once the project has finished importing we are ready to develop our plugin. The first step is to add our plugin class. Right-click the Java Resources > src folder then New > Class.
Enter your desired package name and class name (you will need these later) and use the Add... button to add the interface OnSessionCreatedEventHandler to the class definition. Click Finish to, well, finish.
Within the generated class we will make a few small changes to register the plugin correctly and print a message to System.out every time a session is created.
We need to change line 12 to "return this;" and on line 17 we use a basic println to write something to the output. Go on, type it, it's only one line - but please don't do this in production code!
Now we are finished with building the plugin, we just need to configure Web Determinations to load it. For development we edit the src/configuration/application.properties file to specify the plugin's class name but you can also bundle your plugin into a JAR which will be loaded automatically from the plugins folder. Add the fully qualified name of your plugin class to the "plugin.libraries=" line:
We now copy a rulebase into the src/rulebases folder so we can actually start a session. When a single rulebase is present in the rulebases folder a new session will automatically be launched in that rulebase when the user hits the base URL. Copy in the HealthyEating.zip rulebase from the \examples\rulebases\compiled folder in your expanded OPA runtime location. You can do this by copying from Windows Explorer and pasting via the context menu in eclipse.
Now we are ready to test our new plugin within a Web Deteminations session. We can Run the web-determinations project on the J2EE Preview Server provided in eclipse. Select the project root folder (web-determinations) and from the main menu use Run > Run, then Run on Server. On the next screen select Basic > J2EE Preview and click Finish.
Once the server starts up you should see the summary screen and in the Console window your message printed from the handleEvent method of your class!
This is a very simple example, intended to show how to set up a development environment and develop your first Web Determinations plugin. There a many more things you could do within this event, such as loading some reference data, creating entity instances and so on.
There are also many more event handlers you can implement and other types of plugins for changing the default Web Determinations behaviors, such as Data Adaptors, List Providers and Custom Screen/Control Providers. Check out the Extensions topic in the Oracle Policy Automation 10.4.4 Developer's Guide, starting from the Documentation page on OTN.
Check back soon for a Determinations Server plugin tutorial!