use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class WBCommonServicesBackendTest method testAsKieWbCommonServicesBackendBuilder.
@Test
public void testAsKieWbCommonServicesBackendBuilder() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("wbcommonservicesbackend_app.dmn", this.getClass()), ks.getResources().newClassPathResource("wbcommonservicesbackend_route.dmn", this.getClass()));
final KieContainer kieContainer = ks.newKieContainer(v100);
final KieSession kieSession = kieContainer.newKieSession();
final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(2));
checkApp(runtime);
// the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
// exhibit the issue.
final KieSession kieSession2 = kieContainer2.newKieSession();
final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime2);
assertThat(runtime2.getModels(), hasSize(2));
checkApp(runtime2);
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class PMMLRuntimeFactoryInternal method getPMMLFileFromKieContainerByDefaultKieBase.
/**
* Load a <code>File</code> with the given <b>pmmlFileName</b> from the <code>kjar</code> contained in the
* <code>KieContainer</code> with the given <code>ReleaseId</code>
* It will use the <b>default</b> Kiebase defined inside the <b>kmodule.xml</b> of the loaded <b>kjar</b>
* @param pmmlFileName
* @param releaseId
* @return
*/
private static File getPMMLFileFromKieContainerByDefaultKieBase(final String pmmlFileName, final ReleaseId releaseId) {
KieContainerImpl kieContainer = (KieContainerImpl) KIE_SERVICES.newKieContainer(releaseId);
String defaultKieBase = kieContainer.getKieProject().getDefaultKieBaseModel().getName();
return getPMMLFileFromKieContainerByKieBase(pmmlFileName, defaultKieBase, releaseId);
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.
the class PMMLRuntimeFactoryInternal method getPMMLFileFromKieContainerByKieBase.
/**
* Load a <code>File</code> with the given <b>pmmlFileName</b> from the <code>kjar</code> contained in the
* <code>KieContainer</code> with the given <code>ReleaseId</code>
* @param pmmlFileName
* @param kieBase the name of the Kiebase configured inside the <b>kmodule.xml</b> of the loaded <b>kjar</b>
* @param releaseId
* @return
*/
private static File getPMMLFileFromKieContainerByKieBase(final String pmmlFileName, final String kieBase, final ReleaseId releaseId) {
KieContainerImpl kieContainer = (KieContainerImpl) KIE_SERVICES.newKieContainer(releaseId);
InternalResource internalResource = ((InternalKieModule) (kieContainer).getKieModuleForKBase(kieBase)).getResource(pmmlFileName);
try (InputStream inputStream = internalResource.getInputStream()) {
return getPMMLFile(pmmlFileName, inputStream);
} catch (Exception e) {
throw new ExternalException(e);
}
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project kie-wb-common by kiegroup.
the class Builder method getKieContainer.
public KieContainer getKieContainer() {
BuildResults results = null;
// Kie classes are only available once built
if (!isBuilt()) {
results = build();
} else {
results = new BuildResults();
results.addAllBuildMessages(convertMessages(kieBuilder.getResults().getMessages(), handles));
}
// It's impossible to retrieve a KieContainer if the KieModule contains errors
if (results.getErrorMessages().isEmpty()) {
// Do not retrieve the KieContainer with KieServices.newKieContainer(releaseId) since this looks-up the KieModule to
// create the KieContainer from KieRepository. This holds the most recent KieModule (for the ReleaseId) that was built with
// kieBuilder.buildAll() which *may* be a KieModule created during asset validation and hence will lack many assets.
// See https://bugzilla.redhat.com/show_bug.cgi?id=1202551
final org.kie.api.builder.KieModule kieModule = kieBuilder.getKieModule();
final ReleaseId releaseId = kieModule.getReleaseId();
final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieBuilder.getKieModule(), null);
final KieContainer kieContainer = new KieContainerImpl(kieProject, KieServices.Factory.get().getRepository(), releaseId);
return kieContainer;
} else {
return null;
}
}
use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project jbpm by kiegroup.
the class KModuleRegisterableItemsFactory method getWorkItemHandlers.
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
KieSessionModel ksessionModel = null;
if (StringUtils.isEmpty(ksessionName)) {
ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
if (ksessionModel == null) {
ksessionName = DEFAULT_KIE_SESSION;
ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
}
} else {
ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
}
if (ksessionModel == null) {
throw new IllegalStateException("Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml");
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ksession", runtime.getKieSession());
parameters.put("taskService", runtime.getTaskService());
parameters.put("runtimeManager", ((RuntimeEngineImpl) runtime).getManager());
if (getRuntimeManager().getKieContainer() != null) {
parameters.put("kieContainer", getRuntimeManager().getKieContainer());
}
parameters.put("classLoader", getRuntimeManager().getEnvironment().getClassLoader());
try {
InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
} catch (Exception e) {
e.printStackTrace();
// use fallback mechanism
InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
}
return super.getWorkItemHandlers(runtime);
}
Aggregations