use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class DynamicEvalTest method loadPackages.
public void loadPackages(Resource res, ResourceType type) {
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(res, type);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class VerifierKnowledgeBaseBuilder method newVerifierKnowledgeBase.
public KieBase newVerifierKnowledgeBase(VerifierConfiguration configuration) {
InternalKnowledgeBase verifierKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilderConfiguration kbuilderConfiguration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbuilderConfiguration.setProperty("drools.dialect.java.compiler", "JANINO");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConfiguration);
if (configuration.getVerifyingResources() != null) {
for (Resource resource : configuration.getVerifyingResources().keySet()) {
kbuilder.add(resource, configuration.getVerifyingResources().get(resource));
}
}
if (kbuilder.hasErrors()) {
Iterator<KnowledgeBuilderError> errors = kbuilder.getErrors().iterator();
while (errors.hasNext()) {
this.errors.add(new VerifierError("Error compiling verifier rules: " + errors.next().getMessage()));
}
}
verifierKnowledgeBase.addPackages(kbuilder.getKnowledgePackages());
return verifierKnowledgeBase;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class VariablePersistenceStrategyTest method createKnowledgeBase.
private KieBase createKnowledgeBase(String flowFile) {
KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
conf.setProperty("drools.dialect.java.compiler", "JANINO");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
kbuilder.add(new ClassPathResource(flowFile), ResourceType.DRF);
if (kbuilder.hasErrors()) {
StringBuilder errorMessage = new StringBuilder();
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
errorMessage.append(error.getMessage());
errorMessage.append(System.getProperty("line.separator"));
}
fail(errorMessage.toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class SimpleRuntimeEnvironment method addAsset.
/**
* Adds given asset to knowledge builder to produce KieBase
* @param resource asset to be added
* @param type type of the asset
*/
public void addAsset(Resource resource, ResourceType type) {
/**
* The code below (CSV/XLS) was added because of timelines related to switchyard/fuse.
*
* However, it is an ugly hack: As soon as is possible, the code below should be removed or refactored.
* - an "addAsset(Resource, ResourceType, ResourceConfiguration)" method should be added to this implementation
* - or the kbuilder code should be refactored so that there are two ResourceTypes: CSV and XLS
*
* (refactoring the kbuilder code is probably a better idea.)
*/
boolean replaced = false;
if (resource.getSourcePath() != null) {
String path = resource.getSourcePath();
String typeStr = null;
if (path.toLowerCase().endsWith(".csv")) {
typeStr = DecisionTableInputType.CSV.toString();
} else if (path.toLowerCase().endsWith(".xls")) {
typeStr = DecisionTableInputType.XLS.toString();
}
if (typeStr != null) {
String worksheetName = null;
boolean replaceConfig = true;
ResourceConfiguration config = resource.getConfiguration();
if (config != null && config instanceof DecisionTableConfiguration) {
DecisionTableInputType realType = DecisionTableInputType.valueOf(typeStr);
if (((DecisionTableConfiguration) config).getInputType().equals(realType)) {
replaceConfig = false;
} else {
worksheetName = ((DecisionTableConfiguration) config).getWorksheetName();
}
}
if (replaceConfig) {
Properties prop = new Properties();
prop.setProperty(ResourceTypeImpl.KIE_RESOURCE_CONF_CLASS, DecisionTableConfigurationImpl.class.getName());
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_TYPE, typeStr);
if (worksheetName != null) {
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, worksheetName);
}
ResourceConfiguration conf = ResourceTypeImpl.fromProperties(prop);
this.kbuilder.add(resource, type, conf);
replaced = true;
}
}
}
if (!replaced) {
this.kbuilder.add(resource, type);
}
if (this.kbuilder.hasErrors()) {
StringBuffer errorMessage = new StringBuffer();
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
errorMessage.append(error.getMessage() + ",");
}
this.kbuilder.undo();
throw new IllegalArgumentException("Cannot add asset: " + errorMessage.toString());
}
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testCallActivity.
@Test
public void testCallActivity() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2);
kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2);
if (!kbuilder.getErrors().isEmpty()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
logger.error("{}", error);
}
throw new IllegalArgumentException("Errors while parsing knowledge base");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(((WorkflowProcessInstance) processInstance).getVariable("y")).isEqualTo("new value");
}
Aggregations