KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > webapp > bean > HomeBean


1 package org.jbpm.webapp.bean;
2
3 import java.util.List JavaDoc;
4
5 import org.jbpm.db.GraphSession;
6 import org.jbpm.db.JbpmSession;
7 import org.jbpm.db.TaskMgmtSession;
8 import org.jbpm.graph.def.ProcessDefinition;
9 import org.jbpm.graph.exe.ProcessInstance;
10 import org.jbpm.taskmgmt.exe.TaskInstance;
11 import org.jbpm.webapp.context.Context;
12
13 public class HomeBean {
14
15   UserBean userBean;
16   TaskBean taskBean;
17   GraphSession graphSession;
18   TaskMgmtSession taskMgmtSession;
19   
20   public HomeBean() {
21     JbpmSession jbpmSession = Context.getPersistenceContext().getJbpmSession();
22     this.graphSession = jbpmSession.getGraphSession();
23     this.taskMgmtSession = jbpmSession.getTaskMgmtSession();
24   }
25   
26   public List JavaDoc getTaskInstances() {
27     return taskMgmtSession.findTaskInstances(userBean.getUserName());
28   }
29
30   public List JavaDoc getLatestProcessDefinitions() {
31     return graphSession.findLatestProcessDefinitions();
32   }
33
34   /**
35    * selects a task.
36    */

37   public String JavaDoc selectTaskInstance() {
38     // Get the task instance id from request parameter
39
long taskInstanceId = JsfHelper.getId("taskInstanceId");
40     TaskInstance taskInstance = taskMgmtSession.loadTaskInstance(taskInstanceId);
41     taskBean.initialize(taskInstance);
42     return "task";
43   }
44
45   /**
46    * prepares a task form for starting a new process instance.
47    */

48   public String JavaDoc startProcessInstance() {
49     // Get the task instance id from request parameter
50
long processDefinitionId = JsfHelper.getId("processDefinitionId");
51     ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
52
53     // create a new process instance to run
54
ProcessInstance processInstance = new ProcessInstance(processDefinition);
55
56     // create a new taskinstance for the start task
57
TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
58
59     // Save the process instance along with the task instance
60
graphSession.saveProcessInstance(processInstance);
61     
62     // Fill the task backing bean with useful information
63
taskBean.initialize(taskInstance);
64
65     return "task";
66   }
67   
68   public UserBean getUserBean() {
69     return userBean;
70   }
71   public void setUserBean(UserBean userBean) {
72     this.userBean = userBean;
73   }
74   public TaskBean getTaskBean() {
75     return taskBean;
76   }
77   public void setTaskBean(TaskBean taskBean) {
78     this.taskBean = taskBean;
79   }
80 }
81
Popular Tags