jbpm4.3轻松 实现会签完整版

转自:http://hi.baidu.com/suwey/blog/item/0a5bcf1fa2639d6ff624e4f0.html

 

类似文章:http://phoenix-clt.iteye.com/blog/428242

 

jbpm4.3中会签的实现主要思路也是从网上找的。新接触jbpm简单的实现下,如果有什么疑问或错误,请指正。

JPDL代码


<?xml version="1.0" encoding="UTF-8"?>

<process name="huigao" xmlns="http://jbpm.org/4.3/jpdl " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation="http://jbpm.org/4.3/jpdl http://jbpm.org/4.3/jpdl ">
   <start g="172,34,48,48" name="开始">
      <transition g="-53,-17" name="审稿" to="审稿"/>
   </start>
   <task assignee="shengao" form="com/zhangrun/forms/first.ftl" g="150,125,92,52" name="审稿">
      <transition g="-83,-17" name="会稿或办文" to="会稿或办文"/>
   </task>
   <decision g="178,227,48,48" name="会稿或办文">
      <transition g="-65,-17" name="会稿" to="会稿">
      <condition expr=" # { select=="huigao" } "/>
      </transition>
      <transition g="-53,-17" name="办文" to="办文">
      <condition expr=" # { select==" banwen " } "/>
      </transition>
   </decision>
   <custom class="com.zhangrun.custom.Custom" g="16,230,92,52" name="会稿">
      <transition g="60,153:-53,-17" name="审稿" to="审稿"/>
   </custom>
   <task assignee="banwen" g="298,225,92,52" name="办文">
      <transition g="348,373:-47,-17" name="结束" to="结束"/>
   </task>
   <end g="180,354,48,48" name="结束"/>
</process>

JAVA代码

public class Custom implements ExternalActivityBehaviour {

private static final long serialVersionUID = 1L;

public void execute(ActivityExecution activityExecution) throws Exception {
   ExecutionImpl executionimpl = (ExecutionImpl) activityExecution;

   DbSession dbsession = EnvironmentImpl.getFromCurrent(DbSession.class);
   TaskImpl taskimpl = dbsession.createTask();
   taskimpl.setName("customTem");
   taskimpl.setExecution(executionimpl);
   taskimpl.setProcessInstance(executionimpl.getProcessInstance());
   taskimpl.setSignalling(false);
   taskimpl.setExecutionDbid(executionimpl.getDbid());
   dbsession.save(taskimpl);
   HistoryEvent.fire(new TaskActivityStart(taskimpl), executionimpl);
   // 子任务
   TaskImpl subtaskimpl1 = taskimpl.createSubTask();
   subtaskimpl1.setName("huigao1");
   subtaskimpl1.setAssignee("huigao1");
   subtaskimpl1.setSignalling(false);
   subtaskimpl1.setExecutionDbid(executionimpl.getDbid());
   dbsession.save(subtaskimpl1);
   HistoryEvent.fire(new TaskActivityStart(subtaskimpl1), executionimpl);
   TaskImpl subtaskimpl2 = taskimpl.createSubTask();
   subtaskimpl2.setName("huigao2");
   subtaskimpl2.setAssignee("huigao2");
   subtaskimpl2.setExecutionDbid(executionimpl.getDbid());
   subtaskimpl2.setSignalling(false);
   dbsession.save(subtaskimpl2);
   HistoryEvent.fire(new TaskActivityStart(subtaskimpl2), executionimpl);
   // 流程等待
   executionimpl.waitForSignal();
}

public void signal(ActivityExecution activityExecution, String signalName,
    Map<String, ?> parms) throws Exception {
   ExecutionImpl executionImpl = (ExecutionImpl) activityExecution;
   ProcessInstance pi = (ProcessInstance) executionImpl
     .getProcessInstance();
   TaskService taskService = Configuration.getProcessEngine()
     .getTaskService();
   Activity activity = executionImpl.getActivity();
   List<Task> tasks = taskService.createTaskQuery().processInstanceId(
     pi.getId()).list();

   List<Task> subTask_list = taskService.getSubTasks(tasks.get(0).getId());
   Iterator<Task> iter = subTask_list.iterator();
   while (iter.hasNext()) {
    Task subtask = iter.next();
    if (parms.get("username").equals(subtask.getAssignee())) {
     taskService.completeTask(subtask.getId());
    }
   }
   if (subTask_list == null || subTask_list.size() == 1) {
    Transition transition = null;
    if ((signalName == null)
      || ((Task.STATE_COMPLETED.equals(signalName))
        && (activity.getOutgoingTransitions() != null) && (activity
        .getOutgoingTransitions().size() == 1))) {
     transition = activity.getOutgoingTransitions().get(0);
    } else {
     transition = activity.findOutgoingTransition(signalName);
    }
    taskService.completeTask(tasks.get(0).getId());
    executionImpl.take(transition);
   } else {
    executionImpl.waitForSignal();
   }
}

}

 

转载自:http://www.blogjava.net/pengo/archive/2009/12/09/305226.html

你可能感兴趣的:(html,.net,xml,jbpm,Blog)