Change notification sample details

You can run and rebuild this sample, and you can also look at source files to understand how this sample works.

Running this sample

To trigger notification for modifications:

  1. In the Samples Commands view, navigate to Samples Commands > Decision Center > Change notification.

    Tip:

    To open the Samples Commands view, you can click the View sample commands link in the Samples and Tutorials view.

  2. Execute the run command to create a project, some packages, and two rules to trigger notification.

    Note:

    The sample handles the ActionRule element only.

    The console displays the RSS data in XML format.

  3. Click the following link to subscribe to the RSS feed:

    http://localhost:<PORT>/teamserver/RSSRawProvider.jsp

    Note:
    • You can also configure notification for your RSS reader each time a user modifies a rule.

    • Certain browser versions might not recognize the RSS format. In this case, the tree is shown as XML.

    Look at the changes that you have made.

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.

    This link has the format http://localhost:<PORT>/teamserver/anonymous/faces/explore/details.jsp?project=...

    Notice from 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.

  2. Click the Query tab.

    You still do not have any editing buttons available.

  3. Click the Explore tab.

  4. Click the folder Samplepath > Samplepath1.

    Notice how you see only rules with a status of new.

  5. In the samples console, double-click the resetrss command to reset the RSS data on the server.

  6. Refresh your browser to see how recent changes are cleared.

Rebuilding this sample

To rebuild this sample:

  1. In the Samples Commands view, navigate to Samples Commands > Decision Center > Change notification.

  2. Execute the build command to recompile the code.

  3. In the Sample Server view, click Restore the Sample Server database to return the sample server to its initial state.

How this sample works

When you 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.

Action, notify, commit sequence

When you 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.

Action, notify, delete sequence

To make RSS data available, you use 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.

Action, notify workflow

To configure Decision Center to use the new controller, you implement a custom session controller, specify it in a preferences.properties file (teamserver.controller.class=ilog.rules.rts.samples.notification.model.NotificationController), and store it in a JAR file. You also specify the isUserInRole class as follows: teamserver.isUserInRole.class = ilog.rules.rts.samples.notification.model.MyIsUserInRoleCallback.

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

You perform the customization in the build.xml file. The repack command calls a predefined target named repackage-war which repackages the Decision Center EAR. This command uses the following parameters:

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.

To enable anonymous sign-in, you add 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, remove the comments from the code. In the sample, to do this automatically when repackaging the WAR, two descriptors are merged: anonymous-web.xml located in the \data directory and the original one from the Decision Center WAR (see the build.xml file for more details).

To customize the UI, the following bean classes are redefined DetailsToolbarBean, QueryToolbarBean, TableToolbarBean, TreeToolbarBean, and LinkBean to disable the editing features in the toolbars as well as the Compose tab.

After 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.

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

Source files

This sample is located in <InstallDir>/teamserver/samples/serveractionnotification/src/ilog/rules/rts/samples/notification.

You can also view and modify the sample source files in Rule Designer. To import the sample into your workspace, click the Import projects link in the Samples and Tutorials view, and switch to the Java perspective.