You are previewing Drools JBoss Rules 5.0 Developer's Guide.
O'Reilly logo
Drools JBoss Rules 5.0 Developer's Guide

Book Description

As a Java developer, you can make life a lot easier by using Drools to implement business rules. This book shows you how with clear instructions across the whole range of efficiencies the platform provides.

  • Discover the power of Drools as a platform for developing business rules

  • Build a custom engine to provide real-time capability and reduce the complexity in implementing rules

  • Explore Drools modules such as Drools Expert, Drools Fusion, and Drools Flow, which adds event processing capabilities to the platform

  • Execute intelligent business logic with ease using JBoss/Drools, a stronger business-rules solution

  • Covers examples of a fraud detection system utilizing Drools CEP (Complex Event Processing) capabilities

  • In Detail

    Business rules can help your business by providing a level of agility and flexibility. As a developer, you will be largely responsible for implementing these business rules effectively, but implementing them systematically can often be difficult due to their complexity. Drools, or JBoss Rules, makes the process of implementing these rules quicker and handles the complexity, making your life a lot easier!

    This book guides you through all of the features of Drools, such as dynamic rules, the event model, and Rete implementation with high performance indexing. It will help you to set up the JBoss Rules platform and start creating your own business. It's easy to start developing with Drools if you follow its real-world examples that are intended to make your life easier.

    Starting with an introduction to the basic syntax that is essential for writing rules, the book will guide you through validation and human-readable rules that define, maintain, and support your business agility. As a developer, you will be expected to represent policies, procedures and. constraints regarding how an enterprise conducts its business; this book makes it easier by showing you it can be done.

    A real-life example of a banking domain allows you to see how the internal workings of the rules engine operate. A loan approval process example shows the use of the Drools Flow module. Parts of a banking fraud detection system are implemented with Drools Fusion module, which is the Complex Event Processing part of Drools. This in turn, will help developers to work on preventing fraudulent users from accessing systems in an illegal way.

    Finally, more technical details are shown on the inner workings of Drools, the implementation of the ReteOO algorithm, indexing, node sharing, and partitioning.

    Table of Contents

    1. Drools JBoss Rules 5.0 Developer's Guide
      1. Table of Contents
      2. Drools JBoss Rules 5.0 Developer's Guide
      3. Credits
      4. Foreword
        1. Open Source Decision Management
      5. About the Author
      6. About the Reviewers
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code for the book
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Introduction
        1. Problems with traditional approaches
        2. The solution
          1. Advantages
          2. Disadvantages
            1. When not to use a rule engine
        3. Drools
        4. Alternatives to Drools
        5. Summary
      9. 2. Basic Rules
        1. Rule basics
          1. Executing rules
        2. Rule syntax
          1. Rule concepts
            1. Variables in rules
            2. Types
            3. Comments
          2. Package
            1. Imports
            2. Global variables
            3. Functions
            4. Dialect
              1. mvel
          3. Rule condition
            1. And
            2. Or
            3. Not
            4. Exists
            5. Eval
            6. Return value restriction
            7. Inline eval
              1. Nested accessors
            8. This
            9. Working with collections
              1. (Not) contains
              2. (Not) memberOf
              3. From
          4. Rule consequence
          5. Rule attributes
            1. salience (priority)
            2. No-loop
            3. Dialect
        3. Summary
      10. 3. Validation
        1. Banking domain model
        2. Problem definition
        3. Analysis
        4. Design
        5. Validation package
          1. Object required type rules
          2. Testing
          3. Minimal account balance rule
          4. Student account rule
          5. Unique account number rule
        6. Implementation
        7. Validation service
        8. Summary
      11. 4. Data Transformation
        1. Process overview
        2. Getting the data
          1. Loading facts into the knowledge session
        3. Writing transformation rules
          1. Testing
          2. Address normalization
          3. Testing the findAddress rule
          4. Unknown country
          5. Currency conversion
          6. One account allowed
        4. Transformation results
        5. Implementation of the data loading
          1. Database setup
          2. Project setup
          3. iBatis configuration
          4. Running iBatis
          5. Alternative data loading
        6. Summary
      12. 5. Human-readable Rules
        1. Domain Specific Language
          1. DSL as an interface
          2. DSL for validation rules
          3. File formats
            1. DSL file format
            2. DRL file format
            3. DSLR file format
          4. DSL for multiple constraints in a condition
          5. Named capture groups
          6. DSL for data transformation rules
        2. Decision tables
          1. Advantages of a decision table
          2. Disadvantages of a decision table
          3. Calculating the interest rate
            1. Project setup
            2. Testing
            3. Comma Separated values
          4. Rule Templates
        3. Drools Flow
          1. Drools Agenda
          2. Methods for managing rule execution order
          3. Ruleflow
            1. Start
            2. End
            3. Action
            4. RuleFlowGroup
            5. Split
            6. Join
          4. Example
          5. Rules
          6. KnowledgeBase setup
          7. Tests
        4. Summary
      13. 6. Stateful Session
        1. Introduction to stateful session
        2. Validation using stateful session
          1. Design overview
          2. Stateful validation service
          3. Integration testing
          4. Logical assertions
          5. Keeping the validation report up-to-date
            1. Collect conditional element
              1. Collect
          6. Serialization
            1. Knowledge session re-creation
            2. Testing
            3. Session serialization
            4. Full session serialization
        3. Summary
      14. 7. Complex Event Processing
        1. CEP and ESP
        2. Drools Fusion
        3. Fraud detection
          1. Problem description
            1. Monitoring:
          2. Design and modeling
          3. Fraud detection rules
            1. Notification
              1. Test configuration setup
              2. Testing the notification rule
            2. Monitoring—averageBalanceQuery
              1. Testing the averageBalanceQuery
            3. Two large withdrawals
              1. Testing the twoLargeWithdrawals rule
            4. Sequence of increasing withdrawals
              1. Average balance test
                1. Testing the sequenceOfIncreasingWithdrawals rule
              2. High activity
                1. Testing the highActivity rule
        4. Summary
      15. 8. Drools Flow
        1. Loan approval service
          1. Model
        2. Loan approval ruleflow
          1. Invalid loan application form
            1. Email work item
            2. Fault node
              1. Test setup
              2. Testing the 'otherwise' branch of 'Validated?' node
          2. The size of the loan
            1. Test for a small loan
          3. Rating Calculation
            1. Subflow
            2. Subflow diagram
            3. Rating calculation subflow test
          4. Decisions on rating
            1. Testing the 'Rating?' node
          5. Transfer Funds work item
            1. Work item definition
            2. Work item registration
            3. Work item handler
            4. Work item handler registration
            5. Testing the transfer work item
          6. Human task
            1. Test for the human task
          7. Final Approval
            1. Test for the 'Approve Event' node
          8. Banking service
          9. Disadvantages of a ruleflow
        3. Summary
      16. 9. Sample Application
        1. Users
        2. Architecture
        3. Technologies used
          1. Additional Drools projects used
            1. Libraries used
        4. Business logic
        5. Design
        6. Configuration
          1. JPA annotations for domain objects
          2. JPA configuration
          3. Spring Framework configuration
          4. Web application setup
            1. Tag library
          5. Tomcat setup
          6. Deployment
        7. Repositories
        8. Validation
          1. Services
          2. Transactions
          3. Presentation layer
            1. Localized messages
            2. Customer save form controller
          4. Complex Event Processing service
        9. Loan approval
          1. Loan request form
          2. Process persistence
          3. Task list
          4. Working on a task
          5. Loan approval event
        10. Summary
      17. 10. Testing
        1. How to write unit tests for rules
        2. Rule integration testing
        3. Rule acceptance testing
          1. Creating a test scenario
          2. Running a test scenario
          3. Running all test scenarios
        4. Static analysis of rules
        5. Troubleshooting techniques
          1. Event listeners
          2. Debugging
            1. Ruleflow
          3. Source of generated classes
          4. mvel tricks
        6. Summary
      18. 11. Integration
        1. Dynamic KnowledgeBase loading
          1. KnowledgeAgent
        2. External artifact building
          1. Building with Ant
        3. Drools execution server
          1. Interest rate calculation example
            1. The server
            2. The client
        4. Spring Framework integration
          1. KnowledgeBaseFactoryBean
        5. Standards
          1. JSR94 Java Rule Engine API
        6. Summary
      19. 12. Performance
        1. Rete algorithm
          1. Node types
            1. Rete node
            2. EntryPointNode
            3. ObjectTypeNode
            4. AlphaNode
            5. LeftInputAdapterNode
            6. TerminalNode
              1. Example 1—inserting a fact
            7. BetaNode
              1. Example—inserting a fact
            8. More complex example
            9. EvalNode and FromNode
          2. Retracting or modifying a fact
          3. Initial fact
        2. Node sharing
          1. Example
        3. Node indexing
          1. AlphaNode indexing
            1. Computation complexity
          2. BetaNode indexing
            1. Example
        4. KnowledgeBase partitioning
          1. Parallel execution
        5. Summary
      20. A. Development Environment Setup
        1. Environment setup
          1. Dependencies and their licenses
      21. B. Custom Operator
        1. Summary
      22. C. Dependencies of Sample Application
      23. Index