use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class PricingRuleDTExample method execute.
public static void execute(KieContainer kc) {
StatelessKieSession ksession = kc.newStatelessKieSession("DecisionTableKS");
// now create some test data
Driver driver = new Driver();
Policy policy = new Policy();
ksession.execute(Arrays.asList(new Object[] { driver, policy }));
System.out.println("BASE PRICE IS: " + policy.getBasePrice());
System.out.println("DISCOUNT IS: " + policy.getDiscountPercent());
policy.getBasePrice();
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class ScoringStrategiesTest method executeAndFetchScore.
/* Internal functions */
private double executeAndFetchScore(String sheetName) throws Exception {
ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
InputStream inputStream = PMMLDocumentTest.class.getResourceAsStream("/scoremodel_scoring_strategies.xls");
boolean compileResult = scorecardCompiler.compileFromExcel(inputStream, sheetName);
if (!compileResult) {
for (ScorecardError error : scorecardCompiler.getScorecardParseErrors()) {
System.err.println("Scorecard Compiler Error :" + error.getErrorLocation() + "->" + error.getErrorMessage());
}
return -999999;
}
String drl = scorecardCompiler.getDRL();
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ks.getResources().newByteArrayResource(drl.getBytes()).setSourcePath("scoremodel_scoring_strategies.drl").setResourceType(ResourceType.DRL));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
Results res = kieBuilder.buildAll().getResults();
if (res.hasMessages(Message.Level.ERROR)) {
System.out.println(res.getMessages());
}
assertEquals(0, res.getMessages(Message.Level.ERROR).size());
KieContainer kieContainer = ks.newKieContainer(kieBuilder.getKieModule().getReleaseId());
KieBase kbase = kieContainer.getKieBase();
StatelessKieSession session = kbase.newStatelessKieSession();
FactType scorecardType = kbase.getFactType("org.drools.scorecards.example", "SampleScore");
Object scorecard = scorecardType.newInstance();
scorecardType.set(scorecard, "age", 10);
session.execute(scorecard);
return (Double) scorecardType.get(scorecard, "scorecard__calculatedScore");
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoStatelessKieSessionsOneDefault.
/**
* This test checks if default StatelessKieSessions behave as expected.
*/
@Test
public void testTwoStatelessKieSessionsOneDefault() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(true);
kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(false);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
final StatelessKieSession firstKSession = kieContainer.newStatelessKieSession("firstKSession");
final StatelessKieSession secondKSession = kieContainer.newStatelessKieSession("secondKSession");
Assertions.assertThat(firstKSession).isEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
Assertions.assertThat(secondKSession).isNotEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class SessionInsertMultiThreadingTest method testSingleCommonStatelessSession.
private void testSingleCommonStatelessSession() throws Exception {
final List<Future<?>> futures = new ArrayList<Future<?>>();
final StatelessKieSession statelessKieSession = kbase.newStatelessKieSession();
runTestBySeveralThreads(statelessKieSession, futures);
waitForCompletion(futures);
}
use of org.kie.api.runtime.StatelessKieSession in project drools by kiegroup.
the class DMNValidatorImpl method validateModel.
private List<DMNMessage> validateModel(Definitions dmnModel) {
if (!kieContainer.isPresent()) {
return failedInitMsg;
}
StatelessKieSession kieSession = kieContainer.get().newStatelessKieSession();
MessageReporter reporter = new MessageReporter();
kieSession.setGlobal("reporter", reporter);
kieSession.execute(allChildren(dmnModel).collect(toList()));
return reporter.getMessages().getMessages();
}
Aggregations