I want to check whether the student id is present in emp id of the company class. If a studentid is present in the empidlist, then i should throw the error.
I have tried it in two different ways:
1st
rule :"check the student id is present in empid"
when
$company : Company()
accumulate(Employee(empid !=null, empid : empid) from $company.emplist;
empidlist: collectList(empid))
accumulate(Student(stdid !=null, empidlist.contains(stdid),stdid : stdid) from $company.stdlist; stdidlist: collectList(stdid);stdidlist.size()>0)
then
//throw error.
When running it, I got the following error: cannot use .contains() from accumulate.
2nd
function boolean isStudentidExists(List<String> stdidlist, List<String> empidlist){
for (String s : stdidlist) {
for (String res : empidlist) {
if (res.equals(s))
return true;
}
}
return false;
}
rule :"check the student id is present in empid"
when
$company : Company()
accumulate(Employee(empid !=null, empid : empid) from $company.emplist; empidlist: collectList(empid))
accumulate(Student(stdid !=null,stdid : stdid) from $company.stdlist; stdidlist: collectList(stdid))
eval(isStudentidExists(stdidlist,empidlist))
then
//throw error.
Here it is not reading the List. I have tried giving the type as only List<> in my function, but that still doesn't work.
Class Company {
private List<Employee> emplist;
private List<Student> stdlist;
}
Class Employee {
private String empid;
}
Class Student {
private String stdid;
}