Use of bitwise operators in LHS expression
by CK
Hi,
I am running into some expression evaluation issues, mostly revolving
around MVEL scripting in the RHS and some expression evals on the left
hand side.
Specifically, here are some of my questions
1) Does Drools support bitwise operators inside the rules? I've tried
all different kinds of combinations, but it doesn't seem to like it.
This is happening on the LHS. I believe I tried it on the RHS and it
still causes compile exceptions. My understanding is that MVEL 2.0
supports Bitwise ops.
2) Object casting. Strangely, on the RHS, I have a Float that doesn't
want to cast to float. Doesn't Drools (or perhaps MVEL) do auto-
unboxing?
3) Function calling. I read somewhere that MVEL cannot call out to a
declared function in the rule. So that means, the rule will have to
be in Java mode. Also, the function can only be written in java
style, not mvel. Am I correct on this one?
Thank you,
CK
16 years, 10 months
Problem with updated facts
by thomas moncieu
Hi,
I have a problem when updating fields in rules :
Here's the rule :
when
t : Bill($amount : totalAmount, totalAmount > (new
Double(150.0).doubleValue()));
then
System.out.println("tot : " + $tot);
end
The original totalAmount is 200.
A fact update sets the totalAmount at 100 (with an update of the facthandle
that I can see in the debugger of the working memory) so the condition of
the rule does not be true.
Nevertheless, the System.out is made and prints 100.
I use Statefull session and set shadow facts to true.
Thanks for helping me !
16 years, 10 months
Drools 5.0.0 CR1 : multibyte characters in dsl fails with "no viable alternative at character"
by Yusuke Yamamoto
Hi,
I found that Drools 5.0.0 CR1 is unable to compile DSLs including
multibyte characters in them.
For example, mydsl.dsl as following:
---------
[consequence]print:"{value}" = System.out.println("{value}");
[consequence]出力:"{value}" = System.out.println("{value}");
---------
Fails to be compiled with
---------
line 3:13 no viable alternative at character '出'
line 3:14 no viable alternative at character '力'
---------
"出力" means "print" in Japanese.
It used to be work with Drools 4.0.7.
I couldn't found any related issues on Jira. But is it a known issue?
Best regards,
Yusuke
16 years, 10 months
application for creating rules
by Stjepan Cvitanović
Greetings
After many months of inactivity we have finally released a final version of
MSM Drools Rule Editor.
This version differs from the previous versions in many aspects, most
notable of which are:
- workspace integration
- full separation of data model and logic model
The old features have remained:
- Full graphical rule representation
- Parser for drools and HQL/SQL
- Fast rule testing using HQL/SQL
- Replay of rule fireing (for drools only)
- replay save/load capabilities
New features added:
- plugin support
- docking visual interface (multiple views)
- workspaces
- rules history with SVN
- import from CSV for rule testing
and more...
Java 1.5 required, java 1.6 recommended
Download it from http://www.sourceforge.net/projects/droolsruleedit and tell
us what you think of it
Any feedback is welcome.
MSM Team
16 years, 10 months
Internal type used together with function throws ClassCastException
by Michal Bali
Hi,
Internal type together with a function in one drl file cause
ClassCastException when setting properties of a new instance of this type.
java.lang.ClassCastException: org.drools.generatedbeans.Cheese cannot be
cast to org.drools.generatedbeans.Cheese
at
org.drools.base.org.drools.generatedbeans.Cheese6778431$setType.setValue(Unknown
Source)
at org.drools.base.ClassFieldWriter.setValue(ClassFieldWriter.java:195)
at
org.drools.base.ClassFieldAccessor.setValue(ClassFieldAccessor.java:319)
at org.drools.factmodel.ClassDefinition.set(ClassDefinition.java:207)
at
org.drools.integrationtests.MiscTest.testGeneratedBeansWithFunction(MiscTest.java:1072)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Test case to reproduce:
test_GeneratedBeansWithFunction.drl:
-------------------------------
package org.drools.generatedbeans;
function void someFunction(String arg) {
System.out.println("hello");
}
declare Cheese
type: String
end
-------------------------------
test method:
public void testGeneratedBeansWithFunction() throws Exception {
final KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newInputStreamResource(
getClass().getResourceAsStream( "test_GeneratedBeansWithFunction.drl" ) ),
ResourceType.DRL );
assertFalse( kbuilder.getErrors().toString(),
kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
// Retrieve the generated fact type
FactType cheeseFact = kbase.getFactType(
"org.drools.generatedbeans",
"Cheese" );
// Create a new Fact instance
Object cheese = cheeseFact.newInstance();
cheeseFact.set( cheese,
"type",
"stilton" );
}
The last line throws the ClassCastException. If we remove the function from
the drl file all works fine.
Best Regards,
Michal
16 years, 10 months
single binding for or CE flagged by compiler
by Wolfgang Laun
As far as I know, this should work:
package orel;
import orel.Main.Trigger;
rule ror1
when
$t : (or Trigger(fa == 1)
Trigger(fa == 2))
then
System.out.println( "fired " + $t.getName() );
end
This is what Drools-5.0.0 kbuilder.getErrors().toString() returns:
[5,11]: [ERR 102] Line 5:11 mismatched input 'Trigger' expecting '(' in rule
ror1 in pattern or[6,14]: [ERR 102] Line 6:14 mismatched input 'Trigger'
expecting ')' in rule ror1[6,30]: [ERR 102] Line 6:30 mismatched input ')'
expecting 'then' in rule ror1
Shouldn't toString() insert line ends? As it is, the result is pretty much
useless.
This works:
rule ror1
when
(or $t : Trigger(fa == 1)
$t : Trigger(fa == 2))
then
System.out.println( "fired " + $t.getName() );
end
-W
16 years, 10 months
Missing libs for persistence in 5.0.0CR1
by Petersen, Jan (CH Ext)
Hi
I have been trying to get persistence to work in 5.0.0CR1, but I have
noticed that many of libs decribed in the documentation (chapter 5.1.3)
are missing ....
As they were present in M5 I'm just wondering why this is the case?
Best regards
Jan Petersen
16 years, 10 months
using BigDecimal in rules
by Marina
Hi,
I'm getting unexpected results when when using BigDecimal objects for matching in rules.
I'm generating DRL in my code, using freemaker.
I have a RuleEngineNumericFact object which has two attributes:
String propertyName
BigDecimal propertyValue
Below is an example of a rule where I try to match a RuleEngineNumericFact object based on the two attributes:
rule "aaa"
agenda-group "r1"
dialect "java"
when
(RuleEngineNumericFact( propertyName == "somename" , propertyValue == 10.8 ))
then
String ruleId = drools.getRule().getName();
firedRuleIDs.add(ruleId);
end
Then I create a new RuleEngineNumericFact object and set its propertyValue as following:
String stringValue = "10.8";
BigDecimal propertyValue = new BigDecimal(stringValue, new MathContext(10));
(I also tried to use default precision settings by creating the BigDecimal value as:
BigDecimal propertyValue = new BigDecimal(stringValue);
)
When I insert this fact into the rule engine - the rule does not get fired, so the fact does not match.
One note: if the values are integeres (like, propertyValue == 100) - the rule gets fired. So, it is only the floating point numbers that do not match.
I generate the DRL in my Java code, using freemaker, and I specify the
value that will be used in the rule for matching by calling toString()
method on a BigDecimal object that I get from my business code. The toString() representation ends up to be the "10.8" value (for example).
According to the BigDecimal documentation, marshalling from/to the same string representation shoudl still produce BigDecimal objects that will return TRUE from the equals() method when compared.
any ideas why this is not working here?
How does Drools compare values of objects like BigDecimal?
thanks,
Marina
16 years, 10 months