System.setProperty("drools.dateformat", "dd-mmm-yyyy hh:mm");
java.lang.IllegalArgumentException: Invalid date input format: [36-JUN/2014] it should follow: [dd-MMM-yyyy] at org.drools.core.util.DateUtils.parseDate(DateUtils.java:73) at org.drools.rule.builder.RuleBuilder.buildAttributes(RuleBuilder.java:161) at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:95) at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:2830) at org.drools.compiler.PackageBuilder.compileRules(PackageBuilder.java:970) at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:879) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:871) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40) at com.sample.DrlDateExpires.readKnowledgeBase(DrlDateExpires.java:32) at com.sample.DrlDateExpires.main(DrlDateExpires.java:19)
package com.sample rule "Date Expires InValid" date-expires "06-JUN-2014" when then System.out.println("Rule Fired because Current Date is AFTER date-expires"); end rule "Date Expires Valid" date-expires "06-JUN-2015" when then System.out.println("Rule Fired because Current Date is BEFORE date-expires"); end
DrlDateExpires.java
package com.sample; import org.drools.KnowledgeBase; import org.drools.KnowledgeBaseFactory; import org.drools.builder.KnowledgeBuilder; import org.drools.builder.KnowledgeBuilderError; import org.drools.builder.KnowledgeBuilderErrors; import org.drools.builder.KnowledgeBuilderFactory; import org.drools.builder.ResourceType; import org.drools.io.ResourceFactory; import org.drools.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.StatefulKnowledgeSession; public class DrlDateExpires { public static final void main(String[] args) { try { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test"); ksession.fireAllRules(); logger.close(); } catch (Throwable t) { t.printStackTrace(); } } private static KnowledgeBase readKnowledgeBase() throws Exception { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource("DrlDateExpires.drl"), ResourceType.DRL); KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (errors.size() > 0) { for (KnowledgeBuilderError error: errors) { System.err.println(error); } throw new IllegalArgumentException("Could not parse knowledge."); } KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); return kbase; } }
Rule Fired because Current Date is BEFORE date-expires
good example....
ReplyDelete