background preloader

Templates

Facebook Twitter

Use Drools and JPA for continuous, real-time data profiling. Enterprise developers tasked with managing complex work-flows, business rules, and business intelligence are quick to realize the value of an enterprise platform that integrates a work-flow engine, enterprise service bus (ESB), and rule engine.

Use Drools and JPA for continuous, real-time data profiling

Until now, this sweet spot has been filled by commercial products like IBM WebSphere® Process Server/WebSphere Enterprise Service Bus (see Resources) and Oracle SOA Suite. Drools 5, from JBoss Community, is an open source alternative that seamlessly integrates a jBPM workflow engine and rule engine via a set of unified APIs and a shared, stateful knowledge session. The Drools 5 Business Logic Integration Platform consists primarily of Drools Expert and Drools Fusion, which together comprise the platform's rule engine and infrastructure for complex event processing/temporal reasoning. Drools Rules in a Database, Take 2. Quite some time back, I wrote an article describing how I used Drools with database backed rules.

Drools Rules in a Database, Take 2

Since Drools (version 2) did not support this at the time, I ended up writing some glue code that tied Commons Collections Predicates and Closures into Drools Rule Conditions and Consequences, then built my rules on top of that. It was for a proof of concept project which ultimately never materialized. Over the years, I've had requests for the code backing the article. Fast forward 6 years, and I find myself trying to do something similar for an upcoming project. Time sure flies when you are having fun. What I describe here is a small example I tried out to prove to myself that this will work before putting it into the main application.

Numberguess example using Drools5 Templates. Before I dig into the a Fusion example, I wanted to show current integration with Drools5 Templates.

Numberguess example using Drools5 Templates

Rule templates are helpful when you have a number of rules which follow some sort of pattern(s). In addition you can use templates when you have reoccurring hard-coded values in your rule patterns or actions. The Seam numberguess example is not the best example for rule templates however is good enough for a simple example. If we look at base numberguess.drl DRL, we can see some hard-coded values, for example the guessCount is set to 9, the guess increment value is 1 and we also see hard-coded values for win and loose, all of which we want to externalize from our rule resource. Drools Rule Templates. Drools 5 sees the addition of a new feature - rule templates.

Drools Rule Templates

Rule templates allow you to set up templates (!) That may then be merged with data. You can think of them as similar to decision tables but far more powerful. With Rule Templates the data is separated from the rule and there are no restrictions on which part of the rule is data-driven. So whilst you can do everything you could do in decision tables you can also do the following:store your data in a database (or any other format)conditionally generate rules based on the values in the datause data for any part of your rules (e.g. condition operator, class name, property name)run different templates over the same dataI find the best way to explain things is via example so over a few posts I will take you through three of the examples in the drools-examples project. Ruling with Drools Rule Engine. In a project several years ago I built a rule engine from scratch.

Ruling with Drools Rule Engine

In a recent project, which needed a rule engine, I decided to take different route. I decided to give Drools rule engine from JBOSS a try. It has worked out well so far. In this post, I will share my experience with it. I will use insurance as an example to demonstrate how to use it. Drools complex facts. Salmon Run: Drools Rules in a Database, Take 2. Drools Expert User Guide. The Conditional Element from enables users to specify an arbitrary source for data to be matched by LHS patterns.

Drools Expert User Guide

This allows the engine to reason over data not in the Working Memory. The data source could be a sub-field on a bound variable or the results of a method call. It is a powerful construction that allows out of the box integration with other application components and frameworks. One common example is the integration with data retrieved on-demand from databases using hibernate named queries.

The expression used to define the object source is any expression that follows regular MVEL syntax. Here is a simple example of reasoning and binding on another pattern sub-field: How to Load Resources from Classpath in Java with Example. Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties file, images, icons, thumbnails, or any binary content.

How to Load Resources from Classpath in Java with Example

Java provides API to read these resources as InputStream or URL. Suppose, you have a properties file inside config folder of your project, and you want to load that properties file, how do you do that? Similarly, you have icons and thumbnails for your web applications on icons directory of your project, how do you load them? Answer is by using java.lang.Class' getResource() and getResourceAsStream() method. These method accepts path of resource as String and returns URL and InputStream respectively. If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'. Chapter 6. Authoring. The next example demonstrates the joint effect of a cell defining the pattern type and the code snippet below it.

Chapter 6. Authoring

This spreadsheet section shows how the Person type declaration spans 2 columns, and thus both constraints will appear as Person(age == ..., type == ...). Since only the field names are present in the snippet, they imply an equality test. In the following example the marker symbol $param is used. The result of this column is the pattern Person(age == "42")). You may have noticed that the marker and the operator "==" are redundant. [DROOLS-329] ClassFormatException when compile template with latest JDK8 (b114) Drools Rule Templates. Drools complex facts. Salmon Run: Drools Rules in a Database, Take 2.