use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class KieBuilderSetImpl method buildChanges.
private IncrementalResults buildChanges(Collection<String> filesToBuild) {
Map<String, Collection<KnowledgeBuilderError>> currentErrors = new HashMap<String, Collection<KnowledgeBuilderError>>();
InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModuleIgnoringErrors();
for (KieBaseModel kBaseModel : kieModule.getKieModuleModel().getKieBaseModels().values()) {
KnowledgeBuilder kBuilder = kieModule.getKnowledgeBuilderForKieBase(kBaseModel.getName());
if (kBuilder == null) {
continue;
}
CompositeKnowledgeBuilder ckbuilder = kBuilder.batch();
KnowledgeBuilderImpl.ResourceRemovalResult removalResult = new KnowledgeBuilderImpl.ResourceRemovalResult();
KnowledgeBuilderImpl pkgBuilder = ((KnowledgeBuilderImpl) kBuilder);
Set<String> wrongResources = resourcesWithErrors.get(kBaseModel.getName());
for (String resourceName : wrongResources) {
removalResult.add(pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)));
removalResult.mergeModified(addResource(ckbuilder, kBaseModel, kieModule, resourceName));
}
for (String file : filesToBuild) {
if (wrongResources.contains(file)) {
removalResult.mergeModified(true);
} else {
// remove the objects generated by the old Resource
removalResult.add(pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(file)));
// add the modified Resource
removalResult.mergeModified(addResource(ckbuilder, kBaseModel, kieModule, file));
}
}
if (removalResult.isModified()) {
if (!removalResult.getRemovedTypes().isEmpty()) {
ProjectClassLoader projectClassLoader = (ProjectClassLoader) ((KnowledgeBuilderImpl) kBuilder).getRootClassLoader();
projectClassLoader.reinitTypes();
for (String removedType : removalResult.getRemovedTypes()) {
projectClassLoader.undefineClass(removedType);
}
}
ckbuilder.build();
resourcesWithErrors.put(kBaseModel.getName(), findResourcesWithErrors(kBuilder));
if (kBuilder.hasErrors()) {
currentErrors.put(kBaseModel.getName(), kBuilder.getErrors());
kBuilder.undo();
} else {
KieServices.Factory.get().getRepository().addKieModule(kieModule);
kieBuilder.updateKieModuleMetaInfo();
}
}
}
IncrementalResultsImpl results = getIncrementalResults(currentErrors);
previousErrors = currentErrors;
return results;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project drools by kiegroup.
the class SpreadsheetCompilerUnitTest method readKnowledgeBase.
private KieBase 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.");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class MemoryLeakTest method createKnowledgeBase.
private KieBase createKnowledgeBase() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("memory/BPMN2-RuleTaskWithInsertProcessInstance.bpmn2"), ResourceType.BPMN2);
kbuilder.add(ResourceFactory.newClassPathResource("memory/ProcessInstanceRule.drl"), ResourceType.DRL);
if (!kbuilder.getErrors().isEmpty()) {
Iterator<KnowledgeBuilderError> errIter = kbuilder.getErrors().iterator();
while (errIter.hasNext()) {
KnowledgeBuilderError err = errIter.next();
StringBuilder lines = new StringBuilder("");
if (err.getLines().length > 0) {
lines.append(err.getLines()[0]);
for (int i = 1; i < err.getLines().length; ++i) {
lines.append(", " + err.getLines()[i]);
}
}
logger.warn(err.getMessage() + " (" + lines.toString() + ")");
}
throw new IllegalArgumentException("Errors while parsing knowledge base");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class PersistentStatefulSessionTest method testPersistenceVariables.
@Test
public void testPersistenceVariables() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("VariablesProcess.rf"), ResourceType.DRF);
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
logger.debug(error.toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
long id = ksession.getIdentifier();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("name", "John Doe");
ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess", parameters);
TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("John Doe", workItem.getParameter("name"));
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("John Doe", workItem.getParameter("text"));
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
workItem = handler.getWorkItem();
assertNull(workItem);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.internal.builder.KnowledgeBuilderError in project jbpm by kiegroup.
the class HumanTaskResolver method createKBuilder.
private KnowledgeBuilder createKBuilder(String resource, ResourceType resourceType) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(resource), resourceType);
if (kbuilder.hasErrors()) {
int errors = kbuilder.getErrors().size();
if (errors > 0) {
System.out.println("Found " + errors + " errors");
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.out.println(error.getMessage());
}
}
throw new IllegalArgumentException("Application process definition has errors, see log for more details");
}
return kbuilder;
}
Aggregations