Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering JBoss Drools 6

You're reading from   Mastering JBoss Drools 6 Discover the power of Drools 6 and Business Rules for developing complex scenarios in your applications

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher Packt
ISBN-13 9781783288625
Length 330 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Mariano De Maio Mariano De Maio
Author Profile Icon Mariano De Maio
Mariano De Maio
Esteban Aliverti Esteban Aliverti
Author Profile Icon Esteban Aliverti
Esteban Aliverti
Mauricio Salatino Mauricio Salatino
Author Profile Icon Mauricio Salatino
Mauricio Salatino
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Rules Declarative Nature 2. Writing and Executing Rules FREE CHAPTER 3. Drools Runtime 4. Improving Our Rule Syntax 5. Understanding KIE Sessions 6. Complex Event Processing 7. Human-Readable Rules 8. Rules' Testing and Troubleshooting 9. Introduction to PHREAK 10. Integrating Rules and Processes 11. Integrating Drools with our Apps Index

Writing and executing our first rule

Now that we have our project structure ready, we can write our first rule. For that, we will create a new empty text file. This will be a static resource, therefore, we need to place it in the src/main/resources directory. This text file needs to have the .drl extension so that it can be picked up as a rule file. In the .drl files, we will write as many rules as we want. Now, we will start easy with just one rule.

Let's write our first rule to classify the items based on what they cost us. Our rules.drl text file will look similar to the following:

package myfirstproject.rules
import org.drools.devguide.eshop.model.Item;
import org.drools.devguide.eshop.model.Item.Category;
rule "Classify Item - Low Range"
    when
        $i: Item(cost < 200)
    then
        $i.setCategory(Category.LOW_RANGE);
end

This rule checks for each item that costs less than 200 USD and automatically tags it with a category, in this case, LOW_RANGE. For our shop...

You have been reading a chapter from
Mastering JBoss Drools 6
Published in: Mar 2016
Publisher: Packt
ISBN-13: 9781783288625
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image