1. Trang chủ
  2. » Công Nghệ Thông Tin

Drools JBoss rules 5 x developers guide

338 70 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 338
Dung lượng 4,43 MB

Nội dung

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 Dependencies of Sample Application The following is a listing of third-party dependencies and their versions as needed by the sample application implemented in Chapter 9, Building a Sample Application The dependencies are given in a Maven POM format (Maven is a build tool, and for more information, please visit http://maven.apache.org/) Drools and jBPM dependencies are given in the following code listing: org.drools drools-core ${drools.ver} org.drools drools-compiler ${drools.ver} org.drools drools-spring ${drools.ver} org.drools drools-persistence-jpa ${drools.ver} org.jbpm www.it-ebooks.info Dependencies of Sample Application jbpm-flow-builder ${jbpm.version} org.jbpm jbpm-persistence-jpa ${jbpm.version} Code listing 1: Extract from the sample application pom.xml file (part 1) Next, other third-party dependencies are given in the following code listing: commons-lang commons-lang 2.6 org.slf4j slf4j-log4j12 1.6.4 org.slf4j slf4j-api 1.6.4 org.slf4j jcl-over-slf4j 1.6.4 Spring > org.springframework spring-core ${spring.ver} org.springframework spring-beans ${spring.ver} [ 306 ] www.it-ebooks.info Appendix C org.springframework spring-orm ${spring.ver} org.springframework spring-context ${spring.ver} org.springframework spring-tx ${spring.ver} org.springframework spring-webmvc ${spring.ver} org.springframework spring-web ${spring.ver} org.springframework spring-jdbc ${spring.ver} org.aspectj aspectjrt 1.7.1 org.aspectj aspectjweaver 1.7.1 org.springframework spring-test [ 307 ] www.it-ebooks.info Dependencies of Sample Application test ${spring.ver} Hibernate > org.hibernate hibernate-entitymanager 4.1.9.Final org.hibernate hibernate-core 4.1.9.Final HSQLDB > com.h2database h2 1.3.170 Code listing 2: Extract from the sample application pom.xml file (part 2) Finally, we'll define properties that have been used earlier: 5.5.0.Final 5.4.0.Final 3.2.1.RELEASE Code listing 3: Extract from the sample application pom.xml file (part 3) [ 308 ] www.it-ebooks.info Index Symbols B drl file 90 dslr file format 90 @key annotation 26 == operators 297 @propertyReactive annotation 160 balance property 17 banking domain model account types 38 about 37 analysis 39 design 40, 41 entities 37, 38 UML diagram 37 validation requirements 38 banking service 197 bankingService.approveLoan method 237 bean properties 27 beforeNodeTriggered method 254 BetaNode about 278, 279 fact, inserting 280 BetaNode indexing about 287 example 287, 288 BliP 12 BPMN 170 BRMS 12, 241 buildCustomer method 76 Business logic 201 Business Logic integration Platform See  BliP Business Process Model and Notation See  BPMN Business Rules Management System See  BRMS A abortWorkItem method 188 accept method 132 AccountService class 24 AccountUpdatedEvent 140 activation-group attribute 106 agenda-group attribute 106 AlphaNode 277 AlphaNode indexing about 285, 286 computation complexity 286 AND 109 and element 28 Apache Ant used, for external artifact building 260-262 Approve Event node 196 architecture 200 arrays 27 assertNotFired method 153 Audit log 246 averageBalanceQuery monitoring 147 testing 148 www.it-ebooks.info C CEP 13, 200 137, 138 coercion 27 collections about 33 contains (Not) operator 33 From operator 33 memberOf (Not) operator 33 comments 23 complex event processing See  CEP configuration deployment 210 JPA annotations, for domain objects 203, 204 JPA configuration 204, 205 spring framework configuration 206-208 web application setup 208, 209 contains (Not) operator 33 createContext method 159 createKnowledgeBase method 18 createKnowledgeSession method 131 createSerializableMarshaller method 134 customerMap parameter 75 custom operator creating 297-303 D data facts, loading into rule session 61-63 obtaining 60, 61 database setup 77 data loading implementation about 77 alternative data loading 81 database setup 78 iBatis configuration 79, 80 iBatis, running 80 project setup 78 data transformation about 59 process overview 59, 60 data transformation rules for DSL 93-95 decision tables about 96-98 advantages 99 disadvantages 99 interest rate, calculating 100 rule template 105 dependencies of sample application 305-308 development environment dependencies 295, 296 licenses 295 setting up 293, 294 dialect 26, 36 dispose() method 116 domain-specific language See  DSL DRL file format 90 Drools about 12, 13 development environment 293 modules, Drools Expert 12 modules, Drools Fusion 13 modules, Drools Guvnor 13 modules, jBPM 13 Drools Camel server about 263 interest rate calculation example 263 Drools Fusion 138 Drools serialization class figure 133 full serialization mode 134 identity mode 133 JPA serialization mode 134 DSL about 83-86 as interface 86, 87 data transformation rules 93-95 file formats 89 for multiple constraints in a condition 90, 91 for validation rules 87, 88 named capture groups 92 transformation functions 92 DSL file format 89 DSLR file format 90 Dynamic KnowledgeBase loading about 257 KnowledgeAgent 258-260 [ 310 ] www.it-ebooks.info E Eclipse plugin 253 EDA 137 enterprise service bus (ESB) 147 EntryPointNode 276 equals method 17 error event about 172 otherwise branch, testing 174-176 test setup 172, 173 ESP 137, 138 ETL 81 EvalConditionNode 282 eval element 30 evaluate method 303 event-driven architecture See  EDA Event node 196 event stream processing See  ESP executeRules method 118, 129 exists element 29 external artifact building 260 building, Apache Ant used 260-262 Extract, Transform, Load See  ETL F file formats DRL file format 90 DSL file format 89 DSLR file format 90 final approval about 196 Approve Event node test 196 findAddress rule 68 fireAllRules method 19 FIT 241 Framework for Integrated Test See  FIT fraud detection about 138 business requirements 139 design 139-141 modeling 139-142 rules 142 fraud detection rules averageBalanceQuery, monitoring 147 high activity 163 increasing withdrawal sequence 153, 154 notification 143 two large withdrawals 149, 150 twoLargeWithdrawals rule, testing with 151, 153 FromNode 282 From operator 33 full serialization mode 134 functions 25 G getAge() method 30 getAverageBalance method 149 getConversionToEurFrom function 72 getEvaluator method 301 getFactHandle method 117 getKnowledgeRuntime() method 182 getNodeInstance() method 182 getTasksAssignedAsPotentialOwner method 195 global variables 24 H hashCode method 17, 297 helper method 123 high activity about 163, 164 testing 164-166 human task about 191 test 192-195 I iBatis configuration 79, 80 identity mode 133 imports 23 increasing withdrawal sequence about 153, 154 average balance test 154-159 looping, prevention 159-162 @propertyReactive annotation 160 sequenceOfIncreasingWithdrawals rule, testing 162, 163 initialize method 164 [ 311 ] www.it-ebooks.info inline eval element about 30, 31 nested accessors 31 insertLogical method 127 insertOrUpdateRecursive method 121, 132 integration testing 122-125 interest rate calculation, decision tables about 100, 101 CSV 104 project setup 102 testing 102-104 interest rate calculation example about 263 client 267, 268 server 263-266 interface implementations 53-56 invalid loan application form about 170 e-mail work item 170, 172 error event 172 J Java.lang.System property 22 Java Persistence API See  JPI Java Persistence API (JPA) 193 Java Server Pages See  JSP jBPM about 105, 253, 254 Drools agenda 105 execution order, defining 110, 111 KnowledgeBase set up 111, 112 rule execution order, managing 106, 107 ruleflow-group attribute 107 rules 111 test setup 112, 113 JPA serialization mode 134 JPI 199 JSP 201 K keep it short and simple See  KISS KISS 115 KnowledgeAgent 258 KnowledgeBase partitioning about 289, 290 parallel execution 291 L layer design 202 left-hand side See  LHS LeftInputAdapterNode 277 left unblinking 289 LHS 16 loan approval about 220 event 236, 237 Loan Request form 221, 222 process persistence 223-230 task list 231, 233 task, working on 234-236 Loan approval process about 169 banking service 197 diagram 169 disadvantages 198 disadvantages 198 final approval 196 human task 191 invalid loan application form 170 loan size 176 Rating Calculation 177 rating decision 183 Transfer Funds work item 184 Loan approval service about 168 model 168 loan size about 176 small loan test 176, 177 loanSourceAccount method 173 logical assertions 125, 126 LostCardEvent 140 M Marshaller instance 135 memberOf (Not) operator 33 model-view-controller See  MVC MVC 209 mvel 27 [ 312 ] www.it-ebooks.info N org.drools.spi.KnowledgeHelper 44 owner property 297 nested accessors 31 node indexing about 285 AlphaNode indexing 285, 286 BetaNode indexing 287 node sharing about 284 example 284, 285 node types, Rete algorithm about 275, 276 AlphaNode 277 BetaNode 278 complex example 280, 281 EntryPointNode 276 EvalConditionNode 282 FromNode 282 LeftInputAdapterNode 277 ObjectTypeNode 277 Rete node 276 TerminalNode 278 no-loop attribute 36 not element 29 notification about 143 rule, testing 146, 147 test configuration setup 143-146 null-safe bean navigation 27 P PackageBuilderConfiguration method 299 packages about 23 dialect 26, 28 functions 25 global variables 24 imports 23 type declarations 25, 26 performance 273 Plain Old Java Object See  POJO POJO 16 presentation layer, validation about 215, 216 Complex Event Processing service 220 customer save form controller 217-219 localized messages 217 processCustomer method 75, 77 Process Instances view 254 Process Loan node 195 Process Virtual Machine (PVM) 182 projections 27 project setup 78 R O Object Management Group See  OMG ObjectTypeNode 277 OMG 170 OR 109 or element 28 org.drools.builder.KnowledgeBuilder 20 org.drools.FactHandle 121 org.drools.KnowledgeBase 18 org.drools.runtime.process ProcessContext 182 org.drools.runtime.StatefulKnowledge Session 19, 116 org.drools.runtime.StatelessKnowledge Session 45 Rating Calculation about 177 setting, on-exit action used 182, 183 subprocess, benefits 178 subprocess diagram 178-180 subprocess test 181 rating decision about 183 Rating? node, testing 184 Rating? node 184 readObject method 131, 135 Representational State Transfer See  REST ResourceFactory.newClassPathResource (basicRule.drl) method 20 respositories 210, 211 REST 263 [ 313 ] www.it-ebooks.info Rete algorithm about 273-275 fact, modifying 282 fact, retracting 282 initial fact 283 node types 275 Rete node 276 returned object 80 return element 30 Return values 27 RHS 16 RIF 270 right-hand side See  RHS RightInputAdapterNode node 281 right unblinking 289 rule acceptance testing about 241, 243 all test scenario, running 247, 248 test scenario, creating 243, 244 test scenario, running 245, 246 rule attributes about 35 dialect 36 no-loop attribute 36 salience (priority) strategy 35 rule basics about 15-17 rules, executing 17-21 rule concepts about 21 comments 23 rule variables 22 types 22 rule condition about 28 and conditional element 28 eval element 30 exists element 29 free form expressions 32 inline eval element 30, 31 not element 29 null-safe dereferencing operator 32 or element 28, 29 return element 30 this 32 rule consequence about 34 KnowledgeSession 34 ruleflow-group attribute about 107, 108 end event 108 gateway, converging 110 gateway, diverging 109 rule task 109 script task 108 start event 108 rule integration testing 240 Rule Interchange Format See  RIF Rule Markup Language See  RuleML RuleML 270 rules about 111 static analysis 248 unit test, writing 239, 240 rule syntax about 21 concepts 21 package 23 rule attributes 35 rule conditions 28 rule consequence 34 S salience attribute 106 salience strategy 35 sample application architecture 200 business logic 201 configuration 202 dependencies 305-308 design 202 loan approval 220 repositories 210 technologies used 200 users 199 validation 212 sequenceOfIncreasingWithdrawals rule 162 serialization about 130 full serialization 134, 136 Knowledge session, recreating 130, 131 session serialization 132, 133 testing 131, 132 [ 314 ] www.it-ebooks.info setGlobal method 58 setupClass method 47 Smooks 81 Spring framework integration 269, 270 standards 270 StatefulKnowledgeSession 115 stateful session using, for validation 116, 117 static analysis, rules steps 248, 249 SuspiciousAccount 140 SuspiciousTransaction 140 T technologies Additional Drools projects 201 JSP 201 using 201 TerminalNode about 278 fact, inserting 278 testing about 45-48, 239 batch, executing 48, 49 minimal account balance rule 49, 50 student account rule 50-52 unique account number rule 52, 53 this keyword 32 TrackingProcessEventListener method 173 traditional approache problem advantages 9, 10 disadvantages 11 rule engine, avoiding 11, 12 solution 8, traditional approaches issues 7, TransactionCompletedEvent 140 TransactionCreatedEvent 139 Transfer Funds node 190 Transfer Funds work item about 184, 185 definition 186 handler, implementing 187, 188 handler, registering 189 registration 187 testing 190 transformation functions 92 transformation rules address normalization 67, 68 country error message, creating 70 currency conversion 71, 72 findAddress rule, testing 68 results 74-77 single account permission 73 testing 64, 66 writing 63 troubleshooting techniques about 250 debugging 252-254 event listeners 250, 251 generated classes source 255 rule conditions, debugging 254, 255 twoLargeWithdrawals rule about 149, 150 testing 151-153 type declarations 25 types 22 U unit test, rules writing 239, 240 users about 199 properties 199 V validation about 212 design overview 117 implementing, stateful session used 116, 117 integration testing 122 logical assertions 125, 126 presentation layer 215, 216 services 213, 214 stateful Validation Service 117-122 transactions 214, 215 validation package about 42, 43 object required type rules 44, 45 testing 45, 46 [ 315 ] 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

Ngày đăng: 19/04/2019, 11:11