Decision table management by using APIs sample details
You run this sample in the Samples Console. The sample uses the Decision Center Business console to verify the decision table management result.
You must run the commands to create, copy and delete the rule in order.
Running this sample
In the Rule Designer Samples Commands view, navigate to .
Double-click the run.create command to create a new specialRate decision table complete with data in the Computation rule package.
- To verify the table creation, open the Decision Center Business console.
- In the main branch of the decisiontable-rules
project, click the computation folder on the Decision
Artifacts page.
A new specialRate rule is added. Click the rule name to view its content.
In the Rule Designer Samples Commands view, navigate to .
- Double-click the run.copy command to copy the specialRate decision table and its data to the eligibility rule package. If the operation is successful, you see a message in the Console view:
=================== COPY REPORT Success : computation/specialRate =================== Completed: run.copy To verify that the table is copied, open the Decision Center Business console.
In the main branch of the decisiontable-rules project, click the eligibility folder on the Decision Artifacts page. The specialRate rule is copied. You can click the rule to view its content.
In the Rule Designer Samples Commands view, navigate to .
- Double-click the run.delete command to delete the specialRate decision table from the computation folder. If the operation is successful, you see a message in the Console view:
=================== DELETION REPORT Success : computation/specialRate =================== Completed: run.delete To verify that the table is deleted, open the Decision Center Business console.
In the main branch of the decisiontable-rules project, click the computation folder on the Decision Artifacts page. The specialRate rule is removed.
In the Rule Designer Samples Commands view, navigate to .
- Double-click the run.populate.csv command to load the bankruptcyScore decision table data from a source CSV file that is described in the data/mapping.properties file. If the operation is successful, you see a message in the Console view:
=================== DECISION TABLES LOADING Success : computation/bankruptcyScore from (csv:data/input/bankruptcyScore.data/,) =================== Completed: run.populate.csv To verify that the table is populated with data, open the Decision Center Business console.
In the main branch of the decisiontable-rules project, click the computation folder on the Decision Artifacts page.
- Then click bankruptcyScore to open the content preview.
In the Rule Designer Samples Commands view, navigate to .
- Double-click the run.populate.excel command to load the grade decision table data from a source Excel file that is described in the data/mapping.properties file. If the operation is successful, you see a message in the Console view:
=================== DECISION TABLES LOADING Success : eligibility/grade from (xl:///./data/input/grade.xls/sheet) =================== Completed: run.populate.excel To verify that the table is populated with data, open the Decision Center Business console.
In the main branch of the decisiontable-rules project, click the eligibility folder on the Decision Artifacts page.
- Then click grade to open the content preview.
In the Rule Designer Samples Commands view, navigate to .
- Double-click the run.populate.db command to load the salary2score decision table data from a Derby database that is described in the data/mapping.properties file. If the operation is successful, you see a message in the Console view:
=================== DECISION TABLES LOADING Success : computation/salary2score from (jdbc:./data/input/derby.properties/SELECT * FROM DATATABLE) =================== Completed: run.populate.db To verify that the table is populated with data, open the Decision Center Business console.
In the main branch of the decisiontable-rules project, click the computation folder on the Decision Artifacts page.
- Then click salary2score to open the content preview.
Rebuilding this sample
In the Samples Commands view, navigate to .
Double-click clean to erase the decisiontable-rules project from Decision Center.
How this sample works
You can perform various tasks on decision tables in Decision Center as follows:
-project: Use to specify the target project in which to create the decision table
-decisiontabletocreate: Use to specify the decision table to create. For example: rulepackage/rulename
-rtsdatasource: Use to specify the Decision Center datasource (jdbc/ilogDataSource)
-rtsurl: Use to specify the URL to connect to Decision Center (http://localhost:PORT/teamserver)
-rtsuser: Use to specify the username to connect to Decision Center
-rtspwd: Use to specify the password to connect to Decision Center
-project: Use to specify the project that contains the decision table to copy
-decisiontable.tocopy: Use to specify the decision table to copy along with its package. For example: rulepackage/rulename
-decisiontable.copytotarget: Use to specify the target folder into which to copy the decision table
-rtsdatasource: Use to specify the Decision Center datasource (jdbc/ilogDataSource)
-rtsurl: Use to specify the URL to connect to Decision Center (http://localhost:PORT/teamserver)
-rtsuser: Use to specify the username to connect to Decision Center
-rtspwd: Use to specify the password to connect to Decision Center
This task uses the IlrDefaultSearchCriteria API to find the specified decision table and then calls the IlrSession.copyTo API to perform the copy to the target rule package.
-project: Use to specify the target project from which to delete the decision table
-decisiontabletodelete: Use to specify the decision table to be deleted. For example: rulepackage/rulename
-rtsdatasource: Use to specify the Decision Center datasource (jdbc/ilogDataSource)
-rtsurl: Use to specify the URL to connect to Decision Center (http://localhost:PORT/teamserver)
-rtsuser: Use to specify the username to connect to Decision Center
-rtspwd: Use to specify the password to connect to Decision Center
This task uses the IlrDefaultSearchCriteria API to find the specified decision table and then calls the IlrSession.deleteElement API to perform the deletion.
-project: Use to specify the target project in which to populate the decision table
-rtsdatasource: Use to specify the Decision Center datasource (jdbc/ilogDataSource)
-rtsurl: Use to specify the URL to connect to Decision Center (http://localhost:PORT/teamserver)
-rtsuser: Use to specify the username to connect to Decision Center
-rtspwd: Use to specify the password to connect to Decision Center
-mapping: Use to specify the mapping file containing the decision table that is loaded with the corresponding datasource
Retrieve the decision table from its path and name
Get its IlrDTController
Populate the decision table
Set the body definition
Commit the work to the database
File provider:
# FILE PROVIDER FORMAT csv:PATH_TO_THE_FILE/SHEET_NAME/ COLUMN_SEPARATOR computation/bankruptcyScore=csv:data/input/bankruptcyScore.data/A comma-separated csv file populates the bankruptcyScore decision table located in the computation folder.
Excel provider:
# EXCEL PROVIDER FORMAT xl:PATH_TO_THE_FILE/SHEET_NAME eligibility/grade=xl:///./data/input/grade.xls/sheetAn Excel spreadsheet named sheet populates the gradedecision table located in the eligibility folder.
Database provider:
# DATABASE PROVIDER FORMAT jdbc:PATH_TO_THE_FILE_DB_CONFIGURATION/QUERY computation/salary2score=jdbc:./data/input/derby.properties/SELECT * FROM DATATABLEThe database query populates the salary2score table located in the computation folder.
The derby.properties file provides all the data for the database connection.
Population of the cells uses the following formats:
={12,15}: matches the values 12 and 15
={Gold, Silver}: matches if the value is not Gold or Silver
>=15: matches if the value is greater than 15
[15: matches if the value is greater than 15
]15: matches if the value is less than 15
[10..13]: matches if the value is 10, 11, 12, or 13
<otherwise>: represents an Otherwise cell
Source files
- decisiontable-rules
- decisiontable-xom
Two projects that form the decision service that you publish to Decision Center where you add, copy, delete, and populate decision tables. You can ignore the three warnings for empty decision tables: After you publish the decision service projects, you populate the empty tables in Decision Center by using the API.
- servercopydecisiontable
The Java project that uses the Decision Center API to manage decision tables.
To create a decision table, use the classes in the model/create/ folder:
DecisionTableCreator.java: The main class that creates a decision table in the project.
To copy a decision table, use the classes in the model/copy/ folder:
CopyDecisionTable.java: The class that copies a decision table from a source rule package to a target rule package.
DTCopyArgument.java: The main class that holds the arguments to pass to the copy action.
To delete a decision table from a project, use the classes in the model/delete/ folder:
DeleteDecisionTablesinProject.java: The main class that deletes a decision table from the target project.
ProjectDeletionArgument.java: The class that holds the arguments that are passed to the DeleteDecisionTablesinProject class.
To populate decision tables, use the following classes:
- Under model/load:
DecisionTableCSVLoader.java: The main class that populates a decision table from a CSV file.
DecisionTableExcelLoader.java: The main class that populates a decision table from an Excel file.
DecisionTableDatabaseLoader.java: The main class that populates a decision table from a derby database.
DTLoadArgument.java: The class that holds the arguments that are passed to various DecisionTableXXXLoader classes.
- Under helper/data:
JdbcLoader.java: The class that is called when the application uses a JDBC loader. It reads data from a database.
FileLoader.java: The class that is called when the application uses a file loader. It reads data from a file.
ExcelLoader.java: The class that is called when the application uses an Excel loader. It reads data from an Excel spreadsheet.
DataProvider.java: The class that extends the ilog.rules.dt.model.provider.IlrDTAbstractDataProviderTableModel interface. It is constructed with ilog.rules.studio.samples.dtpopulate.helper.DataLoader. It implements the class and delegates all its work to it.
Three factory methods help to create the data loader:public static IlrDTDataProvider createFileDataProvider (...)
public static IlrDTDataProvider createJDBCDataProvider (...)
public static IlrDTDataProvider createDataProvider (...)
AbstractTabularDataLoader.java: The class that implements most of the methods defined by DataLoader.java.
Decision Center model helper files:
helper/RTSHelper.java: This is the most important class in this sample. It concentrates all the methods that manipulate the Decision Center model.
- Model classes:
Argument.java: An argument wrapper that defines mandatory data to connect to a Decision Center.
Connection.java: The class that opens and maintains a connection to Decision Center on an application server.
Project.java: A class that represents the Decision Center project.
- Utility class:
helper/Utilities.java: The class that helps to print to standard output console and manipulate strings.