package com.gds.web;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.WorkflowProcessInstance;
import org.jbpm.task.AccessType;
import org.jbpm.task.Task;
import org.jbpm.task.TaskData;
import org.jbpm.task.TaskService;
import org.jbpm.task.query.TaskSummary;
import org.jbpm.task.service.ContentData;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.gds.jbpm.JbpmSupport;
import com.gds.jbpm.Order;
@Controller
public class OrderController {
private Logger log = Logger.getLogger(this.getClass());
@Resource
@Qualifier("jbpmSupport")
private JbpmSupport jbpmSupport;
@RequestMapping("/")
public String test() {
log.info("this is the index");
return "index";
}
@RequestMapping(value = "{user}/create", method = GET)
public String create(@PathVariable("user") String user) {
//log.info(user + " prepare to create");
System.out.println("用户["+user+"]进入创建界面,准备创建流程。");
return "create";
}
@RequestMapping(value = "{user}/create", method = { POST, PUT })
public String doCreate(@PathVariable("user") String user, Model model) {
//log.info(user + " create an order");
System.out.println("用户["+user+"]提交了流程单据");
StatefulKnowledgeSession ksession = jbpmSupport.getKsession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("priority", "High");
params.put("modelNumber", "179");
params.put("quantity", "100");
System.out.println("用户["+user+"]赋初始值,并准备启动流程.......");
ksession.startProcess("com.gds.jbpm.sample", params);
ksession.fireAllRules();
System.out.println("用户["+user+"]创建流程,等待处理......");
model.addAttribute("message", "process created!");
System.out.println("---------------------------------------------------单据提交完成:"+user);
return "create";
}
@RequestMapping("{user}/list")
public String list(@PathVariable("user") String user, Model model) {
//log.info(user + " list his tasks");
System.out.println("用户["+user+"]读取任务列表.");
TaskService taskService = jbpmSupport.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner(user, "en-UK");
log.info("\n***Task size::" + tasks.size() + "***\n");
for (TaskSummary taskSummary : tasks) {
log.info(taskSummary.getId() + " :: " + taskSummary.getActualOwner());
}
model.addAttribute("tasks", tasks);
model.addAttribute("tasksCount", tasks.size());
model.addAttribute("user", user);
System.out.println("---------------------------------------------------列表读取完成:"+user);
return "list";
}
@RequestMapping(value = "{user}/work/{task}", method = GET)
public String work(@PathVariable("user") String user, @PathVariable("task") long taskId, Model model) {
//log.info(user + " prepare to work on task " + taskId);
System.out.println("用户["+user+"]读取任务以便处理,任务ID="+taskId);
StatefulKnowledgeSession ksession = jbpmSupport.getKsession();
TaskService taskService = jbpmSupport.getTaskService();
Task task = taskService.getTask(taskId);
TaskData taskData = task.getTaskData();
WorkflowProcessInstance process = (WorkflowProcessInstance) ksession.getProcessInstance(taskData
.getProcessInstanceId());
model.addAttribute("taskData", taskData);
model.addAttribute("order", new Order(user, taskId, process));
System.out.println("---------------------------------------------------任务读取完成:"+user);
return "work";
}
@RequestMapping(value = "{user}/work/{task}", method = { POST, PUT })
public String doWork(@ModelAttribute Order order) {
System.out.println("处理任务信息:"+order.toString());
String user = order.getUser();
long taskId = order.getTaskId();
log.info(user + " complete work on task " + taskId);
TaskService taskService = jbpmSupport.getTaskService();
System.out.println("用户["+user+"]启动人工任务, taskId="+taskId);
taskService.start(taskId, user);
Map<String, Object> data = new HashMap<String, Object>();
data.put("priority", order.getPriority());
data.put("modelNumber", order.getModelNumber());
data.put("quantity", order.getQuantity());
ContentData contentData = null;
if (data != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream outs;
try {
outs = new ObjectOutputStream(bos);
outs.writeObject(data);
outs.close();
contentData = new ContentData();
contentData.setContent(bos.toByteArray());
contentData.setAccessType(AccessType.Inline);
} catch (IOException e) {
e.printStackTrace();
}
}
taskService.complete(taskId, user, contentData);
System.out.println("用户["+user+"]完成人工任务");
System.out.println("---------------------------------------------------处理任务完成:"+user);
return "redirect:/" + user + "/list";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JBPM5Spring.zip (76个子文件)
JBPM5Spring
.project 1KB
src
test
java
main
webapp
WEB-INF
web.xml 2KB
spring
webmvc-config.xml 1KB
spring-main.xml 2KB
work.jsp 3KB
index.jsp 2KB
resources
images
bg-button-green.gif 169B
bg-radial-gradient.gif 17KB
bg-body.gif 21KB
menu-current-arrow.gif 59B
icons
paper_content_pencil_48.png 5KB
exclamation.png 622B
jquery.wysiwyg.gif 4KB
cross.png 540B
clock_48.png 7KB
pencil.png 497B
comment_48.png 5KB
tick_circle.png 741B
pencil_48.png 4KB
bullet_black.png 211B
cross_grey_small.png 3KB
information.png 725B
cross_circle.png 721B
image_add_48.png 5KB
hammer_screwdriver.png 780B
bg-menu-item-current.gif 315B
bg-form-field.gif 97B
tl.png 132B
bg-login-top.png 3KB
bg-menu-item-green.gif 3KB
shortcut-button-bg.gif 1KB
bl.png 124B
logo.png 10KB
b.png 84B
br.png 124B
tr.png 125B
bg-content-box.gif 126B
bg-sidebar.gif 32KB
bg-login.gif 13KB
scripts
css
invalid.css 2KB
reset.css 1KB
style.css 21KB
list.jsp 3KB
create.jsp 2KB
resources
Sample.bpmn 15KB
log4j.properties 1KB
META-INF
persistence.xml 3KB
Taskorm.xml 14KB
JBPMorm.xml 548B
java
com
gds
jbpm
Order.java 1KB
JbpmSupport.java 3KB
web
OrderController.java 6KB
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 231B
maven
com
JBPM5Spring
pom.properties 224B
pom.xml 10KB
generated-sources
annotations
classes
com
gds
jbpm
JbpmSupport.class 3KB
Order.class 2KB
web
OrderController.class 8KB
Sample.bpmn 15KB
log4j.properties 1KB
META-INF
persistence.xml 3KB
Taskorm.xml 14KB
JBPMorm.xml 548B
work
jsp
org
apache
jsp
list_jsp.class 14KB
work_jsp.class 13KB
create_jsp.class 8KB
index_jsp.class 5KB
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 245B
org.eclipse.m2e.core.prefs 86B
org.eclipse.jdt.core.prefs 422B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 664B
.jsdtscope 496B
pom.xml 10KB
.classpath 1KB
共 76 条
- 1
资源评论
- publicorprivate2013-10-24没有运行起来
- 飘落的灿烂2013-12-05不行啊,弄下来报错了,不知道为什么new LocalTaskService(taskServiceSession); 这个报错了
不净之心
- 粉丝: 49
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功