Esempio n. 1
0
  public ActionForward insertPayment(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws AppException {
    String forwardPage = "";
    Inform inf = new Inform();

    Workflow workflow = (Workflow) form;

    JbpmContext jbpmContext = JbpmUtil.getJbpmContext();
    try {
      String issueperson = "user1";
      // 设置当前用户为user1
      jbpmContext.setActorId(issueperson);

      ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("payment");

      ProcessInstance processInstance = pd.createProcessInstance();
      ContextInstance contextInstance = processInstance.getContextInstance();

      //
      contextInstance.setVariable("issueperson", issueperson);

      // 创建开始节点的TaskInstance
      TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();

      // 向任务实例当中写入相关变量
      taskInstance.setVariable("title", workflow.getTitle());
      taskInstance.setVariable("moneyCount", workflow.getMoneyCount());
      taskInstance.setVariable("remark", workflow.getRemark());

      // 结束任务实例,token进入部门经理审批
      taskInstance.end();

      inf.setMessage("报销申请提交成功");
    } catch (Exception e) {
      e.printStackTrace();
      inf.setMessage("异常信息:" + e.getMessage());
    } finally {
      jbpmContext.close();
    }
    return forwardInformPage(inf, mapping, request);
  }
Esempio n. 2
0
  /** Add Task Instance Variable Esto creo que sobra pq no se puede hacer */
  public static void addTaskInstanceVariable(long taskInstanceId, String name, Object value)
      throws WorkflowException {
    log.debug("addTaskInstanceVariable({}, {}, {})", new Object[] {taskInstanceId, name, value});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      org.jbpm.taskmgmt.exe.TaskInstance ti = jbpmContext.getTaskInstance(taskInstanceId);
      ti.setVariable(name, value);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("addTaskInstanceVariable: void");
  }
  public void testTimerInCombinationWithAsyncNode() throws Throwable {
    ProcessDefinition subDefinition =
        ProcessDefinition.parseXmlString(
            "<process-definition name='sub'>"
                + "  <start-state name='start'>"
                + "    <transition to='decision'/>"
                + "  </start-state>"
                + "  <decision name='decision'>"
                + "    <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />"
                + "    <transition name='default' to='task' />"
                + "  </decision>"
                + "  <task-node name='task'>"
                + "    <task name='do stuff'>"
                + "      <controller>"
                + "        <variable name='a' access='read' />"
                + "      </controller>"
                + "      <assignment actor-id='victim' />"
                + "    </task>"
                + "    <transition to='end'/>"
                + "  </task-node>"
                + "  <end-state name='end' />"
                + "</process-definition>");
    jbpmContext.deployProcessDefinition(subDefinition);
    newTransaction();

    ProcessDefinition superDefinition =
        ProcessDefinition.parseXmlString(
            "<process-definition name='super'>"
                + "  <start-state name='start'>"
                + "    <transition to='decision'/>"
                + "  </start-state>"
                + "  <decision name='decision'>"
                + "    <handler class='org.jbpm.scenarios.AsyncTimerAndSubProcessDbTest$ToTimedDecisionHandler' />"
                + "    <transition name='default' to='timed' />"
                + "  </decision>"
                + "  <state name='timed'>"
                + "    <timer name='reminder' "
                + "           duedate='0 seconds' "
                + "           transition='timer fires' />"
                + "    <transition name='timer fires' to='async'/>"
                + "    <transition name='normal continuation' to='end'/>"
                + "  </state>"
                + "  <node name='async' async='true'>"
                + "    <transition to='subprocess'/>"
                + "  </node>"
                + "  <process-state name='subprocess'>"
                + "    <sub-process name='sub' />"
                + "    <variable name='a'/>"
                + "    <variable name='b'/>"
                + "    <transition to='decision' />"
                + "  </process-state>"
                + "  <end-state name='end' />"
                + "</process-definition>");
    jbpmContext.deployProcessDefinition(superDefinition);
    newTransaction();

    ProcessInstance superInstance = jbpmContext.newProcessInstanceForUpdate("super");
    ContextInstance superContext = superInstance.getContextInstance();
    superContext.setVariable("a", "value a");
    superContext.setVariable("b", "value b");
    superInstance.signal();

    processJobs(5000);

    superInstance = jbpmContext.loadProcessInstance(superInstance.getId());
    assertEquals("subprocess", superInstance.getRootToken().getNode().getName());

    List taskInstances = taskMgmtSession.findTaskInstances("victim");
    assertEquals(1, taskInstances.size());
    TaskInstance taskInstance = (TaskInstance) taskInstances.get(0);
    taskInstance.setVariable("a", "value a updated");
    taskInstance.setVariable("b", "value b updated");
    taskInstance.end();

    jbpmContext.save(taskInstance);
    long taskInstanceId = taskInstance.getId();
    long tokenId = taskInstance.getToken().getId();
    newTransaction();

    taskInstance = jbpmContext.loadTaskInstance(taskInstanceId);
    assertEquals("value a updated", taskInstance.getVariable("a"));
    assertEquals("value b updated", taskInstance.getVariable("b"));

    Token token = jbpmContext.loadToken(tokenId);
    ContextInstance subContextInstance = token.getProcessInstance().getContextInstance();
    assertEquals("value a", subContextInstance.getVariable("a"));
    assertEquals("value b updated", subContextInstance.getVariable("b"));
  }