use of org.kie.api.builder.model.KieBaseModel 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.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieModuleModelImpl method moveKBase.
/* (non-Javadoc)
* @see org.kie.kModule.KieProject#removeKieBaseModel(org.kie.kModule.KieBaseModel)
*/
public void moveKBase(String oldQName, String newQName) {
Map<String, KieBaseModel> newMap = new HashMap<String, KieBaseModel>();
newMap.putAll(this.kBases);
KieBaseModel kieBaseModel = newMap.remove(oldQName);
newMap.put(newQName, kieBaseModel);
setKBases(newMap);
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieBuilderTest method createKieProject.
public KieModuleModel createKieProject(String namespace) {
KieServices ks = KieServices.Factory.get();
KieModuleModel kProj = ks.newKieModuleModel();
KieBaseModel kBase1 = kProj.newKieBaseModel(namespace).setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
return kProj;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class DroolsAbstractPMMLTest method readKnowledgeBase.
private static KieBase readKnowledgeBase(List<InputStream> theory) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (int j = 0; j < theory.size(); j++) {
Resource res = ks.getResources().newInputStreamResource(theory.get(j));
kfs.write(RESOURCE_PATH + "source_" + j + ".drl", res);
}
KieModuleModel model = ks.newKieModuleModel();
KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
kfs.writeKModuleXML(model.toXML());
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
return kContainer.getKieBase();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class DroolsAbstractPMMLTest method getModelSession.
protected KieSession getModelSession(File fileName) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel model = ks.newKieModuleModel();
model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.CLOUD);
KieBuilder kb = ks.newKieBuilder(fileName);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieBase kieBase = kContainer.getKieBase();
setKbase(kieBase);
return kieBase.newKieSession();
}
Aggregations