ProcessEngine processEngine = new Configuration()
.buildProcessEngine();
上面的代码演示了如何通过classpath根目录下 默认的配置文件jbpm.cfg.xml创建一个ProcessService。 如果你要指定其他位置的配置文件, 请使用setResource()方法:
ProcessEngine processEngine = new Configuration()
.setResource("my-own-configuration-file.xml")
.buildProcessEngine();
一、processEngine = Configuration.getProcessEngine(); //初始化启动流程引擎
二、RepositoryService repositoryService = processEngine
.getRepositoryService();
String deploymentId = repositoryService.createDeployment()
.addResourceFromClasspath("helloworld.jpdl.xml").deploy(); //流程发布
List<ProcessDefinition> list = repositoryService
.createProcessDefinitionQuery().list(); //已发布的流程定义
for (ProcessDefinition pd : list) {
System.out.println(pd.getId());
}
repositoryService.deleteDeploymentCascade(deploymentId); //流程定义删除
三、 ExecutionService executionService = processEngine.getExecutionService(); //得到流程实例
ProcessInstance pi = executionService
五、 executionService.endProcessInstance(pi.getId(), "cancel"); // 以cancel方式结束流程实例
executionService.deleteProcessInstanceCascade(pi.getId()); // 删除流程实例
六、 List<ProcessInstance> list = executionService.createProcessInstanceQuery().list(); //查询当前已经在运行的流程实例
for (ProcessInstance processInstance : list) {
System.out.println(processInstance.getId());
}
ProcessDefinition pd
pd.getId()
pd.getName()
pd.getVersion()
七、 TaskService taskService = processEngine.getTaskService();
List<Task> taskList = taskService.findPersonalTasks(username); //用户username的任务列表
task.getFormResourceName() // 任务活动中绑定的jsp例如
<task assignee="#{owner}" form="request.jsp" g="172,118,92,52" name="申请">
<transition to="经理审批"/>
</task>
八、 Map map = new HashMap();
map.put("owner", session.getAttribute("username")); //放置username到变量#{owner}中
executionService.startProcessInstanceById(request
.getParameter("id"), map);
九、 Map map = new HashMap();
map.put("day", day); //放入变量
map.put("reason", reason);
taskService.completeTask(taskId, map); //任务完成
申请人:<%=taskService.getVariable(taskId, "owner") %><br/> //取得变量
请假时间:<%=taskService.getVariable(taskId, "day") %><br/>
请假原因:<%=taskService.getVariable(taskId, "reason") %><br/>
taskService.completeTask(taskId, "驳回"); //流程驳回完成
十、 IdentityService identityService = processEngine.getIdentityService(); //身份认证
identityService.createGroup("dev"); //创建用户组
identityService.createUser("user1", "user1", "user1"); //创建用户
identityService.createUser("user2", "user2", "user3");
identityService.createMembership("user1", "dev");
identityService.createMembership("user2", "dev");
taskService.findGroupTasks("user1") //得到候选任务
taskService.takeTask(task.getId(), "user1"); //接受任务
taskService.completeTask(task.getId()); //任务完成
十一、 事件监听
public class ProcessEventListener implements EventListener {
public void notify(EventListenerExecution execution) {
System.out.println(execution);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<process name="event" xmlns="http://jbpm.org/4.3/jpdl">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<start name="start1" g="162,41,48,48">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<transition name="to state1" to="state1" g="-49,-18" />
</start>
<state name="state1" g="106,159,92,52">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<transition name="to end1" to="end1" g="-42,-18" />
</state>
<end name="end1" g="173,278,48,48">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
</end>
</process>
十二、 Set<String> activityNames = processInstance.findActiveActivityNames(); //当前活动节点
十三、历史信息
如果想查找某一特定流程定义的所有流程实例, 可以像这样操作:
List<HistoryProcessInstance> historyProcessInstances = historyService
.createHistoryProcessInstanceQuery()
.processDefinitionId("ICL-1")
.orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME)
.list();
单独的活动流程也可以作为HistoryActivityInstance 保存到历史信息中。
List<HistoryActivityInstance> histActInsts = historyService
.createHistoryActivityInstanceQuery()
.processDefinitionId("ICL-1")
.activityName("a")
.list();
有时,我们需要获得指定流程实例已经过的节点的完整列表。 下面的查询语句可以用来获得所有已经执行的节点列表:
List<HistoryActivityInstance> histActInsts = historyService
.createHistoryActivityInstanceQuery()
.processInstanceId("ICL.12345")
.list();
.buildProcessEngine();
上面的代码演示了如何通过classpath根目录下 默认的配置文件jbpm.cfg.xml创建一个ProcessService。 如果你要指定其他位置的配置文件, 请使用setResource()方法:
ProcessEngine processEngine = new Configuration()
.setResource("my-own-configuration-file.xml")
.buildProcessEngine();
一、processEngine = Configuration.getProcessEngine(); //初始化启动流程引擎
二、RepositoryService repositoryService = processEngine
.getRepositoryService();
String deploymentId = repositoryService.createDeployment()
.addResourceFromClasspath("helloworld.jpdl.xml").deploy(); //流程发布
List<ProcessDefinition> list = repositoryService
.createProcessDefinitionQuery().list(); //已发布的流程定义
for (ProcessDefinition pd : list) {
System.out.println(pd.getId());
}
repositoryService.deleteDeploymentCascade(deploymentId); //流程定义删除
三、 ExecutionService executionService = processEngine.getExecutionService(); //得到流程实例
ProcessInstance pi = executionService
.startProcessInstanceByKey("helloworld"); //启动流程实例
五、 executionService.endProcessInstance(pi.getId(), "cancel"); // 以cancel方式结束流程实例
executionService.deleteProcessInstanceCascade(pi.getId()); // 删除流程实例
六、 List<ProcessInstance> list = executionService.createProcessInstanceQuery().list(); //查询当前已经在运行的流程实例
for (ProcessInstance processInstance : list) {
System.out.println(processInstance.getId());
}
ProcessDefinition pd
pd.getId()
pd.getName()
pd.getVersion()
七、 TaskService taskService = processEngine.getTaskService();
List<Task> taskList = taskService.findPersonalTasks(username); //用户username的任务列表
task.getFormResourceName() // 任务活动中绑定的jsp例如
<task assignee="#{owner}" form="request.jsp" g="172,118,92,52" name="申请">
<transition to="经理审批"/>
</task>
八、 Map map = new HashMap();
map.put("owner", session.getAttribute("username")); //放置username到变量#{owner}中
executionService.startProcessInstanceById(request
.getParameter("id"), map);
九、 Map map = new HashMap();
map.put("day", day); //放入变量
map.put("reason", reason);
taskService.completeTask(taskId, map); //任务完成
申请人:<%=taskService.getVariable(taskId, "owner") %><br/> //取得变量
请假时间:<%=taskService.getVariable(taskId, "day") %><br/>
请假原因:<%=taskService.getVariable(taskId, "reason") %><br/>
taskService.completeTask(taskId, "驳回"); //流程驳回完成
十、 IdentityService identityService = processEngine.getIdentityService(); //身份认证
identityService.createGroup("dev"); //创建用户组
identityService.createUser("user1", "user1", "user1"); //创建用户
identityService.createUser("user2", "user2", "user3");
identityService.createMembership("user1", "dev");
identityService.createMembership("user2", "dev");
taskService.findGroupTasks("user1") //得到候选任务
taskService.takeTask(task.getId(), "user1"); //接受任务
taskService.completeTask(task.getId()); //任务完成
十一、 事件监听
public class ProcessEventListener implements EventListener {
public void notify(EventListenerExecution execution) {
System.out.println(execution);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<process name="event" xmlns="http://jbpm.org/4.3/jpdl">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<start name="start1" g="162,41,48,48">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<transition name="to state1" to="state1" g="-49,-18" />
</start>
<state name="state1" g="106,159,92,52">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<transition name="to end1" to="end1" g="-42,-18" />
</state>
<end name="end1" g="173,278,48,48">
<on event="start">
<event-listener class="com.family168.ProcessEventListener" />
</on>
<on event="end">
<event-listener class="com.family168.ProcessEventListener" />
</on>
</end>
</process>
十二、 Set<String> activityNames = processInstance.findActiveActivityNames(); //当前活动节点
十三、历史信息
如果想查找某一特定流程定义的所有流程实例, 可以像这样操作:
List<HistoryProcessInstance> historyProcessInstances = historyService
.createHistoryProcessInstanceQuery()
.processDefinitionId("ICL-1")
.orderAsc(HistoryProcessInstanceQuery.PROPERTY_STARTTIME)
.list();
单独的活动流程也可以作为HistoryActivityInstance 保存到历史信息中。
List<HistoryActivityInstance> histActInsts = historyService
.createHistoryActivityInstanceQuery()
.processDefinitionId("ICL-1")
.activityName("a")
.list();
有时,我们需要获得指定流程实例已经过的节点的完整列表。 下面的查询语句可以用来获得所有已经执行的节点列表:
List<HistoryActivityInstance> histActInsts = historyService
.createHistoryActivityInstanceQuery()
.processInstanceId("ICL.12345")
.list();