Decision Warehouse customization sample details

You use a web browser to run this sample.

Running this sample

To run this sample:
  1. Open a web browser and type the following URL in the address bar: http://localhost:PORT/dvscustomdecisionwarehouse.
    Note: Make sure that the port number is correct.
  2. Read the explanation at the top of the web page.
  3. Click Submit.

    Wait until all requests are processed or click Cancel to stop processing.

    When you click Submit, the following actions are processed:
    1. The requests are sent to Rule Execution Server.
    2. Rule Execution Server processes the requests.
    3. Rule Execution Server sends the execution results to a Java™ Message Service (JMS) queue.
    4. A message-driven rule bean (MDB) reads the messages from the queue and inserts the execution results in a database.
    5. Rule Execution Server generates reports based on data that is stored in the database.
  4. Select one of the reports.
  5. Click Open Report.

    A web page opens with the report. The first time you use the sample, it might take some time for the report to display.

    Note: Chrome cannot show the report because of a limitation of the underlying BIRT version.

Rebuilding this sample

To rebuild this sample:
  1. Switch to the Samples Console perspective.
  2. In the Samples Commands view, double-click the build target to rebuild and deploy the sample.

How this sample works

This sample contains the following artifacts:

Table 1. Sample artifacts
Object Artifact Comment
Web user interface dvscustomdecisionwarehouseui.war See <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/client/build.xml
Message-driven rule bean (MDB) dwconsumer.jar See <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/consumer/build.xml
Reporting dvscustomdecisionwarehousebirt.war See <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/report/build.xml.

The software layer that controls the graphical user interface (GUI) in this sample is made from JavaServer Faces (JSF) beans. The web form generates the loan requests that you specify in the corresponding field on the form. When you click Submit, the requests are sent to the rule engine through a POJO session. The engine processes the requests and the execution results are put in a JMS queue. An MDB reads each messages from this queue. For each message, an object model is built and SQL insert statements are issued to the database. A dedicated web application displays the reports. The report engine is BIRT.

Data reports are extracted from this database.

To configure Decision Warehouse, you use the IlrTraceDAOFactory class in the Rule Execution Server API. The DAO class is called by the rule session. You specify the properties in the dvs-dw.properties file, which you then add to the class path.

The following configuration properties are mandatory:

// Declare the DAO Factory
factoryClassname=ilog.rules.sample.dvs.dao.factory.CustomDAOFactory
// Declare the default JNDI database. This is needed because in the sample, the traces are persisted in the standard Rule Execution Server database.
JNDI_NAME=jdbc/resdatasource

The following properties are bound to the sample. If you develop a custom DAO, your properties are different:

# Associate a ruleset to a DAO
/loanvalidationrulesruleapp/1.0/loanvalidationrules/1.0=ilog.rules.sample.dvs.dao.impl.LoanValidationTraceDAO
# Specify property bound to the LoanValidationTraceDAO
LoanValidationTraceDAO.jndi_jdbc_customdw=java:jdbc/customdw

# See below how the customization works in this sample
# A new ruleset 'myotherruleset' is bound to a DAO MyOtherTraceDAO
# This DAO takes two properties: property1 and property2
# myotheruleapp/1.0/myotherruleset/1.0=ilog.rules.sample.dvs.dao.impl.MyOtherTraceDAO
# MyOtherTraceDAO.property1=a_value_1
# MyOtherTraceDAO.property2=a_value_2

To call your DAO, you add the dvs-dw.properties file to the class path with the monitoring.enabled property set to true, as follows:

property name="monitoring.enabled" value="true"

The ruleset.bom.enabled property is set to true by default. See the deploy.ruleapp target in the build.xml file.

By setting the Trace DAO factory class name to ilog.rules.sample.dvs.dao.factory.CustomDAOFactory, the class creates the custom DAO and is instantiated with the parameters that in the Decision Warehouse configuration settings.

The createDAO method is called to return an IlrTraceDAO object. If you set the monitoring.enabled ruleset property to true, the IlrTraceDAO.saveTrace( IlrDWTrace, IlrSessionRequest, IlrSessionResponse) method is called each time the ruleset is executed.

There is no standard way to customize a DAO for a ruleset. This sample demonstrates one way to do it.

In this sample, all executed rulesets use standard DAO processing. The following method retrieves the object instance:

public void initialize(Map<String, String> configuration) throws IlrTraceDAOException   {
   this.configuration = configuration;
   IlrTraceDAOFactoryUtil factory = new IlrTraceDAOFactoryUtil (configuration) ;
   delegate = factory.createTraceDAOFactory(IlrTraceDAOFactoryType.JDBC_DATASOURCE);
}

The custom DAO is called as follows:

DAO execution
Note: The standard DAO traces are stored in the standard Rule Execution Server database.

The sample uses standard DAO processing for all executed rulesets, with additional DAO processing for a specific ruleset implemented as follows:

public void saveTrace(IlrDWTrace trace, IlrSessionRequest request, IlrSessionResponse response) throws ... {
   // Do the standard job (Save the trace in the Rule Execution Server database along with other data)
   super.saveTrace(trace, request, response);
   // Retrieve the DAO associated to the ruleset, if any
   WriteOnlyTraceDAO dao = getIlrTraceDAO (request.getRulesetPath());
   if (dao!=null) {
    // The custom configuration has associated the ruleset with a DAO
    dao.saveTrace(trace, request, response);
   }
}

The LoanValidationTraceDAO class is the DAO associated with the sample ruleset. The class retrieves the input and output parameters from IlrSessionRequest and IlrSessionResponse instances and sends them in a message to a database queue for asynchronous processing.

public void saveTrace(IlrDWTrace trace, IlrSessionRequest request, IlrSessionResponse response)  {
   // Add output parameters
   Map<String,Object> parameters = response.getOutputParameters();
   HashMap<String, Serializable> result = new HashMap<String, Serializable> ();
   Iterator<String> it = parameters.keySet().iterator();
   while (it.hasNext()) {
      String key = it.next();
      Object value = parameters.get(key);
      result.put(key, (Serializable)value); 
   }
   // Add input parameters
   parameters = request.getInputParameters();
   it = parameters.keySet().iterator();
   while (it.hasNext()) {
      String key = it.next();
      Object value = parameters.get(key);
      result.put(key, (Serializable)value); 
   }
   // Add specific data
   Date date = (Date) request.getUserData();
      result.put("date", date);
   try {
      service.send(result);
   } catch (Exception e) {
      logger.log(Level.SEVERE, "Uncaught exception", e);
   }
}

A Java Message Service (JMS) artifact is deployed to the sample server through the dwconsumer.jar archive. It contains a message-driven rule bean (MDB) that reads messages from a queue. For each message, an object model is built and SQL insert statements are issued to the database.

public void onMessage(Message msg) {
   try {
      ObjectMessage message = (ObjectMessage) msg;
      HashMap<String, Serializable> map = (HashMap<String, Serializable>)message.getObject();
      DatabaseManager.getInstance().handleMessage(map);
   } catch (Exception e) {
   ...
   }
}
For deployment, the following considerations apply:
  • You can configure the Rule Execution Server console to use a custom DAO factory. For more information, see Adding data sources to Decision Warehouse.
  • Because the client application uses a POJO session that calls the DAO, the CustomDAOFactory class (and other DAO classes) must be available to the POJO session. These classes are included in the web-inf/classes directory of the dvscustomdecisionwarehouse.war file.

Source files

You can find the source files for this sample in <InstallDir>/executionserver/samples, as follows:
  • dvscustomdecisionwarehouse/client/src
  • dvscustomdecisionwarehouse/report/reports
  • dvscustomdecisionwarehouse/consumer/src
  • Web user interface project: <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/client/src/ilog/rules/sample.
  • CONSUMER project: <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/consumer/src/ilog/rules/sample.
  • Web report project: <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/report.

    To build and deploy the WAR file instead of the whole sample, open a shell prompt, browse to <InstallDir>/executionserver/samples/dvscustomdecisionwarehouse/report and type ant.

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.