Samples > Rule Team Server Business Rule Management Extensions > How to Trigger Notifications when Elements Change in Rule Team Server

This sample shows how to:

To show these, the change notification URL is generated using a permanent link on the modified element. This link allows users to access Rule Team Server as anonymous users with read-only permissions. In addition, anonymous users can only view rules that have a status of new.

Implementing these requirements in Rule Team Server involves the following:

Key Features

Key features of this sample include:

Installing this Sample

To install this sample through the Samples Console:

  1. Check that the Samples Server is started. For information on how to start and stop the Samples Server, see Stopping and Restarting the Samples Server from the Samples Console.
  2. Go to the Samples Console and locate the teamserver > serveractionnotification sample.
  3. Execute the deploy command to deploy the new EAR.
  4. This compiles the application, repackages the EAR, and deploys it to the application server.
  5. Wait for the Java EE application to start before continuing.

Running this Sample

This sample can only be opened and run in the Samples Console.

How to Trigger Notifications

To see how you can be notified of modifications:

  1. Execute the run command in the Samples Console to create a project, some packages, and two rules that will be used to trigger notification.
    Note
    The sample handles only the ActionRule element.
  2. The RSS data is displayed on the console in XML format.
  3. Click on the following link to subscribe to the RSS feed:
  4. http://localhost:8080/teamserver/RSSRawProvider.jsp
    Note
    You can also configure your own RSS reader to be notified each time a rule is modified.
    Note
    The RSS format may not be recognized on certain browser versions. In this case, the tree is shown as XML.
    Notice the changes that you have just done.
How to Use Permanent Links and Enable Anonymous Sign-in
  1. In the RSS reader, copy the permanent link from either rulename1 or rulename1Active to your browser.
  2. This link has the format http://localhost:8080/teamserver/anonymous/faces/explore/details.jsp?project=...
    Notice, at the right of the top banner, that you are not signed in, and that as an anonymous user you do not have access to any of the editing buttons in the toolbar.
  3. Click the Query tab.
  4. Here, again, you do not have any editing buttons available.
  5. Click the Explore tab.
  6. Click the folder Samplepath > Samplepath1.
  7. Notice how you only see rules with a status of new.
  8. In the Samples Console, double-click the resetrss command to reset the RSS data on the server.
  9. Refresh your Reader to see how recent changes have been cleared.

Source Files

This sample is located in <InstallDir>/teamserver/samples/serveractionnotification.

Highlights

Highlights of this sample are as follows.

Create or update an element

The NotificationController.onCommitElement() method is called when entering the IlrSession.commit method, just before committing an element. An event containing all relevant data is created and stored in a thread-local storage. The NotificationController.elementCommitted() is called just after an element has been committed. The event is retrieved from a thread-local storage and an RSS item is created in memory.

images/action_notify_commit.png

Delete an element

The NotificationController.onDeleteElement() method is called when entering the IlrSession.delete() method, just before deleting an element. The NotificationController.elementDeleted() method is called just after an element has been deleted.

images/action_notify_delete.png

Make an RSS reader HTTP request

RSS data is made available via an HTTP request. Whenever an RSS reader requests RSS data, the .jsp script is executed and an RSS-formatted string is returned. All RSS items generated by creating, updating, or deleting are stored in memory, as shown above. When the application server shuts down, items are persisted in a file and when the application server is restarted, items are read from the file and loaded into memory.

images/action_notify_workflow.png

Customize the Rule Team Server EAR file

To configure Rule Team Server to use the new controller, a custom session controller is implemented. It is specified in a preferences.properties file (teamserver.controller.class=ilog.rules.rts.samples.notification.model.NotificationController) and stored in a JAR file. Also specified in this file is the isUserInRole class to be used (teamserver.isUserInRole.class = ilog.rules.rts.samples.notification.model.MyIsUserInRoleCallback).

Included are three additional JAR files containing the sample code and an RSS library.

This customization is done in the build.xml file. The repack command calls a predefined target named repackage-ear that helps repack the Rule Team Server EAR. This command uses the following parameters:

Generate permanent link

To get a permanent link on the modified element, you use the method getElementDetailsURL from the class ilog.rules.teamserver.model.permalink.IlrPermanentLinkHelper.

You create an instance of IlrPermanentLinkHelper with anonymous enabled.

Enable anonymous sign-in

Anonymous sign-in is enabled by adding the extensionsFilter, the accessFilter, and the Faces Servlet mapping for anonymous in the web.xml descriptor. These lines are already present in the delivered web.xml file so you simply have to uncomment them. In the sample, to do this automatically when repackging the EAR, two descriptors are merged: anonymous-web.xml located in the \data directory, and the original one we get from the Rule Team Server EAR (see the build.xml file for more details).

Customize the UI to have anonymous users connected to a read-only Rule Team Server

To do this, some bean classes are redefined: DetailsToolbarBean, QueryToolbarBean, TableToolbarBean, TreeToolbarBean, and LinkBean to disable the editing features in the toolbars as well as the Compose tab.

Once these classes are redefined, they are added to the JSF configuration file for extended features, extended-faces-config.xml, and this file is added to the repackaged EAR.

Redefine the search

To redefine the search criteria to have anonymous users view only rules with the status new, redefine the redefineSearch method on the controller.

Rebuilding this Sample

To rebuild this sample, execute the build command to recompile the code.

Related Concepts

Rulesets and Ruleset Archives
Extracting Artifacts to be Put in a Ruleset

Related Tasks

Deploying and Exporting RuleApps