Book Image

JBoss Drools Business Rules

By : Paul Browne
Book Image

JBoss Drools Business Rules

By: Paul Browne

Overview of this book

<p>In business, a lot of actions are trigged by rules: "Order more ice cream when the stock is below 100 units and temperature is above 25&deg; C", "Approve credit card application when the credit background check is OK, past relationship with the customer is profitable, and identity is confirmed", and so on. Traditional computer programming languages make it difficult to translate this "natural language" into a software program. But JBoss Rules (also known as Drools) enables anybody with basic IT skills and an understanding of the business to turn statements such as these into running computer code.<br /><br />This book will teach you to specify business rules using JBoss Drools, and then put them into action in your business. You will be able to create rules that trigger actions and decisions, based on data that comes from a variety of sources and departments right across your business. Regardless of the size of your business, you can make your processes more effective and manageable by adopting JBoss Rules.<br /><br />Banks use business rules to process your mortgage (home loan) application, and to manage the process through each step (initial indication of amount available, actual application, approval of the total according to strict rules regarding the amount of income, house value, previous repayment record, swapping title deeds, and so on).<br /><br />Countries such as Australia apply business rules to visa applications (when you want to go and live there)&mdash;you get points for your age, whether you have a degree or masters, your occupation, any family members in the country, and a variety of other factors.<br /><br />Supermarkets apply business rules to what stock they should have on their shelves and where&mdash;this depends upon analyzing factors such as how much shelf space there is, what location the supermarket is in, what people have bought the week before, the weather forecast for next week (for example, ice cream in hot weather), and what discounts the manufacturers are giving.<br /><br />This book shows how you can use similar rules and processes in your business or organization. It begins with a detailed, clear explanation of business rules and how JBoss Rules supports them.<br /><br />You will then see how to install and get to grips with the essential software required to use JBoss Rules. Once you have mastered the basic tools, you will learn how to build practical and effective of the business rule systems.<br /><br />The book provides clear explanations of business rule jargon. You will learn how to work with Decision Tables, Domain-Specifi c Languages (DSL)s, the Guvnor and JBoss Integrated Development Environment (IDE), workflow and much more.<br /><br />By the end of the book you will know exactly how to harness the power of JBoss Rules in your business.</p>
Table of Contents (18 chapters)
JBoss Drools Business Rules
Credits
Foreword
About the author
About the reviewer
Preface
6
More rules in the JBoss IDE

Rule syntax


We bumped into our first rule ( .drl) file in the previous chapter. We will see a lot more of it here, so it's worth going over it again. Our rule file can contain the following elements:

  1. 1. package: Package-name is the name of the folder in which a rule file lives. This is useful for organising our rules (especially when you build up hundreds of them).

  2. 2. import: This pulls in any Java class files (including fact models) that we use in our rules.

  3. 3. global: This defines the global variables that we use. Remember variables (boxes that hold values)? Earlier, they were emptied as soon as our rule had fired and only changes to the facts lived on. Compared to 'normal' variables, global variables live longer, and allow us to pass information into and out of our rules.

    Note

    Passing information into and out of our rules via a global variable is almost the same as passing a fact into the rules. The difference is that the rule engine does not match (or fire) against global variables...