www.it-ebooks.info Drools JBoss Rules 5.X Developer's Guide Define and execute your business rules with Drools Michal Bali BIRMINGHAM - MUMBAI www.it-ebooks.info Drools JBoss Rules 5.X Developer's Guide Copyright © 2013 Packt Publishing All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information First published: May 2013 Production Reference: 1170513 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78216-126-4 www.packtpub.com Cover Image by Suresh Mogre (suresh.mogre.99@gmail.com) www.it-ebooks.info Credits Author Project Coordinator Michal Bali Arshad Sopariwala Reviewers Proofreader Alaa Abed Jonathan Todd Mario Fusco Indexer Rekha Nair Acquisition Editor Kunal Parikh Graphics Lead Technical Editor Ronak Dhruv Joel Noronha Production Coordinator Melwyn D'sa Technical Editors Kaustubh S Mayekar Nilesh R Mohite Sharvari Baet Cover Work Nilesh R Mohite www.it-ebooks.info About the Author Michal Bali, freelance software developer, has more than years of experience working with Drools and has an extensive knowledge of Java, JEE He designed and implemented several systems for a major dental insurance company He is an active member of the Drools community and can be contacted at michalbali@gmail.com I'd like to thank Drools lead Mark Proctor and his team that consists of Edson Tirelli, Mario Fusco, Kris Verlaenen, and other contributors for giving me something to write about They were of great help while I was writing the book I'd also like to thank all the reviewers and the whole editorial team for their patience and help while I was writing this book and in particular, Sarah Cullington, Suchi Singhal, Anish Ramchandani, Joanna Finchen, Mario Fusco, and other anonymous reviewers Finally, I thank my wife Michala for supporting me and putting up with me while I wrote www.it-ebooks.info About the Reviewers Alaa Abed is a die-hard open source philosophy advocate In 1995, after having his Masters degree in automation, he started his career in software engineering His early projects involved writing assembly language and C/C++ device drivers, TCP/IP stack implementation, and Unix terminal emulation tools His passion with Java started in 1998 when he designed and implemented a content management system for mobile content syndication Since then, he has been working with a diverse set of clients across various industries such as financial, energy, health, and many ISVs For the past several years he enjoyed designing Java frameworks for ORM, MVC-based presentation, analytics and reporting and enabling rapid development for rich web applications He currently is a Senior Architect working on enterprise integration, multichannel delivery, and business intelligence solutions I'd like to thank Sara and Nadia for making my life worth living Mario Fusco is a senior software engineer at Red Hat working at the development of the core of Drools, the JBoss rule engine He has huge experience as a Java developer, having been involved in (and often leading) many enterprise-level projects in several industries ranging from media companies to the financial sector Among his interests, there are also functional programming and domain-specific languages By leveraging these two passions, he also created the open source library lambdaj with the purposes of providing an internal Java DSL for manipulating collections and allowing a bit of functional programming in Java www.it-ebooks.info www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at service@packtpub.com for more details At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library Here, you can access, read and search across Packt's entire library of books Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books Simply use your login credentials for immediate access www.it-ebooks.info www.it-ebooks.info www.it-ebooks.info For Matilda www.it-ebooks.info validation report conditional element, collecting 128, 129 serialization 130 updating 127 validation service 57, 58 X XOR 109 W Web Tools Platform See WTP WTP 210 [ 316 ] www.it-ebooks.info Thank you for buying Drools JBoss Rules 5.X Developer's Guide About Packt Publishing Packt, pronounced 'packed', published its first book "Mastering phpMyAdmin for Effective MySQL Management" in April 2004 and subsequently continued to specialize in publishing highly focused books on specific technologies and solutions Our books and publications share the experiences of your fellow IT professionals in adapting and customizing today's systems, applications, and frameworks Our solution based books give you the knowledge and power to customize the software and technologies you're using to get the job done Packt books are more specific and less general than the IT books you have seen in the past Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike For more information, please visit our website: www.packtpub.com About Packt Open Source In 2010, Packt launched two new brands, Packt Open Source and Packt Enterprise, in order to continue its focus on specialization This book is part of the Packt Open Source brand, home to books published on software built around Open Source licences, and offering information to anybody from advanced developers to budding web designers The Open Source brand also runs Packt's Open Source Royalty Scheme, by which Packt gives a royalty to each Open Source project about whose software a book is sold Writing for Packt We welcome all inquiries from people who are interested in authoring Book proposals should be sent to author@packtpub.com If your book idea is still at an early stage and you would like to discuss it first before writing a formal book proposal, contact us; one of our commissioning editors will get in touch with you We're not just looking for published authors; if you have strong technical skills but no writing experience, our experienced editors can help you develop a writing career, or simply get some additional reward for your expertise www.it-ebooks.info Drools Developer's Cookbook ISBN: 978-1-84951-196-4 Paperback: 310 pages Over 40 recipes for creating a robust business rules implementation by using JBoss Drools rules Master the newest Drools Expert, Fusion, Guvnor, Planner and jBPM5 features Integrate Drools by using popular Java Frameworks Part of Packt's Cookbook series: each recipe is independent and contains practical, step-by-step instructions to help you achieve your goal jBPM Developer Guide ISBN: 978-1-84719-568-5 Paperback: 372 pages A Java developer's guide to the JBoss Business Process Management framework Thoroughly understand how the jBPM framework works Build custom Java Enterprise solutions using the jBPM framework No experience with jBPM required Helpful guidance on converting a business analyst's spec into complete, working software Please check www.PacktPub.com for information on our titles www.it-ebooks.info Oracle WebLogic Server 12c Advanced Administration Cookbook ISBN: 978-1-84968-684-6 Paperback: 300 pages Go beyond the basics of WebLogic Server Administration Using real life scenarios to configure, troubleshoot and tune Learn how to set a WebLogic environment with stability, high availability and performance Premature optmization is the root of all evil Configure and tune only what really matters Understand what are you doing and why Every recipe covers the theory behind the practice Oracle BPM Suite 11g: Advanced BPMN Topics ISBN: 978-1-84968-756-0 Paperback: 114 pages Master advanced BPMN for Oracle BPM Suite including inter-process communication, handling arrays, and exception management Cover some of the most commonly misunderstood areas of BPMN Gain the knowledge to write professional BPMN processes A practical and concise tutorial packed with advanced topics which until now had received little or no documentation for BPM Suite developers and architects Please check www.PacktPub.com for information on our titles www.it-ebooks.info .. .Drools JBoss Rules 5. X Developer's Guide Define and execute your business rules with Drools Michal Bali BIRMINGHAM - MUMBAI www.it-ebooks.info Drools JBoss Rules 5. X Developer's Guide Copyright... 240 241 243 2 45 247 248 250 Event listeners Debugging Source of generated classes 250 252 255 Summary 256 Chapter 11: Integrating 257 Dynamic KnowledgeBase loading KnowedgeAgent External artifact... required type rules 44 Testing 45 Batch execution 48 Minimal account balance rule 49 Student account rule 50 Unique account number rule 52 Implementation 53 Validation service 57 Summary 58 Chapter