Wolfgang,
I have enclosed the template. For debugging purpose, I have removed all but
one rule.
Thanks,
Roger
- O -
template header
summerOnPeakPrimaryRate
summerOnPeakSecondaryRate
summerSemiPeakPrimaryRate
summerSemiPeakSecondaryRate
summerOffPeakPrimaryRate
summerOffPeakSecondaryRate
winterOnPeakPrimaryRate
winterOnPeakSecondaryRate
winterSemiPeakPrimaryRate
winterSemiPeakSecondaryRate
winterOffPeakPrimaryRate
winterOffPeakSecondaryRate
package tradex.contract.sde
import tradex.process.ruler.server.ContractRule
rule "holiday july 4th"
when
$r : ContractRule( year == 2010 && month == 7 && day == 4 &&
holiday ==
false)
then
modify($r){
setHoliday(true)
}
end
rule "holiday xmas"
when
$r : ContractRule( year == 2010 && month == 12 && day == 25 &&
holiday ==
false)
then
modify($r){
setHoliday(true)
}
end
rule "Season summer"
when
$r : ContractRule( dayOfYear >= 121 && dayOfYear <= 273 && season
==
"undefined")
then
modify($r){
setSeason("summer")
}
end
rule "Season winter"
when
$r : ContractRule( (dayOfYear >= 274 || dayOfYear <= 120) && season ==
"undefined")
then
modify($r){
setSeason("winter")
}
end
rule "On peak hour"
when
$r : ContractRule( holiday == false && dayOfWeek >= 1 && dayOfWeek
<= 6
&& hourOfDay >= 1400 && hourOfDay <= 2000 &&
hourType == "undefined")
then
modify($r){
setHourType("onPeak")
}
end
rule "Semi peak hour"
when
$r : ContractRule( holiday == false && dayOfWeek >= 1 && dayOfWeek
<= 6
&& (hourOfDay >= 600 && hourOfDay < 1400 ||
hourOfDay > 2000 && hourOfDay <= 2200) && hourType ==
"undefined")
then
modify($r){
setHourType("semiPeak")
}
end
rule "Off peak hour"
when
$r : ContractRule( (holiday == true || dayOfWeek == 7 || hourOfDay < 600
|| hourOfDay > 2200) && hourType == "undefined" )
then
modify($r){
setHourType("offPeak")
}
end
template contract_rate
rule "Summer on peak primary rate"
when
$r : ContractRule( season == "summer" && hourType ==
"onPeak" && type ==
"primary")
then
$r.setRate(@{summerOnPeakPrimaryRate});
end
end template
2010/11/9 Wolfgang Laun <wolfgang.laun(a)gmail.com>
Seeing the template .drl would help to resolve this. Are all
@{parameter}s
declared in the template header?
-W
2010/11/9 Roger Smith <rogersmith1711(a)gmail.com>
>
> All -
>
> I tried out Drools rule template with a with a proptotype app. Drools is
> throwing NullPointerException as below. I would much appreciate if someone
> on this list can help.
>
> java.lang.NullPointerException
> at
>
org.drools.template.parser.DefaultTemplateColumn.createCellCondition(DefaultTemplateColumn.java:68)
> at
>
org.drools.template.parser.DefaultTemplateColumn.addCondition(DefaultTemplateColumn.java:91)
> at
>
org.drools.template.parser.DefaultTemplateRuleBase.createColumnConditions(DefaultTemplateRuleBase.java:105)
> at
>
org.drools.template.parser.DefaultTemplateRuleBase.createTemplateRule(DefaultTemplateRuleBase.java:98)
> at
>
org.drools.template.parser.DefaultTemplateRuleBase.getDTRules(DefaultTemplateRuleBase.java:85)
> at
>
org.drools.template.parser.DefaultTemplateRuleBase.<init>(DefaultTemplateRuleBase.java:64)
> at
>
org.drools.template.parser.TemplateDataListener.<init>(TemplateDataListener.java:76)
> at
>
org.drools.template.parser.TemplateDataListener.<init>(TemplateDataListener.java:52)
> at
> org.drools.template.ObjectDataCompiler.compile(ObjectDataCompiler.java:44)
>
>
> Here is my code
>
> KnowledgeBuilder kBuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
> ObjectDataCompiler converter = new ObjectDataCompiler();
> InputStream dis = new FileInputStream( new File(
> "/home/pranab/Projects/gridx/ct11_1.drl" ) );
> if (null == dis){
> System.out.println("null rule template stream");
> return;
> }
>
> Collection<Map<String,Object>> paramMaps = new
> ArrayList<Map<String,Object>>();
>
> Map<String,Object> params = new HashMap<String,Object>();
>
> params.put("summerOnPeakPrimaryRate", new Integer(299));
> params.put("summerOnPeakSecondaryRate", new Integer(524));
> params.put("summerSemiPeakPrimaryRate", new Integer(176));
> params.put("summerSemiPeakSecondaryRate", new Integer(305));
> params.put("summerOffPeakPrimaryRate", new Integer(139));
> params.put("summerOffPeakSecondaryRate", new Integer(243));
> params.put("winterOnPeakPrimaryRate", new Integer(249));
> params.put("winterOnPeakSecondaryRate", new Integer(438));
> params.put("winterSemiPeakPrimaryRate", new Integer(176));
> params.put("winterSemiPeakSecondaryRate", new Integer(305));
> params.put("winterOffPeakPrimaryRate", new Integer(139));
> params.put("winterOffPeakSecondaryRate", new Integer(243));
> paramMaps.add(params);
>
> String drl = converter.compile(paramMaps, dis);
> Reader rdr = new StringReader( drl );
> kBuilder.add( ResourceFactory.newReaderResource(rdr),
> ResourceType.DRL);
>
>
> The line in blue is throwing the exception. This code is very similar to
> the example code in Drools Expert guide.
>
> Best,
>
> Roger
>
>
>
> _______________________________________________
> rules-users mailing list
>
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users