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 "now".<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"><<a href="mailto:tirelli@post.com">tirelli@post.com</a>></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 <<a href="mailto:Nathan.Bell@pharmacyonesource.com">Nathan.Bell@pharmacyonesource.com</a>>:<br>
<div><div></div><div class="h5">> To demonstrate the issue I have simplified the following sample rule to just<br>
> the components needed to demonstrate the issue. The example rule I’m posting<br>
> here uses the “after” operator; I have also tried this same test with the<br>
> before operator. In this sample the rule named “AfterRule” will activate if<br>
> the facts are initially inserted in a state matching the pattern. However,<br>
> if the facts are inserted in a state that does not match, and then later<br>
> updated to match the pattern using StatefulKnowledgeSession.update() the<br>
> rule will not activate.<br>
><br>
><br>
><br>
> Consider the following DRL:<br>
><br>
><br>
><br>
> package test.rules;<br>
><br>
><br>
><br>
> dialect "java"<br>
><br>
><br>
><br>
> import java.util.Date;<br>
><br>
> import com.p1s.mps.model.RuleTime;<br>
><br>
> import com.p1s.mps.model.Patient;<br>
><br>
><br>
><br>
> declare RuleTime<br>
><br>
> @role( event )<br>
><br>
> @timestamp( time )<br>
><br>
> end<br>
><br>
><br>
><br>
> declare Patient<br>
><br>
> @role( event )<br>
><br>
> @timestamp( birthDate )<br>
><br>
> end<br>
><br>
><br>
><br>
> rule "AfterRule"<br>
><br>
> when<br>
><br>
> $now : RuleTime( )<br>
><br>
> Patient( this after $now )<br>
><br>
> then<br>
><br>
> System.out.println("after");<br>
><br>
> end<br>
><br>
><br>
><br>
><br>
><br>
> Separately in a unit test the following actions are performed:<br>
><br>
> 1. Insert an instance of RuleTime into the session where time is set<br>
> to now.<br>
><br>
> 2. Insert an instance of a patient into the session where the<br>
> birthdate is set to (now – 1 day). [This makes the birthdate in the past so<br>
> the rule does not activate]<br>
><br>
> 3. Call fireAllRules(). The rule does not activate, as expected.<br>
><br>
> 4. Modify the patient instance to have a birthdate set to (now + 1<br>
> day).<br>
><br>
> 5. Invoke update() on knowledge session.<br>
><br>
> 6. Call fireAllRules(). The rules does not activate. It should<br>
> activate here.<br>
><br>
><br>
><br>
><br>
><br>
> If I change step 5 to a retract + insert then the rule will activate in step<br>
> 6 as expected.<br>
><br>
><br>
><br>
><br>
><br>
> Thank You,<br>
><br>
> Nathan Bell<br>
><br>
</div></div>> _______________________________________________<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>
><br>
><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>