JBPM4.2小例子(swing实现)

本次用的是一个特别流程,假设C提交一个表单,这个表单需要给A和B阅读,而A和B阅读过后,流程结束.
流程定义文件swing.jpdl.xml


<?xml version="1.0" encoding="UTF-8"?>

<process name="swing" xmlns="http://jbpm.org/4.0/jpdl">
<start g="94,64,48,48" name="start1">
<transition g="-52,-22" name="A" to="A"/>
</start>
<task assignee="A" g="73,195,92,52" name="A">
<transition g="-52,-22" name="B" to="B"/>
</task>
<task assignee="B" g="266,192,92,52" name="B">
<transition g="-40,-21" name="end" to="end1"/>
</task>
<end g="290,327,48,48" name="end1"/>
</process>

增加两个表:
用户表p_user:
USER_ 用户登录ID
PASSWORD_ 用户登录密码

表单数据表p_form:
ID_ 表单编号
TITLE_ 表单标题
CONTENT_ 表单内容
PROCESS_ID 流程实例ID
p_form除了记录表单数据,还记录启动流程实例的ID,这个表负责把表单和流程关联起来.


提交表单时的操作,FormPanel.java部分代码:


okBtn = new JButton("提交表单");
okBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String t = title.getText().trim();
String c = content.getText().trim();
String processId = startProcessInstance();

DataBase db = new DataBase();
if(db.saveForm(t, c, processId)){
JOptionPane.showMessageDialog(null, "保存表单数据成功:");
title.setText("");
content.setText("");
}
}
});


private String startProcessInstance(){
Configuration configuration = new Configuration();
ProcessEngine processEngine = configuration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
ProcessInstance processInstance = executionService.startProcessInstanceByKey("swing");
if(processInstance == null){
JOptionPane.showMessageDialog(null, "请先发布流程.");
}
else{
return processInstance.getId();
}
return "";
}

代码很简单,行获取表单的数据,再启动流程实例,并把表单数据和流程实例ID一起保存在数据库表p_form.


在用户处理任务时,先根据用户的ID查找到该用户的待处理任务,并把它添加到任务列表中,


DefaultListModel v = new DefaultListModel();
List list = getTaskList(Login.userName);
if(list.size() > 0){
for(int s = 0; s < list.size(); s++){
Task t = (Task)list.get(s);
String executionId = t.getExecutionId();
DataBase db = new DataBase();
TaskPojo tp = db.findForm(executionId);
tp.setTaskId(t.getId());
if(tp != null){
v.addElement(tp);
}
}
}
jList = new JList(v);
.
private List getTaskList(String userId){
if(configuration == null){
configuration = new Configuration();
}
ProcessEngine processEngine = configuration.buildProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ExecutionService executionService = processEngine.getExecutionService();
TaskService taskService = processEngine.getTaskService();
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
List<Task> taskList = taskService.findPersonalTasks(userId);
return taskList;
}

用户处理任务,根据列表中选中记录中的流程实例任务ID,调用
taskService.completeTask(taskId)完成任务,
okBtn = new JButton("审阅通过");
okBtn.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
Object o = jList.getSelectedValue();
if(o instanceof TaskPojo){
TaskPojo tp = (TaskPojo)o;
completeTask(tp.getTaskId());
JOptionPane.showMessageDialog(null, "审核已经通过!");
DefaultListModel dl = (DefaultListModel)jList.getModel();
dl.remove(jList.getSelectedIndex());
buttomPanel.setVisible(false);
}
}
});
..
private void completeTask(String taskId){
if(configuration == null){
configuration = new Configuration();
}
ProcessEngine processEngine = configuration.buildProcessEngine();
TaskService taskService = processEngine.getTaskService();
taskService.completeTask(taskId);
}

数据库中登录用户:
帐号:A 密码:123
帐号:B 密码:123
帐号:D 密码:123

用户D登录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值