代码
/**
* <pre> 同意
* S -> [提交] -> [审批] -> X审批意见X ----> [扣除假期] -> E
* | ^
* |拒绝 |
* +------------------------+
* </pre>
*
* @author jinli
*/
public class Modeler {
public static void main(String[] args) {
BpmnModelInstance inst = Bpmn.createExecutableProcess("vacation")
.name("请假流程")
.camundaHistoryTimeToLive(0)
.startEvent()
.name("启动")
.userTask()
.name("提交")
.camundaAssignee("demo")
.userTask()
.name("审批")
.camundaAssignee("demo")
.camundaExecutionListenerExpression("start", "${execution.setVariableLocal(\\"approved\\", false)}")
.exclusiveGateway()
.id("gateway")
.name("审批意见")
.gatewayDirection(GatewayDirection.Diverging)
.condition("同意", "${approved}")
.scriptTask()
.name("扣除假期")
.scriptFormat("groovy")
.scriptText("System.out.println(\\">>> \\" + \\"扣除假期\\");")
.endEvent()
.id("End")
.name("结束")
.moveToNode("gateway")
.condition("拒绝", "${!approved}")
.connectTo("End")
.done();
Bpmn.validateModel(inst);
Bpmn.writeModelToFile(new File("src/main/resources/bpmn", "Modeler-API.bpmn"), inst);
}
}
效果
XML解析
public class Modeler {
public static void main(String[] args) {
BpmnModelInstance inst = Bpmn.createExecutableProcess("proc")
.startEvent()
.id("start")
.sequenceFlowId("s1")
.userTask()
.id("user")
.sequenceFlowId("s2")
.camundaAssignee("demo")
.endEvent()
.id("end")
.done();
Bpmn.validateModel(inst);
Bpmn.writeModelToFile(new File("src/main/resources/bpmn", "Modeler-API.bpmn"), inst);
}
}