use of com.salaboy.model.MarketMetric 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 com.salaboy.model.MarketMetric in project jBPM5-Developer-Guide by Salaboy.
the class RulesHelper method evaluate.
public static boolean evaluate(Car car) {
if (cachedResults.containsKey(car.getName())) {
return cachedResults.get(car.getName());
}
StatelessKnowledgeSession session = createStatelessSession("good_old_patterns/car-sell-or-drop-complex-decision.drl");
List list = new ArrayList();
list.add(car);
// Get external information that you don't want to keep in the process, for example:
// - Call an external service to get information about the stock market
// - Check the average price for this type of cars in ebay
// - Check for the competitors prices in the last two months
// We can get a metric about the current status of the market
// when the process is being executed and use that to influence our decision
MarketMetric metric = new MarketMetric(0.8);
list.add(metric);
session.execute(list);
cachedResults.put(car.getName(), metric.getResult());
return metric.getResult();
}
Aggregations