cancel
Showing results for 
Search instead for 
Did you mean: 

BusinessRuleTask - deploy error

rdenner
Champ in-the-making
Champ in-the-making
Hi,

I want to use the new BusinessRuleTask element for a test.
I defined a rule (drl) file, which I include in the Business Archive (bar).
I modeled a simple process and two forms. The BusinessRuleTask
executes 2 rules, gets 2 input variables and delivers 1 result variable.

Here is an example of one of my rules:


rule "salarycheck"

when
    (salary > 3000) && (age < 30)
then
    ruleOutput = "pattern1";
end

I wanted to deploy the bar file, but I get the error:
java.lang.NoClassDefFoundError: org/drools/runtime/rule/AgendaFilter

Do I need the Drools package for working with the BusinessRuleTask?
Does anyone have a simple example?

Thanks & Regards,
Rainer.
33 REPLIES 33

mikedias
Champ in-the-making
Champ in-the-making
Hi Tom and Tijs,

I changed again the BusinessRuleTaskActivityBehavior.java. Now I insert in the Working Memory the ActivityExecution object that, if I understand correctly, already is a impl of lazy loading of the variables:

FactHandle executionFact = ksession.insert(execution);
So, the following rule works fine:

import org.activiti.engine.impl.pvm.delegate.ActivityExecution;

rule "Rulez"
when
  ActivityExecution(getVariable("inputVar") == "myInput")
then
  System.out.println("Rulez executed");
  insert("RulezExecuted");
end
And after execution, I remove the execution from the Working Memory to clean the output:

ksession.retract(executionFact);
What do you think?

Cheers,

bernd_ruecker
Champ in-the-making
Champ in-the-making
Hi Mike.

Actually from a design point of view I have three remarks:

- Inserting the whole execution in such a way does result in poorly expressed rules. You should inserted facts, then you can write better readable rules (which I personally find hard with DRL anyway ;-))
- Inserting the execution will result in poor performance, as you cannot really leverage the RETE algorithm of the rule engine
- Retracting facts is not recommended, the better practice is to throw away the session and create a new one, which is faster

Maybe point 2 & 3 can be ignored for smaller systems, but I consider the first one important, you SHOULD NOT tie your rules to the process engine at all….

Just my two cents 😉

Cheers
Bernd

P.S: Sorry, was Drools Trainer for too long to keep quite 😉

mikedias
Champ in-the-making
Champ in-the-making
Hi Bernd, thanks for the answer!

Sorry for not include your name in the last comment. I thought that "we do not have to reach some sort of agreement" meant "I don't care with this". Smiley Very Happy

Keep in mind that my objective is write a rule without Java code.

-When you say "Fact", you mean a Java Bean filled with some process variables, right? And a mapping is required to fill this bean somewhere, right? If the execution is inserted in Working Memory, this mapping isn't required, allowing write more flexible rules. Remember that write rules with execution is optional and you can keep doing it your way.
-If I understand correctly, the execution is a lazy loading impl, so performance isn't a problem.
-I retract the execution because all Working Memory going to output currently. Have another way to recover produced values from a rule?

Cheers

mrhu
Champ in-the-making
Champ in-the-making
Hi,

I've noticed a couple of things that you should think about when using the business rule task:

1. The drools-api, drools-compiler, drools-core and mvel2 jar files are missing from the activiti-rest application, so you have to add those manually.

Is it possible that with drools 5.3.0 the drools-api.jar is renamed to knowledge-api-5.3.0.Final-sources.jar? Or, are these two jars not the same?

2. In the activiti-cfg.xml inside the activiti-cfg.jar in the activiti-rest application you have to include the following property:

<property name="customPostDeployers">
      <list>
        <bean class="org.activiti.engine.impl.rules.RulesDeployer" />
      </list>
</property>

This is missing in the userguide, but needs to be in the activiti-cfg.xml file to get the rules deployed.

3. Make sure you create a valid drl file. It's important to use Javabeans as input variables and output variables.
So maybe you could create a Javabean with salary and age as attributes. The same for the result variable.
4. I saw the bpmn20.xml in your BAR file is inside the diagrams folder. It's better to have it at the root of the BAR file.

With these changes it should work. Let me know if it works for you.

Best regards,