4 Replies Latest reply on Nov 11, 2009 11:29 PM by peterbasutkar

    how to get all tokens  from processinstance

    peterbasutkar

      i am using following code for getting all tokens from processInstance,but it is giving only currently running token(means tasknode information) information
      ProcessInstance processInstance = getProcessInstance();
      List allTokens = processInstance.findAllTokens();
      for (Token token : allTokens) {
      System.out.println("names of tokess nodes"+token.getNode().getName());
      }

      Is there any API for getting all tokens(means task) for a perticular provessInstance.

        • 1. Re: how to get all tokens  from processinstance
          saraswati.santanu

          In JBPM 3.x Token of a process instance is like an iterator which is pointing to the current node of the process. So the node associated with the token is the currently active node, which is the TaskNode for your case. In JBPM 3.x "Task" is not a node.
          If you need to get the current active tasks then you can use TaskManagementInstance.

          ProcessInstance processInstance= getProcessInstance();
          //get the task management instance of the process instance
          TaskMgmtInstance taskManagementInstance = processInstance.getTaskMgmtInstance();
          
          //find the unfinished tasks
          Collection taskInstances = taskManagementInstance.getUnfinishedTasks(processInstance.getRootToken());
          


          You can also get a "Set" of tasks from the node obtained from the current token.
          Token rootToken = processInstance.getRootToken();
          Node node = rootToken.getNode();
          if (node instanceof TaskNode) {
           Set<Task> tasks = ((TaskNode)node).getTasks();
          }
          


          • 2. Re: how to get all tokens  from processinstance
            peterbasutkar

            i dont want only running task............i am using following this code for getting completed and pending token(task node) as well as running token information but this is keeping track of token data(means previously completed and currenrently running task) if an only if we are performing any signaling,but i want all completed and pending token information irrespective of signaling,means it should give me information when task is started,when it is ended for that processInstance

            ProcessInstance processInstance = getProcessInstance();
            LoggingInstance loggingInstance = processInstance.getLoggingInstance();

            List logs = loggingInstance.getLogs(SignalLog.class);
            for (SignalLog signalLog : logs) {
            List children = signalLog.getChildren();
            if(children.get(0) != null){
            if(children.get(0) instanceof TransitionLog){
            TransitionLog transitionLog = (TransitionLog)children.get(0);
            System.out.println("Node Name:::"+transitionLog.getSourceNode().getName());
            System.out.println("Node Start Time:::");
            System.out.println("Node End Time:::"+transitionLog.getDate());
            System.out.println("=====================================================");
            }
            if(children.get(0) instanceof NodeLog){
            NodeLog nodeLog = (NodeLog)children.get(0);
            System.out.println("Node Name:::"+nodeLog.getNode().getName());
            System.out.println("Node Start Time:::"+nodeLog.getEnter());
            System.out.println("Node End Time:::"+nodeLog.getLeave());
            System.out.println("=====================================================");
            }
            }
            }
            return "success";
            }

            • 3. Re: how to get all tokens  from processinstance
              saraswati.santanu

              LoggingInstance is not persisted. So you cannot really get the history data from it after the transaction is over. For that you need LoggingSession. If you are saving the logs then you can get the information using LoggingSession.

              //create a LoggingSession. getSession() here returns a Hibernate session
              LoggingSession logginSession = new LoggingSession(getSession());
              
              //this map contains Token vs List of logs
              Map logs = logginSession.findLogsByProcessInstance(processInstance.getId());
              
              //Iterate and do whaterver you need to
              Set<Entry> entries = logs.entrySet();
              for (Entry entry : entries) {
               List<ProcessLog> processLogs = (List<ProcessLog>)entry.getValue();
               for (ProcessLog log:processLogs) {
               System.out.println("Log type : " + log.getClass().getSimpleName());
               }
              }
              


              So far I remember, along with the code above, you need to call
               jbpmContext.save(processInstance);
              

              everytime after you do the signalling/task execution. This call saves the logs in db.

              • 4. Re: how to get all tokens  from processinstance
                peterbasutkar

                i am using jsf consol for jbpm,How to activate r start LoggingSession in my scenario ?