use of org.drools.builder.KnowledgeBuilder in project jBPM5-Developer-Guide by Salaboy.
the class GenericWebServiceTaskTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("HospitalInvokeInsuranceScenarioV3-data.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
}
use of org.drools.builder.KnowledgeBuilder in project jBPM5-Developer-Guide by Salaboy.
the class HospitalInsuranceProcessTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("InsuranceProcessV1.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
// Registers an independent mocked work item handler for each task present
// in the process.
PatientDataServiceWorkItemHandler patientDataHandler = new PatientDataServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", patientDataHandler);
InsuranceServiceWorkItemHandler insuranceServiceHandler = new InsuranceServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Insurance Service", insuranceServiceHandler);
CompanyGatewayWorkItemHandler companyGatewayHandler = new CompanyGatewayWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", companyGatewayHandler);
RatesServiceWorkItemHandler ratesServiceHandler = new RatesServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Rates Service", ratesServiceHandler);
InvoiceServiceWorkItemHandler invoiceServiceHandler = new InvoiceServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Invoice Service", invoiceServiceHandler);
}
use of org.drools.builder.KnowledgeBuilder in project jBPM5-Developer-Guide by Salaboy.
the class GoodOldIntegrationPatterns method statelessDecorationTest.
@Test
public void statelessDecorationTest() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("good_old_patterns/process-stateless-rule-evaluation.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.out.println(">>> Error:" + error.getMessage());
}
fail(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.getWorkItemManager().registerWorkItemHandler("Rank Car", new RankCarWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Define Car Price", new DefineCarPriceWorkItemHandler());
Car car = new Car("AUDI 78", new Date(), 5, "manual", "gas", 285, 15000);
Map<String, Object> params = new HashMap<String, Object>();
params.put("car", car);
ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.stateless-rules-decoration", params);
assertEquals(processInstance.getState(), ProcessInstance.STATE_PENDING);
ksession.startProcessInstance(processInstance.getId());
System.out.println("Car : " + car);
}
use of org.drools.builder.KnowledgeBuilder in project jBPM5-Developer-Guide by Salaboy.
the class GoodOldIntegrationPatterns method theRuleEngineWay.
@Test
public void theRuleEngineWay() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("good_old_patterns/car-evaluations.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.out.println(">>> Error:" + error.getMessage());
}
fail(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
Car car = new Car("AUDI 78", new Date(), 5, "manual", "gas", 285, 25000);
MarketMetric metric = new MarketMetric(0.8);
ksession.insert(metric);
ksession.insert(car);
ksession.fireAllRules();
assertEquals(new Double(17500), new Double(car.getCurrentPrice()));
assertEquals(6, car.getRanking());
assertTrue(metric.getResult());
}
use of org.drools.builder.KnowledgeBuilder in project jBPM5-Developer-Guide by Salaboy.
the class GoodOldIntegrationPatterns method javaBasedDecisionTest.
@Test
public void javaBasedDecisionTest() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("good_old_patterns/process-java-decision.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.out.println(">>> Error:" + error.getMessage());
}
fail(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
// Uncomment to see all the logs
// KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
Person person = new Person("Salaboy", 28);
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", person);
ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.SimpleDecision", params);
assertEquals(processInstance.getState(), ProcessInstance.STATE_PENDING);
ksession.startProcessInstance(processInstance.getId());
assertEquals(processInstance.getState(), ProcessInstance.STATE_COMPLETED);
}
Aggregations