基于Excel的规则已创建但未触发规则

时间:2019-05-14 12:46:59

标签: java drools

我正在创建一个基于excel的规则,并且该规则已创建。但是,当规则被触发时,它不会执行。不确定是否将基于excel的规则注入触发规则。 打印给我提供如下规则的drl字符串

package rule_table;
//generated from Decision Table
import import com.jcl.generated.Jcl;
import java.util.ArrayList;
import com.jcl.generated.Jcl.Job.Parm;
import com.jcl.generated.Jcl.Job;;
// rule values at B10, header at B5
rule "jcl rules test_10"
when
    $jcl : Jcl(jcl.getJob().getJobname() contains  "#")
then
    System.out.println($jcl.getJob().getJobname().length + \"job name 
contains # and length is \")
end

// rule values at B11, header at B5
rule "jcl rules test_11"
when
    jcl.getJob().getJobname().length > 4
then
    System.out.println($jcl.getJob().getJobname().length + \"job name 
 contains # and length is \")
 end

下面是Java类

public class DroolsExcelTest {

public void excelBasedTest() {


    Jcl jcl = new Jcl();

    DroolRuleFileTest droolstest = new DroolRuleFileTest();
    jcl=droolstest.convertXmlToJava();

KieServices kieServices = KieServices.Factory.get();

/*Resource dt 
  = ResourceFactory.newClassPathResource("src/main/resources/rules/DroolsJCL_Rule.xlsx",
      getClass());*/
ClassLoader classLoader = getClass().getClassLoader(); 

Resource dt =  ResourceFactory.newFileResource(classLoader.getResource("DroolsJCLRule.xlsx").getFile());    

DecisionTableProviderImpl decisionTableProvider 
  = new DecisionTableProviderImpl();

String drl = decisionTableProvider.loadFromResource(dt, null);

System.out.println(drl);

KieFileSystem kieFileSystem = kieServices.newKieFileSystem().write(dt);

KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();

KieRepository kieRepository = kieServices.getRepository();


ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId();
KieContainer kieContainer 
  = kieServices.newKieContainer(krDefaultReleaseId);

KieSession kieSession = kieContainer.newKieSession();

FactHandle fact1;

fact1 =kieSession.insert(jcl);
System.out.println("fire the rules");

kieSession.fireAllRules();

System.out.println("fired the rules");

}

}

但是没有触发规则,只是将打印语句显示为触发规则,并且触发了规则。

0 个答案:

没有答案