SlideShare a Scribd company logo
Daniel Selman – ODM Product Architect
March 2013




Using the Rules SDK v8.0.1
Business Rules Embedded




                                        © 2009 IBM Corporation
Agenda



    ■   What is the Rules SDK?
    ■   When to use it?
    ■   Code Samples
    ■   Q&A




2                                © 2013 IBM Corporation
IBM Presentation Template Full Version


What 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 necessary




Source If Applicable

3                                                                  © 2013 IBM Corporation
IBM Presentation Template Full Version


When 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 used




Source If Applicable

4                                                                      © 2013 IBM Corporation
IBM Presentation Template Full Version


When 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 Applicable

5                                                                  © 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 ODM
Capability                 Rules SDK    ODM
If/Then Rule (SWT)         Yes          Yes
If/Then Rule (Web)         Yes          Yes
Project export to ODM      Yes          Yes
Decision Tables (Web)      Yes          Yes
Decision Tables (Swing)    No           Yes
# rules per ruleset        <100         <100,000
Execution algorithms       Sequential   Sequential, Rete, Fastpath
Governance / Lifecycle /   No           Yes
Simulation
Vocabulary/model editing   No           Yes
ODM project model:         No           Yes
Decision Trees, Ruleflow
etc.
JEE execution support      No           Yes
Rule refactoring           No           Yes
7                                                       © 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 table
DecisionTableBuilder dtBuilder = new DecisionTableBuilder(ruleLanguageService, "dt1", locale,
readDTXmlModel("dt1.xml"));
rsBuilder.addDecisionTable(Locale.US, "dt1", dtBuilder.getDTModel());

// define a decision table via API
DecisionTableBuilder 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 project
ByteArrayOutputStream 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 Editor




12               © 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 Editor




14               © 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 Servlet
public 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 Editor




17              © 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 Corporation
19
     }
Any Questions?




20               © 2013 IBM Corporation

More Related Content

PPT
TheServerSide Java Symposium 2005 : Business Rule Management, Enables Agile A...
Dan Selman
 
PDF
IBM zUniversity 2004 : ILOG JRules on IBM eServer zSeries
Dan Selman
 
PPT
WebSphere Technical Conference 2009 : Enhancing your BPM Solution with ILOG J...
Dan Selman
 
PPT
Paris Java User Group : Enabling Agile Business and IT Collaboration
Dan Selman
 
PPT
A Model-Based Approach for Extracting Business Rules out of Legacy Informatio...
Valerio Cosentino
 
PDF
Introduction to OSGi
Dan Selman
 
PDF
Improve business process with microservice integration
Christina Lin
 
PPT
Best practices in IBM Operational Decision Manager Standard 8.7.0 topologies
Pierre Feillet
 
TheServerSide Java Symposium 2005 : Business Rule Management, Enables Agile A...
Dan Selman
 
IBM zUniversity 2004 : ILOG JRules on IBM eServer zSeries
Dan Selman
 
WebSphere Technical Conference 2009 : Enhancing your BPM Solution with ILOG J...
Dan Selman
 
Paris Java User Group : Enabling Agile Business and IT Collaboration
Dan Selman
 
A Model-Based Approach for Extracting Business Rules out of Legacy Informatio...
Valerio Cosentino
 
Introduction to OSGi
Dan Selman
 
Improve business process with microservice integration
Christina Lin
 
Best practices in IBM Operational Decision Manager Standard 8.7.0 topologies
Pierre Feillet
 

What's hot (18)

PDF
Impact 2011 2899 - Designing high performance straight through processes usin...
Brian Petrini
 
PDF
Deploy, Monitor and Manage in Style with WebSphere Liberty Admin Center
WASdev Community
 
PDF
Building Operational Intelligence in Telecom with IBM ODM @Claro
Icaro Tech
 
PDF
Impact 2008 1994A - Exposing services people want to consume: a model-driven ...
Brian Petrini
 
PDF
Cloud Technology: Now Entering the Business Process Phase
finteligent
 
PPT
Best practices in deploying IBM Operation Decision Manager Standard 8.8.0
Pierre Feillet
 
ODP
Red Hat JBoss BRMS Primer - JBoss Business Rules and BPM Solutions
Eric D. Schabell
 
PPTX
Bpms ecu2014
Bob Brodt
 
ODP
2829 liberty
nick_garrod
 
PDF
Impact 2013 2971 - Fundamental integration and service patterns
Brian Petrini
 
PDF
Ibm pure systems pov_idr_spig_v1
Marco Laucelli
 
PDF
Supercharge Your Integration Services
Christina Lin
 
PDF
Impact 2013 2963 - IBM Business Process Manager Top Practices
Brian Petrini
 
PDF
Impact 2012 1640 - BPM Design considerations when optimizing business process...
Brian Petrini
 
PDF
Improving Software Delivery with Software Defined Environments (IBM Interconn...
Michael Elder
 
PPTX
EclipseCon BPM Day Ludwigsburg - Roundtrip Modelling with Eclipse Stardust
Sopra Steria
 
PDF
AIMMS product presentation
jhjsmits
 
PPTX
Migrating Legacy Code
Siddhi
 
Impact 2011 2899 - Designing high performance straight through processes usin...
Brian Petrini
 
Deploy, Monitor and Manage in Style with WebSphere Liberty Admin Center
WASdev Community
 
Building Operational Intelligence in Telecom with IBM ODM @Claro
Icaro Tech
 
Impact 2008 1994A - Exposing services people want to consume: a model-driven ...
Brian Petrini
 
Cloud Technology: Now Entering the Business Process Phase
finteligent
 
Best practices in deploying IBM Operation Decision Manager Standard 8.8.0
Pierre Feillet
 
Red Hat JBoss BRMS Primer - JBoss Business Rules and BPM Solutions
Eric D. Schabell
 
Bpms ecu2014
Bob Brodt
 
2829 liberty
nick_garrod
 
Impact 2013 2971 - Fundamental integration and service patterns
Brian Petrini
 
Ibm pure systems pov_idr_spig_v1
Marco Laucelli
 
Supercharge Your Integration Services
Christina Lin
 
Impact 2013 2963 - IBM Business Process Manager Top Practices
Brian Petrini
 
Impact 2012 1640 - BPM Design considerations when optimizing business process...
Brian Petrini
 
Improving Software Delivery with Software Defined Environments (IBM Interconn...
Michael Elder
 
EclipseCon BPM Day Ludwigsburg - Roundtrip Modelling with Eclipse Stardust
Sopra Steria
 
AIMMS product presentation
jhjsmits
 
Migrating Legacy Code
Siddhi
 
Ad

Similar to Rules SDK IBM WW BPM Forum March 2013 (20)

DOCX
Oracle business rules
xavier john
 
PPT
Overview of vidhita_business_rules_composer
Om Visvanathan
 
PDF
A Model Driven Reverse Engineering framework for extracting business rules ou...
Valerio Cosentino
 
PPT
Flex 360 Rules Engine
Effective
 
PPT
Flex 360 Rules Engine
EffectiveUI
 
PPT
Obey The Rules: Implementing a Rules Engine in Flex
RJ Owen
 
PDF
Lab 2) develop a java application
techbed
 
PPTX
Rules in Artificial Intelligence
Pierre Feillet
 
PDF
IBM Paris Bluemix Meetup #12 - Ecole 42 - 9 décembre 2015
IBM France Lab
 
PDF
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
eterdavud
 
PDF
A Model Driven Reverse Engineering framework for extracting business rules ou...
RuleML
 
PDF
Ibm wodm-decision-design
Guo-Guang Chiou
 
PDF
Intro to Drools - St Louis Gateway JUG
Ray Ploski
 
PDF
Guvnor presentation jervis liu
jbossug
 
PDF
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 
DOC
Tibco business events (be) online training institute
Mindmajix Technologies
 
PDF
Extracting Business Rules from COBOL: A Model-Based Framework
Valerio Cosentino
 
PDF
From COBOL to Models: an MDE framework to extract business logic out of legac...
Jordi Cabot
 
PPTX
Wodm or ilog jrules online training in chennai
GoLogica Technologies
 
PPT
Drools Presentation for Tallink.ee
Anton Arhipov
 
Oracle business rules
xavier john
 
Overview of vidhita_business_rules_composer
Om Visvanathan
 
A Model Driven Reverse Engineering framework for extracting business rules ou...
Valerio Cosentino
 
Flex 360 Rules Engine
Effective
 
Flex 360 Rules Engine
EffectiveUI
 
Obey The Rules: Implementing a Rules Engine in Flex
RJ Owen
 
Lab 2) develop a java application
techbed
 
Rules in Artificial Intelligence
Pierre Feillet
 
IBM Paris Bluemix Meetup #12 - Ecole 42 - 9 décembre 2015
IBM France Lab
 
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
eterdavud
 
A Model Driven Reverse Engineering framework for extracting business rules ou...
RuleML
 
Ibm wodm-decision-design
Guo-Guang Chiou
 
Intro to Drools - St Louis Gateway JUG
Ray Ploski
 
Guvnor presentation jervis liu
jbossug
 
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 
Tibco business events (be) online training institute
Mindmajix Technologies
 
Extracting Business Rules from COBOL: A Model-Based Framework
Valerio Cosentino
 
From COBOL to Models: an MDE framework to extract business logic out of legac...
Jordi Cabot
 
Wodm or ilog jrules online training in chennai
GoLogica Technologies
 
Drools Presentation for Tallink.ee
Anton Arhipov
 
Ad

More from Dan Selman (6)

PPTX
Hyperleger Composer Architecure Deep Dive
Dan Selman
 
PPTX
Hyperledger Composer Update 2017-04-05
Dan Selman
 
PPT
Service Oriented Architecture - Agility Rules!
Dan Selman
 
PPT
European Business Rules Conference 2005 : Rule Standards
Dan Selman
 
PDF
European Business Rules Conference 2004: The Business Rules Platform and Ente...
Dan Selman
 
PPT
October Rules Fest 2008 - Distributed Data Processing with ILOG JRules
Dan Selman
 
Hyperleger Composer Architecure Deep Dive
Dan Selman
 
Hyperledger Composer Update 2017-04-05
Dan Selman
 
Service Oriented Architecture - Agility Rules!
Dan Selman
 
European Business Rules Conference 2005 : Rule Standards
Dan Selman
 
European Business Rules Conference 2004: The Business Rules Platform and Ente...
Dan Selman
 
October Rules Fest 2008 - Distributed Data Processing with ILOG JRules
Dan Selman
 

Recently uploaded (20)

PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The Future of Artificial Intelligence (AI)
Mukul
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 

Rules SDK IBM WW BPM Forum March 2013

  • 1. Daniel Selman – ODM Product Architect March 2013 Using the Rules SDK v8.0.1 Business Rules Embedded © 2009 IBM Corporation
  • 2. Agenda ■ What is the Rules SDK? ■ When to use it? ■ Code Samples ■ Q&A 2 © 2013 IBM Corporation
  • 3. IBM Presentation Template Full Version What 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 necessary Source If Applicable 3 © 2013 IBM Corporation
  • 4. IBM Presentation Template Full Version When 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 used Source If Applicable 4 © 2013 IBM Corporation
  • 5. IBM Presentation Template Full Version When 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 Applicable 5 © 2013 IBM Corporation
  • 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. Rules SDK vs ODM Capability Rules SDK ODM If/Then Rule (SWT) Yes Yes If/Then Rule (Web) Yes Yes Project export to ODM Yes Yes Decision Tables (Web) Yes Yes Decision Tables (Swing) No Yes # rules per ruleset <100 <100,000 Execution algorithms Sequential Sequential, Rete, Fastpath Governance / Lifecycle / No Yes Simulation Vocabulary/model editing No Yes ODM project model: No Yes Decision Trees, Ruleflow etc. JEE execution support No Yes Rule refactoring No Yes 7 © 2013 IBM Corporation
  • 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. Using the DecisionTableBuilder // add a decision table DecisionTableBuilder dtBuilder = new DecisionTableBuilder(ruleLanguageService, "dt1", locale, readDTXmlModel("dt1.xml")); rsBuilder.addDecisionTable(Locale.US, "dt1", dtBuilder.getDTModel()); // define a decision table via API DecisionTableBuilder 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. 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. Export the RuleSetBuilder to a Zipped Rule Project // generate the archive that contains the rule project ByteArrayOutputStream 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. SWT BAL Editor 12 © 2013 IBM Corporation
  • 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. Web BAL Editor 14 © 2013 IBM Corporation
  • 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. Web BAL Editor Servlet public 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. Web DT Editor 17 © 2013 IBM Corporation
  • 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. 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 Corporation 19 }
  • 20. Any Questions? 20 © 2013 IBM Corporation