Web authoring application sample details

You use Decision Center to run this sample.

Running this sample

Before you run this sample, note that Decision Center manages different user groups. The Paul user that is provided by default belongs to the rtsAdministrator group, which has all the permissions. In this sample, the rmtuser user is defined with permissions that are described in data/rmtUserGroup.properties. Users who belong to this group can do the following tasks:
  • Create action rules and decision tables.

  • Update the definition property for action rules and decision tables that are created by users in the group.

  • Update any other elements.

  • View any elements.

  • Delete action rules and decision tables if created by users in the group.

  • Delete all other elements.

Decision Center provides a locking mechanism for rule elements to prevent concurrent editing. You cannot edit an element if it is locked. Elements are locked when you edit them, and unlocked afterward, when you close the elements with or without changes.

In the following procedures, you learn these tasks:
  • Viewing project security settings.
  • Using the web application that gives access to Decision Center data.
  • Checking the permissions of the Loan Validation Service project.
To view the security settings of the Loan Validation Service project:
  1. Open a web browser and enter the following URL to access Decision Center:

    http://localhost:<PORT>/decisioncenter/

  2. Sign in to Decision Center by using the following details:

    User name: Paul

    Password: Paul

  3. Click the Administration menu, and open the Project Security tab.

  4. Inspect the Loan Validation Service. Notice that security is enforced on all the rule projects in Loan Validation Service, and that rmtUserGroup is one of the groups set for all the rule projects in Loan Validation Service.

  5. Sign out of Decision Center.

To use the web application that is connected to Decision Center:
  1. Open your web browser and enter the following URL:

    http://localhost:<PORT>/dcclient

  2. Sign in by using the following details:

    User name: rmtuser

    Password: rmtuser

  3. The selected project is Loan Validation Scoring, which is part of the Loan Validation Service decision service.

  4. Click Choose your action rule to view the action rules in the Loan Validation Scoring project.

  5. Open the Decision Table tab to see the decision tables in the project.
  6. Go back to the Rule tab, and select neverBankruptcy.

    Notice that the Save and Remove buttons are enabled but clicking them produces a permission error. This is because you signed in as rmtuser and can update only the rules that were created by your group.

  7. Go to the Decision Table tab, and select bankruptcyScore in the Decision Table tab.

    It displays the definition of the decision table. Notice that all the decision table buttons are enabled, but you get a permission error when you click Save or Remove. This error occurs because the decision table was not created by your group.

  8. Go back to the Rule tab.

  9. Create a new action rule in the computation package, and name it NewRule.

    Notice that the Remove and Save buttons now work.

  10. Sign out.

To check the permission of the projects in the Loan Validation Service decision service:
  1. Open a web browser and enter the following URL:

    http://localhost:<PORT>/dcclient

  2. Sign in by using the following details:

    User name: Paul

    Password: Paul

  3. Select the rule neverBankruptcy.

    Notice that the Save and Remove buttons now work. By signing in as Paul, you can update any rule.

Rebuilding this sample

To rebuild this sample:
  1. In the Samples Commands view, navigate to Samples Commands > Decision Center > Web authoring application.

  2. Double-click build to compile the code.

Note:

To restore the initial security settings for the Loan Validation Service project, run the run.remove.permission Ant command.

How this sample works

In this sample you learn:
  • How to set and unset the permissions on a project.

  • How to use the Decision Center web components.

  • How to lock and unlock objects.

The main of the class PermissionHelper (located in <InstallDir>/teamserver/samples/servercomponents/src/com/ibm/rules/web/sample/utils) unsets the permission if there is an argument, otherwise it sets them. To set the permissions, see the setPermissionsForRole() function.

The following APIs come with this sample:
  • addGroup(session, userGroup): Adds the user and group to Decision Center.

  • enForceSecurity(session, project, userGroup): Enforces the permission and adds the new group for all the rule projects in Loan Validation Service.

  • loadSorted(resourceName): Reads the properties file and builds a map of permissions with it. The property file is data/rmtUserGroup.properties.

  • setPermissionsForRole(session, usergroup, propertiesMap): Sets the permissions map to the user.

To unset the permissions, see the function disableSecurity(session, project). It calls the Decision Center API to disable the security for a project.

The editing component is managed by three servlets declared in the WEB-INF/web.xml description file:
  • AppServlet: This servlet manages the load of projects from Decision Center, selects the current project to use, and top-level project content (the lists of packages, decision tables, and action rules for the project). The commands for this servlet can be found in src/com/ibm/rules/web/sample/servlet/command/app.
  • DecisionTableEditorServlet: This servlet manages the commands for decision tables, for example, create, save, and remove. The commands are in src/com/ibm/rules/web/sample/servlet/command/dt.
  • RuleEditorServlet: This servlet manages commands for action rules, for example, load, create, save, and remove. The commands are in src/com/ibm/rules/web/sample/servlet/command/rule.

The editing components are used in sample.jsp. The sample uses drop-down menus for selecting projects, rules, and decision tables. The page is dynamic, and its content is based on Dojo.

To lock or unlock objects, use the class RTSHelper in <InstalDir>teamserver/samples/servercomponents/src/com/ibm/rules/web/sample/utils. It provides functions that call the Decision Center API before and after editing:
  • isElementBusy(session, element): Checks whether the element can be edited.
  • lockElement(session, element): Locks the element.
  • unlockElement(session, element): Unlocks the element.

Source files

This sample is located in <InstallDir>/teamserver/samples/servercomponents/src/com/ibm/rules/web/sample.

The connection to the decision center data is allowed by utils/ConnectionBean.java. It is used in servercomponents/webapp/header.jsp, and uses the following methods for logging in and out:
  • login()

    This method creates a new Decision Center session with the provided parameters.

  • logout()

    This method signs you out of the Decision Center session.

A helper class provides functions to create action rules or decision tables in the Decision Center, and to check the permissions: utils/RTSHelper.java.

Commands to manage projects, decision tables, and action rules are dispatched to different places based what is managed:

  • src/com/ibm/rules/web/sample/servlet/command/app
  • src/com/ibm/rules/web/sample/servlet/command/dt
  • src/com/ibm/rules/web/sample/command/rule/
The installer package modifies the Loan Validation Service project security with Ant tasks. They are not used by the web application. This class manages the permissions:
  • utils/PermissionHelper.java

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.