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;
    }
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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");
  }
Exemplo n.º 5
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();
    }
  }
Exemplo n.º 6
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();
    }
  }
Exemplo n.º 7
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);
    }
  }
Exemplo n.º 8
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");
  }
Exemplo n.º 9
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();
    }
  }
Exemplo n.º 10
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();
    }
  }
Exemplo n.º 11
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");
  }
Exemplo n.º 12
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");
  }
Exemplo n.º 13
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");
  }
Exemplo n.º 14
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");
  }
Exemplo n.º 15
0
  /** Set Token Node */
  public static void setTokenNode(long tokenId, String nodeName) throws WorkflowException {
    log.debug("setTokenNode({}, {})", new Object[] {tokenId, nodeName});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      org.jbpm.graph.exe.Token t = jbpmContext.getToken(tokenId);
      org.jbpm.graph.def.Node node =
          t.getProcessInstance().getProcessDefinition().getNode(nodeName);
      t.setNode(node);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("setTokenNode: void");
  }
Exemplo n.º 16
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());
    }
  }
Exemplo n.º 17
0
  /** Delete Process Definition */
  public static void deleteProcessDefinition(long processDefinitionId) throws WorkflowException {
    log.debug("deleteProcessDefinition({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

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

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      graphSession.deleteProcessDefinition(processDefinitionId);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("deleteProcessDefinition: void");
  }
Exemplo n.º 18
0
 public CustomSession(JbpmContext jbpmContext) {
   _session = jbpmContext.getSession();
 }