Daniel Selman – ODM Product ArchitectMarch 2013Using the Rules SDK v8.0.1Business Rules Embedded                          ...
Agenda    ■   What is the Rules SDK?    ■   When to use it?    ■   Code Samples    ■   Q&A2                               ...
IBM Presentation Template Full VersionWhat is the Rules SDK?    ■   APIs and embeddable components for:             –Defin...
IBM Presentation Template Full VersionWhen should it be used?    ■   To allow business users to customize the behavior of ...
IBM Presentation Template Full VersionWhen should it not be used?    ■   To re-implement a Decision Management Platform or...
Getting Access    ■   The Rules SDK ships with ODM and requires an ODM license.    ■   After installing ODM you can find t...
Rules SDK vs ODMCapability                 Rules SDK    ODMIf/Then Rule (SWT)         Yes          YesIf/Then Rule (Web)  ...
Defining a Vocabulary and a BAL Rule    // the locale / encoding for the test    final Locale locale = Locale.US;    final...
Using the DecisionTableBuilder// add a decision tableDecisionTableBuilder dtBuilder = new DecisionTableBuilder(ruleLanguag...
Generating and Executing the Ruleset Archive // generate the archive byte[] rs = rsBuilder.buildRuleset("ruleset.jar"); As...
Export the RuleSetBuilder to a Zipped Rule Project// generate the archive that contains the rule projectByteArrayOutputStr...
SWT BAL Editor12               © 2013 IBM Corporation
Using the SWT BAL Editor                                                /**                                               ...
Web BAL Editor14               © 2013 IBM Corporation
Web BAL Editor GUI (index.jsp)         <script type="text/javascript">             dojo.registerModulePath("com.ibm.bdsl.w...
Web BAL Editor Servletpublic class WebRuleEditorServlet extends IntelliTextEditorServlet {    public static final String E...
Web DT Editor17              © 2013 IBM Corporation
Web DT Editor GUI (index.jsp)         <script type="text/javascript">             dojo.registerModulePath("com.ibm.bdsl.we...
Web DT Editor Servlet     public class WebDtEditorServlet extends DTEditorServlet {           public static final String E...
Any Questions?20               © 2013 IBM Corporation
Upcoming SlideShare
Loading in …5
×

Rules SDK IBM WW BPM Forum March 2013

2,917 views

Published on

A description of the ODM Rules SDK, a set of APIs and components to embedd business rules authoring and execution functionality inside custom applications.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,917
On SlideShare
0
From Embeds
0
Number of Embeds
202
Actions
Shares
0
Downloads
43
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Rules SDK IBM WW BPM Forum March 2013

  1. 1. Daniel Selman – ODM Product ArchitectMarch 2013Using the Rules SDK v8.0.1Business Rules Embedded © 2009 IBM Corporation
  2. 2. Agenda ■ What is the Rules SDK? ■ When to use it? ■ Code Samples ■ Q&A2 © 2013 IBM Corporation
  3. 3. IBM Presentation Template Full VersionWhat is the Rules SDK? ■ APIs and embeddable components for: –Defining business object models and vocabularies –Authoring rules in Eclipse and on the Web –Building ruleset archives –Executing rules ■ APIs are significantly simpler than full ODM APIs ■ Full ODM APIs are available and may be used if necessarySource If Applicable3 © 2013 IBM Corporation
  4. 4. IBM Presentation Template Full VersionWhen should it be used? ■ To allow business users to customize the behavior of an application using rules ■ Provide a highly customized and limited authoring and management environment: –Relatively small numbers of rules (< 500?) –XSD models –Only If/Then rules and Decision Tables may be usedSource If Applicable4 © 2013 IBM Corporation
  5. 5. IBM Presentation Template Full VersionWhen should it not be used? ■ To re-implement a Decision Management Platform or Business Rules Management Platform –Just use ODM! :-) ■ With great power comes great responsibility...Source If Applicable5 © 2013 IBM Corporation
  6. 6. Getting Access ■ The Rules SDK ships with ODM and requires an ODM license. ■ After installing ODM you can find the components and samples within the rules-sdk directory.6 © 2013 IBM Corporation
  7. 7. Rules SDK vs ODMCapability Rules SDK ODMIf/Then Rule (SWT) Yes YesIf/Then Rule (Web) Yes YesProject export to ODM Yes YesDecision Tables (Web) Yes YesDecision Tables (Swing) No Yes# rules per ruleset <100 <100,000Execution algorithms Sequential Sequential, Rete, FastpathGovernance / Lifecycle / No YesSimulationVocabulary/model editing No YesODM project model: No YesDecision Trees, Ruleflowetc.JEE execution support No YesRule refactoring No Yes7 © 2013 IBM Corporation
  8. 8. Defining a Vocabulary and a BAL Rule // the locale / encoding for the test final Locale locale = Locale.US; final String encoding = "UTF-8"; // create the ObjectModelBuilder ObjectModelBuilder omBuilder = new ObjectModelBuilder(); // add an XSD String xsd = "customer.xsd"; InputStream is = this.getClass().getClassLoader().getResourceAsStream( xsd ); omBuilder.addXmlSchema(new XmlSchema(xsd, encoding, is)); // create the RuleLanguageService RuleLanguageService ruleLanguageService = new RuleLanguageService(); // create the vocabulary for the locale ruleLanguageService.registerVocabulary( omBuilder.createVocabulary(locale) ); // define a parameter ruleLanguageService.addParameter("com.ilog.rules.customer.Customer", "cust", "the customer", locale); // create the RulesetBuilder RulesetBuilder rsBuilder = new RulesetBuilder(ruleLanguageService); // add a rule rsBuilder.addBusinessRule(locale, "rule1", "if the name of the customer contains "Smith" then print "Hello John!";");8 © 2013 IBM Corporation
  9. 9. Using the DecisionTableBuilder// add a decision tableDecisionTableBuilder dtBuilder = new DecisionTableBuilder(ruleLanguageService, "dt1", locale,readDTXmlModel("dt1.xml"));rsBuilder.addDecisionTable(Locale.US, "dt1", dtBuilder.getDTModel());// define a decision table via APIDecisionTableBuilder builder = new DecisionTableBuilder(ruleLanguageService, "test", locale);builder.addConditionColumn( "cust", "Category", "the category");builder.addConditionColumn( "cust", "Age", "the age");builder.addActionColumn( "cust", "Category", "the resulting category");builder.addContent(new String[][] {{ "Gold", "< 20", "Silver" }, { "Gold", "[20..30]", "Gold" }, { "Gold", ">= 30", "Platinum" }, { "Bronze", "< 30", "Silver" }, { "Bronze", ">= 30", "Platinum" }});9 © 2013 IBM Corporation
  10. 10. Generating and Executing the Ruleset Archive // generate the archive byte[] rs = rsBuilder.buildRuleset("ruleset.jar"); Assert.assertEquals( "Unexpected build issues", 0, rsBuilder.getBuildIssues().size() ); // create the rule service IlrRuleService ruleService = new XMLRuleService(new PrintWriter(System.out)); IlrPath path = new IlrPath("RuleApp", "Ruleset"); // undeploy the ruleset if required if (ruleService.isRulesetDeployed(path)) { ruleService.undeployRuleset(path); } // deploy the ruleset Map<String, String> properties = new HashMap<String, String>(); properties.put(IlrRulesetArchiveProperties.KEY_SEQUENTIAL_TRACE_ENABLED, Boolean.toString(true)); ruleService.deployRuleset(path, rs, properties); // load instance document is = this.getClass().getClassLoader().getResourceAsStream( "sample-customer.xml" ); // execute the engine Map<String, Object> params = new HashMap<String, Object>(); params.put( "cust", inputStreamToString( encoding, is )); // retrieve the results IlrSessionResponse response = ruleService.executeRuleset(path, params, true); IlrBusinessExecutionTrace businessTrace = new IlrBusinessExecutionTrace(response.getRulesetExecutionTrace());10 © 2013 IBM Corporation
  11. 11. Export the RuleSetBuilder to a Zipped Rule Project// generate the archive that contains the rule projectByteArrayOutputStream bytes = new ByteArrayOutputStream();ZipOutputStream out = new ZipOutputStream( bytes );// The following line of code can be used to dump that project on disk//ZipOutputStream out = new ZipOutputStream( new FileOutputStream(new File(System.getProperty("user.dir"),"textProject.zip")) );rsBuilder.export(out, "testProject");11 © 2013 IBM Corporation
  12. 12. SWT BAL Editor12 © 2013 IBM Corporation
  13. 13. Using the SWT BAL Editor /** * Represents a BAL rule in the model. */ public class BalRule { private Locale locale; Editing private String name; private String contents; // creation and display of the rule editor component IntelliTextDefaultEnvironment environment = new IntelliTextDefaultEnvironment(); // set some prediction configuration environment.getPreferenceStore().setValue(IntelliTextPreferences.FILTER_UNREACHABLE, true); // create the JFace element final IntelliTextViewer ruleEditor = new IntelliTextViewer(composite, SWT.NONE, environment); // create a document to hold the edited text IntelliTextDocument document = new IntelliTextDocument(IlrBAL.BAL_DEFINITION, rule.getLocale(), ruleLanguageService.getParserManager()); // register the variables document.setVariableProvider(ruleLanguageService.getVariableProvider(rule.getLocale())); // set the text document.set(rule.getContents()); // add a listener to react to text changes document.addDocumentListener(new IDocumentListener() { @Override public void documentChanged(DocumentEvent event) { rule.setContents(event.getDocument().get()); } @Override public void documentAboutToBeChanged(DocumentEvent event) { // nothing to do } }); // assign the document to the editor ruleEditor.setInput(document);13 © 2013 IBM Corporation
  14. 14. Web BAL Editor14 © 2013 IBM Corporation
  15. 15. Web BAL Editor GUI (index.jsp) <script type="text/javascript"> dojo.registerModulePath("com.ibm.bdsl.web", "$ {pageContext.request.contextPath}/WebRuleEditor/com/ibm/bdsl/web"); dojo.registerModulePath("com.ibm.rules.bdsl.dt", "$ {pageContext.request.contextPath}/WebDTEditor/resources/js/com/ibm/rules/bdsl/dt"); // Decision Tables dojo.require("com.ibm.rules.bdsl.dt.DecisionTable"); dojo.require("com.ibm.rules.bdsl.dt.EditableDecisionTable"); // Rules dojo.require("com.ibm.bdsl.web.editor.dojo.DojoIntelliTextEditorDecorated"); // create a rule editor var ruleEditor = new com.ibm.bdsl.web.editor.dojo.DojoIntelliTextEditorDecorated({ id: ruleEditor, handlerUrl: ${pageContext.request.contextPath}/WebRuleEditor }, dojo.create(div, null, rulePane)); ruleEditor.startup();15 © 2013 IBM Corporation
  16. 16. Web BAL Editor Servletpublic class WebRuleEditorServlet extends IntelliTextEditorServlet { public static final String ENV_ATTRIBUTE_NAME = "intellitextEnvironment"; @Override protected IntelliTextEditorEnvironment getEnvironment(HttpServletRequest req) { HttpSession session = req.getSession(); IntelliTextEditorEnvironment env = (IntelliTextEditorEnvironment) session.getAttribute(ENV_ATTRIBUTE_NAME); if (env == null) { env = createEnvironment(session); } return env; } public static synchronized IntelliTextEditorEnvironment createEnvironment(HttpSession session) { Locale locale = new Locale(SessionUtils.DEFAULT_LOCALE); RuleLanguageService ruleLanguageService = SessionUtils.getRuleLanguageService(session); IlrBRLDefinition definition = IlrBAL.getDefinition(locale); IlrBRLParserManager parserManager = ruleLanguageService.getParserManager(); IlrBRLVariableProvider variableProvider = ruleLanguageService.getVariableProvider(locale); IntelliTextEditorEnvironment environment = new DefaultIntelliTextEditorEnvironment(parserManager, variableProvider, definition, null); session.setAttribute(ENV_ATTRIBUTE_NAME, environment); return environment; }} 16 © 2013 IBM Corporation
  17. 17. Web DT Editor17 © 2013 IBM Corporation
  18. 18. Web DT Editor GUI (index.jsp) <script type="text/javascript"> dojo.registerModulePath("com.ibm.bdsl.web", "$ {pageContext.request.contextPath}/WebRuleEditor/com/ibm/bdsl/web"); dojo.registerModulePath("com.ibm.rules.bdsl.dt", "$ {pageContext.request.contextPath}/WebDTEditor/resources/js/com/ibm/rules/bdsl/dt"); // Decision Tables dojo.require("com.ibm.rules.bdsl.dt.DecisionTable"); dojo.require("com.ibm.rules.bdsl.dt.EditableDecisionTable"); // Rules dojo.require("com.ibm.bdsl.web.editor.dojo.DojoIntelliTextEditorDecorated"); // Create a decision table editor dojo.xhrPost({ url: ${pageContext.request.contextPath}/WebDTEditor/command/create, handleAs: json, preventCache: true, load: function (response) { if (response) { var dt = new com.ibm.rules.bdsl.dt.EditableDecisionTable({ id: dt, model: response, baseUrl:${pageContext.request.contextPath}/WebDTEditor/ }, dojo.create(div, null, gridPanel)); dt.startup(); dt.getSelectionService().selectCells(0, 1); } } });18 © 2013 IBM Corporation
  19. 19. Web DT Editor Servlet public class WebDtEditorServlet extends DTEditorServlet { public static final String ENV_ATTRIBUTE_NAME = "dtEditorEnv"; @Override protected DTEditorEnvironment getDtEnvironment(HttpServletRequest request) { HttpSession session = request.getSession(); WebDTEditorEnvironment env = (WebDTEditorEnvironment) session .getAttribute(WebDtEditorServlet.ENV_ATTRIBUTE_NAME); if (env == null) { session.setAttribute(WebDtEditorServlet.ENV_ATTRIBUTE_NAME, env = new WebDTEditorEnvironment()); } return env; } @Override protected IlrDTModel getModelTemplate(HttpServletRequest request) { DTEditorEnvironment env = (DTEditorEnvironment) request.getSession() .getAttribute(WebDtEditorServlet.ENV_ATTRIBUTE_NAME); if (env != null) { DTHandle dtHandle = env.getDTHandle(); if (dtHandle != null) { return dtHandle.getModelTemplate(); } } return null; } @Override protected IlrBRLDefinition getBALDefinition(HttpServletRequest request) { return IlrBAL.getDefinition(new Locale(SessionUtils.DEFAULT_LOCALE)); } @Override protected IlrBRLParserService getBALParser(HttpServletRequest request) { return SessionUtils.getRuleLanguageService(request.getSession()) .getParserManager(); } © 2013 IBM Corporation19 }
  20. 20. Any Questions?20 © 2013 IBM Corporation

×