Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-505

Using a GLOBAL value in predicates in more than one rule - rule fails to evaluate correctly.

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 3.0.4
    • Fix Version/s: 3.0.5, 3.1-m1
    • Component/s: All
    • Labels:
      None
    • Environment:

      Windows XP, JBoss 4.0.3SP1, JRules3.0.4, PackageBuilderConfiguration.JANINO

      Description

      SAMPLE CODE:
      ===============================================
      package net.rockshore.rmf.rules

      #list any import classes here.
      import net.rockshore.rmf.entities.SubscriptionLocal;
      import net.rockshore.rmf.entities.EventLocal;
      import java.lang.String;

      #declare any global variables here
      global java.util.Collection resultsCollection;
      global java.lang.String eventType;

      rule "KeepSubscriptionsToEventType"

      when
      subscription : SubscriptionLocal (eventTypeDiscriminator == (eventType))
      then
      resultsCollection.add(subscription);
      System.out.println("Keeping Subscription:" + subscription + " is of type:" + eventType);

      end

      rule "DiscardSubscriptionsToWrongEventType"
      when
      wrongSubscription : SubscriptionLocal (eventTypeDiscriminator != (eventType))
      then
      System.out.println("Discarding Subscription:" + wrongSubscription + " NOT of type:" + eventType);
      retract (wrongSubscription);
      end

      ===============================================

      TEST DATA SET:
      -------------------------

      SubscriptionLocal objects asserted
      KEY, EVENTTYPEDISCRIMINATOR
      ---------------------------------------------------------------------------------------------------------
      5c4o12-mexdpy-esmukytr-1-esmx439o-58 , net.rockshore.rmf.entities.events.business.TravelAlertEvent
      5c4o12-mexdpy-esmukytr-1-esmx438t-57 , net.rockshore.rmf.entities.events.business.FlightDelayEvent
      5c4o12-mexdpy-esmukytr-1-esmx438t-56 , net.rockshore.rmf.entities.events.business.FlightDelayEvent

      GLOBAL variable
      eventType = "net.rockshore.rmf.entities.events.business.FlightDelayEvent"

      PROBLEM DESCRIPTION:
      -------------------------------------
      When firing the above rules with data shown above, the result shows that "DiscardSubscriptionsToWrongEventType" rule was fired for Subscriptions with keys ending 57 and 56. This is the wrong way round as that rule should have fired only with Subscription 58.

      Further, rule "KeepSubscriptionsToEventType" did not fire.

      FURTHER ANALYSIS:
      -------------------------------
      If one rule OR the other is deleted then the remaining rule fires correctly.

      If both rules have the predicate replaced with a String literal "net.rockshore.rmf.entities.events.business.FlightDelayEvent" then both rules fire correctly.

      The problem still occurs when eventType predicate is replaced with eventType.toString()

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                mattgreenuk Matt Green (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: