2
votes

I'm creating an decision table using Drools and having trouble with the greater than character ('>'). I saw on the drools documentation that you could use '>' and '<' but I seem to get something wrong.

The column is (I don't have enough reputation yet to post images):

  • |CONDITION|
  • | | (empty cell)
  • |duration >|
  • |Duration|
  • |50|
  • |200|

The thing is that the architecture doesn't allow me to get the full object. I can only have some fields from the RemoteObject. So the thing I can do is:

Integer duration = getRemoteObjectDuration();
kSession.insert(duration);
kSession.fireAllRules();

Which results in:

[6,2]: [ERR 102] Line 6:2 mismatched input '>' in rule "RuleTable_11"
[14,2]: [ERR 102] Line 14:2 mismatched input '>' in rule "RuleTable_12"
[0,0]: Parser returned a null Package

I could create a dummy object containing my field, but there must be something better to do. Does anyone have an idea about this?

2
You can't have an empty cell immediately below CONDITION. What is the name of the class where field (!) duration is located? There is nothing like an "Integer on the java side". Inserting Integer objects as facts isn't useful except in very special situations. - laune
Thanks, I edited the post. I tried with with a dummy object containing only my field and it works, Maybe it is the only solution... - John Theonet

2 Answers

3
votes

To match an Integer you can use a rule like

rule findInt
when
    Integer( $iv: intValue > 42 )
then
    System.out.println( "got an Integer > 42: " + $iv );
end

and, consequently, a spreadsheet column according to

CONDITION
Integer
intValue >
- ... -
42

This is, of course, doomed to fail when you have several Integer objects floating around in working memory, not being able to identify what is what.

For your predicament I'd create a shadow object for holding all fields of the remote object rather than wrap the fields individually.

1
votes

Thanks to laune's comment, I finally made it work, but I had to create a custom object only containing the field I needed and I wrote the name of this new class below CONDITION.