use of com.salaboy.model.Car in project jBPM5-Developer-Guide by Salaboy.
the class GoodOldIntegrationPatterns method statelessGatewayCallTest.
@Test
public void statelessGatewayCallTest() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("good_old_patterns/process-stateless-rule-evaluation-rules-gateway.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, 25000);
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());
assertEquals(new Double(17500), new Double(car.getCurrentPrice()));
assertEquals(6, car.getRanking());
}
use of com.salaboy.model.Car in project jBPM5-Developer-Guide by Salaboy.
the class GoodOldIntegrationPatterns method statelessDecisionTest.
@Test
public void statelessDecisionTest() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("good_old_patterns/process-stateless-rule-evaluation-java-gateway.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, 25000);
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 com.salaboy.model.Car in project jBPM5-Developer-Guide by Salaboy.
the class DefineCarPriceWorkItemHandler method executeWorkItem.
public void executeWorkItem(WorkItem wi, WorkItemManager wim) {
Car car = (Car) wi.getParameter("carInput");
System.out.println("Defining Car Price" + car);
StatelessKnowledgeSession session = createStatelessSession();
session.execute(car);
Map<String, Object> params = new HashMap<String, Object>();
params.put("carOutput", car);
wim.completeWorkItem(wi.getId(), params);
}
use of com.salaboy.model.Car in project jBPM5-Developer-Guide by Salaboy.
the class RankCarWorkItemHandler method executeWorkItem.
public void executeWorkItem(WorkItem wi, WorkItemManager wim) {
Car car = (Car) wi.getParameter("carInput");
System.out.println("Ranking Car" + car);
StatelessKnowledgeSession session = createStatelessSession();
session.execute(car);
Map<String, Object> params = new HashMap<String, Object>();
params.put("carOutput", car);
wim.completeWorkItem(wi.getId(), params);
}
use of com.salaboy.model.Car 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());
}
Aggregations