0

My rule is as follows:

when
  C : Company()
  $empname : List() collect from (Employee($empname : empname) from C.employees)
then
  System.out.println($empname);

The corresponding class:

public class Company {
  private List<Employee> employees;
  private Stringlocation;
}

public class Employee {
  private String empname;  
  private int empid;
}

With my code, I am only getting the Employee Objects but how do I get the empnames list?

Anvesh
  • 1
  • 3

1 Answers1

0

It's preferable to implement simple data processing algorithms as methods in the class where they belong. Writing rules for this is possible but it's the wrong tool.

rule "employees"
when
   Company( $emps: employees )
   accumulate( Employee( $name: empname ) from $emps; 
               $name: collectList( $name ) )
then
   ... use List $name
end
laune
  • 31,114
  • 3
  • 29
  • 42
  • rule "employees" when Company( $emps: employees ) accumulate( Employee( $name: empname ) from $emps; $name: collectList( $name ) ) then ... use List $name end – Anvesh Dec 18 '17 at 13:43
  • Here I have added a line $name contains "12345". It's not working because List cannot be compared to the type in String . I have also tried writing a function in drl file like function boolean checkContains(List<> a, String b){ return a.contains(b);} – Anvesh Dec 18 '17 at 13:44
  • Don't post a new question in comments. Complete one question properly; then ask the next one as a new question. – laune Dec 18 '17 at 14:16