use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class DroolsDeclaredTypeSequenceFlowExpressionTest method testDeclaredTypesInSequenceFlowDroolsExpression.
@Test
public void testDeclaredTypesInSequenceFlowDroolsExpression() {
// DROOLS-1327
String drl = "package org.drools.test;" + "declare TestFact \n" + "value: Integer\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
Resource drlResource = new InputStreamResource(new ByteArrayInputStream(drl.getBytes(StandardCharsets.UTF_8)));
Resource bpmn2Resource = new ClassPathResource("BPMN2-DroolsDeclaredTypeSequenceFlowExpressionTest.bpmn2");
ckbuilder.add(drlResource, ResourceType.DRL);
ckbuilder.add(bpmn2Resource, ResourceType.BPMN2);
ckbuilder.build();
// Assert that we don't have any issues in the build.
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors kbErrors = kbuilder.getErrors();
for (KnowledgeBuilderError nextError : kbErrors) {
fail(nextError.getMessage());
}
}
if (kbuilder.hasResults(ResultSeverity.WARNING)) {
KnowledgeBuilderResults kbResults = kbuilder.getResults(ResultSeverity.WARNING);
for (KnowledgeBuilderResult nextResult : kbResults) {
fail(nextResult.getMessage());
}
}
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class BPMN2DataServiceImpl method buildProcessDefinition.
@Override
public ProcessDefinition buildProcessDefinition(String deploymentId, String bpmn2Content, KieContainer kieContainer, boolean cache) throws IllegalArgumentException {
if (StringUtils.isEmpty(bpmn2Content)) {
return null;
}
KnowledgeBuilder kbuilder = null;
if (kieContainer != null && kieContainer.getClassLoader() != null) {
KnowledgeBuilderConfigurationImpl pconf = new KnowledgeBuilderConfigurationImpl(kieContainer.getClassLoader());
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
} else {
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
}
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 null;
}
KiePackage pckg = kbuilder.getKnowledgePackages().iterator().next();
Process process = pckg.getProcesses().iterator().next();
ProcessDescriptor helper = (ProcessDescriptor) process.getMetaData().get("ProcessDescriptor");
ProcessAssetDesc definition = fillProcessDefinition(helper, kieContainer);
// cache the data if requested
if (cache) {
validateNonEmptyDeploymentIdAndProcessId(deploymentId, "no proc id");
Map<String, ProcessDescriptor> definitions = null;
synchronized (definitionCache) {
Map<String, ProcessDescriptor> newDef = new ConcurrentHashMap<String, ProcessDescriptor>();
definitions = definitionCache.putIfAbsent(deploymentId, newDef);
if (definitions == null) {
definitions = newDef;
}
definitions.put(process.getId(), helper);
}
}
return definition;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class ProcessSplitTest method testSplitWithProcessInstanceConstraint2.
@Test
public void testSplitWithProcessInstanceConstraint2() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Reader source = new StringReader("<process xmlns=\"http://drools.org/drools-5.0/process\"" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"org.jbpm.process-split\" package-name=\"org.jbpm\" >" + "" + " <header>" + " <imports>" + " <import name=\"org.jbpm.integrationtests.test.Person\" />" + " <import name=\"org.kie.api.runtime.process.WorkflowProcessInstance\" />" + " </imports>" + " <globals>" + " <global identifier=\"list\" type=\"java.util.List\" />" + " </globals>" + " <variables>\n" + " <variable name=\"name\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " </variables>\n" + " </header>" + "" + " <nodes>" + " <actionNode id=\"2\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >insert(kcontext.getProcessInstance());</action>" + " </actionNode>" + " <split id=\"4\" name=\"Split\" type=\"2\" >" + " <constraints>" + " <constraint toNodeId=\"8\" toType=\"DROOLS_DEFAULT\" priority=\"2\" type=\"rule\" dialect=\"mvel\" >eval(true)</constraint>" + " <constraint toNodeId=\"6\" toType=\"DROOLS_DEFAULT\" name=\"constraint\" priority=\"1\" type=\"rule\" dialect=\"mvel\" >processInstance: WorkflowProcessInstance()" + "Person( name == ( processInstance.getVariable(\"name\") ) )</constraint>" + " </constraints>" + " </split>" + " <end id=\"8\" name=\"End\" />" + " <actionNode id=\"6\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >list.add(kcontext.getProcessInstance().getId());</action>" + " </actionNode>" + " <start id=\"1\" name=\"Start\" />" + " <end id=\"3\" name=\"End\" />" + " </nodes>" + " <connections>" + " <connection from=\"1\" to=\"2\" />" + " <connection from=\"2\" to=\"4\" />" + " <connection from=\"4\" to=\"8\" />" + " <connection from=\"4\" to=\"6\" />" + " <connection from=\"6\" to=\"3\" />" + " </connections>" + "" + "</process>");
kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
logger.error(error.toString());
}
Collection<KiePackage> kpkgs = kbuilder.getKnowledgePackages();
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kpkgs);
KieSession ksession = kbase.newKieSession();
List<Long> list = new ArrayList<Long>();
ksession.setGlobal("list", list);
Person john = new Person("John Doe", 20);
Person jane = new Person("Jane Doe", 20);
Person julie = new Person("Julie Doe", 20);
ksession.insert(john);
ksession.insert(jane);
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", john.getName());
ProcessInstance processInstance1 = ksession.startProcess("org.jbpm.process-split", params);
params = new HashMap<String, Object>();
params.put("name", jane.getName());
ProcessInstance processInstance2 = ksession.startProcess("org.jbpm.process-split", params);
params = new HashMap<String, Object>();
params.put("name", julie.getName());
ProcessInstance processInstance3 = ksession.startProcess("org.jbpm.process-split", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance1.getState());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance2.getState());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance3.getState());
assertEquals(2, list.size());
}
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