In your decision service project generate the ruleapp archive.
Select your decision service project in the explorer. Right click and select the "Rule execution Server > Deploy..." item.
Now select the decision service operation for which you want to generate the executable RuleApp archive, and where you choose to write it.
Congratulations. Your RuleApp archive has been written. In this example under mydeployment.jar name that can be changed.
Alternatively you can generate the ruleapp archive for your decision service project in Decision Center.
At the end of this step you have obtained a ruleapp archive downloaded on your file system
Add theses librairies to load and execute a decision service compiled as a ruleapp archive:
${odm.install}/executionserver/lib/jrules-res-${odm.version}-execution.jar
${odm.install}/executionserver/lib/jrules-engine-${odm.version}.jar
${odm.install}/executionserver/lib/j2ee_connector-1_5-fr.jar
Add the eXecutable Object Model library to the classpath of the Java application. Add associated third party jars if needed.
${basedir}/yourxom.jar
An example of Maven pom file is available at ../simple-loan-validation-res-runner/pom.xml
The code snipplet has a generic base. It just varies depending on the signature of the decision service operation, the level of trace that your request, and optionaly the configuration of the embedded Rule Execution Server RuleSession factory.
First add ODM includes.
import ilog.rules.res.model.IlrPath;
import ilog.rules.res.session.IlrJ2SESessionFactory;
import ilog.rules.res.session.IlrSessionRequest;
import ilog.rules.res.session.IlrSessionResponse;
import ilog.rules.res.session.IlrStatelessSession;
import ilog.rules.res.session.config.IlrPersistenceType;
import ilog.rules.res.session.config.IlrSessionFactoryConfig;
import ilog.rules.res.session.config.IlrXUConfig;
Second create a method to initiate an embedded Rule Execution Server with an in memory persistence. In this mode the rule execution will search ruleapps in ithe classpath of the application.
private static IlrJ2SESessionFactory GetRuleSessionFactory() {
IlrSessionFactoryConfig factoryConfig = IlrJ2SESessionFactory.createDefaultConfig();
IlrXUConfig xuConfig = factoryConfig.getXUConfig();
xuConfig.setLogAutoFlushEnabled(true);
xuConfig.getPersistenceConfig().setPersistenceType(IlrPersistenceType.MEMORY);
xuConfig.getManagedXOMPersistenceConfig().setPersistenceType(IlrPersistenceType.MEMORY);
return new IlrJ2SESessionFactory(factoryConfig);
}
Third a method to automate a rule based decision
- the specified rulesetPath matches with the ruleapp/ruleset path of the ruleapp archive
- the trace configuration is tunable depending on your needs
- put all input parameters in the map for the execution
- retrieve the output parameters and the trace from the response
public IlrSessionResponse execute(Borrower borrower, LoanRequest loan) {
try {
IlrJ2SESessionFactory sessionFactory = GetRuleSessionFactory();
// Creating the decision request
IlrSessionRequest sessionRequest = sessionFactory.createRequest();
String rulesetPath = "/loanvalidation/loan_validation_with_score_and_grade";
sessionRequest.setRulesetPath(IlrPath.parsePath(rulesetPath));
sessionRequest.setTraceEnabled(true);
//sessionRequest.getTraceFilter().setInfoAllFilters(true);
sessionRequest.getTraceFilter().setInfoRules(true);
sessionRequest.getTraceFilter().setInfoRulesNotFired(true);
sessionRequest.getTraceFilter().setInfoTasks(true);
sessionRequest.getTraceFilter().setInfoTotalTasksNotExecuted(true);
sessionRequest.getTraceFilter().setInfoExecutionEvents(true);
Map<String, Object> inputParameters = sessionRequest
.getInputParameters();
inputParameters.put("loan", loan);
inputParameters.put("borrower", borrower);
// Creating the rule session
IlrStatelessSession session = sessionFactory
.createStatelessSession();
IlrSessionResponse response = session.execute(sessionRequest);
return response;
} catch (Exception exception) {
exception.printStackTrace(System.err);
}
return null;
}
An complete source code is available in LoanValidationRESRunner.java
Add the ruleapp archive jar to the Java application classpath, as a regular library.
javac commonly through a maven command. An example of Maven pom file is available at ../simple-loan-validation-res-runner/pom.xml
Launch our Java application. It executes the business rules as modeled in Rule Designer and Decision Center compiled and fully packaged within your application. No need of the RES DB, HTDS or other ODM parts.
You are now ready to execute at scale and maximum speed your business rules in Java. Et voila.
A full code example is available at ../simple-loan-validation-res-runner