Hendy Irawan | 3 Aug 2012 13:05
Gravatar

How to check if a property IS null ?

I'm trying to check if property is null, but the rule is never fired :

Sample :

rule "Cancel"
    when
        $action				: CancelProductBookingDetail( created == null ) 
    then

end

(created is of type java.util.Date)

Any help is appreciated.

Hendy

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Wolfgang Laun | 3 Aug 2012 14:22
Picon

Re: How to check if a property IS null ?

Works for me.

You'll have to provide a *complete* example, Java and DRL to reproduce
the effect you are describing.

-W

On 03/08/2012, Hendy Irawan <hendy <at> soluvas.com> wrote:
> I'm trying to check if property is null, but the rule is never fired :
>
> Sample :
>
> rule "Cancel"
>     when
>         $action				: CancelProductBookingDetail( created == null )
>     then
>
> end
>
> (created is of type java.util.Date)
>
> Any help is appreciated.
>
> Hendy
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014.html
(Continue reading)

Hendy Irawan | 15 Aug 2012 19:29
Gravatar

Re: How to check if a property IS null ?

Thank you.

Here's a very simple use case : https://github.com/ceefour/droolsnull

Running this on Drools 5.4.0 will output:

00:29:34.122 [main] INFO  c.h.droolsnull.BookingService - getNullQty()
called!
00:29:34.125 [main] INFO  c.h.droolsnull.BookingService - getFilledQty()
called!
00:29:34.139 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - Notify has
filled sentTime: Thu Aug 16 00:29:34 WIT 2012
00:29:34.139 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - Notify has
NULL sentTime
00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - You've got a
filled booking with qty 5.0
00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - You've got a
NULL booking
00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull -
BookingService can return filled qty: 10.0

Expected is one more:

BookingService can return NULL qty

BookingService.getNullQty() is called by the Drools rule but then ignored.
How to capture this?

The rules :

(Continue reading)

Wolfgang Laun | 15 Aug 2012 20:01
Picon

Re: How to check if a property IS null ?

Using a Java condition like "this == null" is a slip of the keyboard.
-W

On 15/08/2012, Hendy Irawan <hendy <at> soluvas.com> wrote:
> Thank you.
>
> Here's a very simple use case : https://github.com/ceefour/droolsnull
>
> Running this on Drools 5.4.0 will output:
>
> 00:29:34.122 [main] INFO  c.h.droolsnull.BookingService - getNullQty()
> called!
> 00:29:34.125 [main] INFO  c.h.droolsnull.BookingService - getFilledQty()
> called!
> 00:29:34.139 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - Notify has
> filled sentTime: Thu Aug 16 00:29:34 WIT 2012
> 00:29:34.139 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - Notify has
> NULL sentTime
> 00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - You've got
> a
> filled booking with qty 5.0
> 00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull - You've got
> a
> NULL booking
> 00:29:34.140 [main] INFO  c.hendyirawan.droolsnull.DroolsNull -
> BookingService can return filled qty: 10.0
>
> Expected is one more:
>
> BookingService can return NULL qty
(Continue reading)

Hendy Irawan | 15 Aug 2012 20:54
Gravatar

Re: How to check if a property IS null ?

Thank you.

"this == null" is weird indeed in Java, but I honestly don't know how to
express this expression in Drools DSL.

A more realistic rule would be:

when 
    $product : Product( )
    Double( this == null ) from bookingService.getQty( $product ) 

So what I want to do is detect when a method call returns null. The method
call can contain parameters but it can be a simple method like before.

How to do this?

Thank you.

Hendy

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014p4019155.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Michael Anstis | 15 Aug 2012 21:01
Picon
Gravatar

Re: How to check if a property IS null ?

Hi,

I assume you mean Drools DRL (DSL is something different and none of your examples suggest use of this so far).

How about checking for the absence of the Double instead of it being null:-

when
    $product : Product( )
    not Double( ) from bookingService.getQty( $product )

I've not tried it personally.

With kind regards,

Mike

On 15 August 2012 19:54, Hendy Irawan <hendy <at> soluvas.com> wrote:
Thank you.

"this == null" is weird indeed in Java, but I honestly don't know how to
express this expression in Drools DSL.

A more realistic rule would be:

when
    $product : Product( )
    Double( this == null ) from bookingService.getQty( $product )

So what I want to do is detect when a method call returns null. The method
call can contain parameters but it can be a simple method like before.

How to do this?

Thank you.

Hendy



--
View this message in context: http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014p4019155.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
Hendy Irawan | 15 Aug 2012 21:11
Gravatar

Re: How to check if a property IS null ?

Thank you Mike for the correction, yes I meant the DRL.


And your suggestion works! Thank you!

I'll update my toy project at https://github.com/ceefour/droolsnull :)

Thanks a lot!

Hendy

On Thu, Aug 16, 2012 at 2:04 AM, manstis [via Drools] <[hidden email]> wrote:
Hi,

I assume you mean Drools DRL (DSL is something different and none of your examples suggest use of this so far).

How about checking for the absence of the Double instead of it being null:-

when
    $product : Product( )
    not Double( ) from bookingService.getQty( $product )

I've not tried it personally.

With kind regards,

Mike

--
Hendy Irawan - on Twitter - on LinkedIn
Web Developer | Bippo Indonesia | Akselerator Bisnis | Bandung


View this message in context: Re: [rules-users] How to check if a property IS null ?
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun | 16 Aug 2012 10:32
Picon

Re: How to check if a property IS null ?

"this" in DRL is just like "this" in Java.

"this == null" is just another way of saying "false".

-W

On 15/08/2012, Hendy Irawan <hendy <at> soluvas.com> wrote:
> Thank you.
>
> "this == null" is weird indeed in Java, but I honestly don't know how to
> express this expression in Drools DSL.
>
> A more realistic rule would be:
>
> when
>     $product : Product( )
>     Double( this == null ) from bookingService.getQty( $product )
>
> So what I want to do is detect when a method call returns null. The method
> call can contain parameters but it can be a simple method like before.
>
> How to do this?
>
> Thank you.
>
> Hendy
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014p4019155.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users <at> lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users <at> lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Gmane