4

I have a system where 'dynamic logic' is implemented as Drools Rules, using Rules engine.

For each client implementation, custom pricing and tax calculation logic is implementted using the drl files for that specific implementation.

rule 'abc'
when
    name = 'X'
then
    price= '12'
end

And one rule's condition is dependent on what's set in the previous rules, so there is basically rules transition.

This is really painful as the drools rules are not sequential programming and is not developer friendly. There get introduced lots of bugs due to mis-interpretation of how drools evaluates.

Are there a better 'java/groovy' alternative that could easily replace it?

openSource
  • 191
  • 2
  • 6

1 Answers1

2

I think the answer is going to depend on what you ultimately want the end solution to be. If you are wanting to pull your business rules out of a rules engine and put them into java/groovy, that is very different from wanting to pull them out of one rules engine and into another.

Your questions seems to lean towards the prior, so I'll address that. Be very careful with this approach. The previous individuals who implemented this appear to have done this the proper way with respect to using the Rete algorithm, as it sounds like the firing of one rule can execute other rules, this is good business rules - they aren't sequential they are declarative. Remember that imperative software is written for engineers mostly, it doesn't map back to the real world 100% of the time :) If you put want to move this into java/groovy you are moving into an imperative language, which could put you into an if/then/else hell. I would suggest the following:
  1. Isolate this code away from the rest of your codebase - you will be doing a lot of maintenance on this code in the future when the business changes their rules. Good interface design and encapsulation here will payoff big time down the road.
  2. Develop some type of DSL with your business customer so when they say something like "Credit Policy", you know exactly what they are referring to and can change the related rules appropriately.
  3. Unit Test, Unit Test, Unit Test. This applies to your current configuration too. If you are finding bugs now, why aren't your tests? It doesn't take long to setup junit to create an object and invoke your Drools engine and test the response. If you add some loops to test ranges of variables that expect the same response you can be in the hundreds of thousands of tests in no time.

As an aside: If you don't want to go down this route, then I highly suggest getting some training on Drools so that you understand the engine and Rete if you don't already. There are some big wins you can make with your customers if you are able to quickly translate their rules into implementable software.

JasonH
  • 317
  • 1
  • 2
  • 7