コード例 #1
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;
  }
コード例 #2
0
  void submitVariables() {
    TaskController taskController = (task != null ? task.getTaskController() : null);
    // if there is a task controller,
    if (taskController != null) {
      // the task controller is responsible for copying variables back into the process
      taskController.submitParameters(this);

      // if there is no task controller
    } else if ((token != null) && (token.getProcessInstance() != null)) {
      // the default behaviour is that all task-local variables are flushed to the process
      if (variableInstances != null) {
        ContextInstance contextInstance = token.getProcessInstance().getContextInstance();
        Iterator iter = variableInstances.values().iterator();
        while (iter.hasNext()) {
          VariableInstance variableInstance = (VariableInstance) iter.next();
          log.debug(
              "flushing variable '"
                  + variableInstance.getName()
                  + "' from task '"
                  + name
                  + "' to process variables");
          TokenVariableMap tokenVariableMap = contextInstance.getOrCreateTokenVariableMap(token);
          variableInstance.setTokenVariableMap(tokenVariableMap);
          tokenVariableMap.addVariableInstance(variableInstance);
        }
      }
    }
  }
コード例 #3
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;
  }
  public void testAprioriRuntimeKnowledgeScenario1() {
    scenario = 1;

    ProcessInstance processInstance = new ProcessInstance(processDefinition);
    Token token = processInstance.getRootToken();
    processInstance.signal();
    processInstance.signal();
    assertSame(c, token.getNode());
  }
コード例 #5
0
  /**
   * marks this task as done and specifies a transition leaving the task-node for the case that the
   * completion of this task instances triggers a signal on the token. If this task leads to a
   * signal on the token, the given transition name will be used in the signal. If this task
   * completion does not trigger execution to move on, the transition is ignored.
   */
  public void end(Transition transition) {
    if (this.end != null) {
      throw new IllegalStateException("task instance '" + id + "' is already ended");
    }
    if (this.isSuspended) {
      throw new JbpmException("task instance '" + id + "' is suspended");
    }

    // mark the end of this task instance
    this.end = new Date();
    this.isOpen = false;

    // fire the task instance end event
    if ((task != null) && (token != null)) {
      ExecutionContext executionContext = new ExecutionContext(token);
      executionContext.setTask(task);
      executionContext.setTaskInstance(this);
      task.fireEvent(Event.EVENTTYPE_TASK_END, executionContext);
    }

    // log this assignment
    if (token != null) {
      token.addLog(new TaskEndLog(this));
    }

    // submit the variables
    submitVariables();

    // verify if the end of this task triggers continuation of execution
    if (isSignalling) {
      this.isSignalling = false;

      if (this.isStartTaskInstance() // ending start tasks always leads to a signal
          || ((task != null)
              && (token != null)
              && (task.getTaskNode() != null)
              && (task.getTaskNode().completionTriggersSignal(this)))) {

        if (transition == null) {
          log.debug(
              "completion of task '"
                  + task.getName()
                  + "' results in taking the default transition");
          token.signal();
        } else {
          log.debug(
              "completion of task '"
                  + task.getName()
                  + "' results in taking transition '"
                  + transition
                  + "'");
          token.signal(transition);
        }
      }
    }
  }
コード例 #6
0
  /** Resume Token */
  public static void resumeToken(long tokenId) throws WorkflowException {
    log.debug("resumeToken({})", tokenId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

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

    log.debug("resumeToken: void");
  }
コード例 #7
0
 /**
  * is the list of transitions that can be used in the end method and it is null in case this is
  * not the last task instance.
  */
 public List getAvailableTransitions() {
   List transitions = null;
   if ((!isLast()) && (token != null)) {
     transitions = new ArrayList(token.getNode().getLeavingTransitions());
   }
   return transitions;
 }
コード例 #8
0
  public void execute(ExecutionContext executionContext) throws Exception {
    TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance();

    // 取得当前流程实例所有的子Token上的任务实例

    Token rootToken = executionContext.getProcessInstance().getRootToken();
    Collection childTokeList = rootToken.getChildren().values();

    for (Iterator iterator = childTokeList.iterator(); iterator.hasNext(); ) {
      Token childToken = (Token) iterator.next();
      Collection c = tmi.getUnfinishedTasks(childToken);
      for (Iterator iterator2 = c.iterator(); iterator2.hasNext(); ) {
        TaskInstance ti = (TaskInstance) iterator2.next();
        ti.cancel();
      }
    }
  }
コード例 #9
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");
  }
コード例 #10
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");
  }
コード例 #11
0
 public static ScopeInstance create(Scope scope, Token token) {
   EventInstance instance = new EventInstance(scope, token);
   // normal processing is initial state
   instance.setState(ActiveState.NORMAL_PROCESSING);
   token
       .getProcessInstance()
       .getContextInstance()
       .createVariable(Scope.VARIABLE_NAME, instance, token);
   return instance;
 }
コード例 #12
0
 public void addComment(Comment comment) {
   if (comment != null) {
     if (comments == null) comments = new ArrayList();
     comments.add(comment);
     comment.setTaskInstance(this);
     if (token != null) {
       comment.setToken(token);
       token.addComment(comment);
     }
   }
 }
コード例 #13
0
  /** Get Token */
  public static Token getToken(long tokenId) throws WorkflowException {
    log.debug("getToken({})", tokenId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    Token vo = new Token();

    try {
      org.jbpm.graph.exe.Token t = jbpmContext.getToken(tokenId);
      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("getToken: " + vo);
    return vo;
  }
コード例 #14
0
 public void setUp() throws Exception {
   super.setUp();
   // create process instance
   ProcessInstance pi = process.createProcessInstance();
   // commit changes
   jbpmContext.save(pi);
   newTransaction();
   // reassociate the process instance with the new session
   jbpmContext.getSession().lock(pi, LockMode.READ);
   token = pi.getRootToken();
   token.setNode((Node) receiver.getInboundMessageActivity());
   // initiate correlation set
   CorrelationSetInstance csi =
       receiver.getCorrelations().getCorrelation("csId").getSet().getInstance(token);
   csi.initialize(Collections.singletonMap(ID_PROP, ID_VALUE));
 }
コード例 #15
0
 protected void setUp() throws Exception {
   /* the bpel definition uses the jbpm configuration, so create a context before the definition
    * to avoid loading another configuration from the default resource */
   jbpmContext = jbpmConfiguration.createJbpmContext();
   // process and token
   BpelDefinition pd = new BpelDefinition();
   token = new ProcessInstance(pd).getRootToken();
   Scope scope = pd.getGlobalScope();
   // port type 1
   PortType portType1 = new PortTypeImpl();
   portType1.setQName(new QName("pt1"));
   // port type 2
   PortType portType2 = new PortTypeImpl();
   portType2.setQName(new QName("pt2"));
   // partner link type
   PartnerLinkType partnerLinkType = new PartnerLinkTypeImpl();
   partnerLinkType.setQName(new QName("plt"));
   // role 1
   Role role1 = partnerLinkType.createRole();
   role1.setName("r1");
   role1.setPortType(portType1);
   partnerLinkType.setFirstRole(role1);
   // role 2
   Role role2 = partnerLinkType.createRole();
   role2.setName("r2");
   role2.setPortType(portType2);
   partnerLinkType.setSecondRole(role2);
   // partner link
   PartnerLinkDefinition partnerLink = new PartnerLinkDefinition();
   partnerLink.setName("pl1");
   partnerLink.setPartnerLinkType(partnerLinkType);
   partnerLink.setMyRole(role1);
   partnerLink.setPartnerRole(role2);
   scope.addPartnerLink(partnerLink);
   // from
   from.setPartnerLink(partnerLink);
   // initialize scope
   scope.initScopeData(token);
   // provide a way to the partner link definition
   Empty activity = new Empty();
   scope.addNode(activity);
   token.setNode(activity);
 }
コード例 #16
0
  /**
   * (re)assign this task to the given actor.
   *
   * @param actorId is reference to the person that is assigned to this task.
   * @param overwriteSwimlane specifies if the related swimlane should be overwritten with the given
   *     swimlaneActorId.
   */
  public void setActorId(String actorId, boolean overwriteSwimlane) {
    // do the actual assignment
    this.previousActorId = this.actorId;
    this.actorId = actorId;
    if ((swimlaneInstance != null) && (overwriteSwimlane)) {
      log.debug("assigning task '" + name + "' to '" + actorId + "'");
      swimlaneInstance.setActorId(actorId);
    }

    // fire the event
    if ((task != null) && (token != null)) {
      ExecutionContext executionContext = new ExecutionContext(token);
      executionContext.setTask(task);
      executionContext.setTaskInstance(this);
      task.fireEvent(Event.EVENTTYPE_TASK_ASSIGN, executionContext);
    }

    // add the log
    if (token != null) {
      // log this assignment
      token.addLog(new TaskAssignLog(this, previousActorId, actorId));
    }
  }
コード例 #17
0
  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"));
  }
コード例 #18
0
 public String toString() {
   return "tokenend[" + child.getFullName() + "]";
 }
  /**
   * extract the list of information from the process variables and make them available locally.
   * Note that if no task instance variables are specified, the full process variables scope will be
   * visible (that means that the user did not specify a special task instance scope).
   */
  public void initializeVariables(TaskInstance taskInstance) {
    ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      // set context class loader correctly for delegation class
      // (https://jira.jboss.org/jira/browse/JBPM-1448)
      Thread.currentThread()
          .setContextClassLoader(
              JbpmConfiguration.getProcessClassLoader(
                  taskInstance.getTask().getProcessDefinition()));

      if (taskControllerDelegation != null) {
        TaskControllerHandler taskControllerHandler =
            (TaskControllerHandler) taskControllerDelegation.instantiate();
        ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
        ContextInstance contextInstance =
            (processInstance != null ? processInstance.getContextInstance() : null);
        Token token = taskInstance.getToken();

        if (UserCodeInterceptorConfig.userCodeInterceptor != null) {
          UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerInitialization(
              taskControllerHandler, taskInstance, contextInstance, token);
        } else {
          taskControllerHandler.initializeTaskVariables(taskInstance, contextInstance, token);
        }

      } else {
        Token token = taskInstance.getToken();
        ProcessInstance processInstance = token.getProcessInstance();
        ContextInstance contextInstance = processInstance.getContextInstance();

        if (variableAccesses != null) {
          Iterator iter = variableAccesses.iterator();
          while (iter.hasNext()) {
            VariableAccess variableAccess = (VariableAccess) iter.next();
            String mappedName = variableAccess.getMappedName();
            if (variableAccess.isReadable()) {
              String variableName = variableAccess.getVariableName();
              Object value = contextInstance.getVariable(variableName, token);
              log.debug(
                  "creating task instance variable '"
                      + mappedName
                      + "' from process variable '"
                      + variableName
                      + "', value '"
                      + value
                      + "'");
              taskInstance.setVariableLocally(mappedName, value);
            } else {
              log.debug(
                  "creating task instance local variable '"
                      + mappedName
                      + "'. initializing with null value.");
              taskInstance.setVariableLocally(mappedName, null);
            }
          }
        }
      }
    } finally {
      Thread.currentThread().setContextClassLoader(surroundingClassLoader);
    }
  }
  /** update the process variables from the the task-instance variables. */
  public void submitParameters(TaskInstance taskInstance) {
    ClassLoader surroundingClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      // set context class loader correctly for delegation class
      // (https://jira.jboss.org/jira/browse/JBPM-1448)
      Thread.currentThread()
          .setContextClassLoader(
              JbpmConfiguration.getProcessClassLoader(
                  taskInstance.getTask().getProcessDefinition()));

      if (taskControllerDelegation != null) {
        TaskControllerHandler taskControllerHandler =
            (TaskControllerHandler) taskControllerDelegation.instantiate();
        ProcessInstance processInstance = taskInstance.getTaskMgmtInstance().getProcessInstance();
        ContextInstance contextInstance =
            (processInstance != null ? processInstance.getContextInstance() : null);
        Token token = taskInstance.getToken();

        if (UserCodeInterceptorConfig.userCodeInterceptor != null) {
          UserCodeInterceptorConfig.userCodeInterceptor.executeTaskControllerSubmission(
              taskControllerHandler, taskInstance, contextInstance, token);
        } else {
          taskControllerHandler.submitTaskVariables(taskInstance, contextInstance, token);
        }

      } else {

        Token token = taskInstance.getToken();
        ProcessInstance processInstance = token.getProcessInstance();
        ContextInstance contextInstance = processInstance.getContextInstance();

        if (variableAccesses != null) {
          String missingTaskVariables = null;
          Iterator iter = variableAccesses.iterator();
          while (iter.hasNext()) {
            VariableAccess variableAccess = (VariableAccess) iter.next();
            String mappedName = variableAccess.getMappedName();
            // first check if the required variableInstances are present
            if ((variableAccess.isRequired()) && (!taskInstance.hasVariableLocally(mappedName))) {
              if (missingTaskVariables == null) {
                missingTaskVariables = mappedName;
              } else {
                missingTaskVariables += ", " + mappedName;
              }
            }
          }

          // if there are missing, required parameters, throw an
          // IllegalArgumentException
          if (missingTaskVariables != null) {
            throw new IllegalArgumentException("missing task variables: " + missingTaskVariables);
          }

          iter = variableAccesses.iterator();
          while (iter.hasNext()) {
            VariableAccess variableAccess = (VariableAccess) iter.next();
            String mappedName = variableAccess.getMappedName();
            String variableName = variableAccess.getVariableName();
            if (variableAccess.isWritable()) {
              Object value = taskInstance.getVariable(mappedName);
              if (value != null) {
                log.debug(
                    "submitting task variable '"
                        + mappedName
                        + "' to process variable '"
                        + variableName
                        + "', value '"
                        + value
                        + "'");
                contextInstance.setVariable(variableName, value, token);
              }
            }
          }
        }
      }
    } finally {
      Thread.currentThread().setContextClassLoader(surroundingClassLoader);
    }
  }
コード例 #21
0
 private void detachFromSuperProcess(ProcessInstance processInstance, Token superProcessToken) {
   processInstance.setSuperProcessToken(null);
   superProcessToken.setSubProcessInstance(null);
 }
 public static void endOneTask(Token token) {
   TaskMgmtInstance tmi = token.getProcessInstance().getTaskMgmtInstance();
   TaskInstance taskInstance = (TaskInstance) tmi.getUnfinishedTasks(token).iterator().next();
   taskInstance.end();
 }
コード例 #23
0
 public void testMilestoneScenario2() {
   ProcessDefinition pd = milestoneProcessDefinition;
   Token root = startScenario();
   Token tokenM = root.getChild("m");
   Token tokenD = root.getChild("d");
   assertSame(pd.getNode("b"), tokenM.getNode());
   assertSame(pd.getNode("d"), tokenD.getNode());
   tokenD.signal();
   assertSame(pd.getNode("b"), tokenM.getNode());
   assertSame(pd.getNode("join"), tokenD.getNode());
   tokenM.signal();
   assertSame(pd.getNode("c"), tokenM.getNode());
   assertSame(pd.getNode("join"), tokenD.getNode());
 }
コード例 #24
0
 @Override
 public void initializeTaskVariables(
     TaskInstance taskInstance, ContextInstance contextInstance, Token token) {
   taskInstance.addComment((Comment) token.getComments().get(token.getComments().size() - 1));
   taskInstance.setVariableLocally("directive", WORKFLOW_DIRECTIVE_TASK_REJECTED);
 }