[rules-users] How to check if a property IS null ?

Hendy Irawan hendy at soluvas.com
Wed Aug 15 13:29:59 EDT 2012


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 :

package com.hendyirawan.droolsnull
dialect "mvel"

import org.slf4j.*;

import com.hendyirawan.droolsnull.*;

global Logger log;
global BookingService bookingService;

rule "Booking data with not null qty exists"
	when
		$booking      : Booking( $qty : qty != null )
	then
		log.info("You've got a filled booking with qty {}", {$qty});
end

rule "Booking data with null qty exists" 
	when
		$booking      : Booking( qty == null )
	then
		log.info("You've got a NULL booking");
end

rule "BookingService can return null qty" 
	when
		Double( this == null ) from bookingService.getNullQty()
	then
		log.info("BookingService can return NULL qty");
end

rule "BookingService can return filled qty" 
	when
		$qty      : Double() from bookingService.getFilledQty()
	then
		log.info("BookingService can return filled qty: {}", {$qty});
end

rule "Notify has null sentTime" 
	when
		$notify		: Notify( sentTime == null )
	then
		log.info("Notify has NULL sentTime");
end

rule "Notify has filled sentTime" 
	when
		$notify		: Notify( $sentTime : sentTime != null )
	then
		log.info("Notify has filled sentTime: {}", {$sentTime});
end

The rule that isn't working :

rule "BookingService can return null qty" 
	when
		Double( this == null ) from bookingService.getNullQty()
	then
		log.info("BookingService can return NULL qty");
end

Thank you.

Hendy


(I also once had a criteria like " $notify		: Notify( sentTime == null ) "
not working but can't reproduce it again yet. if I can find it I'll post
again)



--
View this message in context: http://drools.46999.n3.nabble.com/How-to-check-if-a-property-IS-null-tp4019014p4019150.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list