轻松对比Activiti5与jBPM5技术组成
- - 企业架构 - ITeye博客jBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baeyens离开JBoss后,jBPM的下一个版本jBPM5完全放弃了jBPM4的基础代码,基于Drools Flow重头来过,目前官网已经推出了jBPM6的beta版本;Tom Baeyens加入Alfresco后很快推出了新的基于jBPM4的开源工作流系统Activiti.
关于jbpm5的人工任务实现这里提供一个思路
流程图如下:
在流程中创建流程变量的方式
这个变量会在发起流程的时候初始化,或在任务处理的时候更新
而在分支节点的判断逻辑是
<!--StartFragment -->
private void test_05_多任务审批(StatefulKnowledgeSession session) { org.jbpm.task.service.TaskService internalTaskService = knowledgeSessionTemplate.getInternalTaskService(); TaskServiceSession taskServiceSession = internalTaskService.createSession(); taskServiceSession.addUser(new User("Administrator")); taskServiceSession.addUser(new User("zhangsan")); taskServiceSession.addUser(new User("lisi")); taskServiceSession.addUser(new User("wangwu")); taskServiceSession.dispose(); Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("actors", "zhangsan,lisi,wangwu"); ProcessInstance pi = session.startProcess("defaultPackage.New_Process", variableMap); WorkflowProcessInstance wfpi = (WorkflowProcessInstance)pi; String actors = (String)wfpi.getVariable("actors"); TaskService taskService = knowledgeSessionTemplate.getTaskService(); printTasks(taskService); long taskid = taskService.getTasksAssignedAsPotentialOwner("zhangsan", "en-UK").get(0).getId(); actors = handleTask(session, taskService, actors, "zhangsan", taskid, pi.getId()); printTasks(taskService); taskid = taskService.getTasksAssignedAsPotentialOwner("wangwu", "en-UK").get(0).getId(); actors = handleTask(session, taskService, actors, "wangwu", taskid, pi.getId()); printTasks(taskService); taskid = taskService.getTasksAssignedAsPotentialOwner("lisi", "en-UK").get(0).getId(); actors = handleTask(session, taskService, actors, "lisi", taskid, pi.getId()); printTasks(taskService); } private void printTasks(TaskService taskService) { List<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("zhangsan", "en-UK"); List<TaskSummary> tasks2 = taskService.getTasksAssignedAsPotentialOwner("lisi", "en-UK"); List<TaskSummary> tasks3 = taskService.getTasksAssignedAsPotentialOwner("wangwu", "en-UK"); System.err.println("张三 :" + tasks1); System.err.println("李四 :" + tasks2); System.err.println("王五 :" + tasks3); } private String handleTask(StatefulKnowledgeSession session, TaskService taskService, String actors, String actor, long taskid, long piid) { String newActors = resetActors(actors, actor); ((WorkflowProcessInstance)session.getProcessInstance(piid)).setVariable("actors", newActors); // taskService.claim(taskid, actor); taskService.start(taskid, actor); taskService.complete(taskid, actor, null); ProcessInstance pi = session.getProcessInstance(piid); if(pi != null) { return ((WorkflowProcessInstance)pi).getVariable("actors").toString(); } return ""; } private String resetActors(String actors, String actor) { String[] actorArr = actors.split(","); StringBuffer sb = new StringBuffer(); for (String a : actorArr) { if (!a.equals(actor)) { sb.append(a).append(","); } } int i = sb.lastIndexOf(","); if(i!=-1){ sb.deleteCharAt(i); } return sb.toString(); }
测试结果