本文整理汇总了Java中org.kie.api.runtime.KieSession.insert方法的典型用法代码示例。如果您正苦于以下问题:Java KieSession.insert方法的具体用法?Java KieSession.insert怎么用?Java KieSession.insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.kie.api.runtime.KieSession
的用法示例。
在下文中一共展示了KieSession.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
public void execute(Object object) {
try {
KieSession ksession = kbase.newKieSession();
if (!getRulenames().isEmpty()) {
if (executor != null) {
ksession.setGlobal("executor", executor);
ksession.setGlobal("logger", logger);
ksession.insert(object);
int rulesFired = ksession.fireAllRules();
logger.debug("Number of rules fired on event: " + rulesFired);
if (rulesFired > 0) {
logger.info("Event triggered " + rulesFired + "rules: " + (Event) object);
}
} else
logger.error("Command Executor not available - no command sent for event: " + object);
} else {
logger.debug("No rules in the system - skipping firing rules");
}
ksession.dispose();
} catch (Exception e) {
logger.error("Error during rules enging processing: " + e.getMessage());
}
}
示例2: execute
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
public static void execute( KieContainer kc ) throws Exception{
// From the container, a session is created based on
// its definition and configuration in the META-INF/kmodule.xml file
KieSession ksession = kc.newKieSession("point-rulesKS");
List<Order> orderList = getInitData();
for (int i = 0; i < orderList.size(); i++) {
Order o = orderList.get(i);
ksession.insert(o);
ksession.fireAllRules();
// 执行完规则后, 执行相关的逻辑
addScore(o);
}
ksession.dispose();
}
示例3: test
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping("/address")
public void test(int num){
Address address = new Address();
address.setPostcode(generateRandom(num));
KieSession kieSession = ReloadDroolsRulesService.kieContainer.newKieSession();
AddressCheckResult result = new AddressCheckResult();
kieSession.insert(address);
kieSession.insert(result);
int ruleFiredCount = kieSession.fireAllRules();
kieSession.destroy();
System.out.println("触发了" + ruleFiredCount + "条规则");
if(result.isPostCodeResult()){
System.out.println("规则校验通过");
}
}
示例4: test
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@ResponseBody
@RequestMapping("/address")
public void test(int num){
Address address = new Address();
address.setPostcode(generateRandom(num));
KieSession kieSession = kieContainer.newKieSession();
AddressCheckResult result = new AddressCheckResult();
kieSession.insert(address);
kieSession.insert(result);
int ruleFiredCount = kieSession.fireAllRules();
kieSession.destroy();
System.out.println("触发了" + ruleFiredCount + "条规则");
if(result.isPostCodeResult()){
System.out.println("规则校验通过");
}
}
示例5: validateCandidate
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Transactional(readOnly = false)
@RequestMapping(value = "/{container}", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public
@ResponseBody
ValidateCandidateResponse validateCandidate(@PathVariable("container") String container, @Valid @RequestBody ValidateCandidateRequest req) {
KieSession session = ruleService.getKieSession(container);
RulePlaceholder candidate = new RulePlaceholder(req.getDetail());
session.insert(candidate);
session.fireAllRules();
session.dispose();
candidate.getResult().forEach((k, v) -> {
logger.info(k + " : " + v);
});
ValidateCandidateResponse resp = new ValidateCandidateResponse();
resp.setDetail(candidate.getResult());
resp.setAnswer(candidate.getResult().size() == 0);
return resp;
}
示例6: insertIntoSession
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
private void insertIntoSession(KieSession sessionStatefull, CostCalculationRequest request) {
sessionStatefull.insert(request);
if (request.getOrder() != null) {
sessionStatefull.insert(request.getOrder());
for (OrderLine orderLine : request.getOrder().getOrderLines()) {
sessionStatefull.insert(orderLine);
sessionStatefull.insert(orderLine.getProduct());
}
}
if (request.getTrip() != null) {
sessionStatefull.insert(request.getTrip());
for (Step step : request.getTrip().getSteps()) {
sessionStatefull.insert(step);
sessionStatefull.insert(step.getStepStart());
sessionStatefull.insert(step.getStepEnd());
}
}
}
示例7: houseWithNoRoomsTest
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void houseWithNoRoomsTest() {
KieSession kSession = kBase.newKieSession();
ArrayList<String> errors = new ArrayList<String>();
kSession.setGlobal( "errors", errors );
House house = new House( "Mansion" );
kSession.insert( house );
int fired = kSession.fireAllRules();
assertEquals( 1, fired );
assertEquals( 1, errors.size() );
assertThat(errors, Matchers.contains("Warn: Your House ( " + house.getName() + " ) has no Rooms"));
kSession.dispose();
}
示例8: roomWithoutAHouseAndDoorsTest
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void roomWithoutAHouseAndDoorsTest() {
KieSession kSession = kBase.newKieSession();
ArrayList<String> errors = new ArrayList<String>();
kSession.setGlobal( "errors", errors );
Room roomA = new Room( "Room A" );
kSession.insert( roomA );
int fired = kSession.fireAllRules();
assertEquals( 2, fired );
assertEquals( 2, errors.size() );
assertThat(errors, Matchers.containsInAnyOrder("Warn: there is room ( " + roomA.getName() + " ) but there is no house",
"Warn: Your Room ( " + roomA.getName() + " ) has no Doors"));
kSession.dispose();
}
示例9: lockedDoorWithNoKeyRulesTest
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void lockedDoorWithNoKeyRulesTest() {
KieSession kSession = kBase.newKieSession();
ArrayList<String> errors = new ArrayList<String>();
kSession.setGlobal( "errors", errors );
House house = new House( "Mansion" );
Room roomA = new Room( "Room A" );
Door doorA = new Door( "Door A" );
kSession.insert( doorA );
roomA.getDoors().add( doorA );
kSession.insert( roomA );
house.getRooms().add( roomA );
kSession.insert( house );
int fired = kSession.fireAllRules();
assertEquals( 1, fired );
assertEquals( 1, errors.size() );
assertThat(errors, Matchers.contains("Warn: There is no key for this Door ( " + doorA.getName() + " )"));
kSession.dispose();
}
示例10: testPatientWithBloodPressureObservations
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void testPatientWithBloodPressureObservations() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
System.out.println(" ---- Starting testPatientWithBloodPressureObservations() Test ---");
kSession.insert(generatePatients(1).get(0));
List<Observation> observations = generateBloodPressureObservations(60);
for (Observation observation : observations) {
kSession.insert(observation);
}
Assert.assertEquals(1, kSession.fireAllRules());
System.out.println(" ---- Finished testPatientWithBloodPressureObservations() Test ---");
kSession.dispose();
}
示例11: testServiceCallInRHS
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void testServiceCallInRHS() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
kSession.setGlobal("myDataProviderService", new MyDataProviderServiceImpl());
System.out.println(" ---- Starting testServiceCallInRHS() Test ---");
University university = new University("My Uni");
FactHandle univFactHandle = kSession.insert(university);
Assert.assertEquals(50, kSession.fireAllRules());
university.setName("My Uni (updated)");
kSession.update(univFactHandle, university);
Assert.assertEquals(50, kSession.fireAllRules());
System.out.println(" ---- Finished testServiceCallInRHS() Test ---");
kSession.dispose();
}
示例12: fireAllRules
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
private int fireAllRules(Message inputMessage, KnowledgeOperation operation) {
KnowledgeRuntimeEngine runtime = getSingletonRuntimeEngine();
RulesOperationType operationType = (RulesOperationType) operation
.getType();
// sessionIdentifier = runtime.getSessionIdentifier();
setGlobals(inputMessage, operation, runtime, true);
KieSession session = runtime.getKieSession();
List<Object> facts = getInputList(inputMessage, operation, runtime);
for (Object fact : facts) {
session.insert(fact);
}
if (RulesOperationType.FIRE_ALL_RULES.equals(operationType)) {
return session.fireAllRules();
}
return 0;
}
示例13: testObservationAndPatient
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void testObservationAndPatient() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
System.out.println(" ---- Starting testObservationAndPatient() Test ---");
Patient patient = (Patient) new Patient().setId("Patient/1");
kSession.insert(patient);
Observation observation = (Observation) new Observation().setId("Observation/1");
kSession.insert(observation);
Assert.assertEquals(1, kSession.fireAllRules());
System.out.println(" ---- Finished testObservationAndPatient() Test ---");
kSession.dispose();
}
示例14: testUsingGlobalToTrackRulesFiring
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void testUsingGlobalToTrackRulesFiring() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
List<String> rulesFired = new ArrayList<>();
kSession.setGlobal("rulesFired", rulesFired);
System.out.println(" ---- Starting testUsingGlobalToTrackRulesFiring() Test ---");
Patient patient = (Patient) new Patient()
.setId("Patient/1");
Condition condition = createDiabetesCondition(patient, "Condition/1");
kSession.insert(patient);
kSession.insert(condition);
Assert.assertEquals(1, kSession.fireAllRules());
Assert.assertTrue(rulesFired.contains("Identify Diabetic Patients"));
System.out.println(" ---- Finished testUsingGlobalToTrackRulesFiring() Test ---");
kSession.dispose();
}
示例15: testObservationAndPatientRelated
import org.kie.api.runtime.KieSession; //导入方法依赖的package包/类
@Test
public void testObservationAndPatientRelated() {
Assert.assertNotNull(kBase);
KieSession kSession = kBase.newKieSession();
System.out.println(" ---- Starting testObservationAndPatientRelated() Test ---");
Patient patient = (Patient) new Patient().setId("Patient/1");
Observation observation = (Observation) new Observation().setId("Observation/1");
observation.setSubject(new ResourceReferenceDt(patient));
kSession.insert(observation);
Assert.assertEquals(0, kSession.fireAllRules());
System.out.println(" ---- Finished testObservationAndPatientRelated() Test ---");
kSession.dispose();
}