[rules-users] How to use the xls file as decision table?
I create an xls file as follows, http://drools.46999.n3.nabble.com/file/n3703234/xlsData.jpg how to use this decision table in drools eclipse plugin? thanks in advance. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-the-xls-file-as-decision-table-tp3703234p3703234.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use the xls file as decision table?
Write a java program that loads and use the spreadsheet - in the same way that you use would do so for a DRL file. The eclipse plugin is just an environment to help development and testing, it doesn't actually run anything - Afterall having rules is just half the picture, you also need to insert facts. Thomas -Original Message- From: rules-users-boun...@lists.jboss.org [mailto:rules-users- boun...@lists.jboss.org] On Behalf Of ponmanirajan Sent: 31 January 2012 13:16 To: rules-users@lists.jboss.org Subject: [rules-users] How to use the xls file as decision table? I create an xls file as follows, http://drools.46999.n3.nabble.com/file/n3703234/xlsData.jpg how to use this decision table in drools eclipse plugin? thanks in advance. -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use- the-xls-file-as-decision-table-tp3703234p3703234.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ** This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmas...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00 ** ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] How to use the xls file as decision table?
Please check this code, Edit and reply me. package com.sample; import java.io.StringReader; 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.KnowledgeBuilderError; import org.drools.builder.KnowledgeBuilderErrors; import org.drools.builder.KnowledgeBuilderFactory; import org.drools.builder.ResourceType; import org.drools.compiler.PackageBuilder; import org.drools.io.Resource; import org.drools.io.ResourceFactory; import org.drools.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.rule.Package; import org.drools.runtime.StatefulKnowledgeSession; import org.drools.decisiontable.ExternalSpreadsheetCompiler; import org.drools.decisiontable.InputType; import org.drools.decisiontable.SpreadsheetCompiler; public class DecisionTable { public static void main(String[] args) { try { // load up the knowledge base KnowledgeBase kbase = createKnowledgeBaseFromSpreadsheet(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, test); // go ! Person p=new Person(); p.setAge(23); p.setName(ponmani); ksession.insert(p); ksession.fireAllRules(); logger.close(); } catch (Throwable t) { t.printStackTrace(); } } public static KnowledgeBase createKnowledgeBaseFromSpreadsheet() throws Exception { DecisionTableConfiguration dtconf =KnowledgeBuilderFactory.newDecisionTableConfiguration(); dtconf.setInputType( DecisionTableInputType.XLS ); dtconf.setWorksheetName(Sheet1); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Resource r = ResourceFactory.newUrlResource( file:///D://Auto_Gen_Rules//data.xls); System.out.println(XLS ResouceBuilder...); kbuilder.add(r, ResourceType.DTABLE, dtconf); System.out.println(Loaded Resource File..); if (kbuilder.hasErrors()) { throw new RuntimeException(kbuilder.getErrors().toString()); } KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(); knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages()); return knowledgeBase; } public static class Person { private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } } -- View this message in context: http://drools.46999.n3.nabble.com/How-to-use-the-xls-file-as-decision-table-tp3703234p3703544.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users