Is rule introspection available from the Drools API?
by milen igrachev
Hello, is there a way to introspect a Drools file from within java code? What I need is to be able to identify the facts and the fact attributes that are used in a given DRL file.
For example if I have a rule stored in a customer.drl DRL file within my project, containing the following definition:
package myRulePackage
import org.rules.model.Customer import org.rules.model.Mambership
rule "is eligible customer" when $c:Customer(status == "active") Membership(customer == $c, type == "premium") then $c.setEligibilityStatus(true); end
What i need is a way to understand that this ruleset customer.drl is using two fact types - Customer and Membership and three of their attributes - Customer.status, Membership.customer and Membership.type.
I found some information on the internet that such functionality is not supported, however the information was a bit too old, so I decided to ask again.
Big thanks for the support!
Milen
12 years, 2 months
how can I resolve java.lang.RuntimeException: Unknown accessor type
by brachi
I'm using drools 5.5.0.Final.
I noticed that I got the bellow exception in my logs, but my process is
finished. I mean that this exception wasn't break the process, only logged
out.
what is the meaning of this exception and how can I resolve it.
I tried to upgrade mvel2 to the latest final version (2.1.8.Final) but it
wasn't solve the exception.
java.lang.RuntimeException: Unknown accessor type:
org.mvel2.optimizers.impl.refl.collection.ArrayCreator@5b8452eb
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:264)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
at
org.drools.rule.constraint.ConditionAnalyzer.statementToExpression(ConditionAnalyzer.java:467)
at
org.drools.rule.constraint.ConditionAnalyzer.readInvocationParams(ConditionAnalyzer.java:450)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:345)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeExpressionNode(ConditionAnalyzer.java:326)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeAccessor(ConditionAnalyzer.java:286)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeNode(ConditionAnalyzer.java:250)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeSingleCondition(ConditionAnalyzer.java:133)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:99)
at
org.drools.rule.constraint.ConditionAnalyzer.analyzeCondition(ConditionAnalyzer.java:70)
at
org.drools.rule.constraint.MvelConditionEvaluator.getAnalyzedCondition(MvelConditionEvaluator.java:83)
at
org.drools.rule.constraint.MvelConstraint.executeJitting(MvelConstraint.java:270)
at
org.drools.rule.constraint.MvelConstraint.access$200(MvelConstraint.java:51)
at
org.drools.rule.constraint.MvelConstraint$ConditionJitter.run(MvelConstraint.java:250)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
--
View this message in context: http://drools.46999.n3.nabble.com/how-can-I-resolve-java-lang-RuntimeExce...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
DRL file not getting picked
by dwipin
Hi,
I am using kie-spring.6.0.0.Final artefact to build my project.
This is my app ctx data -
<kie:kmodule id="module-1">
<kie:kbase name="kbase" packages="validation_rules">
<kie:ksession name="ksession">
<kie:consoleLogger />
</kie:ksession>
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor"
class="org.kie.spring.KModuleBeanFactoryPostProcessor" />
<bean id="ruleService" class="com.poc.RuleService">
<property name="ksession" ref="ksession" />
</bean>
My Rule Service ->
ksession.fireAllRules();
log.debug("...finished running .");
My DRL File input ->
package validation_rules
rule "Test Rule"
when
then
System.out.println("Testing...");
end
I wanted to test with a sample rule without any conditions. However this
never gets executed. This DRL file is present under
src/main/resources/validation_rules. The KieSession gets injected properly
though.
Thanks and Regards,
Dwipin Chandran.
--
View this message in context: http://drools.46999.n3.nabble.com/DRL-file-not-getting-picked-tp4027476.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
getting object from hashMap in when clause and using it across the rule
by Avin
Hi,
I have an list of objects (objectList) and an hashmap (referenceMap) with
similiar kind of objects. I have to check which objects in list matches with
hashMap.
i can iterate list and check it with hashMap but i am not able to get value
from from the hashmap which itself is an custom object and i need to check
its value
below code i am using to iterate list and check it from hashMap
when
TempStorage($object : concentrationDataTable )
TempStorage($mapObject : concPercentRefObjects)
$dataObject : ConcentrationDataTable($keyObject : concPercentRefkey) from
$object
eval( $mapObject.get($keyObject) != null)
I want to add variable to get this value *$mapObject.get($keyObject)* and
also check if its property getMax returns me other than 10
--
View this message in context: http://drools.46999.n3.nabble.com/getting-object-from-hashMap-in-when-cla...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
iterating through list of object and checking if object is present in Hashmap
by Avin
Hi Guys,
I am new to drools and i have done some PoC of small things. Now i want to
implement a business functionality and it seems very complex to me. I didnt
get much time to go through docs but i went through it as much as can do.
but still no luck
My issue is I have list of employee objects it has methods say empId,
empPhone and empFName.
this employee class has overridden hashcode and equals method. It uses empId
and empPhone to check if user is right user.
I have hashMap of emp objects this map contains all employees of all depts
and locations.
I want to check if objects present in list are present in hashmap. if they
are present then i want to add them to different list and return
corresponding java code is as below
List <Emp> empList = new ArrayList<Emp>();
Map<Emp,Emp> map = new HashMap<Emp,Emp>();
for(Emp emp : empList){
if(map.contains(emp)){
// do something
}
}
I need to convert above code in drools format in drl file. can I iterate
list and use contains in when clause ? so that i can put my actions in then.
through java i am providing drl with employeelist and hashmap
Please help i am in real trouble now
I tried doing
rule "rule for emp"
when
//$o : MyClass( id == "1", name == "name" )
empDetails : TempStorage($object : empDetails)
empTable: TempStorage($mapObject : empTableData)
$mapObject.contains($object)
and
Emp(empId == $object.empId , empPhone == $object.empPhone) from $object
then
System.out.println("hiiiii");
end
but no luck i get exception as *Unable to resolve ObjectType
'$mapObject.contains' : [Rule name='calculation for 10%']*
--
View this message in context: http://drools.46999.n3.nabble.com/iterating-through-list-of-object-and-ch...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
write a rule file, longest matching?
by merry0900
hello,here is my java code
main(){
MyPojo myPojo=new MyPojo();
myPojo.setA("aaa")
myPojo.setB("bbb")...
.
.
.
List<MyPojo> myPojos=getAllFromDb()// get all object by mybatis form
database ,and each one is different from another.
ksession.setGlobal("myPojos", myPojos);
ksession.insert(myPojo);
}
class MyPojo {
private Long id;
private String a;
private String b;
private String c;
private String d;
//getters;
//setters;
}
i want to write a drl file whitch can find a List<MyPojo> myPojoSub that
Each MyPojo From myPojoSub is come from myPojos and limited by some rules。
for example:
myPojos={{id:1,a:"kkk",b:"iii",c:"ppp"},{id:2,a:"kkk",b:"iii"},{id:3,a:"kkk"},{id:4,a:"kkk",b:"iii",c:"ooo"},{id:5,a:"mmm",b:"fff",c:"ttt"}}
and if there is a myPojo{a:kkk,b:"iii",c:"ppp"} then
{id:1,a:"kkk",b:"iii",c:"ppp"} from myPojos is a member of myPojoSub
if there is a myPojo{a:kkk,b:"iii",c:"ttt"} then
{id:2,a:"kkk",b:"iii",}from myPojos is a member of myPojoSub
if there is a myPojo{a:kkk,b:"fff",c:"ttt"} then {id:3,a:"kkk"}from myPojos
is a member of myPojoSub
if there is a myPojo{a:"lll",b:"fff",c:"ttt"} then
{id:5,a:"mmm",b:"fff",c:"ttt"}from myPojos is a member of myPojoSub
if there is a myPojo{a:"ppp",b:"jjj",c:"zzz"} then no any MyPojo from
myPojos is a member of myPojoSub
how do i write my drl rules? any one can help me or give some
suggestions? thank you
here is a rule file templet:
package com.test.tules;
import com.test.MyPojo;
import java.util.List;
globle List<com.test.MyPojo> myPojos;
rule "aaaaa"
salience 65523
when
then
--
View this message in context: http://drools.46999.n3.nabble.com/write-a-rule-file-longest-matching-tp40...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
java.lang.RuntimeException: Cannot find a default KieSession
by sdjoe
I am using Drools 6.0.0.FINAL on JBOSS EAP 5.1.2. My code:
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession();
kSession.insert(mdxObj);
kSession.fireAllRules();
Works fine outside of the JBOSS container. I am deploying this code within a
JAR file that is the main part of my EAR file. I feel as though I have tried
every possible answer I have found on the web for the past two days and this
is my last resort.
Does anyone have any ideas on what could be the problem?
Thanks,
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-RuntimeException-Cannot-find-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months
Drools 6.0.1 micro benchmark Miss Manners troubles
by Tom DC
Hello,
For my master thesis I'm benchmarking different rule engines by making use
of the micro benchmarks Miss Manners, Waltz and Waltzdb.
In the previous version of Drools Expert (5.5.0) the results were
surprisingly fast!
So when I saw the release of the latest Drools Expert version, 6, I was
wondering if there would be a difference in execution time as well.
So I started making a new project, using Netbeans, and added the old
benchmark code and modified the imports according to the example projects
(there is a benchmark project included in the latest release of Drools). I
also checked for possible differences between the old code and the new, but
didn't find any.
When I now run the benchmark for Miss Manners, it seems that Drools is
unable to even solve the easiest problem with 16 visitors. It keeps on
executing the same rule over and over without going to the next one when it
becomes available.
To see if this was a problem in my custom edition of the ruleset, I also ran
the example benchmark, but also noticed that this one could not run the Miss
Manners benchmark anymore.
Did somebody already figure out what is wrong with this benchmark?
Thx
Tom DC
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-6-0-1-micro-benchmark-Miss-Manne...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 2 months