📄 approveactionhandler_db.java
字号:
package com.myrequest;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.node.*;
import java.io.FileInputStream;
import java.util.*;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.taskmgmt.*;
import org.jbpm.identity.*;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.db.GraphSession;
import org.jbpm.taskmgmt.exe.*;
import junit.framework.TestCase;
import com.myrequest.*;
public class ApproveActionHandler_db extends TestCase
{
static JbpmConfiguration jbpmConfiguration = null;
static {
// An example configuration file such as this can be found in
// 'src/config.files'. Typically the configuration information is in the
// resource file 'jbpm.cfg.xml', but here we pass in the configuration
// information as an XML string.
// First we create a JbpmConfiguration statically. One JbpmConfiguration
// can be used for all threads in the system, that is why we can safely
// make it static.
jbpmConfiguration = JbpmConfiguration.parseXmlString(
"<jbpm-configuration>" +
// A jbpm-context mechanism separates the jbpm core
// engine from the services that jbpm uses from
// the environment.
" <jbpm-context>" +
" <service name='persistence' " +
" factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />" +
" </jbpm-context>" +
// Also all the resource files that are used by jbpm are
// referenced from the jbpm.cfg.xml
" <string name='resource.hibernate.cfg.xml' " +
" value='hibernate.cfg.xml' />" +
" <string name='resource.business.calendar' " +
" value='org/jbpm/calendar/jbpm.business.calendar.properties' />" +
" <string name='resource.default.modules' " +
" value='org/jbpm/graph/def/jbpm.default.modules.properties' />" +
" <string name='resource.converter' " +
" value='org/jbpm/db/hibernate/jbpm.converter.properties' />" +
" <string name='resource.action.types' " +
" value='org/jbpm/graph/action/action.types.xml' />" +
" <string name='resource.node.types' " +
" value='org/jbpm/graph/node/node.types.xml' />" +
" <string name='resource.varmapping' " +
" value='org/jbpm/context/exe/jbpm.varmapping.xml' />" +
"</jbpm-configuration>"
);
}
boolean isChiefHere;
String userId = "";
long processInstant_id;
public void setUp() {
userId = "dust";
isChiefHere = true;
}
public void test14DayAndBossNotApprove() throws Exception {
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
//this.deployProcessDefinition();
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
this.createProcessInstance();
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("----------------------------------------------------------------");
this.userWriteRequest(14);
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
System.out.println("----------------------------------------------------------------");
this.chiefDecide(true);
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
this.bossDecide(false);
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
this.checkTasks();
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
System.out.println("****************************************************************");
/*
*/
}
/*
public void test4DayAndChiefApprove() throws Exception {
this.deployProcessDefinition();
this.createProcessInstance();
this.userWriteRequest(4);
this.chiefDecide(true);
this.checkTasks();
}
public void test14DayAndChiefApproveAndUserCancel() throws Exception {
this.deployProcessDefinition();
this.createProcessInstance();
this.userWriteRequest(14);
this.chiefDecide(true);
this.userCancel();
this.checkTasks();
}
*/
protected void deployProcessDefinition() throws Exception {
System.out.println("==MyRequestProcessTest.deployProcessDefinition()==");
ProcessDefinition processDefinition = null;
FileInputStream fis = new FileInputStream(
"E://JAVA_PROJECT//workspace//jbpm.3//src//java.jbpm//com//myrequest//processdefinition.xml");
processDefinition = ProcessDefinition.parseXmlInputStream(fis);
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
// Deploy the process definition in the database
jbpmContext.deployProcessDefinition(processDefinition);
jbpmContext.close();
assertNotNull("Definition should not be null", processDefinition);
}
protected void createProcessInstance() throws Exception {
System.out.println("==MyRequestProcessTest.createProcessInstance()==");
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
GraphSession graphSession = jbpmContext.getGraphSession();
ProcessDefinition processDefinition =
graphSession.findLatestProcessDefinition("MyRequest");
assertNotNull("Definition should not be null", processDefinition);
ProcessInstance processInstance =
new ProcessInstance(processDefinition);
assertNotNull("processInstance should not be null", processInstance);
this.processInstant_id = processInstance.getId();
Join join_Request = (Join) processInstance.getProcessDefinition().getNode(
"Join_Request");
assertNotNull("should find join_request node !", join_Request);
join_Request.setDiscriminator(true);
// 设置申请人
processInstance.getContextInstance().createVariable(RequestVariable.userId,
this.userId);
processInstance.getContextInstance().createVariable(RequestVariable.isChiefHere,
new Boolean(this.isChiefHere));
// 启动流程
processInstance.getRootToken().signal();
jbpmContext.save(processInstance);
jbpmContext.close();
/*
System.out.println("==MyRequestProcessTest.createProcessInstance()==");
assertNotNull("Definition should not be null", pdf);
pi = new ProcessInstance(pdf);
assertNotNull("processInstance should not be null", pi);
Join join_Request = (Join) pi.getProcessDefinition().getNode(
"Join_Request");
assertNotNull("should find join_request node !", join_Request);
join_Request.setDiscriminator(true);
// 设置申请人
pi.getContextInstance().createVariable(RequestVariable.userId,
this.userId);
// 设置流程运行是,部门主管是否在岗
pi.getContextInstance().createVariable(RequestVariable.isChiefHere,
new Boolean(this.isChiefHere));
// 启动流程
pi.getRootToken().signal();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -