use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class CommonTestMethodBase method createJar.
public static byte[] createJar(KieServices ks, ReleaseId releaseId, String... drls) {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
for (int i = 0; i < drls.length; i++) {
if (drls[i] != null) {
kfs.write("src/main/resources/r" + i + ".drl", drls[i]);
}
}
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertFalse(kb.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).toString(), kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR));
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class DroolsAbstractPMMLTest method createExecutor.
protected RuleUnitExecutor createExecutor(String sourceName) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
ReleaseId releaseId = new ReleaseIdImpl("org.kie:pmmlTest:1.0-SNAPSHOT");
((KieRepositoryImpl) kr).setDefaultGAV(releaseId);
Resource res = ResourceFactory.newClassPathResource(sourceName);
kbase = new KieHelper().addResource(res, ResourceType.PMML).build();
assertNotNull(kbase);
RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
KieContainer kc = ((KnowledgeBaseImpl) ((InternalRuleUnitExecutor) executor).getKieSession().getKieBase()).getKieContainer();
InternalKieModule ikm = (InternalKieModule) kr.getKieModule(releaseId);
try (FileOutputStream fos = new FileOutputStream("/tmp/outputModule.jar")) {
fos.write(ikm.getBytes());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kc.getKieBaseNames().forEach(n -> {
System.out.println(n);
});
data = executor.newDataSource("request");
resultData = executor.newDataSource("results");
pmmlData = executor.newDataSource("pmmlData");
return executor;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class BaseModelTest method createAndDeployJar.
protected void createAndDeployJar(KieServices ks, KieModuleModel model, ReleaseId releaseId, KieFile... ruleFiles) {
KieBuilder kieBuilder = createKieBuilder(ks, model, releaseId, ruleFiles);
InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModule();
ks.getRepository().addKieModule(kieModule);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class BuildFromKJarTest method test.
@Test
public void test() {
KieServices ks = KieServices.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test", "1.0");
KieRepository repo = ks.getRepository();
repo.removeKieModule(releaseId);
InternalKieModule kmodule = createKieModule(ks, releaseId);
repo.addKieModule(kmodule);
executeSession(ks, releaseId);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieCDIExtension method addKSessionBean.
public void addKSessionBean(AfterBeanDiscovery abd, KieCDIEntry entry) {
ReleaseId releaseId = entry.getReleaseId();
// default to classpath, but allow it to be overriden
KieContainerImpl kieContainer = classpathKContainer;
if (releaseId != null) {
kieContainer = (KieContainerImpl) gavs.get(releaseId);
if (kieContainer == null) {
log.error("Unable to create KSession({}), could not retrieve KieContainer for ReleaseId {}", entry.getValue(), releaseId.toString());
return;
}
}
KieProject kProject = kieContainer.getKieProject();
String kSessionName = entry.getValue();
KieSessionModel kSessionModel = null;
if (StringUtils.isEmpty(kSessionName)) {
kSessionModel = (entry.getType() == KieSession.class) ? kProject.getDefaultKieSession() : kProject.getDefaultStatelessKieSession();
} else {
kSessionModel = kProject.getKieSessionModel(kSessionName);
}
if (kSessionModel == null) {
log.error("Annotation @KSession({}) found, but no KieSessionModel exists.\nEither the required kmodule.xml does not exist, is corrupted, or is missing the KieBase entry", kSessionName);
return;
}
if (kSessionModel.getScope() != null && !kSessionModel.getScope().trim().equals(entry.getScope().getClass().getName())) {
try {
if (kSessionModel.getScope().indexOf('.') >= 0) {
entry.setScope((Class<? extends Annotation>) Class.forName(kSessionModel.getScope()));
} else {
entry.setScope((Class<? extends Annotation>) Class.forName("javax.enterprise.context." + kSessionModel.getScope()));
}
} catch (ClassNotFoundException e) {
log.error("KieBaseModule {} overrides default annotation, but it was not able to find it {}\n{}", new String[] { kSessionName, kSessionModel.getScope(), e.getMessage() });
}
}
if (KieSessionType.STATELESS.equals(kSessionModel.getType())) {
if (log.isDebugEnabled()) {
InternalKieModule kModule = kProject.getKieModuleForKBase(((KieSessionModelImpl) kSessionModel).getKieBaseModel().getName());
log.debug("Added Bean for Stateless @KSession({}) from: {}", kSessionName, kModule);
}
abd.addBean(new StatelessKSessionBean(kSessionModel, kieContainer, entry.getKReleaseId(), entry.getScope(), entry.getName(), entry.getInjectionPoints()));
} else {
InternalKieModule kModule = kProject.getKieModuleForKBase(((KieSessionModelImpl) kSessionModel).getKieBaseModel().getName());
log.debug("Added Bean for Stateful @KSession({}) from: {}", kSessionName, kModule);
abd.addBean(new StatefulKSessionBean(kSessionName, kSessionModel, kieContainer, entry.getKReleaseId(), entry.getScope(), entry.getName(), entry.getInjectionPoints()));
}
}
Aggregations