Ejemplo n.º 1
0
  @Test
  public void testFixedPattern() throws FileNotFoundException {

    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(
        ResourceFactory.newClassPathResource("fixedPattern.xls", getClass()),
        ResourceType.DTABLE,
        dtconf);
    if (kbuilder.hasErrors()) {
      fail(kbuilder.getErrors().toString());
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

    List<Long> list = new ArrayList<Long>();
    ksession.setGlobal("list", list);

    ksession.insert(1L);
    ksession.insert(2);
    ksession.fireAllRules();

    assertEquals(1, list.size());
    assertEquals(1L, (long) list.get(0));

    ksession.dispose();
  }
Ejemplo n.º 2
0
 public static Resource getDecisionTableResourceFromClasspath(
     final String resourceName,
     final Class classLoaderFromClass,
     final DecisionTableInputType type) {
   final Resource dtable =
       KieServices.Factory.get()
           .getResources()
           .newClassPathResource(resourceName, classLoaderFromClass);
   final DecisionTableConfiguration resourceConfig = new DecisionTableConfigurationImpl();
   resourceConfig.setInputType(type);
   dtable.setConfiguration(resourceConfig);
   return dtable;
 }
Ejemplo n.º 3
0
  KieBase loadDecisionTableDirect(String decisionTableResourceName) {
    logDecisionTableAsDrools(decisionTableResourceName);
    KnowledgeBase kieBase = KnowledgeBaseFactory.newKnowledgeBase();

    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);

    KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kBuilder.add(
        ResourceFactory.newClassPathResource("rules/" + decisionTableResourceName),
        ResourceType.DTABLE,
        dtconf);
    validate(kBuilder);

    kieBase.addKnowledgePackages(kBuilder.getKnowledgePackages());
    return kieBase;
  }
Ejemplo n.º 4
0
 private KnowledgeBase readKnowledgeBase(String resource) throws Exception {
   KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
   DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();
   config.setInputType(DecisionTableInputType.XLS);
   kbuilder.add(
       ResourceFactory.newClassPathResource(resource, getClass()), ResourceType.DTABLE, config);
   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;
 }