예제 #1
0
  @SuppressWarnings("rawtypes")
  public static ProcessDefinition findLastProcessDefinition(String name) throws WorkflowException {
    log.debug("findLastProcessDefinition()");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessDefinition pd = new ProcessDefinition();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findLatestProcessDefinitions().iterator(); it.hasNext(); ) {
        org.jbpm.graph.def.ProcessDefinition procDef =
            (org.jbpm.graph.def.ProcessDefinition) it.next();

        if (procDef.getName().equals(name)) {
          pd = WorkflowUtils.copy(procDef);
        }
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findLastProcessDefinition: {}", pd);
    return pd;
  }
예제 #2
0
  /** End Task Instance */
  public static void endTaskInstance(long taskInstanceId, String transitionName)
      throws WorkflowException {
    log.debug("endTaskInstance({}, {})", new Object[] {taskInstanceId, transitionName});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
      org.jbpm.taskmgmt.exe.TaskInstance ti = taskMgmtSession.getTaskInstance(taskInstanceId);

      if (transitionName != null && !transitionName.equals("")) {
        if (ti.getStart() == null) {
          ti.start();
        }

        ti.end(transitionName);
      } else {
        if (ti.getStart() == null) {
          ti.start();
        }

        ti.end();
      }

      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("endTaskInstance: void");
  }
예제 #3
0
  /** Find All Process Definition Versions */
  @SuppressWarnings("rawtypes")
  public static List<ProcessDefinition> findAllProcessDefinitionVersions(String name)
      throws WorkflowException {
    log.debug("findAllProcessDefinitionVersions({})", name);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    List<ProcessDefinition> al = new ArrayList<ProcessDefinition>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findAllProcessDefinitionVersions(name).iterator();
          it.hasNext(); ) {
        org.jbpm.graph.def.ProcessDefinition procDef =
            (org.jbpm.graph.def.ProcessDefinition) it.next();
        al.add(WorkflowUtils.copy(procDef));
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findAllProcessDefinitionVersions: {}", al);
    return al;
  }
예제 #4
0
  /** Find Task Instances */
  @SuppressWarnings("rawtypes")
  public static List<TaskInstance> findTaskInstances(long processInstanceId)
      throws WorkflowException {
    log.debug("findTaskInstances({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ArrayList<TaskInstance> al = new ArrayList<TaskInstance>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.exe.ProcessInstance pi = graphSession.getProcessInstance(processInstanceId);
      TaskMgmtInstance taskMgmtInstance = pi.getTaskMgmtInstance();

      if (taskMgmtInstance.getTaskInstances() != null) {
        for (Iterator it = taskMgmtInstance.getTaskInstances().iterator(); it.hasNext(); ) {
          org.jbpm.taskmgmt.exe.TaskInstance ti = (org.jbpm.taskmgmt.exe.TaskInstance) it.next();
          al.add(WorkflowUtils.copy(ti));
        }
      }

      // Sort
      Collections.sort(al);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findTaskInstances: {}", al);
    return al;
  }
예제 #5
0
  /** Register Process Definition */
  public static void registerProcessDefinition(InputStream is)
      throws WorkflowException, ParseException, IOException {
    log.debug("registerProcessDefinition({})", is);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    InputStream isForms = null;
    ZipInputStream zis = null;

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      zis = new ZipInputStream(is);
      org.jbpm.graph.def.ProcessDefinition processDefinition =
          org.jbpm.graph.def.ProcessDefinition.parseParZipInputStream(zis);

      // Check xml form definition
      FileDefinition fileDef = processDefinition.getFileDefinition();
      isForms = fileDef.getInputStream("forms.xml");
      FormUtils.parseWorkflowForms(isForms);

      // If it is ok, deploy it
      jbpmContext.deployProcessDefinition(processDefinition);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      IOUtils.closeQuietly(isForms);
      IOUtils.closeQuietly(zis);
      jbpmContext.close();
    }

    log.debug("registerProcessDefinition: void");
  }
예제 #6
0
  /** Find Pooled Task Instances */
  @SuppressWarnings("rawtypes")
  public static List<TaskInstance> findPooledTaskInstances(String user) throws WorkflowException {
    log.debug("findPooledTaskInstances({})", user);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ArrayList<TaskInstance> al = new ArrayList<TaskInstance>();

    try {
      TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();

      for (Iterator it = taskMgmtSession.findPooledTaskInstances(user).iterator(); it.hasNext(); ) {
        org.jbpm.taskmgmt.exe.TaskInstance ti = (org.jbpm.taskmgmt.exe.TaskInstance) it.next();
        al.add(WorkflowUtils.copy(ti));
      }

      // Sort
      Collections.sort(al);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findPooledTaskInstances: {}", al);
    return al;
  }
예제 #7
0
  public ActionForward processPayment(
      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 {
      long taskInstanceId = workflow.getTaskInstanceId();
      TaskInstance taskInstance = jbpmContext.getTaskInstance(taskInstanceId);
      // String isSubmit 结束/总经理处理 此处省略
      taskInstance.end();
      inf.setMessage("处理完成");
      inf.setForwardPage("../workflow/workflowList.do?thisAction=listTask");
    } catch (Exception e) {
      e.printStackTrace();
      inf.setMessage("异常信息:" + e.getMessage());
    } finally {
      jbpmContext.close();
    }
    return forwardInformPage(inf, mapping, request);
  }
예제 #8
0
  /** Get Process Definition Forms */
  public static Map<String, List<FormElement>> getProcessDefinitionForms(long processDefinitionId)
      throws ParseException {
    log.debug("getProcessDefinitionForms({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();
    InputStream is = null;

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      FileDefinition fileDef = pd.getFileDefinition();
      is = fileDef.getInputStream("forms.xml");

      if (is != null) {
        forms = FormUtils.parseWorkflowForms(is);
      } else {
        log.warn("Process definition '{}' has no forms.xml file", processDefinitionId);
      }
    } finally {
      IOUtils.closeQuietly(is);
      jbpmContext.close();
    }

    log.debug("getProcessDefinitionForms: {}", forms);
    return forms;
  }
예제 #9
0
  /** Find Process Instance */
  @SuppressWarnings("rawtypes")
  public static List<ProcessInstance> findProcessInstances(long processDefinitionId)
      throws WorkflowException {
    log.debug("findProcessInstances({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    List<ProcessInstance> al = new ArrayList<ProcessInstance>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findProcessInstances(processDefinitionId).iterator();
          it.hasNext(); ) {
        org.jbpm.graph.exe.ProcessInstance procInst =
            (org.jbpm.graph.exe.ProcessInstance) it.next();
        al.add(WorkflowUtils.copy(procInst));
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findProcessInstances: {}", al);
    return al;
  }
예제 #10
0
  /** Send Token Signal */
  public static Token sendTokenSignal(long tokenId, String transitionName)
      throws WorkflowException {
    log.debug("sendTokenSignal({}, {})", new Object[] {tokenId, transitionName});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    Token vo = new Token();

    try {
      org.jbpm.graph.exe.Token t = jbpmContext.getToken(tokenId);

      if (transitionName != null && !transitionName.equals("")) {
        t.signal(transitionName);
      } else {
        t.signal();
      }

      jbpmContext.getSession().flush();
      vo = WorkflowUtils.copy(t);

      // Avoid recursion
      vo.setProcessInstance(WorkflowUtils.copy(t.getProcessInstance()));
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("sendTokenSignal: {}", vo);
    return vo;
  }
예제 #11
0
  /** Send Process Instance Signal */
  public static ProcessInstance sendProcessInstanceSignal(
      long processInstanceId, String transitionName) throws WorkflowException {
    log.debug(
        "sendProcessInstanceSignal({}, {})", new Object[] {processInstanceId, transitionName});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.exe.ProcessInstance pi = graphSession.getProcessInstance(processInstanceId);
      org.jbpm.graph.exe.Token t = pi.getRootToken();

      if (transitionName != null && !transitionName.equals("")) {
        t.signal(transitionName);
      } else {
        t.signal();
      }

      jbpmContext.getSession().flush();
      vo = WorkflowUtils.copy(pi);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("sendProcessInstanceSignal: {}", vo);
    return vo;
  }
예제 #12
0
  @Test
  public void startProcess() {
    JbpmContext jbpmContext = null;
    try {
      jbpmContext = ProcessContainer.getContainer().createJbpmContext();
      ProcessContext ctx = new ProcessContext();
      ctx.setRowId(UUID32.getUUID()); // 审核表的记录ID,类型要匹配
      ctx.setActorId("joy"); // 参与者,登录用户帐户
      ctx.setTitle("单据编号:" + ctx.getRowId()); // 流程标题
      ctx.setProcessName("SimpleProcess"); // 流程名称(英文的名称)

      Collection<DataField> datafields = new java.util.concurrent.CopyOnWriteArrayList<DataField>();

      DataField datafield = new DataField();
      datafield.setName("isAgree"); // 控制参数名称
      datafield.setValue("true"); // 控制参数值
      datafields.add(datafield);

      DataField datafield2 = new DataField();
      datafield2.setName("money");
      datafield2.setValue(2345.88D);
      datafields.add(datafield2);

      DataField datafield3 = new DataField();
      datafield3.setName("Auditor1"); // 控制参数名称
      datafield3.setValue("joe,dane"); // 控制参数值
      datafields.add(datafield3);

      DataField datafield4 = new DataField();
      datafield4.setName("Auditor2"); // 控制参数名称
      datafield4.setValue("jack,rick"); // 控制参数值
      datafields.add(datafield4);

      DataField datafield5 = new DataField();
      datafield5.setName("signatureDate");
      datafield5.setValue(new Date());
      datafields.add(datafield5);

      ctx.setDataFields(datafields); // 控制参数

      processInstanceId = ProcessContainer.getContainer().startProcess(ctx);

      // 如果流程实例编号不为空,那么已经成功创建流程实例,否则抛出异常
      if (processInstanceId != null) {
        System.out.println("processInstanceId=" + processInstanceId);
        System.out.println("OK!");
      }
    } catch (Exception ex) {
      if (jbpmContext != null) {
        jbpmContext.setRollbackOnly();
      }
      ex.printStackTrace();
      throw new JbpmException(ex);
    } finally {
      Context.close(jbpmContext);
    }
    complateTask(processInstanceId);
  }
예제 #13
0
  /** Start Process Definition */
  public static ProcessInstance runProcessDefinition(
      String user, long processDefinitionId, String uuid, List<FormElement> variables)
      throws WorkflowException {
    log.debug(
        "runProcessDefinition({}, {}, {}, {})",
        new Object[] {user, processDefinitionId, uuid, variables});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      jbpmContext.setActorId(user);
      GraphSession graphSession = jbpmContext.getGraphSession();
      Map<String, Object> hm = new HashMap<String, Object>();
      hm.put(Config.WORKFLOW_PROCESS_INSTANCE_VARIABLE_UUID, uuid);

      for (FormElement fe : variables) {
        hm.put(fe.getName(), fe);
      }

      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      org.jbpm.graph.exe.ProcessInstance pi = pd.createProcessInstance(hm);

      if (pi != null) {
        org.jbpm.taskmgmt.exe.TaskMgmtInstance tmi = pi.getTaskMgmtInstance();

        // http://community.jboss.org/thread/115182
        if (tmi.getTaskMgmtDefinition().getStartTask() != null) {
          org.jbpm.taskmgmt.exe.TaskInstance ti = tmi.createStartTaskInstance();

          if (Config.WORKFLOW_START_TASK_AUTO_RUN) {
            ti.start();
            ti.end();
          }
        } else {
          pi.getRootToken().signal();
        }

        jbpmContext.save(pi);
        vo = WorkflowUtils.copy(pi);
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("runProcessDefinition: {}", vo);
    return vo;
  }
예제 #14
0
  public ProcessInstance getProcessInstance(Long id) {
    JbpmContext context = Jbpm.instance().getJbpmConfiguration().createJbpmContext();
    // log.debug("!!!!!!!!!!!!!!!!!!!!!!!!!: " + context);
    /*
    try {
    	log.debug("!!!!!!!!!!!!!!!!!!!!!!!!!: " + context.getConnection().isClosed());
    }catch(SQLException e) {
    	e.printStackTrace();
    }
    */

    return context.getProcessInstance(id);
  }
예제 #15
0
  /** Delete Process Instance */
  public static void deleteProcessInstance(long processInstanceId) throws WorkflowException {
    log.debug("deleteProcessInstance({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      graphSession.deleteProcessInstance(processInstanceId);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }
  }
예제 #16
0
  /** Resume Process Instance */
  public static void resumeProcessInstance(long processInstanceId) throws WorkflowException {
    log.debug("resumeProcessInstance({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      org.jbpm.graph.exe.ProcessInstance pi = jbpmContext.getProcessInstance(processInstanceId);
      pi.resume();
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }
  }
예제 #17
0
  /** End Token */
  public static void endToken(long tokenId) throws WorkflowException {
    log.debug("endToken({})", tokenId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      jbpmContext.getToken(tokenId).end();
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("endToken: void");
  }
예제 #18
0
  public void updateProcessDefinition(
      String xmlProcessDefinition, WorkflowProcessDef wfProcessDefEntity)
      throws OperationException {
    Long l = Long.parseLong(wfProcessDefEntity.getProcessDefEngineKey());
    GraphSession graphSession = jbpmContext.getGraphSession();
    ProcessDefinition processDefinition = graphSession.getProcessDefinition(l);
    if (processDefinition != null) {
      ProcessDefinition newPD = processDefinition.parseXmlString(xmlProcessDefinition);
      processDefinition.setProcessDefinition(newPD);

      jbpmContext.getSession().merge(processDefinition);
    } else {
      throw new OperationException("Could not find process definition with (engine) key ID: " + l);
    }
  }
예제 #19
0
  /** Delete Process Instance */
  public static void deleteProcessInstanceVariable(long processInstanceId, String name)
      throws WorkflowException {
    log.debug("deleteProcessInstanceVariable({}, {})", new Object[] {processInstanceId, name});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      org.jbpm.graph.exe.ProcessInstance pi = jbpmContext.getProcessInstance(processInstanceId);
      pi.getContextInstance().deleteVariable(name);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }
  }
  public Object execute(JbpmContext jbpmContext) throws Exception {
    this.jbpmContext = jbpmContext;
    try {
      ArrayList result = new ArrayList();
      log.debug("executing " + this);

      // batch tokens
      if (tokenIds != null && tokenIds.length > 0) {
        for (int i = 0; i < tokenIds.length; i++) {
          Token token = jbpmContext.loadTokenForUpdate(tokenIds[i]);
          result.add(execute(token));
        }
      }

      // search for tokens in process/state
      if (processName != null && stateName != null) {
        this.operateOnSingleObject = false;

        Query query = null;
        if (processVersion > 0) {
          query =
              jbpmContext
                  .getSession()
                  .getNamedQuery("GraphSession.findTokensForProcessVersionInNode");
          query.setInteger("processDefinitionVersion", processVersion);
        } else {
          query = jbpmContext.getSession().getNamedQuery("GraphSession.findTokensForProcessInNode");
        }
        query.setString("processDefinitionName", processName);
        query.setString("nodeName", stateName);

        Iterator iter = query.list().iterator();
        while (iter.hasNext()) {
          Token token = (Token) iter.next();
          result.add(execute(token));
        }
      }

      if (operateOnSingleObject) {
        if (result.size() < 1) return null;
        else return result.get(0);
      } else {
        return result;
      }
    } finally {
      this.jbpmContext = null;
    }
  }
예제 #21
0
  /** Add Task Instance Comment */
  public static void addTaskInstanceComment(String user, long taskInstanceId, String message)
      throws WorkflowException {
    log.debug("addTaskInstanceComment({}, {}, {})", new Object[] {user, taskInstanceId, message});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      TaskMgmtSession taskMgmtSession = jbpmContext.getTaskMgmtSession();
      org.jbpm.taskmgmt.exe.TaskInstance ti = taskMgmtSession.getTaskInstance(taskInstanceId);
      ti.addComment(new org.jbpm.graph.exe.Comment(user, message));
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }
  }
예제 #22
0
  public List<Extension> getExtensionTasks(JbpmContext jbpmContext, String processName) {
    List<Extension> extensions = new java.util.ArrayList<Extension>();
    SqlExecutor queryExecutor = new SqlExecutor();
    String hql =
        " select a from "
            + Extension.class.getSimpleName()
            + " as a where a.processName = :processName and a.taskName is not null and a.locked = 0 ";
    Map<String, Object> paramMap = new java.util.HashMap<String, Object>();
    paramMap.put("processName", processName);
    queryExecutor.setSql(hql);
    queryExecutor.setParameter(paramMap);

    List<Object> rows = jbpmEntityDAO.getList(jbpmContext, queryExecutor);
    if (rows != null && rows.size() > 0) {
      ProcessDefinition processDefinition =
          jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
      Map<String, Task> taskMap = processDefinition.getTaskMgmtDefinition().getTasks();
      Iterator<Object> iterator = rows.iterator();
      while (iterator.hasNext()) {
        Extension model = (Extension) iterator.next();
        model.setProcessDescription(processDefinition.getDescription());
        Task task = taskMap.get(model.getTaskName());
        model.setTaskDescription(task.getDescription());
        extensions.add(model);
      }
    }
    return extensions;
  }
예제 #23
0
  public ProcessDefinition getProcessDefinition(WorkflowProcessDef wfProcessDefEntity) {
    Long l = Long.parseLong(wfProcessDefEntity.getProcessDefEngineKey());
    GraphSession graphSession = jbpmContext.getGraphSession();
    ProcessDefinition processDefinition = graphSession.getProcessDefinition(l);

    return processDefinition;
  }
예제 #24
0
 public void messageReceived(Receiver receiver, Token token) {
   // close the receiver
   IntegrationService integrationService =
       Receiver.getIntegrationService(JbpmContext.getCurrentJbpmContext());
   integrationService.endReception(receiver, token);
   // execute the next activity
   leave(new ExecutionContext(token));
 }
예제 #25
0
  /** Set Task Instance Actor Id */
  public static void setTaskInstanceActorId(long taskInstanceId, String actorId)
      throws WorkflowException {
    log.debug("setTaskInstanceActorId({}, {})", new Object[] {taskInstanceId, actorId});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

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

    log.debug("setTaskInstanceActorId: void");
  }
예제 #26
0
  /** Delete Task Instance Variable */
  public static void deleteTaskInstanceVariable(long taskInstanceId, String name)
      throws WorkflowException {
    log.debug("deleteTaskInstanceVariable({}, {})", new Object[] {taskInstanceId, name});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

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

    log.debug("deleteTaskInstanceVariable: void");
  }
예제 #27
0
  /** Resume Task Instance */
  public static void resumeTaskInstance(long taskInstanceId) throws WorkflowException {
    log.debug("resumeTaskInstance({})", taskInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

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

    log.debug("resumeTaskInstance: void");
  }
예제 #28
0
  /** Add Token Comment */
  public static void addTokenComment(String user, long tokenId, String message)
      throws WorkflowException {
    log.debug("addTokenComment({}, {}, {})", new Object[] {user, tokenId, message});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      org.jbpm.graph.exe.Token t = jbpmContext.getToken(tokenId);
      t.addComment(new org.jbpm.graph.exe.Comment(user, message));
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("addTokenComment: void");
  }
예제 #29
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);
  }
예제 #30
0
  public void deployProcessDefinition(
      String xmlProcessDefinition, WorkflowProcessDef wfProcessDefEntity)
      throws OperationException {
    try {
      ProcessDefinition pd = jbpm.getProcessDefinitionFromXml(xmlProcessDefinition);
      wfProcessDefEntity.setUniqueName(pd.getName());
      wfProcessDefEntity.setVersion(pd.getVersion());
      wfProcessDefEntity.setDescription(pd.getDescription());
      log.trace("Deploying workflow process definition name #0", pd.getName());
      jbpmContext.deployProcessDefinition(pd);
      wfProcessDefEntity.setProcessDefEngineKey(String.valueOf(pd.getId()));

      jbpmContext.getSession().flush();
      // }catch (JpdlException e) {
    } catch (Exception e) {
      throw new OperationException("Could not deploy process definition: " + e.getMessage());
    }
  }