use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class TimerAndCalendarTest method buildKnowledgePackage.
private Collection<KiePackage> buildKnowledgePackage(Resource resource, ResourceType resourceType) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(resource, resourceType);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors != null && errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println("Error: " + error.getMessage());
}
Assert.fail("KnowledgeBase did not build");
}
Collection<KiePackage> packages = kbuilder.getKnowledgePackages();
return packages;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class MapPersistenceTest method createPersistentSessionWithRules.
@Test
public void createPersistentSessionWithRules() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
String rule = "package org.drools.persistence.map.impl\n";
rule += "import org.drools.persistence.map.impl.Buddy;\n";
rule += "rule \"echo2\" \n";
rule += "dialect \"mvel\"\n";
rule += "when\n";
rule += " $m : Buddy()\n";
rule += "then\n";
rule += " System.out.println(\"buddy inserted\")";
rule += "end\n";
kbuilder.add(new ByteArrayResource(rule.getBytes()), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors != null && errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
logger.warn("Error: " + error.getMessage());
}
Assert.fail("KnowledgeBase did not build");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createSession(kbase);
FactHandle buddyFactHandle = ksession.insert(new Buddy());
ksession.fireAllRules();
Assert.assertEquals(1, ksession.getObjects().size());
ksession = disposeAndReloadSession(ksession, kbase);
Assert.assertNotNull(ksession);
Assert.assertEquals(1, ksession.getObjects().size());
Assert.assertNull("An object can't be retrieved with a FactHandle from a disposed session", ksession.getObject(buddyFactHandle));
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class CommonTestMethodBase method genSession.
public KieSession genSession(String[] sources, int numerrors) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (String source : sources) kbuilder.add(ResourceFactory.newClassPathResource(source, getClass()), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (kbuilder.getErrors().size() > 0) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.err.println(error);
}
}
assertEquals(numerrors, errors.size());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return createKnowledgeSession(kbase);
}
use of org.kie.internal.builder.KnowledgeBuilderError in project kie-wb-common by kiegroup.
the class BpmnFileIndexer method buildProcessDefinition.
private List<BpmnProcessDataEventListener> buildProcessDefinition(String bpmn2Content, ClassLoader moduleClassLoader) throws IllegalArgumentException {
if (StringUtils.isEmpty(bpmn2Content)) {
return Collections.<BpmnProcessDataEventListener>emptyList();
}
// Set class loader
KnowledgeBuilder kbuilder = null;
if (moduleClassLoader != null) {
KnowledgeBuilderConfigurationImpl pconf = new KnowledgeBuilderConfigurationImpl(moduleClassLoader);
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
} else {
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
}
// Build
kbuilder.add(new ByteArrayResource(bpmn2Content.getBytes()), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
logger.error("Error: {}", error.getMessage());
}
logger.debug("Process Cannot be Parsed! \n {} \n", bpmn2Content);
return Collections.<BpmnProcessDataEventListener>emptyList();
}
// Retrieve ProcessInfoHolder
List<BpmnProcessDataEventListener> processDataList = new ArrayList<>();
kbuilder.getKnowledgePackages().forEach(pkg -> pkg.getProcesses().forEach(p -> {
BpmnProcessDataEventListener processData = (BpmnProcessDataEventListener) p.getMetaData().get(BpmnProcessDataEventListener.NAME);
processDataList.add(processData);
}));
return processDataList;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class JBRULESTest method testJBRULES2872.
@Test
public void testJBRULES2872() {
final String str = "package org.drools.compiler.test\n" + "import org.drools.compiler.FactA\n" + "rule X\n" + "when\n" + " FactA( enumVal == TestEnum.ONE || == TestEnum.TWO )\n" + "then\n" + "end\n";
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
assertEquals(1, errors.size());
final KnowledgeBuilderError error = errors.iterator().next();
assertEquals(5, error.getLines()[0]);
}
Aggregations