Thanks for your help Vincent.<br><br>To be sure i have understood all well.<br><br>I've just created 2 class like you show me with some changes to fit and test all (timestamp are long in fact, i have put int, double and string as well) :<br>
<br>First class : <br><br>import java.util.HashMap;<br><br>public class MapPojo extends HashMap<String, Object> {<br><br> public Object getId() {<br> return this.get("id");<br> }<br><br> @Override<br>
public boolean equals(Object o) {<br> return (o instanceof MapPojo) && ((MapPojo)o).getId().equals(getId());<br> }<br><br> public long getTimeStamp() {<br> return (Long) this.get("timeStamp");<br>
}<br><br> public boolean isBefore(MapPojo other) {<br> if (this.getTimeStamp() < other.getTimeStamp())<br> return true;<br> else<br> return false; <br> }<br>
}<br><br>Second class :<br><br>public class MapTest1 extends MapPojo {<br><br> private String Att1String;<br> private String id;<br> private double Att2Double;<br> private int Att3Int;<br>
private long timeStamp;<br>
<br> public String getId() {<br> return (String)this.get("id");<br> }<br> public void setId(String val) {<br> this.put("id",val);<br> }<br> <br> public String getAtt1String() {<br>
return (String)this.get("Att1String");<br> }<br> public void setAtt1String(String val) {<br> this.put("Att1String",val);<br> }<br><br> public double getAtt2Double() {<br> return (Double)this.get("Att2Double");<br>
}<br> public void setAtt2Double(double val) {<br> this.put("Att2Double",val);<br> }<br> <br> public int getAtt3Int() {<br> return Integer.parseInt((String)this.get("Att3Int"));<br>
}<br> public void setAtt3Int(int val) {<br> this.put("Att3Int",val);<br> }<br><br> public long getTimeStamp() {<br> return (Long)this.get("timeStamp");<br> }<br> public void setTimeStamp(Long val) {<br>
this.put("timeStamp",val);<br> }<br>}<br><br>Then i have imported this in Guvnor.<br><br>I have made 2 categories. I have put the model (jar) in the 2 categories. I have created 2 simple rules playing with the attributes id, timestamp...<br>
<br>Then i get some code like this (when i clic on view code or get the drl file) :<table id="ext-gen555"><tbody id="ext-gen559"><tr><td></td></tr><tr><td><table id="ext-gen857"><tbody id="ext-gen859"><tr id="ext-gen855">
<td><span style="color: grey;">1.</span></td><td><span id="ext-gen856" style="color: green;">|</span></td><td><span style="color: red;">rule</span> <span id="ext-gen858" style="color: green;">"Rule1InCat1"</span></td>
</tr><tr id="ext-gen888"><td><span id="ext-gen887" style="color: grey;">2.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen889"> <span style="color: red;">dialect</span> <span id="ext-gen860" style="color: green;">"mvel"</span></td>
</tr><tr><td id="ext-gen881"><span id="ext-gen880" style="color: grey;">3.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen861"> <span id="ext-gen890" style="color: red;">when</span></td></tr><tr>
<td><span id="ext-gen876" style="color: grey;">4.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen862"> $m1 : MapTest1( att1String == <span style="color: green;">"value1"</span> )</td>
</tr><tr><td id="ext-gen874"><span id="ext-gen875" style="color: grey;">5.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen863"> $m2 : MapTest1( att1String == <span style="color: green;">"value1"</span> )</td>
</tr><tr><td id="ext-gen873"><span style="color: grey;">6.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen864"> MapTest1( att2Double == 3.5 )</td></tr><tr><td id="ext-gen872"><span style="color: grey;">7.</span></td>
<td><span id="ext-gen871" style="color: green;">|</span></td><td id="ext-gen865"> <span style="color: red;">then</span></td></tr><tr id="ext-gen870"><td><span id="ext-gen886" style="color: grey;">8.</span></td><td><span style="color: green;">|</span></td>
<td id="ext-gen866"> MapTest1 fact0 = new MapTest1();</td></tr><tr id="ext-gen883"><td id="ext-gen884"><span id="ext-gen885" style="color: grey;">9.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen867">
fact0.setId( <span style="color: green;">"id4"</span> );</td></tr><tr id="ext-gen882"><td><span style="color: grey;">10.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen868"> insert(fact0 );</td>
</tr><tr><td><span style="color: grey;">11.</span></td><td><span style="color: green;">|</span></td><td id="ext-gen869"><span style="color: red;"><span style="color: red;">end</span></span></td></tr></tbody></table><br>1) For the condition Map $m1 different then Map $m2. I suppose i have to use the function define in MapPojo? I have to write it by hand using "free from drl" : eval($m1 != $m2) ? or is there a better way? <br>
<br>The same for testing that $m1 timestamp (Long) is befor $m2. I have to write it by hand : eval($m1.isBefore($m2))? So they have to know it exist a method isBefore if not said by the gui?<br><br>2) In the code It's written MapTest1(..) instead of Map(...) so i suppose drools has to do it with the precompiled package .pkg to know about the MapPojo and MapTest1.. If i take only the .drl, drools won't know about class MapTest1.<br>
</td></tr><tr><td></td></tr></tbody></table><div class="gmail_quote"><br>I think it could be for the biggest file about 100+ rules. And the smallest about 2-3 only.<br><br>I can have : MapTest1, MapTest2, MapTest3, MapTest4 for example with each their own attributes. And For now if i have 4 drl files (file1.drl go for MapTest1 objects, file2.drl go for MapTest2 objects...) with their own rules, i know when to use which file.<br>
<br>Yes i can set a category to each of my rule. Do you mean create 4 categories (cat1, cat2, cat3, cat4) and for rules of file1.drl, put them it cat1, for file2.drl, put them in cat2... ? Set a first condition in the rules? Am i obliged to create a package per file and filter by category or is it possible to make a package with all and filtering when creating the knowledgeBase or something like that?<br>
<br><br>Thanks again for your precious help.<br><br><br><br>On Fri, Mar 4, 2011 at 7:35 PM, Vincent Legendre <span dir="ltr"><<a href="mailto:vincent.legendre@eurodecision.com">vincent.legendre@eurodecision.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im"><br>
> I just tried to make a pojo. But i will have to do a single Pojo<br>
> called "Map" with all the properties? Right now i had 4 Enum. Here i<br>
> will have to have all in the same POJO with name "Map".<br>
</div><div><div></div><div class="h5">No. Don't name the Pojo "Map" ... And create as much Pojo that you have<br>
different enums. Make them extend a common class where are defined<br>
common behaviour.<br>
To make that clear once for all, see this code :<br>
<br>
public class MapPojo extends HashMap<String, Object> {<br>
<br>
public Object getId() {<br>
return this.get("id");<br>
}<br>
<br>
@Override<br>
public boolean equals(Object o) {<br>
return (o instanceof MapPojo)<br>
&& ((MapPojo)o).getId().equals(getId());<br>
}<br>
<br>
public Date getTimeStamp() {<br>
return (Date) this.get("timeStamp");<br>
}<br>
<br>
public boolean isBefore(MapPojo other) {<br>
return this.getTimeStamp().before(other.getTimeStamp());<br>
}<br>
}<br>
<br>
// for enum 1<br>
public class MapPojoGroup1 extends MapPojo {<br>
<br>
public String getAtt1() {<br>
return (String)this.get("att1");<br>
}<br>
public void setAtt1(String val) {<br>
this.put("att1",val);<br>
}<br>
<br>
public Long getAtt2() {<br>
return (Long)this.get("att2");<br>
}<br>
public void setAtt2(Long val) {<br>
this.put("att2",val);<br>
}<br>
<br>
}<br>
<br>
... etc etc etc for other enums<br>
Easy to generate isn't it ?<br>
<br>
><br>
</div></div><div class="im">> The advantage i suppose is that with the Pojo, we can directly tell<br>
> this attribute is a String, this one is a Integer, this one a Double<br>
> and this one a Long and in the rules all will be done automatically<br>
> without casting?<br>
</div><div class="im">Yep. And Guided editor will work "out of the box", providing the<br>
suitable list of fields, and suitable operators according to the field<br>
type.<br>
And if subsequent Pojo generation remove a field, compilation will warn you.<br>
<br>
<br>
For the files, please tell how you cut them. Can you set a category ? If<br>
yes, you can also set a first condition. How many rules do you (plan to)<br>
have ?<br>
And yes, you can compile only rules that match a given category. But you<br>
will have to store it in a snapshot just after that. Please refer to the<br>
doc for this point.<br>
_______________________________________________<br>
</div><div class="im">rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
</div><div><div></div><div class="h5"><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>