'Is there a way to call query from a rule in DRL file?

I have a requirement to chain a window rule to a window rule. My use case is :

If the occurrence of temperature > 50 in 5 min window is greater than 10 then find the max(average) of the temperature in that window frame or any other chain rule on that window data.

I tried the following aprroach:

query getFactFromMemory(long time)
   $fact : Fact(timepoing < (drools.getWorkingMemory().getSessionClock().getCurrentTime() + time))
end

rule "window rule"
when
   //condition
then
   //action
end

rule "chain rule"
when
   //condition
then
  getFactFromMemory(1000L)
 //loop over facts and then perform some action
end

I am getting errors while calling the query. I tried calling the query in when part and assigning it to a variable but that also giving error (Query's must use positional or bindings, not field constraints:1000L and Query binding is not supported by non-abductive queries : $variable).

Can anyone help me in solving this error or suggesting any other approach to the problem?



Solution 1:[1]

We can get drools runtime object inside drl by invoking drools.getKieRuntime(). So, the working rule for the question is:

query getFactFromMemory(long time)
   $fact : Fact(timepoing < (drools.getWorkingMemory().getSessionClock().getCurrentTime() + time))
end

rule "window rule"
when
   //condition
then
   //action
end

rule "chain rule"
when
   //condition
then
  getFactFromMemory(1000L)
 //loop over facts and then perform some action
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prog_G