Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-117

The "from" CE does not manage @events correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 5.5.1.Final, 6.0.0.Final
    • None
    • None
    • None
    • Hide

      package org.drools.test

      declare MyEvent
      @role(event)
      @timestamp( stamp )
      id : int
      stamp : long
      end

      declare MyBean
      id : int
      event : MyEvent
      end

      rule "Init"
      when
      then
      MyEvent ev = new MyEvent( 1, 1000 );
      MyBean bin = new MyBean( 99, ev );
      MyEvent ev2 = new MyEvent( 2, 2000 );

      insert( ev2 );
      insert( bin );
      end

      rule "Check"
      when
      $e2 : MyEvent( id == 2 )
      $b1 : MyBean( id == 99, $ev : event )
      MyEvent( this before $e2 ) from $ev
      then
      System.out.println( "Success" );
      end

      Show
      package org.drools.test declare MyEvent @role(event) @timestamp( stamp ) id : int stamp : long end declare MyBean id : int event : MyEvent end rule "Init" when then MyEvent ev = new MyEvent( 1, 1000 ); MyBean bin = new MyBean( 99, ev ); MyEvent ev2 = new MyEvent( 2, 2000 ); insert( ev2 ); insert( bin ); end rule "Check" when $e2 : MyEvent( id == 2 ) $b1 : MyBean( id == 99, $ev : event ) MyEvent( this before $e2 ) from $ev then System.out.println( "Success" ); end

      If an event type (i.e. an instance of a class marked with @role(event)) is returned by a "from" node, it is not wrapped by an EventFactHandle as expected, so e.g. any attempt to use temporal operators will fail.

      See the test case below for an example

      The problem is in FromNode.java around line 200, where the new handles are created without passing an ObjectTypeConfiguration, leading to the default creation of a DefaultFactHandle.

      I wonder if it's possible to simply retrieve the ObjectTypeConf:
      workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( context.getEntryPoint(), object )

      and pass it to the handle factory method.
      I tested it and it works for the test case below, but there may be other
      side-effects I'm not seeing.

      ---------------------------------------------------------------------------
      May be related (but not the same as) #JBRULES-2423

            mfusco@redhat.com Mario Fusco
            dsotty Davide Sottara (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: