日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用JBPM工作流引擎測試的一個例子

本文提供使用jBPM工作流引擎測試的一個例子。

創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站設(shè)計、做網(wǎng)站與策劃設(shè)計,廣信網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:廣信等地區(qū)。廣信做網(wǎng)站價格咨詢:028-86922220

提供一個Persistence,用于存儲全局的變量值,方便存儲和獲取

 
 
 
 
  1. public class Persistence {
  2. private static Map variables = null;
  3. private static String tmpfile = System.getProperty("java.io.tmpdir") + "/temp.object";
  4. static{
  5. //加載文件
  6. try{
  7. if(new File(tmpfile).exists()){
  8. FileInputStream in = new FileInputStream(tmpfile);
  9. ObjectInputStream s = new ObjectInputStream(in); 
  10.     variables = (Map)s.readObject();
  11. }
  12. if(variables == null){
  13. variables = new HashMap();
  14. }
  15. }catch(Exception e){
  16. e.printStackTrace();
  17. }
  18. }
  19. //設(shè)置一個變量的值
  20. public static void setVariable(String name,Serializable object){
  21. if(variables != null){
  22. variables.put(name, object);
  23. }
  24. try {
  25. FileOutputStream fos = new FileOutputStream(tmpfile);
  26. ObjectOutputStream oos = new ObjectOutputStream(fos);
  27. oos.writeObject(variables);
  28. oos.flush();
  29. oos.close();
  30. fos.flush();
  31. fos.close();
  32. catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. //獲取一個變量的值
  37. public static Serializable getVariable(String name){
  38. if(variables != null){
  39. return (Serializable)variables.get(name);
  40. }
  41. return null;
  42. }
  43. }

1.首先使用流程設(shè)計器,創(chuàng)建一個簡單的流程規(guī)則

2.創(chuàng)建數(shù)據(jù)庫表,創(chuàng)建流程定義對象,并部署流程定義

 
 
 
 
  1. //創(chuàng)建數(shù)據(jù)庫表
  2. public class Jbpm_01_CreateTable extends TestCase {
  3. public void testCreateTable(){
  4. JbpmConfiguration.getInstance().createSchema();
  5. }
  6. }
  7. //定義流程定義對象,并部署流程
  8. public class Jbpm_02_DeployProcessDefinition extends TestCase {
  9. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  10. public void testDeployProcessDefinition(){
  11. //讀取流程定義文件,得到流程定義對象
  12. ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("test01/processdefinition.xml");
  13. //可以得到流程定義的名稱
  14. Persistence.setVariable("processName", processDefinition.getName());
  15. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  16. JbpmContext context = jbpmConfiguration.createJbpmContext();
  17. try{
  18. context.deployProcessDefinition(processDefinition);
  19. }catch(Exception e){
  20. e.printStackTrace();
  21. context.setRollbackOnly();
  22. }finally{
  23. context.close();
  24. }
  25. }
  26. }

3.定義公文Doucment 及其映射文件Doucment.hbm.xml

 
 
 
 
  1. public class Document {
  2. private int id;
  3. private String title;
  4. private String content;
  5. private Long processInstanceId;
  6. public String getContent() {
  7. return content;
  8. }
  9. public void setContent(String content) {
  10. this.content = content;
  11. }
  12. public int getId() {
  13. return id;
  14. }
  15. public void setId(int id) {
  16. this.id = id;
  17. }
  18. public Long getProcessInstanceId() {
  19. return processInstanceId;
  20. }
  21. public void setProcessInstanceId(Long processInstanceId) {
  22. this.processInstanceId = processInstanceId;
  23. }
  24. public String getTitle() {
  25. return title;
  26. }
  27. public void setTitle(String title) {
  28. this.title = title;
  29. }
  30. }
  31. //Document映射文件Document.hbm.xml
  32.   <class table="tbl_document" name="Document">
  33.     
  34.       class="native"/>
  35.     
  36.     
  37.     
  38.     
  39.   class>

4.創(chuàng)建公文并與流程實例綁定

 
 
 
 
  1. public class Jbpm_03_CreateDocument extends TestCase {
  2. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  3. public void testCreateDocument(){
  4. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  5. JbpmContext context = jbpmConfiguration.createJbpmContext();
  6. try{
  7. Document doc = new Document();
  8. doc.setTitle("測試公文"+new Random().nextInt(9999));
  9. context.getSession().save(doc);
  10. Persistence.setVariable("docId", doc.getId());
  11. }catch(Exception e){
  12. e.printStackTrace();
  13. context.setRollbackOnly();
  14. }finally{
  15. context.close();
  16. }
  17. }
  18. }

5.提交公文到流程,觸發(fā)流程流轉(zhuǎn)

 
 
 
 
  1. public class Jbpm_05_SubmitDocument extends TestCase {
  2. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  3. //提交公文到第一個環(huán)節(jié)
  4. public void testSubmitDocument(){
  5. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  6. JbpmContext context = jbpmConfiguration.createJbpmContext();
  7. try{
  8. //已知公文的信息
  9. int docId = (Integer)Persistence.getVariable("docId");
  10. Document doc = (Document)context.getSession().load(Document.class, docId);
  11. long processInstanceId = doc.getProcessInstanceId();
  12. ProcessInstance processInstance = context.getProcessInstance(processInstanceId);
  13. //觸發(fā)流程實例流轉(zhuǎn)到下一個環(huán)節(jié)
  14. processInstance.signal();
  15. }catch(Exception e){
  16. e.printStackTrace();
  17. context.setRollbackOnly();
  18. }finally{
  19. context.close();
  20. }
  21. }
  22. }

6.查看公文所處的當前任務(wù)節(jié)點

 
 
 
 
  1. public class Jbpm_06_CurrentNode extends TestCase {
  2. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  3. //公文當前所處的環(huán)節(jié)
  4. public void testCurrentNode(){
  5. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  6. JbpmContext context = jbpmConfiguration.createJbpmContext();
  7. try{
  8. //已知公文的信息
  9. int docId = (Integer)Persistence.getVariable("docId");
  10. Document doc = (Document)context.getSession().load(Document.class, docId);
  11. long processInstanceId = doc.getProcessInstanceId();
  12. ProcessInstance processInstance = context.getProcessInstance(processInstanceId);
  13. String currentNode = processInstance.getRootToken().getNode().getName();
  14. System.err.println("公文【"+doc.getTitle()+"】當前所處的環(huán)節(jié)" +
  15. "是:"+currentNode+",流程實例是否已結(jié)束?"+processInstance.hasEnded());
  16. }catch(Exception e){
  17. e.printStackTrace();
  18. context.setRollbackOnly();
  19. }finally{
  20. context.close();
  21. }
  22. }
  23. }

7.獲取流轉(zhuǎn)個某個參與者處待處理的任務(wù)列表

 
 
 
 
  1. public class Jbpm_07_SearchMyTaskList extends TestCase {
  2. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  3. //搜索流轉(zhuǎn)到某個參與者手上的公文列表
  4. public void testSearchMyTaskList(){
  5. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  6. JbpmContext context = jbpmConfiguration.createJbpmContext();
  7. try{
  8. printTask(context,"張三");
  9. printTask(context,"李四");
  10. printTask(context,"王五");
  11. }catch(Exception e){
  12. e.printStackTrace();
  13. context.setRollbackOnly();
  14. }finally{
  15. context.close();
  16. }
  17. }
  18. private void printTask(JbpmContext context,String actorId){
  19. List taskInstances = context.getTaskMgmtSession().findTaskInstances(actorId);
  20. for (Iterator iter = taskInstances.iterator(); iter.hasNext();) {
  21. TaskInstance ti = (TaskInstance) iter.next();
  22. Integer docId = (Integer)ti.getProcessInstance().getContextInstance().getVariable("documnt");
  23. Document doc = (Document)context.getSession().load(Document.class, docId);
  24. System.err.println("正在等待【"+actorId+"】審批的公文是:"+doc.getTitle());
  25. }
  26. }
  27. }

8.參與者執(zhí)行審批操作,觸發(fā)流程流轉(zhuǎn)到下一個環(huán)節(jié)

 
 
 
 
  1. public class Jbpm_08_NextNode extends TestCase {
  2. static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
  3. //從一個TaskNode的中間節(jié)點出發(fā),觸發(fā)流程流轉(zhuǎn)到下一個環(huán)節(jié)
  4. public void testNextNode(){
  5. //JbpmContext對象封裝了hibernate session 對象的功能,可以執(zhí)行與數(shù)據(jù)庫持久化相關(guān)的操作
  6. JbpmContext context = jbpmConfiguration.createJbpmContext();
  7. try{
  8. //*******************************************
  9. //某某用戶要將其手上的某某公文提交到下一個環(huán)節(jié)
  10. //*******************************************
  11. //已知要提交的公文
  12. Integer docId = (Integer)Persistence.getVariable("docId");
  13.  
  14.                     nextStep(context,"張三",docId);
  15.                     nextStep(context,"李四",docId);
  16. nextStep(context,"王五",docId);
  17.  
  18. }catch(Exception e){
  19. e.printStackTrace();
  20. context.setRollbackOnly();
  21. }finally{
  22. context.close();
  23. }
  24. }
  25. private void nextStep(JbpmContext context,String actorId,Integer docId){
  26. List taskInstances = context.getTaskMgmtSession().findTaskInstances(actorId);
  27. for (Iterator iter = taskInstances.iterator(); iter.hasNext();) {
  28. TaskInstance ti = (TaskInstance) iter.next();
  29. Integer _docId = (Integer)ti.getProcessInstance().getContextInstance().getVariable("documnt");
  30. //找到對應(yīng)的任務(wù)實例
  31. if(docId.equals(_docId)){
  32. Document doc = (Document)context.getSession().load(Document.class, docId);
  33. //參與者的任務(wù)已經(jīng)處理完成,需要結(jié)束這個任務(wù)實例
  34. //這個動作,在缺省的情況下,會觸發(fā)對應(yīng)的Token的signal()方法,即流向下一個環(huán)節(jié)
  35. ti.end();
  36. System.err.println("公文【"+doc.getTitle()+"】已被【"+actorId+"】審批完成,已提交到下一個環(huán)節(jié)");
  37. }
  38. }
  39. }
  40. }

本文題目:使用JBPM工作流引擎測試的一個例子
URL鏈接:http://www.5511xx.com/article/dhpgcgc.html