| Samples > Rule Team Server Authoring Extensions > How to Use Web Components for Rule Editing |
How to Use Web Components for Rule Editing |
PREVIOUS NEXT |
This sample shows how to build a web application using ILOG JRules web components to display and edit action rules and decision tables. It also manages permissions on a project. The web application opens a connection with Rule Team Server to get data from its database. The rules and decision tables are displayed and edited in the user web application using the following web components:
This sample contains a configuration file to describe the new user roles and permissions needed for the sample.
Key features of this sample include:
To install this sample:
teamserver > servercomponents sample.
run command to compile and package the application, and then deploy it to JBoss.
The application has been deployed
Executing the run target builds and deploys the Server Components application on JBoss. In addition, the loanvalidation-rules project is modified as follows:
rmtuser is associated with the project
Before running the sample, note that Rule Team Server manages different user groups. The user rtsAdmin provided by default belongs to the rtsAdministrator group, which has all permissions. In this sample, the user rmtuser is defined with permissions described in data/rmtUserGroup.properties. They specify that users belonging to this group can:
definition property for action rules and decision tables if they were created by someone from their own group
The following describes:
rmtuser
rtsAdmin
To view the security settings of the loanvalidation-rules project:
rmtUserGroup from the drop-down list and view its current security settings. Note that users belonging to this group can update the content of action rules created by members of their own group.
To use the web application connected to Rule Team Server:
rmtuser can only update rules that were created by your group.
To check the permission of the loanvalidation-rules project:
| Note |
You can restore the initial security settings for the loanvalidation-rules project by executing the run.remove.permission Ant command
|
This sample is located in <InstallDir>/teamserver/samples/servercomponents.
The sample is based on the Sun JSF framework. A typical JavaServer Faces application includes one or more backing beans (JavaBean components associated with UI components used in a page). A backing bean defines UI component properties, each of which is bound to either a component's value or a component instance. A backing bean also defines methods that perform functions associated with a component. In our case, the beans feed the model that will be displayed and handle navigation processing.
The beans are in the package ilog.rule.sample.tree:
AbstractBean.java - The base class of the backing beans. It manages a list of errors.
ConnectionBean.java - The backing bean that stores the Rule Team Server connection parameters. It is used in servercomponents/WebContent/loginform.jsp
login() - Called to create a new Rule Team Server session with the given parameters.
logout() - Called to sign out of the Rule Team Server session.
TreeBean.java - The backing bean that manages the Rule Team Server project data. It is used in servercomponents/WebContent/treesample.jsp
treeController - The tree controller is provided to the Rule Team Server tree component to build the Rule Team Server project data tree. It gives access to the rule elements to display: the folders, the action rules, and the decision tables.
create() - Creates a new decision table or action rule in the current Rule Team Server project.
delete() - Deletes the decision table or action rule currently selected in the tree component.
display() - Displays the rule element in read-only.
edit() - Available if the user has permission to edit the rule and if the element is not already locked. It opens the editor corresponding to the decision table or action rule currently selected in the tree component. It relies on RuleEditorFacade to get the right web component editor. It locks the rule element.
save() - Saves all editor modifications to Rule Team Server and unlocks the element.
cancel() - Disregards all editor modifications to Rule Team Server and unlocks the element.
errors - This list contains the errors raised by Rule Team Server when saving rules.
BeanHelper.java - A utility class to get the bean from the JSF framework.
RTSHelper.java - Provides functions to create action rules or decision tables in Rule Team Server and to check the permissions.
The editors part is in the package ilog.rule.sample.editor:
Editor.java - An abstract editor class used by the Editor facade.
doPrint() - Displays the editor in a port.
doSave() - Saves the editor contents to Rule Team Server.
DecisionTableEditor.java - Extends the editor class for the decision table. It uses an instance of IlrDTWTableComponent to edit the decision table.
RuleEditor.java - Extends the editor class for the action rule. It uses an instance of IlrWSyntacticEditor to edit the action rule.
RuleEditorFacade.java - Lets the tree controller choose the correct editor according to the type of selected rule.
The JSF specific part is in package ilog.rule.sample.jsf:
JSFHelper.java - Provides functions to get information from JSF such as the session or the request and to add or remove messages in JSF.
JSFRuleEditorFacade.java - The editor facade implementation for the JSF framework.
The utilities class are in the package ilog.rule.sample.util:
Messages.java - Reads all messages from data/servercomponents.properties.
The installer package is used to modify the loanvalidation-rules project security with Ant tasks. They are not used by the web application.
PermissionHelper.java - Manages the permissions.
In this sample you learn:
The main of the class PermissionHelper unsets the permission if there is an argument, otherwise it sets them. To set the permissions, see the setPermissionsForRole() function:
addGroup(session, userGroup) function - Adds the user and group to Rule Team Server.
enForceSecurity(session, project, userGroup) - Enforces the permission and adds the new group for the loanvalidation-rules project.
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 function disableSecurity(session, project). It calls the Rule Team Server API to disable the security for the given project.
Editing of components is managed by a controller. This controller is a servlet declared in the WEB-INF/web.xml description file. The components are:
teamserver tag library. The component is declared in the WEB-INF/faces-config.xml description file, and used in treesample.jsp with the Rule Team Server tag teamserver:treeview.
treesample.jsp through the tree bean. This calls the editor facade to get the editor corresponding to the selected type. The editor for action rules is an instance of IlrWSyntacticEditor. The editor for decision tables is an extension of IlrDTWTableComponent. See the following functions in DecisionTableEditor.java and RuleEditor.java:
doPrint(port, readonly, session, response, element) - Calls the print function of the component to print it into the port.
doSave(session, element) - For action rules it saves the modification registered by the controller using IlrSessionHelper.setDefinition. For decision tables, it builds an instance of IlrCommitableObject containing the modification registered by the controller. Then it commits it on the Rule Team Server session.
The class RTSHelper provides functions calling the Rule Team Server API. They are called in the TreeBean function before and after editing:
isElementBusy(session, element) - Asks the session if the element can be edited.
lockElement(session, element) - Asks the session to lock the element.
unlockElement(session, element) - Asks the session to unlock the element.
To rebuild this sample:
| Note |
You can restore the initial security settings for the loanvalidation-rules project by executing the run.remove.permission Ant command
|
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |