JBoss Drools - Business Rules Management System - User Guide
From Kb
Contact Article Author | Blog of Article Author | FirstPartners.net Home | LinkedIn profile of Author
Business Rules Management System (BRMS)
Notes
- Intended to be standalone guide / chapter within documentation
- Split BRMS Guide into bits for Business end users and Technical setup
- Split already there in chapter
- This guide needs to be transformed into XML
- Refer to other useful bits of the Drools documentation
- This is aimed at business users; a set of pages that they can be handed and lets them start from scratch
- Split BRMS Guide into bits for Business end users and Technical setup
- Intended to be standalone guide / chapter within documentation
- == What am I doing reading this? ==
- If you are reading this, the chances are that you have some sort of knowledge in your head. You might be in the Medical, Legal or Accountancy professions. You may be the only person in the company that understands how to process refunds to tractor dealers in the Chicago area. You may have the most experience underwriter in the mortgage application department. Or You may be the person that they're most able to spare to talk to 'those guys in IT'. Perhaps you've taken part in one or more IT projects, or maybe this is your first one.
- Whoever you are, you've got a problem. Maybe your group or team is too busy for the workload they have to do. Maybe you can't recruit enough people to work with you. Or maybe you can get the people, but it takes a long time and a lot of money to train them. Whatever the cause, there are not enough minds to go around, and costly or embarrassing mistakes are being made as a result.
- You've probably already joked about being able to clone your key people. Wouldn't it be great to leave your clone working at the desk while you got some time on the beach. Or even got home on time. While JBoss Drools does not allow you to clone yourself, it does allow you to put your knowledge into a computer. Once there it can be copied, reviewed and keep on working after you go home.
- Your second thought after hearing the 'put your knowledge into a computer' bit (after the relief) is probably 'if the computer knows what I know, will I be out of a job?'. Maybe. Or more likely you'll no longer do the routine 80% of your job that you hate – the rubbish that fills up your day. It means that you spend more time at the 20% you enjoy; talking to people, meeting customers, improving the process.
- This document is aimed at non-technical users, although it contains a lot of information that people that want to get under the covers of Drools will find useful. Don't worry though – if the entire extent of your PC skills is writing a couple of formula in Excel, then you're going to be ok.
- == What is a business rule? ==
- You're going to be hearing a lot about 'business rules' over the next couple of pages, so it might be helpful to say clearly what it is. We use the term 'business rule' to show that the rule is non technical, so they could equally be called 'medical rules', 'financial rules', 'insurance rules', 'benefit payment rules' etc. It all depends on the organization you work for, and the particular niche that it finds itself in.
- A business rule is any bit of knowledge that can be expressed in the following format:
- when 'something' is true, then do 'this'.
- All companies and organisations already have business rules, even if they are implied (i.e. Unwritten) or buried (as code) in existing systems (e.g. the ones with black screens and green text). Examples of these rules may be:
- When football team wins a game, jump up and down and shout loudly
- When a staff member gets promoted give them a pay rise of 10%.
- When a person's salary is less than Eur40,000, apply a tax rate of 20%
- When somebody leaves the office before 3pm, make sarcastic comment about 'taking a half-day vacation'.
-
-
- Business rules themselves tend to be simple. Their power comes from the fact that there are many of them (tens, hundreds or even thousands). Just as you have many rules in your head (when you see a bear, run away) the trick is knowing when to apply them (what happens when you see a bear in the zoo?). Later we'll look at writing your rules clearly and testing them to ensure they do what you want.
- [todo: ensure this section exists]
- Business rules should be written as clearly as possible (in English, or your human language of choice). While this makes your life easier when writing the rules, more importantly, it allows other people to review your rules in the future. Various estimates show that 95% of all effort on a system is in this 'review and update' phase, so clarity is one of the biggest gains of using rule engines.
- What happens to my rules once I've written them (i.e. How do they get out into the real world?). That's one for the techie guys you work with to worry about (i.e. Outside the scope of this guide), but we'll give you enough information later so that you'll know what is going on.
- Business rules themselves tend to be simple. Their power comes from the fact that there are many of them (tens, hundreds or even thousands). Just as you have many rules in your head (when you see a bear, run away) the trick is knowing when to apply them (what happens when you see a bear in the zoo?). Later we'll look at writing your rules clearly and testing them to ensure they do what you want.
- == So what is JBoss Drools and how can it help? ==
-
- Your boss, somebody from the IT department or a consultant has mentioned JBoss Drools as part of the solution. After a good laugh at the name (it's a long story) you want to find out more. We'll answer this question in 2 parts: Who are JBoss, and what is the Drools team.
- JBoss is a division of Red Hat [Insert Company Blurb here]. What this means is Drools is supported by an industry leading commercial company. And support from that company is available should you need it.
- A key part of JBoss and Drools is Open Source. To put this in quality terms, both the JBoss and Drools teams are confident enough about the quality of the product to let you poke around inside – it's a bit like getting a tour of the Mercedes car factory. It also shows the confidence the team have in the quality of their support: If you don't think the support is good enough, you are free (and able!) to get 3rd parties to do the job to your satisfaction.
- Drools is an advanced Rule Engine (and a lot more besides, as we shall see later). It allows you to state things that you know to be correct (e.g. If the expenses claim is above $5000, then a senior manager needs to sign it off). As somebody who has knowledge of business rules, you'll be able to feed the Rule Engine with what you know. The tool that you use to do this is the Business Rules Management System.
- == The bigger picture ==
- You're unlikely to go to the trouble of putting your knowledge into a Rules system and leave it at that. You've a problem that you're trying to solve. For that, you're going to use Rules as part of a bigger system.
- [todo: simplified version of 3 tier diagram]
- Here's the 5 minute guide to almost any computer system: They take information from users (these days, mainly via a web page) , do something with it, then store it somewhere (normally in a Database). You may recognise some Database brand names such as Oracle, SQL Server or MySql - Think of them as a very big version of Excel. Sometimes the flow of information goes the other way – access information in the database, then show it on the web page. That's it. What are you paying all these IT consultants for?
- Drools helps you with the middle 'do something with the information bit'. Here you apply the business knowledge (the stuff that's currently in your head) to the information passing through. We recommend Drools as one of the other options is to to put your brain into a glass jar (think mad scientist lab with rows of brains suspended in bubbling liquid) and wire it in somehow.
- Members of your team
- Unless you're a business user by day and techie by night, we don't expect you to build the entire web system by yourself. In general , as a business user, you'll supply two bits of information to the IT team. The rest should be considered 'plumbing' – stuff that should be done according to Industry standards / best practice , but that otherwise be hidden from you / the user and should 'just work' (like water coming out of the tap).
- The two sorts of information you'll generally need to provide are:
- The user's interactions with the completed system. For example , the web page the user uses to log in, the first screen they see after they log in, what the various buttons on this screen does. Entire books have been written on this subject so we won't go over it here.
- The actual business rules. Unlike the screens, this is 'behind the scenes' stuff. This is your knowledge applied to the data that's being capture on the web pages. Even if you don't use Drools / another Rule engine you'll still need to do this step. Otherwise , how will the system know that pay for prescriptions for Viagra, but not for aspirin?
- Why can't the tech guys write the rules for me? The answer is the tech guys can but it's a bit like booking a flight through a travel agent rather than over the internet.
- Ever turned up at the airport and found that the travel agent got it wrong? Doing it yourself means that there is one less link in the chain to go wrong.
- Booking your own flight (and writing your own rules) is quicker and easier.
- Ever understood what all the hieroglypic codes on the paper ticket meant? (I'm showing my age- most airlines phased out paper tickets years ago). The chances are if you give a technical person the rules to write they're probably going to do it in a computer language like C#, Java or VB. Nothing wrong with that. It's just that they might as well write it in Egyptian Hieroglyphics for all that you will able to understand it. - no way are you going to be able to check if you got them write.
- For simple flights (e.g. Dublin – London return) booking online is fine. For multi-stop round the world tickets getting advice from a travel agent is often a good idea. Likewise for rules: write most of the simple ones yourself, then get the Tech guys to write the harder ones.
- [todo: more later on the IT project process]
- Bring in Fit for Rules other Agile methods
- You're unlikely to go to the trouble of putting your knowledge into a Rules system and leave it at that. You've a problem that you're trying to solve. For that, you're going to use Rules as part of a bigger system.
- == So how do I write the rules? ==
- You've got four choices when it comes to writing rules:
- You can use the Business Rules Management System (BRMS) from Drools. This is a web based application that's aimed at people like you. Not only is it easy to use, but it can be setup once by the technical support for the entire team to use via Internet Explorer, Firefox or your favourite web browser. Strangely enough for a BRMS guide, this is the option we recommend, so we'll come back to it later.
- You could write the rules via a simple text editor like notepad. It's a bit masochistic and dull – staring at black and white text with no help as to what is expected. We mention it here only to show that there is nothing special about the rules format – it's just plain text.
- You can write rules in Microsoft Excel, or any spreadsheet that can output excel like spreadsheets (e.g. Sun OpenOffice). You do have to follow a certain template (it's not that difficult once you see it). However, the excel format lends itself to rules that repeat themselves a lot (the sample Drools gives for Decision Tables is lots of different categories of car insurance claims). So we'll come back to Decision tables later, but they're not the main focus of this article.
- [todo: more later on Decision tables for end-users]
- Use the Drools IDE, based on Eclipse. IDE stands for integrated development environment , so Eclipse is a bit like 'Microsoft Office for Techies'. Chances are your technical team are using it anyway (to write in a language called Java, although it can be used with other computer languages).
- The Drools IDE bit adds plugins to Eclipse to allow Rule Editing and debugging. The IDE is more powerful , but more complex. We'll talk about the extra features later, but most of the commonly used ones are already in the BRMS (and over time , the remainder will be implemented). It's possible to switch between the two (IDE and BRMS).
- Whatever way you choose, the rules that get fed into the the rule engine are pretty much the same. In fact, the BRMS allows you to import and manage rules written as text / decision tables / via the IDE so following the BRMS for now is a good choice.
- You've got four choices when it comes to writing rules:
- == What is the BRMS ==
-
- What is the BRMS
- The BRMS is a web page that you open in Internet Exporer, Firefox, or your favourite internet browser. You've seen web pages before, right? The BRMS allows you to enter your knowledge as business rules via a web page.
- At the start you can enter rules via the guided editor (similar idea to the helpful 'wizards' that you might have come across in Windows). Later, as you get more used to the rules syntax you might want to edit the rules directly in the text editor.
- Before you start rules, there are items (e.g. placeholders for the data the rules need)
- how to import
- Other things the BRMS gives you
- Version Management
- Deployment
- Security (Login)
- What is the BRMS
-
- == Rule Engines and the BRMS ==
- By now you should understand the concept that a rule engine allows you to capture your knowledge and allow it to be integrated into an enterprise web system. However, a rule engine isn't just a 'black box'. There's a couple of parts to it, that it's useful to know about (I don't know much about car mechanics , but I can check the oil and tyre pressures. We'll keep the Drools technical bits at that level).
- Rules Editor
- This is the choice of BRMS/ IDE / Decision Table or plain text file. All produce a similar underlying rule language. And the mechanism for deploying these rules (RuleAgent or some other equivalent) is similar.
- Rules Compiler
- Something needs to translate the near-english rules language into something the rules engine can understand – this is what the compiler does. Your main awareness of the compiler (as a BRMS user) is when it complains about that it does not understand the way the you a phrasing your rules.
- Runtime
- As the information flows through your system, something has to apply to the (compiled) rules to it. This is where the Drools Runtime comes in. In general , you don't worry about the technical aspects of this; you just care that there is something applying the business rules you have written in the live / production system.
- Fact Model
- So we have a working system, with information flowing from the web , modified by the rules, then saved in the database. Obviously, when writing our rules, we need to know what this information will be (will we ask the user for salary before or after tax? Will we ask the user what country they live in or just their post/zip code?). The information has to be in a certain format (think excel spreadsheet – we need to know which column the salary information is stored in , and if it's before or after tax). The description of the information we need and the format it is stored in is known as the fact model.
- Rather than writing the fact model in excel, most of the time it's written in Java. Don't worry; at the level we're working at (specifying the names of the information that we're collecting and if it's a number, piece of text etc) it's not that complicated; remember if you can handle Excel, you can do this. We've two approaches to building the fact model:
- For most of this guide, we'll assume that somebody else has done the analysis and that all the information that you need when writing the rules will magically be there.
- Realistically, you're going to find things that are missing when you start writing your rules. Later in the guide, we'll tell you how to get your technical guys to update the fact model with the fields (bits of information) that you need.
- [todo: write this bit of the guide]
- It's probably not beyond your ability to modify the fact model (just follow the recipe we suggest, even if you don't fully understand the low level details). The main reason you don't update it is that other parts of the system (the web screens, the database) also use the fact model – it's a key part of how the system is linked together. So change a bit here without talking to the other guys, and you risk breaking things for them.
- Rules Editor
- An important note is that the BRMS helps you edit the rules, and typically does not form part of the production system that the end users will see – that task is left to the core rules engine.
- By now you should understand the concept that a rule engine allows you to capture your knowledge and allow it to be integrated into an enterprise web system. However, a rule engine isn't just a 'black box'. There's a couple of parts to it, that it's useful to know about (I don't know much about car mechanics , but I can check the oil and tyre pressures. We'll keep the Drools technical bits at that level).
- What do I need beforehand (ask your tech support)
- So you're ready to start playing with the BRMS? There's a couple of things that you need setup. Rather than explain it all here, get your friendly technical department to do the work for you: The guide is at: http://labs.jboss.com/drools/documentation.html
- What you need is to ask for:
- The BRMS setup of on a Java Web Server like Tomcat or Jboss (both of which are freely available). This can either be on your PC, or a company server.
- The URL (website address) that you access the BRMS. Often this will be something like : http://some-server-name/drools-jbrms.
- The username and password that you'll login as. If they've followed a standard install , they will both be blank , (they may have taken the option to secure it).
- Note that that security probably isn't an issue when you're 'playing' with the BRMS. Later you'll probably want to implement one of the security / signon options (we'll talk about these options later). Business Rules are pretty core to the company knowledge – you don't want people wantonly changing them, nor do you want the knowledge leaking (allowing people to 'game' the system).
- [todo: make sure that this section exists ]
- Sample Application
- The BRMS comes pre loaded with some sample car insurance rules. Ask whoever is setting up the BRMS to leave thse in place – we'll talk through the rules to show what each section does. These sample rules are easy enough to delete later.
- Starting with the Business Rules Management System (BRMS)
- How do I get started?
- Walk through functionality
- Login
- [screenshot: Login Screen]
- Info Tab
- Welcome Page
- [screenshot: welcome screen]
- http://localhost:8080/drools-jbrms/org.drools.brms.JBRMS/JBRMS.html
- 4 links in the middle of the screen to the community
- [screenshot: welcome screen]
- Rules
- [screenshot]
- Allows you to view existing and create new rules
- Packages
- [screenshot]
- Allows you to group rules (and other 'assets' that rules depend on) into folders – so that they are easier to understand and manage.
- Java follows a notation for these packages – while you don't have to follow it here there is no harm in doing so (especially when we start talking about the Java Based rule model later. The package name looks a little bit like an internet web address (although it doesn't actually link to anything). The format is: companyurl.projecturl.subproject.anyotherdivisionsrequired. Examples of this are:
- org.drools.brms.client
- com.megacorp.insurance.cars.
- net.firstpartners.redpiranha.rules
- ie.drinks.guinness
- Most of the packages that you create will only need 3 or four levels (like above). However, there can be as many subdivisions as you need. You see more of these subdivisions when we talk about Java code (Fact models)
- Login
-
-
- QA
- [screenshot]
- (in progress) : When you have finished writing your rules, you'll (probably) want to test them before you release them to the real world. This Tab will help you automate this testing so that you don't have to manually test everything if you change even one small rule.
- Note that while this funcitonality is 'in progress' within the BRMS, Drools already has equivalent funcitonal for automated end-user testing. See the FIT section of the Drools manual for more detail.
- Deployment
- [screenshot]
- When you edit your rules, they don't get deployed (to the live/ real world system) right away.
- Can you imagine being in the middle of writing the 2nd of 3 new rules, and having the incomplete ruleset be deployed?
- The Deployment tab allows you to control when your rules are released to the end users.
- Admin
- [screenshot]
- Various admin functionality not directly related to rules editing, but vital for managing the system e.g. Important and exporting rules.
- QA
-
- Essential Concepts
- [todo: cover, based on what is needed in the following section ]
- More Functionality on the BRMS
- We look at the initial talbs in the BRMS earlier. Now, armed with our essential rules concepts, we're going to look at these tabs (and the tabs within these tabs) in more detail
- [todo : screenshot and talk about these]
- Admin
- Create new Category
- Name and Save
- Packages
- Create new Package
- small , using tooltip
- Create new Model
- small using toolltip
- upload Jar
- Save Changes
- Create new Package
- Info
- Rules
- These are still in flux, so will probably be the last bit to get written From QuickStart Guide (aka missing manual)
- Holy crap we're almost there! Now click on the "MyPackage" package in the tree, then "Edit Package Configuration" in the main window.
- In the "Header" section in the main window you need to actually tell Drools about your bean. To do so: import com.mycompany.MyBeanNo semicolon at the end.
- Wow we should actually be able to make a rule now! AWESOME!Click on the massive 16px button that will let you "Create New Rule"
- Give it a name and category and type it as "Business rule". Save.
- Ok, now comes the real test. Click on the big green plus sign to the right of "WHEN". You should see a window that says "Add a condition to the rule..." If everything was set up correctly -- and that's a big if -- then you should see two selects: "Fact", and "Condition Type". If all it says is "Add a condition to the rule..." and nothing else, then you screwed up. Also these instructions may be wrong. It is much more likely that you screwed up because I have a blog. If it doesn't work please go to step RTFM, else continue.
- Fact. Click on it. Select your bean.
- (Fill in the obvious bits instead of leaving to figure out on your own)
-
- Packages
- create new package
- QA
- Deployment
- Packages
- The Fact Model - Just enough Java to get by
- We mentioned the fact model earlier, and likened it to Excel spreadsheets used to move data around all parts of the system, not just the rules engine. This means (for example) that we can get the information from a web page, apply the rules to it, then show it on the web page. The good news is because the facts (written in Java) are shared, it's likely to be someone else writing them, not you. This is the approach we took in the previous section, where we assumed that the fact model didn't need to be changed.
- This 'sharing' of the fact model means that, even if you had the time or the inclination, you're not going to edit it in Java. Even if you did, you probably couldn't / wouldn't want to edit the web pages that use it as well. But nobody gets everything right first time so here's how to have a what we're telling you here is how to have a conversation with the people who do.
- What you're going to need.
- Explain Java Facts by using Excel Spreadsheets
- Just enough to edit and build a Fact Model
- e.g. Take sample, build , use it in BRMS
- Testing your rules
- Use the new testing features in 4.1
- [todo: feature in progress. Either ask Mike was is coming, or base on fitness section
- Getting your Rules into the Real World
- Develop – Test – Deploy – Retire
-
-
- Where are my rules being stored?
- How do I use my rules?
-
-
- Parts of the rules system
- How to prepare your rules for deployment
- What the techies do to your rules once you are finished with them
- [todo: bit from ]
- Where to get more information
- What to do before asking for help
- Where to get help
- Drools Home page
- Drools Documentation
- Wiki
- Mailing Lists
- How to ask for help
- [todo: take from Mark's email on the subject]
- Where to get help
- Background to the Drools Project
- What is this open source stuff?
- Home page/ wiki etc
- Examples
- What examples are they
- How relevent to business users
- Where to get them
- What to do before asking for help
- More Advanced BRMS stuff
- [todo] Paragraph highlight of the features, links to more detail in the current documentation.
- Development, Test and Production
- Are Rules Code or Data?
- Decision Tables
- Loading Rule Flow
- What is rule flow
- how to load it
- Extend the BRMS as part of solution
- Restricting access to BRMS
- More advanced Rules stuff
- [todo] More of a advertisement to go read the Drools Manual
- Rule Syntax
- [todo: link to refernce]Reference
- A bit of rule theory ...
- not too much , just enough to understand common gotchas
- [todo]
- Eclipse Based Rule Editor
- [todo: list Stuff that can't yet be done in the BRMS
- Domain Specific Languages (DSL's)
- Rule Flow
- [todo: explain what is]
- Order of rules firing
- Workflow
- Examples
- Summary of exisitng
- BRMS setup guide
- Web Server
- Database
- Non Derby Databases
- Other Drools Features not (yet)supported by BRMS
- Advertisement for the Drools project , esp if they are Business / Architect types using this guide to evaluate Drools
© Paul Browne 2007-2008. Made available under the terms of the GNU Free Documentation License.

