Search in sources :

Example 1 with RankCarWorkItemHandler

use of com.salaboy.jbpm5.RankCarWorkItemHandler 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());
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) DefineCarPriceWorkItemHandler(com.salaboy.jbpm5.DefineCarPriceWorkItemHandler) ClassPathResource(org.drools.io.impl.ClassPathResource) Date(java.util.Date) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) Car(com.salaboy.model.Car) ProcessInstance(org.drools.runtime.process.ProcessInstance) RankCarWorkItemHandler(com.salaboy.jbpm5.RankCarWorkItemHandler)

Example 2 with RankCarWorkItemHandler

use of com.salaboy.jbpm5.RankCarWorkItemHandler 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);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) DefineCarPriceWorkItemHandler(com.salaboy.jbpm5.DefineCarPriceWorkItemHandler) ClassPathResource(org.drools.io.impl.ClassPathResource) Date(java.util.Date) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) Car(com.salaboy.model.Car) ProcessInstance(org.drools.runtime.process.ProcessInstance) RankCarWorkItemHandler(com.salaboy.jbpm5.RankCarWorkItemHandler)

Example 3 with RankCarWorkItemHandler

use of com.salaboy.jbpm5.RankCarWorkItemHandler 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);
}
Also used : KnowledgeBuilderError(org.drools.builder.KnowledgeBuilderError) HashMap(java.util.HashMap) StatefulKnowledgeSession(org.drools.runtime.StatefulKnowledgeSession) DefineCarPriceWorkItemHandler(com.salaboy.jbpm5.DefineCarPriceWorkItemHandler) ClassPathResource(org.drools.io.impl.ClassPathResource) Date(java.util.Date) KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) Car(com.salaboy.model.Car) ProcessInstance(org.drools.runtime.process.ProcessInstance) RankCarWorkItemHandler(com.salaboy.jbpm5.RankCarWorkItemHandler)

Aggregations

DefineCarPriceWorkItemHandler (com.salaboy.jbpm5.DefineCarPriceWorkItemHandler)3 RankCarWorkItemHandler (com.salaboy.jbpm5.RankCarWorkItemHandler)3 Car (com.salaboy.model.Car)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 KnowledgeBase (org.drools.KnowledgeBase)3 KnowledgeBuilder (org.drools.builder.KnowledgeBuilder)3 KnowledgeBuilderError (org.drools.builder.KnowledgeBuilderError)3 ClassPathResource (org.drools.io.impl.ClassPathResource)3 StatefulKnowledgeSession (org.drools.runtime.StatefulKnowledgeSession)3 ProcessInstance (org.drools.runtime.process.ProcessInstance)3