gdufo

           

          一個(gè)簡(jiǎn)單的會(huì)簽實(shí)例

          http://www.aygfsteel.com/jbpm/archive/2007/10/15/153036.html

           一個(gè)簡(jiǎn)單的會(huì)簽實(shí)例

          作者:tomkoo
          以下例子中 采用了jbpm console 的幾個(gè)實(shí)例用戶

          項(xiàng)目提交人 : ernie .

          主管審批 : bert

          會(huì)簽 : ernie , bert , grover

          老板審批 : grover

           

          正常流程: 項(xiàng)目金額 >= 500W RMB

          提交項(xiàng)目 --> 主管審批 --> 會(huì)簽 --> 老板審批 --> 審批通過(guò)(結(jié)束)

          正常流程: 項(xiàng)目金額 < 500W RMB

          提交項(xiàng)目 --> 主管審批 --> 會(huì)簽 --> 審批通過(guò)(結(jié)束)

          其中主管審批, 會(huì)簽, 老板審批 , 不通過(guò), 全部退回給項(xiàng)目提交人修改.

          會(huì)簽中: 所有人全通過(guò), 則通過(guò). 任何一人不通過(guò), 停止其他會(huì)簽任務(wù).退回給提交人.

          流程定義如下:

             1. <?xml version="1.0" encoding="UTF-8"?> 
             2.  
             3. <process-definition xmlns="urn:jbpm.org:jpdl-3.1" 
             4.     name="tc_prj_approval"> 
             5.  
             6.     <swimlane name="initiator" /> 
             7.  
             8.     <!項(xiàng)目提交人 > 
             9.     <swimlane name="requester"> 
            10.         <assignment expression="user(ernie)" /> 
            11.     </swimlane> 
            12.  
            13.     <! 主管 > 
            14.     <swimlane name="chief"> 
            15.         <assignment expression="user(bert)" /> 
            16.     </swimlane> 
            17.  
            18.     <!老板 > 
            19.     <swimlane name="boss"> 
            20.         <assignment expression="user(grover)" /> 
            21.     </swimlane> 
            22.  
            23.     <!會(huì)簽人 > 
            24.     <swimlane name="cosinger"> 
            25.         <assignment class="net.chenj.jbpm.sample.CosingerAssiHandler"> 
            26.         </assignment> 
            27.     </swimlane> 
            28.     <start-state name="start"> 
            29.         <task name="tc_prj_newprj" swimlane="initiator"></task> 
            30.         <transition name="to_submit" to="tc_prj_submit"></transition> 
            31.     </start-state> 
            32.     <task-node name="tc_prj_submit"> 
            33.         <task name="tc_prj_submit"></task> 
            34.         <transition name="to_chiefapprove" to="tc_prj_chiefapprove"></transition> 
            35.     </task-node> 
            36.     <task-node name="tc_prj_chiefapprove"> 
            37.         <task name="tc_prj_chiefapprove"></task> 
            38.         <transition name="approve" to="tc_prj_countersign"></transition> 
            39.         <transition name="disapprove" to="tc_prj_submit"></transition> 
            40.     </task-node> 
            41.     <task-node name="tc_prj_countersign" signal="last-wait" 
            42.         create-tasks="false"> 
            43.         <task name="tc_prj_countersign"> 
            44.             <event type="task-end"> 
            45.                 <action 
            46.                     class="net.chenj.jbpm.sample.TaskEndCountersign"> 
            47.                 </action> 
            48.             </event> 
            49.  
            50.         </task> 
            51.  
            52.         <event type="node-enter"> 
            53.             <action name="createInstance" 
            54.                 class="net.chenj.jbpm.sample.CreateTaskInstanceCountersign"> 
            55.             </action> 
            56.         </event> 
            57.  
            58.         <transition name="approve" to="amount_decision"></transition> 
            59.         <transition name="disapprove" to="tc_prj_submit"></transition> 
            60.     </task-node> 
            61.     <decision name="amount_decision"> 
            62.         <transition name="to_bossapprove" to="tc_prj_bossapprove"></transition> 
            63.         <transition name="to_end" to="end1"></transition> 
            64.     </decision> 
            65.     <task-node name="tc_prj_bossapprove"> 
            66.         <task name="tc_prj_bossapprove"></task> 
            67.         <transition name="approve" to="end1"></transition> 
            68.         <transition name="disapprove" to="tc_prj_submit"> 
            69.             <condition>#{amount >= 500}</condition> 
            70.         </transition> 
            71.     </task-node> 
            72.     <end-state name="end1"></end-state> 
            73. </process-definition> 
            74.  

           

          會(huì)簽swimlane class

             1. package net.chenj.jbpm.sample;  
             2.  
             3. import org.jbpm.graph.exe.*;  
             4. import org.jbpm.taskmgmt.def.*;  
             5. import org.jbpm.taskmgmt.exe.Assignable;  
             6.  
             7. public class CosingerAssiHandler implements AssignmentHandler {  
             8.  
             9.     private static final long serialVersionUID = 1L;  
            10.  
            11.     public void assign(Assignable assignable, ExecutionContext executionContext) {  
            12.         // 從數(shù)據(jù)庫(kù)或者ldap 讀取會(huì)簽人設(shè)置  
            13.         String[] a = { "ernie", "bert", "grover" };  
            14.         assignable.setPooledActors(a);  
            15.     }  
            16.  
            17. }  
            18.  


          創(chuàng)建會(huì)簽任務(wù)實(shí)現(xiàn)類

           

           

             1. package net.chenj.jbpm.sample;  
             2.  
             3. import org.jbpm.graph.def.ActionHandler;  
             4. import org.jbpm.graph.exe.ExecutionContext;  
             5. import org.jbpm.graph.exe.Token;  
             6. import org.jbpm.graph.node.TaskNode;  
             7. import org.jbpm.taskmgmt.def.Task;  
             8. import org.jbpm.taskmgmt.exe.TaskMgmtInstance;  
             9.  
            10. public class CreateTaskInstanceCountersign implements ActionHandler {  
            11.  
            12.     private static final long serialVersionUID = 1L;  
            13.  
            14.     public void execute(ExecutionContext executionContext) throws Exception {  
            15.  
            16.         Token token = executionContext.getToken();  
            17.         TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();  
            18.         TaskNode taskNode = (TaskNode) executionContext.getNode();  
            19.         Task task = taskNode.getTask("tc_prj_countersign");  
            20.         // 從數(shù)據(jù)庫(kù)或者ldap 讀取會(huì)簽人設(shè)置創(chuàng)建任務(wù)實(shí)例  
            21.         tmi.createTaskInstance(task, token).setActorId("ernie");  
            22.         tmi.createTaskInstance(task, token).setActorId("bert");  
            23.         tmi.createTaskInstance(task, token).setActorId("grover");  
            24.  
            25.     }  
            26.  
            27. }  

           

          結(jié)束不通過(guò)時(shí)結(jié)束其他會(huì)簽任務(wù)實(shí)現(xiàn)

             1. package net.chenj.jbpm.sample;  
             2.  
             3. import java.util.Collection;  
             4. import java.util.Iterator;  
             5. import org.jbpm.graph.def.ActionHandler;  
             6. import org.jbpm.graph.exe.ExecutionContext;  
             7. import org.jbpm.taskmgmt.exe.TaskInstance;  
             8. import org.jbpm.taskmgmt.exe.TaskMgmtInstance;  
             9.  
            10. public class TaskEndCountersign implements ActionHandler {  
            11.  
            12.     private static final long serialVersionUID = 1L;  
            13.  
            14.     public void execute(ExecutionContext executionContext) throws Exception {  
            15.  
            16.       
            17.         boolean isDisapprove = Boolean.valueOf((String) executionContext  
            18.                 .getVariable("isDisapprove"));  
            19.         // 如果有一個(gè)任務(wù)實(shí)例拒絕通過(guò)則結(jié)束除當(dāng)前任務(wù)實(shí)例外其他任務(wù)實(shí)例  
            20.         if (isDisapprove) {  
            21.             TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();  
            22.             TaskInstance ti = executionContext.getTaskInstance();  
            23.             final String actorId = ti.getActorId();  
            24.             Collection c = tmi.getSignallingTasks(executionContext);  
            25.             for (Iterator it = c.iterator(); it.hasNext();) {  
            26.                 TaskInstance task = (TaskInstance) it.next();  
            27.                 if (!(actorId.equals(task.getActorId())) && (!task.hasEnded())) {  
            28.                     task.end("disapprove");  
            29.                 }  
            30.             }  
            31.         }  
            32.  
            33.     }  
            34.  
            35. }  

          task-node"主管會(huì)計(jì)復(fù)核"則是我們需要進(jìn)行會(huì)簽的節(jié)點(diǎn)。在這個(gè)節(jié)點(diǎn)我們?cè)O(shè)置了幾個(gè)重要的屬性:

            1) signal="last-wait",這個(gè)屬性決定了該節(jié)點(diǎn)將在完成該節(jié)點(diǎn)內(nèi)的所有Task的TaskInstance以后才會(huì)進(jìn)入下一個(gè)節(jié)點(diǎn)。)

            2) create-tasks="false",這個(gè)屬性決定了在進(jìn)入該節(jié)點(diǎn)的時(shí)候,不會(huì)自動(dòng)為該節(jié)點(diǎn)的任何Task創(chuàng)建任何的TaskInstance。因?yàn)槲覀冃枰鶕?jù)會(huì)簽的人員來(lái)自己創(chuàng)建TaskInstance。
          1. <eventtype="node-enter">
          進(jìn)入流程節(jié)點(diǎn)的時(shí)候,執(zhí)行ActionHandler類com.sky.plugin.jbpm.def.DynamicCreateTaskInstance,用來(lái)動(dòng)態(tài)生成TaskInstance。
          2. <eventtype="task-end">
          Task結(jié)束的時(shí)候調(diào)用com.sky.plugin.jbpm.def.ConuntersignActionHandler進(jìn)行會(huì)簽處理。判斷會(huì)簽路徑來(lái)決定會(huì)簽的執(zhí)行和走向。

          參考文章
          http://linliangyi2007.javaeye.com/blog/176356
          http://tomkoo.javaeye.com/blog/24690
          http://cache.baidu.com/c?m=9d78d513d99405f804ab837e7c509c244e4380127a84914c68d5e35f93124c403731bfed3365505adc9f3a2143b8482ff7ed7337721420c0c39bcc198af0c53f2fff76692f01c41c539504afca4322ca2b&p=9174c64ad1830ac308e2957e1e55&user=baidu







          posted on 2008-09-18 11:57 gdufo 閱讀(757) 評(píng)論(0)  編輯  收藏 所屬分類: workflow

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          Hibernate

          友情鏈接

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 荔浦县| 独山县| 渝中区| 闸北区| 伊宁市| 南皮县| 云霄县| 乐至县| 石景山区| 乾安县| 揭西县| 蓝山县| 德化县| 祁门县| 兴化市| 金秀| 昆明市| 资兴市| 卢湾区| 车致| 新兴县| 庐江县| 宁强县| 唐河县| 屏东市| 延安市| 宜阳县| 丁青县| 分宜县| 交城县| 贺州市| 天镇县| 祁门县| 五华县| 香格里拉县| 宾阳县| 八宿县| 麻江县| 波密县| 石棉县| 广南县|