Using JBoss Rules in cases where users need to add / remove rules
by Robert Burdick
Hello All:
I am trying to figure out if JBoss Rules will be suitable for my
application
needs. Maybe you can give some insight.
My application needs to implement / use a rules engine for evaluating
conditions and firing off events when those conditions are met. So far
this
sounds exactly like the sort of thing that JBoss Rules is for. The
twist is
that my application will also provide an administrative utility that
allows
admins to add or remove rules, as well as modify the conditions that
trigger
these rules. Can JBoss Rules be used to do this? All of the examples
I've
seen so far seem to incorporate rules whose consequences are fixes, but
with
changeable conditions. For example, there are lots of samples out there
like an insurance application. Such an example has consequences such as
offerQuote, turnDownCustomer etc. that don't change, but with conditions
that do change. For example, today offer quotes to all good drivers,
tomorrow change the rule to offer quotes to all good drivers over the
age of
18. The conditions change, but the basic actions in the system are
common.
What I think my requirement implies is a way to define rules with
conditions
and the corresponding consequences code at runtime. This seems to imply
that the application code needs to be dynamic, in order to allow users
to
define arbitrary consequence code. Has anyone ever tried to do
something
this generic with JBoss Rules, and better, can you fill me in on how to
go
about this?
Thanks, Robert
16 years, 11 months
Agenda filter based on package name
by Hooman Mozaffari
It seems "Rule" class doesn't store its parent "Package" information and Rule.getPackage() always returns null.
I would like to create an AgendaFilter based on package name but there is no way to get the parent package of each rule.
Thanks,
Hooman
public class PackageNameAgendaFilter implements AgendaFilter {
private final String packageSuffix;
private final boolean accept;
public PackageNameAgendaFilter(String packageSuffix){
this(packageSuffix, true);
}
public PackageNameAgendaFilter(String packageSuffix, boolean accept){
this.packageSuffix = packageSuffix;
this.accept = accept;
}
public boolean accept(Activation activation) {
if(activation.getRule().getPackage().startsWith(packageSuffix))
return accept;
else
return false;
}
}
_________________________________________________________________
Discover the new Windows Vista
http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE
17 years
Drools 4.0 StateExampleWithDynamicRules Question
by Daren Chylinski
Hello,
I am a new Drools user working my way through the examples. To test my
understanding of how the rules work, I modified the
StateExampleUsingSalience.drl file used in the
StateExampleWithDynamicRules example. The result of my change
conflicted with my understanding of how the rules should work.
I made two modifications in the StateExampleUsingSalience.drl file. The
two modifications (shown below) are the commenting out of the two lines
in the RHS portion of the "B to D" rule. My understanding of how this
would affect the result was: because the "D" State object never changes
state to "State.FINISHED" the RHS portion of the "D to E" rule (shown
below) would not execute because the first pattern in the LHS would fail
to find a State object in working memory that met the criteria of the
constraint groups defined within it.
My question is: Why does the "D to E" rule in the
StateExampleDynamicRules.drl execute the statements in the RHS portion
of the rule?
>From StateExampleUsingSalience.drl: My changes in this file are the two
lines commented out in the RHS portion.
rule "B to D"
when
State(name == "B", state == State.FINISHED )
d : State(name == "D", state == State.NOTRUN )
then
//System.out.println(d.getName() + " finished" );
//d.setState( State.FINISHED );
end
>From StateExampleDynamicRules.drl: This is the rule where I expected
the RHS portion to NOT get executed because there aren't any State
objects in working memory that have their name == "D" and its state ==
State.FINISHED because the setState( State.FINISHED ) was never executed
on the "D" state object.
rule "D to E"
when
State(name == "D", state == State.FINISHED )
e : State(name == "E", state == State.NOTRUN )
then
System.out.println(e.getName() + " finished" );
e.setState( State.FINISHED );
end
After my modifications, the output was:
A finished
B finished
C finished
E finished
I did not expect the "E finished" message to be printed.
Regards,
Daren
17 years, 1 month
LHS functions not in eval()...
by wasabifan
I am trying to write a function that takes a numeric value and returns a
string. Basically, I have a numeric number I need to match to a string
number (so I need to convert one to the other type). I wrote a function to
do this, but it only seems to work in the RHS or inside an eval().
Is there a way to convert numerics to strings (or vice-versa) in the LHS not
in an eval? Or is a big function inside the eval() the only way to do this?
Thanks,
Bryan
--
View this message in context: http://www.nabble.com/LHS-functions-not-in-eval%28%29...-tf4362273.html#a...
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 2 months
DSL field constraint question
by Andy Mei
Hi,
I am new to Drools and working with 4.0.1 version.
I am playing with DSL and having trouble with conditional field
constraints.
I really appreciate any help, i like drools a lot and would love to use
it.
Here is the simple rule i have:
rule "Credit Approved"
salience 5
when
//notice here we are using our own domain specific language that's
defined within
#credit.dsl file
There is a person with
#-must has a name
-age is at least 18 years old
then
> System.out.println( "[ALLOW] Credit approved for " + person.getName
());
end
Here is my dsl definition:
[when]There is a person with=person:Person()
[when]-age is at least {age} years old=(age >= {age})
[when]-age is less than {age} years old=(age < {age})
[when]-must has a name=(name != "" && name != null)
[when]-id must be positive integer=id > 0
Everything works fine if i use only 'age is least 18 years old' or 'must has
a name'.
However, if i try to do a connective and between these two constraints, i am
getting
package build errors:
Package build error found:
[13,43]: unknown:13:43 mismatched token: [@59,331:331=',',<11>,13:43];
expecting type RIGHT_PAREN[13,59]: unknown:13:59 mismatched token:
[@71,347:347=')',<12>,13:59]; expecting type THEN
Exception in thread "main" org.drools.rule.InvalidRulePackage: [13,43]:
unknown:13:43 mismatched token: [@59,331:331=',',<11>,13:43]; expecting type
RIGHT_PAREN[13,59]: unknown:13:59 mismatched token:
[@71,347:347=')',<12>,13:59]; expecting type THEN
at org.drools.rule.Package.checkValidity(Package.java:419)
at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java
:292)
at com.trg.play.rules.PersonTest.readRule(PersonTest.java:103)
at com.trg.play.rules.PersonTest.main(PersonTest.java:51)
I have attached my test program for your review.
17 years, 2 months
single result
by Tim.Nguyen@expeditors.com
Is there anyway to only display 1 error message in the RHS instead of
displaying bunch of duplicate error message when I have multiple data
matching the condition in the LHS.
Or, if the first time the data matches the condition in the LHS, then do
the RHS then stop
Is there anyway to do either 1 of those above? Thank you!
Tim
17 years, 3 months
check dups
by Tim.Nguyen@expeditors.com
Hi List,
I'd like to check if any duplicate exists in my collection as below:
rule "check Duplicate"
when
ref1: Reference ($type1: referenceType, $value1:
referenceValue)
ref2: Reference (this != ref1, referenceType == $referenceType,
referenceValue == $value1)
then
errorHandler.record("Duplicate Reference is not allowed.");
end
Both my referenceType and referenceValue are String. I didn't get any error
but it didn't work. Any idea?
I am using 4.01 GA
Thanks,
Tim
17 years, 3 months
mvel bug ??
by hypnosat7
Hi,
I have a variable declaration as bellow :
>list:Variable() from ruleApp.getVariable("variableName")
and this is the result :
Exception in thread "AWT-EventQueue-0" org.mvel.CompileException: cannot
invoke method
at
org.mvel.optimizers.impl.refl.MethodAccessor.getValue(MethodAccessor.java:54)
at
org.mvel.optimizers.impl.refl.VariableAccessor.getValue(VariableAccessor.java:39)
at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:26)
at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:19)
at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
at org.mvel.CompiledExpression.getValue(CompiledExpression.java:99)
at org.mvel.MVEL.executeExpression(MVEL.java:236)
at
org.drools.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:45)
at org.drools.reteoo.FromNode.assertTuple(FromNode.java:61)
at
org.drools.reteoo.CompositeTupleSinkAdapter.createAndPropagateAssertTuple(CompositeTupleSinkAdapter.java:73)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:131)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:160)
at org.drools.reteoo.Rete.assertObject(Rete.java:176)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:196)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:164)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1260)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:864)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:826)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:627)
at
mcmipih.rules.rules.integration.drools.ExecutionContext.executeRuleFlow(ExecutionContext.java:54)
at
mcmipih.rules.demo.service.DemoRuleService.validerRumList(DemoRuleService.java:50)
at
mcmipih.rules.demo.service.DemoRuleService$$FastClassByCGLIB$$beeddc5a.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:693)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
at
mcmipih.rules.demo.service.DemoRuleService$$EnhancerByCGLIB$$961244c9.validerRumList(<generated>)
at
mcmipih.rules.demo.controller.ValidationAppController$ActionValiderSelectionLst.actionPerformed(ValidationAppController.java:185)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.mvel.optimizers.impl.refl.MethodAccessor.getValue(MethodAccessor.java:46)
... 54 more
--
View this message in context: http://www.nabble.com/mvel-bug----tf4360199.html#a12426549
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 3 months
in 4.0.1 "this" required in nested accessors?
by Manukyan, Sergey
Folks,
I Started using 4.0.1,
Regarding nested accessors, looks like they work, but they require to
put "this" at the beginning.
So rule
when
TestSupplier(testBusiness.statusActive == true) --> FAILS
When
TestSupplier(this.testBusiness.statusActive == true) --> OK!
It fails with the following exception:
org.drools.rule.InvalidRulePackage: Unable to determine the used
declarations : [Rule name=HQ To Active From Probation. Mfg On Probation
Exists., agendaGroup=MAIN, salience=10, no-loop=false]
at org.drools.rule.Package.checkValidity(Package.java:419)
Please confirm this to be a bug and then I will open JIRA for this, or
please let me know the reason behind this functionality,
Thanks,
-Sergey
**********************
** LEGAL DISCLAIMER **
**********************
This E-mail message and any attachments may contain
legally privileged, confidential or proprietary
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of
this message to the intended recipient(s), you are
hereby notified that any dissemination, distribution
or copying of this E-mail message is strictly
prohibited. If you have received this message in
error, please immediately notify the sender and
delete this E-mail message from your computer.
17 years, 3 months