Issue with literals in Drools Verifier 5.1.1
by Nathan Bell
Using org.drools.verifier found in "drools-verifier-5.1.1.jar" I get an
org.drools.RuntimeDroolsException if a pattern in a rule LHS contains a
comparison to a literal value using the equals operator.
Please consider the following rule I created solely for the purposes of
isolating this issue.
package com.simple.test.rule
import com.p1s.mps.rulevalidator.TestFact;
rule "TestRule"
when
$fact : TestFact(value == 1)
then
System.out.println($fact.getValue());
end
The following class definition for the TestFact.
package com.p1s.mps.rulevalidator;
public class TestFact
{
private int value;
public TestFact(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + value;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TestFact other = (TestFact) obj;
if (value != other.value)
return false;
return true;
}
}
The following unit test which attempts to use Verifier.
@Test
public final void testVerifierOnLiteral()
{
VerifierBuilder verBuilder =
VerifierBuilderFactory.newVerifierBuilder();
Verifier ver = verBuilder.newVerifier();
String ruleText = getRuleFromResource(TEST_RULE);
ver.addResourcesToVerify( ResourceFactory.newReaderResource(
new StringReader( ruleText ) ), ResourceType.DRL );
Assert.assertTrue(ver.fireAnalysis());
}
Running the test with JUnit produces the following exception.
java.lang.RuntimeException: org.drools.RuntimeDroolsException: Exception
executing ReturnValue constraint
org.drools.rule.ReturnValueRestriction@589f81 : [Error: cannot convert
<1> to a numeric type: class java.lang.Integer [0]]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.drools.verifier.builder.VerifierImpl.analyse(VerifierImpl.java:148)
at
org.drools.verifier.builder.VerifierImpl.fireAnalysis(VerifierImpl.java:
117)
at
com.p1s.mps.rulevalidator.NumericConversionTest.testVerifierOnLiteral(Nu
mericConversionTest.java:64)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMet
hod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallab
le.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMetho
d.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod
.java:20)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.jav
a:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner
.java:73)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner
.java:46)
at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at
org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.jav
a:28)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
31)
at
org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Tes
tReference.java:46)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
va:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:197)
Caused by: org.drools.RuntimeDroolsException: Exception executing
ReturnValue constraint org.drools.rule.ReturnValueRestriction@589f81 :
[Error: cannot convert <1> to a numeric type: class java.lang.Integer
[0]]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.drools.rule.ReturnValueConstraint.isAllowedCachedRight(ReturnValueCo
nstraint.java:168)
at
org.drools.common.TripleBetaConstraints.isAllowedCachedRight(TripleBetaC
onstraints.java:211)
at
org.drools.reteoo.NotNode.assertObject(NotNode.java:140)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleOb
jectSinkAdapter.java:59)
at
org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:145)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(Com
positeObjectSinkAdapter.java:450)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(Compo
siteObjectSinkAdapter.java:378)
at
org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:190)
at
org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:145)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.jav
a:1174)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.jav
a:1123)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.jav
a:917)
at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSes
sionImpl.java:251)
at
org.drools.verifier.builder.VerifierImpl.analyse(VerifierImpl.java:136)
... 26 more
Caused by: org.drools.RuntimeDroolsException: [Error: cannot convert <1>
to a numeric type: class java.lang.Integer [0]]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.drools.rule.ReturnValueRestriction.isAllowed(ReturnValueRestriction.
java:236)
at
org.drools.rule.ReturnValueConstraint.isAllowedCachedRight(ReturnValueCo
nstraint.java:162)
... 39 more
Caused by: [Error: cannot convert <1> to a numeric type: class
java.lang.Integer [0]]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.math.MathProcessor.getInternalNumberFromType(MathProcessor.jav
a:577)
at
org.mvel2.math.MathProcessor._doOperations(MathProcessor.java:155)
at
org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:79)
at
org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation
.java:102)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:1
04)
at org.mvel2.MVEL.executeExpression(MVEL.java:978)
at
org.drools.base.mvel.MVELReturnValueExpression.evaluate(MVELReturnValueE
xpression.java:92)
at
org.drools.rule.ReturnValueRestriction.isAllowed(ReturnValueRestriction.
java:226)
... 40 more
However, if I use the following version of the same rule where I have
added parentheses it works.
package com.simple.test.rule
import com.p1s.mps.rulevalidator.TestFact;
rule "TestRule"
when
$fact : TestFact(value == (1))
then
System.out.println($fact.getValue());
end
Note that both versions of the DRL file compile, run, and produce the
correct results.
Thank You,
Nathan Bell
15 years, 7 months
KnowledgeAgent ChangeSet failing to reload resources
by Fink, Eric [USA]
Greetings. I am using Drools 5.1.1's KnowledgeAgent ChangeSet functionality and have come across an issue.
here is the use case:
Fire up the application with a valid DRL file. Works as designed.
Update the DRL file. ChangeSet senses updated file, KnowledgeBase is updated with updated rules, yadda, yadda. Works as designed.
Update the DRL file and introduce errors in the LHS of the rule. For example, I changed Sensor to Sccensor in the example below and $masterId is not defined. The following is reported as expected:
KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
[2010:11:308 09:11:515:info] KnowledgeAgent performing an incremental build of the ChangeSet
[2010:11:308 09:11:843:debug] KnowledgeAgent has KnowledgeBuilder errors object=Unable to resolve ObjectType 'Sccensor' : [Rule name='18) sensorCount derived variable']
Rule Compilation error : [Rule name='18) sensorCount derived variable']
bass/enrichment/Rule_18__sensorCount_derived_variable_0.java (7:590) : $masterID cannot be resolved
bass/enrichment/Rule_18__sensorCount_derived_variable_0.java (8:624) : $masterID cannot be resolved
bass/enrichment/Rule_18__sensorCount_derived_variable_0.java (9:769) : $masterID cannot be resolved
Update the DRL file to the previously working version. The ChangeSet never senses that the file has been updated. It just runs along checking every x seconds.
Has anyone experienced this? Is there a listener that should be firing somewhere?
Thanks is advance.
- Eric
15 years, 7 months
[flow][bpmn2] Variable not available in workitem?
by David Wynter
Hi,
My first bpmn2 workflow. With this the important part of the bpmn2 xml
definition, transformationTest.bpmn2.
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.jboss.org/drools"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL
BPMN20.xsd"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
xmlns:tns="http://www.jboss.org/drools">
<itemDefinition id="_ETLGroupItem"
structureRef="com.example.model.impl.ETLGroupImpl" />
<process processType="Private" isExecutable="true" id="Test" name="Test
Process" >
<!-- process variables -->
<property id="ETLGroup" itemSubjectRef="_ETLGroupItem"/>
<!-- nodes -->
<startEvent id="_1" name="StartProcess" />
<task id="_2" name="ETLGroup" tns:taskName="ETLGroup" >
<ioSpecification>
<inputSet>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
</task>
<endEvent id="_3" name="End" >
<terminateEventDefinition/>
</endEvent>
<!-- connections -->
<sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2" />
<sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3" />
</process>
I have this test case
@Before
public void setUp() throws Exception {
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
kb.add(ResourceFactory.newClassPathResource("transformationTest.bpmn2"),
ResourceType.BPMN2);
if (kb.hasErrors()) {
throw new RuntimeException(kb.getErrors().toString());
}
KnowledgeBaseConfiguration configuration =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
configuration.setProperty("drools.workDefinitions", "WorkDefinitions.conf
etlgroup.conf");
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(configuration);
knowledgeBase.addKnowledgePackages(kb.getKnowledgePackages());
session = knowledgeBase.newStatefulKnowledgeSession();
TrackingProcessEventListener trackingprocel = new
TrackingProcessEventListener();
session.addEventListener(trackingprocel);
session.getWorkItemManager().registerWorkItemHandler("ETLGroup", new
ETLGroupWorkItemHandler());
WorkflowLoader wrkflwLdr = new WorkflowLoader();
etlGroup = wrkflwLdr.loadETLGroup("etlGroup",
"/home/david/workspace/EDMEngine/META-INF/content.xml");
}
@Test
public void testSessionRun() {
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("ETLGroup", etlGroup);
session.insert(etlGroup);
ProcessInstance processInstance = session.startProcess("Test", parameterMap);
session.insert(processInstance);
session.fireAllRules();
}
I have this work item handler
public class ETLGroupWorkItemHandler implements WorkItemHandler {
private ETLGroupService service = null;
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
ETLGroup etlGrp = (ETLGroup) workItem.getParameter("ETLGroup");
...
etlGroup in the @Before section is not null but etlGrp is always null? I must
have missed something, but cannot see what it is. Can someone point it out to
me?
Thx.
David
15 years, 7 months
Support for Drools Guvnor / Expert in Latin America
by Miguel Fernando Cabrera
Hello to all,
In my company (an insurance company in Colombia) and we are evaluating
various BRMS.
We have been testing iLog JRules and now we are evaluating Drools
Expert/Guvnor (or JBoss BRMS).
As I am an open source guy, I want to use Drools. As we use a lot of
open source libraries right now (like CXF) is easy for me to use the BRE as
a library.
However, when planning to use a full BRMS like Guvnor, we will need someone
to install and support it.
The obvious choice would be Red Hat / JBoss, However we have tried to
contact sales department but it has been impossible to get an aswer from
them.
So, my question is, Does Anyone know a company (could be the states or south
america) willing to provide the installation and support services for the
BRMS and the maybe the BRE ?
I really appreciate any help on the matter.
--
Miguel Fernando Cabrera Granados
"A los hombres fuertes les pasa lo que a los barriletes; se elevan cuando es
mayor el viento que se opone a su ascenso." - José Ingenieros
15 years, 7 months
Using an array column header in Drools Template
by sk
I am given a list of strings (Comma separated) as input and I need to check
if any of the strings satisfy a given condition. I am trying to implement it
using Drools Rule template with an array column header of unknown size.
To be more specific I need to be be able to generalize the below Template to
include any number of names in the eval statement.
The idea is to give any number of names as input and check if any of the
names satisy the condition given in the template.
template header
name[]
package gms.drools.templates;
global java.util.Map nameMap;
import java.util.Map;
template "RuleTemplate_name"
rule "rule_name"
when
//Generalize the below line to check if the nameMap contains any of the
names given in the input //eval(nameMap.containsKey("@{name1}") ||
nameMap.containsKey("@{name2}") || nameMap.containsKey("@{name3}") ||
nameMap.containsKey("@{name4}"))
then
System.out.println("SUCCESS");
end
end template
Please let me know if anyone has a solution for this or any other
suggestions.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Using-an-array-column...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 7 months
Unable to locate a login configuration
by Klaus Teller
Hi,
Please I need your help on this one. I keep getting the following exception on Tomcat (both 6 and 7) when running Guvnor. I can deploy it without problem, but when I hit the URL (http://localhost:8080/drools-guvnor/) the error message is printed on the Tomcat console and a 500 error message (
500 The call failed on the server; see server log for details) is displayed in the browser.
What am I missing in the installation process?
Thanks,
Klaus.
ERROR 10-11 05:02:53,771 (LoggingHelper.java:error:76) Service method 'public
abstract org.drools.guvnor.client.rpc.UserSecurityContext org.drools.guvnor.clie
nt.rpc.SecurityService.getCurrentUser()' threw an unexpected exception: java.lan
g.SecurityException: Unable to locate a login configuration
java.lang.SecurityException: Unable to locate a login configuration
at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:93)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
--
GRATIS! Movie-FLAT mit über 300 Videos.
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome
15 years, 7 months
Re: [rules-users] rules-users Digest, Vol 48, Issue 36
by Dennis Duggan
Thankyou! This was extremely helpful and solved the issue. The manual has very limited information on this. I needed to go through the examples to find it. Also limited information on queries.
Thanks again for your help!
Dennis
15 years, 7 months
Re: [rules-users] Query query...
by Dennis Duggan
I have a super interface, that both objects implement.
The matching rule looks like:
rule "Match"
when
$oRecord1 : MyObject1( )
$oRecord2 : MyObject2(RefID==$oRecord1. RefID )
then
$oRecord1.setStatus( "Matched" );
$oRecord2.setStatus( "Matched" );
end
I can breakpoint right after running the query and I see objects with all statuses so the matching rule is firing correctly.
Thanks!
Dennis
Dennis Duggan
Principal Software Engineer, Software Engineering
ESP Technologies Corp. "THE Buy-Side Solution"
One Indian Head Plaza Suite 701, Nashua, NH 03060
603.324.2444 ext. 1304 Office | 603.324.2447 Fax
dennis(a)esptechnologies.com
ESP Technologies, winner 2009 Red Herring North America 100 and 2008 Deloitte Technology Fast 500.
This e-mail and/or attachments may contain privileged, confidential or proprietary information. Unintended recipients should notify the sender immediately and delete. Disclosure, copying, distribution or use of this e-mail or any attachment is prohibited. Brokerage services provided by Electronic Securities Processing (ESP) LLC. Member FINRA, SIPC. This is neither an offer or recommendation to buy or sell any security or other financial instrument. Email compliance(a)esptechnologies.com with questions regarding this disclosure.
From: Dennis Duggan
Sent: Tuesday, November 09, 2010 1:55 PM
To: 'rules-users(a)lists.jboss.org'
Subject: Query query...
I have 2 types of objects in my knowledge base that I am trying to equate. Equality is based on a number of different variables contained in the objects. Once I find equal objects I set a status member in each to "Matched", otherwise it will be "OneKnows" or "TwoKnows".
After I fire the rules I use queries that I call from Java code to get the three different types of objects.
query "OneFirmKnows"
oRecord : MyObject1( status=="OneKnows" )
end
query "TwoKnows"
oRecord : MyObject2( status=="TwoKnows" )
end
query "Matched"
oRecord : MyObject1( status=="Matched" )
end
Each query sends back all objects no matter what the status is. The objects have a getStatus( ) method. What am I doing wrong?
Thanks!
Dennis
15 years, 7 months
Query query...
by Dennis Duggan
I have 2 types of objects in my knowledge base that I am trying to equate. Equality is based on a number of different variables contained in the objects. Once I find equal objects I set a status member in each to "Matched", otherwise it will be "OneKnows" or "TwoKnows".
After I fire the rules I use queries that I call from Java code to get the three different types of objects.
query "OneFirmKnows"
oRecord : MyObject1( status=="OneKnows" )
end
query "TwoKnows"
oRecord : MyObject2( status=="TwoKnows" )
end
query "Matched"
oRecord : MyObject1( status=="Matched" )
end
Each query sends back all objects no matter what the status is. The objects have a getStatus( ) method. What am I doing wrong?
Thanks!
Dennis
15 years, 7 months