I need some advice on how to write a rule for the following case. First, here are my facts:
SessionClock($now : new Date(getCurrentTime()))
ClickEvent( $userId : userId, $productId : productId, $event : "FAVORITE" / "REMOVE_FAVORITE" )
Product($id : id, $endDate : endDate)
Purchase ( $userId : userId, $purchasedProducts : purchasedProducts )
where purchasedProducts
is a List
of:
PurchasedProduct( $id : id, $price : price)
Now I would like to send a notification everytime at a particular hour:
ClickEvent
) andPurchase
) andcollect
products)I appreciate any help on this.
Thanks in advance!
It may be a good idea to do this in steps
rule "interesting user/product"
when
SessionClock( $now: time )
Purchase( $uid: userId, $purchases: purchasedProducts )
ClickEvent( userId == $uid, $pid: productId,
event == "FAVORITE" )
not ClickEvent( userId == $uid, productId == $pid,
event == "REMOVE_FAVORITE" )
Product( id == $pid, $endDate: endDate )
eval( endDateIsToday( $now, $endDate ) )
then
end
rule "make Collection" extends "interesting user/product"
when
not Collection( userId == $uid )
then
insert( new Collection( $uid ) )
end
rule "fill Collection" extends "interesting user/product"
when
$coll: Collection( userId == $uid, products not contains $pid )
then
modify( $coll ){ addProduct( $pid ) }
end
A third rule, running with reduced salience, can do the notification.
Edit To clarify, endDateIsToday
is a (DRL) function or static method. Collection is a class you need to define with a couple of fields: userId and set of product ids.