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.
11 years, 10 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.
11 years, 10 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.
11 years, 10 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.
11 years, 10 months