0

I am trying to call Drools Json api and one of my facts is of type Date. I am not sure how to construct the json string for that. !!!!????????? :(

here is what I have:

my drl file: package com.beachmint.common

declare Order orderId: Integer customerId: Integer total: java.math.BigDecimal cartId: Integer createdAt: java.util.Date productIds: java.util.ArrayList end

declare Customer customerId: Integer referrerId: Integer customerStatus: Integer createdAt: java.util.Date end

declare Points status: String count: Integer customerId: Integer reason: String ruleId: String end

declare Event name: String storeId: Integer end

rule 'Purchase Promo' dialect "mvel" when e : Event( name matches "Purchase" ) o : Order( total > 0 , createdAt > "08-Oct-2012" , createdAt <= "01-Jan-2013" )

then p.setCount( p.getCount() + 2000 );

I tried sending the date as UTC and string ('y-M-d) format.

createdAt":{"date":"2012-Jan-01"} createdAt": 1351637683 createdAt": "2012-Jan-01"

none of these work :(

1 Answers1

0

You can either use the default date format or, change it using drools.dateformat system property. See the manual.

4.8.3.3.7.1. Date literal

The date format dd-mmm-yyyy is supported by default. You can customize this by providing an alternative date format mask as the System property named drools.dateformat. If more control is required, use a restriction.

Example 4.36. Date Literal Restriction

Cheese( bestBefore < "27-Oct-2009" )

ali köksal
  • 1,217
  • 1
  • 12
  • 19
  • yes I tried that but in the json request when I passed the date as a string ("27-Oct-2009") the rule engine fails since it's expecting a Date object. and I don't know how I can trick the drools to expect that as a Date object. I am using JSON api in PHP – Faraz Zahabian Oct 30 '12 at 22:58
  • A workaround would be adding another String attribute to your objects that keeps the date in String format, and writing a conversion rule that fires when your date attribute is null and converts string value to date. – ali köksal Oct 31 '12 at 00:29