Search in sources :

Example 11 with DroolsError

use of org.drools.drl.parser.DroolsError in project drools by kiegroup.

the class PackageBuilderErrors method readExternal.

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    SerializableDroolsError[] temp = (SerializableDroolsError[]) in.readObject();
    this.errors = temp;
    for (DroolsError error : temp) {
        add(error);
    }
}
Also used : DroolsError(org.drools.drl.parser.DroolsError)

Example 12 with DroolsError

use of org.drools.drl.parser.DroolsError in project drools by kiegroup.

the class RuleBuilder method registerError.

private static void registerError(String error, RuleImpl rule, RuleBuildContext context) {
    DroolsError err = new RuleBuildError(rule, context.getParentDescr(), null, error);
    context.addError(err);
}
Also used : DroolsError(org.drools.drl.parser.DroolsError) RuleBuildError(org.drools.compiler.compiler.RuleBuildError)

Example 13 with DroolsError

use of org.drools.drl.parser.DroolsError in project drools by kiegroup.

the class DRLDumperTest method testDumpers.

@Test
public void testDumpers() throws Exception {
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    final Resource resource = new InputStreamResource(getClass().getResourceAsStream("drl/test_Dumpers.drl"));
    final PackageDescr pkg = parser.parse(resource);
    if (parser.hasErrors()) {
        for (final DroolsError error : parser.getErrors()) {
            logger.warn(error.toString());
        }
        fail(parser.getErrors().toString());
    }
    final Resource descrResource = KieServices.Factory.get().getResources().newDescrResource(pkg);
    descrResource.setSourcePath(TestConstants.TEST_RESOURCES_FOLDER + "test_Dumpers.descr");
    KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, descrResource);
    KieSession ksession = kbase.newKieSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Cheese brie = new Cheese("brie", 12);
    ksession.insert(brie);
    ksession.fireAllRules();
    assertEquals(3, list.size());
    assertEquals("3 1", list.get(0));
    assertEquals("MAIN", list.get(1));
    assertEquals("1 1", list.get(2));
    // ---------------------------
    final DrlDumper drlDumper = new DrlDumper();
    final String drlResult = drlDumper.dump(pkg);
    System.out.println(drlResult);
    kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drlResult);
    ksession = kbase.newKieSession();
    list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(brie);
    ksession.fireAllRules();
    assertEquals(3, list.size());
    assertEquals("3 1", list.get(0));
    assertEquals("MAIN", list.get(1));
    assertEquals("1 1", list.get(2));
}
Also used : DroolsError(org.drools.drl.parser.DroolsError) KieBase(org.kie.api.KieBase) InputStreamResource(org.drools.core.io.impl.InputStreamResource) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) DrlParser(org.drools.drl.parser.DrlParser) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Cheese(org.drools.mvel.compiler.Cheese) PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) InputStreamResource(org.drools.core.io.impl.InputStreamResource) Test(org.junit.Test)

Aggregations

DroolsError (org.drools.drl.parser.DroolsError)13 RuleBuildError (org.drools.compiler.compiler.RuleBuildError)5 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IOException (java.io.IOException)2 DescrResource (org.drools.core.io.impl.DescrResource)2 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)2 PackageDescr (org.drools.drl.ast.descr.PackageDescr)2 RuleDescr (org.drools.drl.ast.descr.RuleDescr)2 Resource (org.kie.api.io.Resource)2 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1