[rules-users] Guvnor and drools implementation - questions

Vincent Legendre vincent.legendre at eurodecision.com
Fri Mar 4 13:35:19 EST 2011


> I just tried to make a pojo. But i will have to do a single Pojo 
> called "Map" with all the properties? Right now i had 4 Enum. Here i 
> will have to have all in the same POJO with name "Map".
No. Don't name the Pojo "Map" ... And create as much Pojo that you have 
different enums. Make them extend a common class where are defined 
common behaviour.
To make that clear once for all, see this code :

public class MapPojo extends HashMap<String, Object> {

     public Object getId() {
         return this.get("id");
     }

     @Override
     public boolean equals(Object o) {
         return (o instanceof MapPojo)
&& ((MapPojo)o).getId().equals(getId());
     }

     public Date getTimeStamp() {
         return (Date) this.get("timeStamp");
     }

     public boolean isBefore(MapPojo other) {
         return this.getTimeStamp().before(other.getTimeStamp());
     }
}

// for enum 1
public class MapPojoGroup1 extends MapPojo {

     public String getAtt1() {
         return (String)this.get("att1");
     }
     public void setAtt1(String val) {
         this.put("att1",val);
     }

     public Long getAtt2() {
         return (Long)this.get("att2");
     }
     public void setAtt2(Long val) {
         this.put("att2",val);
     }

}

... etc etc etc for other enums
Easy to generate isn't it ?

>
> The advantage i suppose is that with the Pojo, we can directly tell 
> this attribute is a String, this one is a Integer, this one a Double 
> and this one a Long and in the rules all will be done automatically 
> without casting?
Yep. And Guided editor will work "out of the box", providing the 
suitable list of fields, and suitable operators according to the field 
type.
And if subsequent Pojo generation remove a field, compilation will warn you.


For the files, please tell how you cut them. Can you set a category ? If 
yes, you can also set a first condition. How many rules do you (plan to) 
have ?
And yes, you can compile only rules that match a given category. But you 
will have to store it in a snapshot just after that. Please refer to the 
doc for this point.



More information about the rules-users mailing list