Thank you for your answer.
Yes it's what i have done as i didn't find a better idea. User will have to enter it but if the DSL is clear shouldn't be a problem.

In fact 1 rule will be something like :
- Find a map with properties 'prop1' = "value1" and store it in variable $m1 (because i will need access in the Then part also)
- Find a map with properties 'prop1' = "value1" (and different then $m1) and store it in variable $m2.
- And using properties 'unixTimestampInSecond' and 'unixTimestampInMillisecond' (so complete timestamp in Millisecond = 'unixTimestampInSecond' * 1000 + 'unixTimestampInMillisecond') of the 2 Maps, $m1 has to be before $m2.

So i use 2 times this one to find $m1 and $m2 : [when]The property {key:ENUM:Map.properties} of the map {mapVar} is {value}={mapVar} : Map((this["{key}"] == "{value}"))

Then this one to drop the case when the Map would be the same : [when]The map {mapVar1} is not map {mapVar2} = eval ({mapVar1}["id"] != {mapVar2}["id"]))

Then i can do something like : [when]The map {mapVar1} is before {mapVar2} = eval (orderTimeStamp((Long) {mapVar1}["unixTimestampInSecond"], (Long) {mapVar1}["unixTimestampInMillisecond"], (Long) {mapVar2}[" unixTimestampInSecond"], (Long) {mapVar2}["unixTimestampInMillisecond"]))

where i would have a function :   
function Boolean orderTimeStamp(Long a, Long b, Long c, Long d)

{
    Long timestamp1 = a*1000+b;
    Long timestamp2 = c*1000+d;

    if (timestamp1 <= timestamp2)
        return true;
    else
        return false;
}

I will rethink of POJO but i think, it will be more ennoying to update any change. I will need a reference to these maps in almost every case in the THEN clause so not a big problem finally.


For the second question :

In fact i have to make rules using these Enum and DSL and put rules in their specific files.
For example now i am working with 4 different drl files :

- file1.drl which contains rule1, rule2, rule3, rule4
- file2.drl which contains rule5, rule6, rule7, rule8
- file3.drl which contains rule9, rule10, rule11, rule12
- file4.drl which contains rule13, rule14, rule15, rule16

These files have to have this specific name and the name cannot change because the java code use this name to load the drl file in the session.

To put each rule in its specific file, do i have to create a package per file and name the package with the name of the file i want? And copy Enum and DSL in each package or can i put this in global? Or maybe be is there a better way i didn't find?


To use the Test Scenario, do you know if we have to do special things? I tried to add Maps in the Given part and run the scenario but i get an error ; "unable to find constructor for java.util.Map" and the same if i put a boolean, string...   Is the Guvnor Test Scenario not able to find java class and how to make it reachable?
I have already tried Test Scenario with adding object for which i gave a Pojo but never with basic java type.

Thanks again


Le 4/03/2011 11:50, Vincent Legendre a écrit :
For your problem of different instances of a map : If you want to match 2 maps, and compare them, your have to set a placeholder in your DSL to set the variable's name
[when]The property {key:ENUM:Map.properties} of the map {mapVar} is {value}={mapVar} : Map((this["{key}"] == "{value}"))

And another DSL phrase to check that instances are different
[when]The map {mapVar1} is not map {mapVar2} = eval ({mapVar1}["id"] != {mapVar2}["id"]))

But it will force your users to handle variables. I can't see simpler way for doing that with DSL.

You may consider completely another way. If your property lists are constant (and they are because you can create static enums), you can write a simple program to generate the corresponding POJOs (which contains the map inside them and use it in set/get methods for corresponding key) and create a jar with them.
Each POJO will then have its fields listed automatically in Guided Editor, which will prevent you for writing complex DSL and enums, and provide a good way for users to edit rules. For instance, you can bind an object to a variable only if you need it (with DSL you are forced to bind a variable at each time you use the phrase), and you can use other operator (not only equals) without writing a new DSL phrase.


I did not understand this question :

I have to put my rules in 4 drl files separate (i know which rules go in which drl file), is the only way to create a different package for each drl file i want? And to put the Enum and DSL part in Global if i have to use it for the 4 files? If i want a precise name for my drl file, i have to give this exact name to the package?
But yes, a DSL (and enums) is specific to its package.

_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users