List/Collection on the RHS - DSL or Decision Table possible?

111 views
Skip to first unread message

Doesnt Matter

unread,
Sep 11, 2015, 1:43:37 PM9/11/15
to Drools Usage
Hi all,

I am new to drools and evaluating a switch from JRules/ODM to it. For the following situation I was not able to find a solution yet: We need to have multiple values on the rhs of a rule. Example for that:

POJO for LHS
public class Company {

   
private int id;
   
// getters, setters, ...
}

POJO for RHS
public class SelectionCriteria {

   
List<Manufacturer> allowedManufacturer;
   
//getters, setters, ...
}

now a business user should be able to design a rule that company 1 is allowed to use manufacturer X,Y,Z while company 2 can only continue with manufacturer D.
For a hard coded rule this could work like that:

sc
:SelectionCriteria;
when c:Company(id == "1")
 
then sc.setAllowedManufacturer.addAll(java.util.Arrays.asList("X","Y","Z"));

But I cannot hand over this way to the business department.
My question now is: Is there any DSL that covers specifying lists for the rhs? Or even better: Can I use this somewho in a guided decision table in the workbench? XLS decision tables are unfortunately not an option for us.
Or did I misunderstood something completely?

Thanks in advance for any hint.

Florian

Jonathan MERCIER

unread,
Sep 15, 2015, 4:04:01 PM9/15/15
to Drools Usage
Hi,

I do not know If I well understood, but it seem you try to link a company to a manufacturer by using company's id and manufacturer's name.

My snippet code:

public enum Relation {
    ADD
,
    REMOVE
}

public interface CompanyManufacturerRelation {
   
String getCompanyId();
   
String getManufacturerName();
   
Relation getRelation();
}

public class CompanyManufacturerRelationImpl implements  CompanyManufacturerRelation {
   
private final String id;
   
private final String name;
   
private final Relation relation;

   
public CompanyManufacturerRelationImpl( final String id, final String name, Relation relation ){
       
this.id = id;
       
this.name = rame;
       
this.relation = relation;
   
}

   
String getCompanyId(){
       
return id;
   
}

   
String getManufacturerName(){
       
return name;
   
}

   
String getRelation(){
       
return relation;
   
}
}

dialect
"mvel"

rule
"Add relation between company and manufacturer"
when  
    $c
: Company()
    $cmr
: CompanyManufacturerRelation( $c.id:= id, relation == Relation.ADD )
then
    sc
.setAllowedManufacturer.add( $c )
end

rule
"Remove relation between company and manufacturer"
when  
    $c
: Company()
    $cmr
: CompanyManufacturerRelation( $c.id:= id, relation == Relation.REMOVE )
then
    sc
.setAllowedManufacturer.remove( $c )
end


Reply all
Reply to author
Forward
0 new messages