Search in sources :

Example 1 with StatelessKnowledgeSession

use of org.drools.runtime.StatelessKnowledgeSession 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);
}
Also used : Car(com.salaboy.model.Car) HashMap(java.util.HashMap) StatelessKnowledgeSession(org.drools.runtime.StatelessKnowledgeSession)

Example 2 with StatelessKnowledgeSession

use of org.drools.runtime.StatelessKnowledgeSession 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);
}
Also used : Car(com.salaboy.model.Car) HashMap(java.util.HashMap) StatelessKnowledgeSession(org.drools.runtime.StatelessKnowledgeSession)

Example 3 with StatelessKnowledgeSession

use of org.drools.runtime.StatelessKnowledgeSession 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();
}
Also used : MarketMetric(com.salaboy.model.MarketMetric) ArrayList(java.util.ArrayList) StatelessKnowledgeSession(org.drools.runtime.StatelessKnowledgeSession) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

StatelessKnowledgeSession (org.drools.runtime.StatelessKnowledgeSession)3 Car (com.salaboy.model.Car)2 HashMap (java.util.HashMap)2 MarketMetric (com.salaboy.model.MarketMetric)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1