Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
95 views

JBoss Drools Guvnor Example - Examples Java Code Geeks - 2021

Uploaded by

John Jack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

JBoss Drools Guvnor Example - Examples Java Code Geeks - 2021

Uploaded by

John Jack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

News Knowledge Base Deals About      è Sea

ANDROID CORE JAVA DESKTOP JAVA ENTERPRISE JAVA JAVA BASICS JVM LANGUAGES PYTHON SOFTWARE DEVELOPMENT DEVOPS

⌂ Home » Enterprise Java » JBoss Drools » JBoss Drools Guvnor Example


NEWSLETTER
ABOUT RAM MOKKAPATY
121,825 insiders are alread
Ram holds a master's degree in Machine Design from IT B.H.U. His expertise lies in test driven development and re-factoring. He is updates and complimentary whit
passionate about open source technologies and actively blogs on various java and open-source technologies like spring. He works as a
principal Engineer in the logistics domain.
Join them now to gain
access to the latest news in th


well as insights about Android, S
other related technologies.

Email address:

JBoss Drools Guvnor Example Your email address

 Posted by: Ram Mokkapaty


 in JBoss Drools
 August 21st, 2015
 1 Comment
 Views Receive Java & Developer jo
Area
In this article, we will see an example of Drools Guvnor. We use Guvnor as ‘Business Rules Manager’. Guvnor is the name of the web and  
network related components for managing rules with drools.
Sign up
If you want to more know about Drools Introduction or its setup, read here.

This example uses the following frameworks:

1. Maven 3.2.3 JOIN US
2. Guvnor 5.1.1 With 1,
unique v
500 au
 

placed a
 
related s
Constan
lookout
encoura
So If yo
unique and interesting content t
check out our JCG partners prog
be a guest writer for Java Cod

1. What is a Drools Guvnor? your writing skills!

In order to know Drools Guvnor, we first need to know what is a business rules manager. Business Rules manager allows people to manage
rules in a multi user environment. It is a single point of truth for your business rules. It allows to manage the rules in a controlled fashion. We
can keep track of different versions of the rules, its deployment. It also allows multiple users of different skill levels access to edit rules with
user friendly interfaces. Guvnor is the name of the web and network related components for managing rules with drools.

2. Installing Guvnor
First you need to install JBoss app server from http://jbossas.jboss.org/downloads/. Once your download is complete, unzip the files to a
folder of your choice. To start the JBoss App Server, open the bin folder and double-click on run.bat. Download Drools Guvnor war file.
Rename the war file to guvnor.war and copy to {JBossHome}/server/default/deploy. Start Jboss. Open
http://localhost:8080/guvnor/org.drools.guvnor.Guvnor/Guvnor.html.

You should see the below login screen:

Guvnor Login


You don’t need to enter user/password. Simply click on Ok. You will be taken to the welcome screen.

Guvnor Welcome Screen

Click on ‘No thanks’.

3. Main Features of Guvnor
Browse the main areas. You will see:

1. Knowledge Base
2. QA
3. Package Snapshots
4. Administration

Main Features of Guvnor

4. Upload Domain Model to Guvnor


Before rules can be defined in Guvnor, a business model(a set of Java classes) jar needs to be uploaded to Guvnor.

go to the “Knowledge Bases” tab. Click on “Create New” right under the tab and choose “New Package”. Give your package a name – I
choose “banking” – and press Ok. Then “Create new” – “Upload new Model Jar”.


Create new Package

Create new package.

New package

Create new domain model.

Create new model 


You can see the new model in the ‘Model’ tab.

Model Tab

Go to shopping car to upload the domain model.

Upload domain model

Click on choose file to select the jar file.

You can either use maven to create jar file or use eclipse File->Export->Java->Jar file option to generate the domain model Jar file.

Select the domain model jar

Once uploaded you will see a ‘Upload successful’ message.


Upload Successful Message

You can see the model classes in the package tab. Click on ‘Save and validate configuration’ so that the model files become available as facts
to the rules.

Package View

5. Define Rules
Adding a sample rule. Now the model is uploaded, we can start defining rules. To add a rule, you have to create a Category first
(Administration>Category>New Category).

New Category

Create ‘ShoppingCart’ category.

Create new category ‘ShoppingCart’

Once the category is created, will go back to the “Knowledge Bases” tab and choose Create New>New Rule to create our first rule.

Create new rule

Click on the ‘+’ green button to add conditions. To add a condition to the rule, we need to choose fact type as Cart. After choosing this, we’ll
automatically be taken back to the guided rule-editing screen. This is where we define the rule.

Add conditions to rule

6. Define the rule


We’ll see that Cart has been added as a condition. Currently, this rule will fire for all carts, we need to add constraint that it fires only when
the total price > 5000. To add constraint, we need to click on the ‘+’ button on the WHEN condition. We’ll choose total price as the field and
‘Greater than’ as constraint with value set to 5000. Next, we will add ‘THEN’ part. Click on the green plus sign next to the Then section. The
Add a new action dialog box will be displayed. Here we will select ‘call on method’ cart.addDiscount(), set the value to 2%.

Define Rule

7. Create and Run the Test Scenario


After defining the rule, we will create a test scenario to test the rule. Select the package and click on ‘Create new scenario’.


Create Test Scenario

1. We will have to click on the ‘+’ sign to insert a new GIVEN/EXPECT, the small green arrow to refine the scenario, and the ‘–’ sign to
remove.
2. We will click on GIVEN to insert a new cart fact and then on Add.
3. Next, we will click on the Add a field button that appears. In the dialog box, select the ‘totalPrice’ field.
4. Next, we will set a constraint for ‘totalPrice’, that is, if it is greater than 5000.
5. Click on the green ‘+’ next to EXPECT. In the New Expectation dialog box that is displayed, click on show list and then choose the added
rule.
6. Change the default (that we expect this rule to fire at least once) to Expect Rules, to fire this many times, and then enter ‘1’ in the new
text box that appears.
7. Save this test scenario using the button at the top of the screen.
8. Finally, we will click on the Run Scenario button, you will get a green bar at the top of the screen saying Results 100%.

8. Download the Eclipse Project


This was an example about Drools Guvnor.

Download

You can download the full source code of this example here: DroolsGuvnorExample.zip

Do you want to know how to develop your skillset to become a Java


Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
 
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
 
and many more ....
 

Email address:
Your email address

Receive Java & Developer job alerts in your Area


 
Sign up

LIKE THIS ARTICLE? READ MORE FROM JAVA CODE GEEKS

 Subscribe 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 COMMENT   Oldest

Koijam Baleshwor Singh 


2 years ago

very nice article. i was trying to follow the steps you had mentioned above. had a small challenge
deploying the guvnor.war file in jboss server. below is the exception while deploying the war file.
21:31:30,296 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting
deployment of “guvnor.war” 21:32:30,306 INFO [org.jboss.as.server] (DeploymentScanner-threads
– 1) JBAS015870: Deploy of deployment “guvnor.war” was rolled back with failure message
Operation cancelled 21:32:30,306 ERROR [org.jboss.as.server.deployment.scanner]
(DeploymentScanner-threads – 2) JBAS015052: Did not receive a response to the deployment
operation within the allowed timeout period [60 seconds]. Check the server configuration file and
the server logs to find more… Read more »

0
Reply

KNOWLEDGE BASE HALL OF FAME ABOUT JAVA CODE GEEKS


JCGs (Java Code Geeks) is an independent online community focused o
Courses Android Alert Dialog Example
ultimate Java to Java developers resource center; targeted at the techn
technical team lead (senior developer), project manager and junior dev
Minibooks Android OnClickListener Example
JCGs serve the Java, SOA, Agile and Telecom communities with daily ne
domain experts, articles, tutorials, reviews, announcements, code snipp
News How to convert Character to String and a
source projects.
String to Character Array in Java
Resources
Java Inheritance example DISCLAIMER
Tutorials
Java write to File Example
All trademarks and registered trademarks appearing on Java Code Geek
THE CODE GEEKS NETWORK java.io.FileNotFoundException – How to property of their respective owners. Java is a trademark or registered tr
Oracle Corporation in the United States and other countries. Examples J
solve File Not Found Exception
is not connected to Oracle Corporation and is not sponsored by Oracle C
.NET Code Geeks java.lang.arrayindexoutofboundsexception
– How to handle Array Index Out Of
Java Code Geeks Bounds Exception

System Code Geeks java.lang.NoClassDefFoundError – How to


solve No Class Def Found Error
Web Code Geeks
JSON Example With Jersey + Jackson

Spring JdbcTemplate Example

Examples Java Code Geeks and all content copyright © 2010-2021, Exelixis Media P.C. | Terms of Use | Privacy Policy | Contact 

You might also like