There may be very good reasons to have Patient with @role(event).<br><br>But for testing rules with temporal operators I find it much easier to<br>use a pseudo-clock for telling the Session about &quot;now&quot;.<br><br>Also, a rule with a timer, inserting events with a very short expiry time<br>
provides a very good way of producing ticks, discrete moments in<br>time, with which it is easy to reason.<br><br>-W<br><br><br><br><div class="gmail_quote">On 23 November 2010 04:54, Edson Tirelli <span dir="ltr">&lt;<a href="mailto:tirelli@post.com">tirelli@post.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">   I believe the documentation mentions this: events are supposed to<br>
be immutable, except for data enrichment. Timestamp is cloned at the<br>
moment an event is inserted into the session to prevent inconsistent<br>
reasoning (you know, in case a creative user tries to modify the<br>
timestamp field... ;) ).<br>
<br>
   Besides that, Patient is an odd name for an event class, so either<br>
there is a misunderstanding here, or you are using the wrong tool for<br>
the job. If Patient is just a regular entity in your domain model, it<br>
should not be declared as an event. Remember that you can use<br>
point-in-time temporal operators (before, after, coincides) with any<br>
Date/long attribute, no need to declare the class as an event class:<br>
<br>
Patient( birthdate after $someTimestamp )<br>
<br>
   If you do that, you will be able to modify patient instances and<br>
rules will behave correctly.<br>
<br>
   Try this:<br>
<br>
<a href="http://blog.athico.com/2010/07/events-to-be-or-not-to-be-that-is.html" target="_blank">http://blog.athico.com/2010/07/events-to-be-or-not-to-be-that-is.html</a><br>
<br>
   Edson<br>
<br>
<br>
<br>
2010/11/22 Nathan Bell &lt;<a href="mailto:Nathan.Bell@pharmacyonesource.com">Nathan.Bell@pharmacyonesource.com</a>&gt;:<br>
<div><div></div><div class="h5">&gt; To demonstrate the issue I have simplified the following sample rule to just<br>
&gt; the components needed to demonstrate the issue. The example rule I’m posting<br>
&gt; here uses the “after” operator; I have also tried this same test with the<br>
&gt; before operator. In this sample the rule named “AfterRule” will activate if<br>
&gt; the facts are initially inserted in a state matching the pattern. However,<br>
&gt; if the facts are inserted in a state that does not match, and then later<br>
&gt; updated to match the pattern using StatefulKnowledgeSession.update() the<br>
&gt; rule will not activate.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Consider the following DRL:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; package test.rules;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; dialect &quot;java&quot;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; import java.util.Date;<br>
&gt;<br>
&gt; import com.p1s.mps.model.RuleTime;<br>
&gt;<br>
&gt; import com.p1s.mps.model.Patient;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; declare RuleTime<br>
&gt;<br>
&gt;     @role( event )<br>
&gt;<br>
&gt;     @timestamp( time )<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; declare Patient<br>
&gt;<br>
&gt;     @role( event )<br>
&gt;<br>
&gt;     @timestamp( birthDate )<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; rule &quot;AfterRule&quot;<br>
&gt;<br>
&gt; when<br>
&gt;<br>
&gt;     $now : RuleTime(  )<br>
&gt;<br>
&gt;     Patient( this after $now )<br>
&gt;<br>
&gt; then<br>
&gt;<br>
&gt;       System.out.println(&quot;after&quot;);<br>
&gt;<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Separately in a unit test the following actions are performed:<br>
&gt;<br>
&gt; 1.       Insert an instance of RuleTime into the session where time is set<br>
&gt; to now.<br>
&gt;<br>
&gt; 2.       Insert an instance of a patient into the session where the<br>
&gt; birthdate is set to (now – 1 day). [This makes the birthdate in the past so<br>
&gt; the rule does not activate]<br>
&gt;<br>
&gt; 3.       Call fireAllRules(). The rule does not activate, as expected.<br>
&gt;<br>
&gt; 4.       Modify the patient instance to have a birthdate set to (now + 1<br>
&gt; day).<br>
&gt;<br>
&gt; 5.       Invoke update() on knowledge session.<br>
&gt;<br>
&gt; 6.       Call fireAllRules(). The rules does not activate. It should<br>
&gt; activate here.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; If I change step 5 to a retract + insert then the rule will activate in step<br>
&gt; 6 as expected.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Thank You,<br>
&gt;<br>
&gt; Nathan Bell<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
--<br>
  Edson Tirelli<br>
  JBoss Drools Core Development<br>
  JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>