org.drools.examples.PricingRuleDTExample Maven / Gradle / Ivy
The newest version!
package org.drools.examples;
import java.util.Arrays;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.DecisionTableConfiguration;
import org.drools.builder.DecisionTableInputType;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.examples.decisiontable.Driver;
import org.drools.examples.decisiontable.Policy;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatelessKnowledgeSession;
/**
* This shows off a decision table.
*/
public class PricingRuleDTExample {
public static final void main(String[] args) throws Exception {
PricingRuleDTExample launcher = new PricingRuleDTExample();
launcher.executeExample();
}
public int executeExample() throws Exception {
DecisionTableConfiguration dtableconfiguration = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtableconfiguration.setInputType( DecisionTableInputType.XLS );
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "ExamplePolicyPricing.xls",
getClass() ),
ResourceType.DTABLE,
dtableconfiguration );
if ( kbuilder.hasErrors() ) {
System.err.print( kbuilder.getErrors() );
return -1;
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
// typical decision tables are used statelessly
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
//now create some test data
Driver driver = new Driver();
Policy policy = new Policy();
ksession.execute( Arrays.asList( new Object[]{driver, policy} ) );
System.out.println( "BASE PRICE IS: " + policy.getBasePrice() );
System.out.println( "DISCOUNT IS: " + policy.getDiscountPercent() );
return policy.getBasePrice();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy