use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class CalendarTimerResourcesTest method init.
@Before
public void init() {
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
// README when path is set then test works
kfs.write(ks.getResources().newClassPathResource("calendar_timer.xls", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
clock = ksession.getSessionClock();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class BuildFromKJarTest method getDefaultKieModuleModel.
private KieModuleModel getDefaultKieModuleModel(KieServices ks) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
return kproj;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class PMML4Compiler method buildResourcesFromModel.
protected List<PMMLResource> buildResourcesFromModel(PMML pmml, Miningmodel miningModel, List<PMMLResource> resourcesList, ClassLoader classLoader, KieModuleModel module) {
if (resourcesList == null) {
resourcesList = new ArrayList<>();
}
// new PMMLResource(PMML_DROOLS+".mining.model_"+miningModel.getModelId());
PMMLResource resource = new PMMLResource(miningModel.getModelPackageName());
KieBaseModel rootKieBaseModel = module.newKieBaseModel(resource.getPackageName());
rootKieBaseModel.addPackage(resource.getPackageName());
rootKieBaseModel.setDefault(true);
resource.setKieBaseModel(rootKieBaseModel);
resource.addRules(miningModel.getModelId(), miningModel.generateRules());
resourcesList.add(resource);
getChildResources(pmml, miningModel, resourcesList, classLoader, module);
return resourcesList;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class DroolsAbstractPMMLTest method getModelSession.
protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (int j = 0; j < pmmlSources.length; j++) {
Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
kfs.write(res);
}
KieModuleModel model = ks.newKieModuleModel();
model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.CLOUD);
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());
// KieBase kieBase = kContainer.getKieBase("SampleMine_SampleMineSegmentation_SEGMENT_1");
KieBase kieBase = kContainer.getKieBase();
setKbase(kieBase);
return kieBase.newKieSession();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieModuleMavenTest method testKieModuleFromMavenNoDependencies.
@Test
public void testKieModuleFromMavenNoDependencies() throws Exception {
final KieServices ks = new KieServicesImpl() {
@Override
public KieRepository getRepository() {
// override repository to not store the artifact on deploy to trigger load from maven repo
return new KieRepositoryImpl();
}
};
ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJar(ks, releaseId, true, "rule1", "rule2");
String pomText = getPom(releaseId);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
assertNotNull("Default kbase was not found", kbaseModel);
String kbaseName = kbaseModel.getName();
assertEquals("KBase1", kbaseName);
// Check classloader
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources(""));
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test"));
assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test/"));
}
Aggregations