CustomerEvaluation流程是一个较复杂的流程,我们多次使用Gateway,以及Rule Task,流程示意如下图:
System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node"); if (request == null) { System.out.println("There as no evaluation objects defined, adding default ones for demo purposes."); // define request object. request = new Request("1"); request.setPersonId("kylin"); request.setAmount(5000); kcontext.setVariable("request", request); // define person object. person = new Person("kylin", "Kylin Soong"); kcontext.setVariable("person", person); } System.out.println("Leaving " + kcontext.getNodeInstance().getNodeName() +" Node");
System.out.println("Gateway: " + kcontext.getNodeInstance().getNodeName() + " adult"); return person.getAge() > 17;
System.out.println("Gateway: " + kcontext.getNodeInstance().getNodeName() + " under age"); return person.getAge() < 18;
System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node"); // Setting our request to invalid. System.out.println("Detected and reporting invalid request."); kcontext.setVariable("validRequest", false); request.setInvalid("Customer is underaged."); System.out.println("Set validRequest to: " + kcontext.getVariable("validRequest")); System.out.println("Leaving " + kcontext.getNodeInstance().getNodeName() +" Node"); System.out.println("Process ended in End Minor Node.");
System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node"); // Setting request to valid. System.out.println("Detected and reporting valid request"); kcontext.setVariable("validRequest", true); request.setValid(); System.out.println("Set validRequest to: " + kcontext.getVariable("validRequest")); // Insert Person and Request into our session for the rules to use. insert(person); insert(request); System.out.println("Leaving " + kcontext.getNodeInstance().getNodeName() +" Node"); System.out.println("Entering Finance Rules Node");
package org.jbpm.quickstarts; rule "Check Amount Customer" ruleflow-group "Validation" when r: Request(); Person(id == r.personId, r.amount < 1000); then System.out.println("Under funded customer"); r.setInvalid("Poor customer"); System.out.println("Set Request invalid comment to: Poor customer."); System.out.println("Customer request= " + r); end
System.out.println("Leaving Finance Rules Node."); System.out.println("Gateway: " + kcontext.getNodeInstance().getNodeName()); // determine results of fincancial rules decision by checking if request is valid. if (request.isValid()) { System.out.println("Determined request is valid, heading to Rich Customer Node"); return true; } System.out.println("Determined request is NOT valid, heading to Poor Customer Node"); System.out.println("Request validity reason is: " + request.getInvalidReason()); return request.isValid();
System.out.println("Leaving Finance Rules Node."); System.out.println("Gateway: " + kcontext.getNodeInstance().getNodeName() + " broke"); System.out.println("Detected request is invalid, heading to Poor Customer Node"); System.out.println("Request not valid reason is: " + request.getInvalidReason()); return true;
System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node"); // Setting request to valid. System.out.println("Detected and reporting valid request"); System.out.println("Customer has amount: " + request.getAmount() + " in the bank."); kcontext.setVariable("validRequest", true); System.out.println("Leaving " + kcontext.getNodeInstance().getNodeName() +" Node"); System.out.println("Process ended in End Rich Customer Node.");
System.out.println("Entering " + kcontext.getNodeInstance().getNodeName() +" Node"); // Setting request to invalid. System.out.println("Customer has amount: " + request.getAmount() + " in the bank."); kcontext.setVariable("validRequest", false); System.out.println("Leaving " + kcontext.getNodeInstance().getNodeName() +" Node"); System.out.println("Process ended in End Poor Customer Node.");
运行org.jbpm.quickstarts.evaluation.CustomerEvaluationStart可执行CustomerEvaluation流程,CustomerEvaluationStart中假设了机制情况,可以执行流程的每个节点,运行CustomerEvaluationStart结果输出如下:
========================================= = Starting Process Underaged Test Case. = ========================================= Entering Initialize Node Leaving Initialize Node Gateway: Gateway under age Gateway: Gateway adult Entering Underaged Node Detected and reporting invalid request. Set validRequest to: false Leaving Underaged Node Process ended in End Minor Node. ========================================== = Starting Process Poor Adult Test Case. = ========================================== Entering Initialize Node Leaving Initialize Node Gateway: Gateway under age Gateway: Gateway adult Entering Adult Customer Node Detected and reporting valid request Set validRequest to: true Leaving Adult Customer Node Entering Finance Rules Node Under funded customer Set Request invalid comment to: Poor customer. Customer request= Request [id=1, personId=kylin, amount=2, valid=false, invalidReason=Poor customer, canceled=false] Leaving Finance Rules Node. Gateway: Gateway Determined request is NOT valid, heading to Poor Customer Node Request validity reason is: Poor customer Leaving Finance Rules Node. Gateway: Gateway broke Detected request is invalid, heading to Poor Customer Node Request not valid reason is: Poor customer Entering Poor Customer Node Customer has amount: 2 in the bank. Leaving Poor Customer Node Process ended in End Poor Customer Node. ========================================== = Starting Process Rich Adult Test Case. = ========================================== Entering Initialize Node Leaving Initialize Node Gateway: Gateway under age Gateway: Gateway adult Entering Adult Customer Node Detected and reporting valid request Set validRequest to: true Leaving Adult Customer Node Entering Finance Rules Node Leaving Finance Rules Node. Gateway: Gateway Determined request is valid, heading to Rich Customer Node Entering Rich Customer Node Detected and reporting valid request Customer has amount: 2000 in the bank. Leaving Rich Customer Node Process ended in End Rich Customer Node. ============================================= = Starting Process Empty Request Test Case. = ============================================= Entering Initialize Node There as no evaluation objects defined, adding default ones for demo purposes. Leaving Initialize Node Gateway: Gateway under age Gateway: Gateway adult Entering Underaged Node Detected and reporting invalid request. Set validRequest to: false Leaving Underaged Node Process ended in End Minor Node.