• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rules SDK IBM WW BPM Forum March 2013
 

Rules SDK IBM WW BPM Forum March 2013

on

  • 1,857 views

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

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

Statistics

Views

Total Views
1,857
Views on SlideShare
1,844
Embed Views
13

Actions

Likes
0
Downloads
20
Comments
0

3 Embeds 13

http://newsblur.com 6
http://www.ibm.com 6
http://www.newsblur.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rules SDK IBM WW BPM Forum March 2013 Rules SDK IBM WW BPM Forum March 2013 Presentation Transcript

    • Daniel Selman – ODM Product ArchitectMarch 2013Using the Rules SDK v8.0.1Business Rules Embedded © 2009 IBM Corporation
    • Agenda ■ What is the Rules SDK? ■ When to use it? ■ Code Samples ■ Q&A2 © 2013 IBM Corporation
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • SWT BAL Editor12 © 2013 IBM Corporation
    • 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
    • Web BAL Editor14 © 2013 IBM Corporation
    • 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
    • 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
    • Web DT Editor17 © 2013 IBM Corporation
    • 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
    • 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 }
    • Any Questions?20 © 2013 IBM Corporation