cancel
Showing results for 
Search instead for 
Did you mean: 

how can get process instance's task node out transition

ant1
Champ in-the-making
Champ in-the-making
ls there some API for get the process instance's an task node  out transition?
following list my step:
1. get the task by login user;
2. get the process instance id ;
3. use runtimeService to get the ProcessInstance by process instance id;
4. cast the ProcessInstance to ExecutionEntity;
5. call the getActivity() method to get PvmActivity;
6. call the getOutgoingTransitions() method to get the out transition;
but in the step 5 throw a nullpointException;

someone can tell me what's the problem in my step? or there is other way to get a task node's out transition?

thanks very much.
7 REPLIES 7

ant1
Champ in-the-making
Champ in-the-making
there is the code:


  List<Task> tList = taskService.createTaskQuery().taskAssignee("person1").list();
  if (null != tList && tList.size() > 0) {
    for (Task task : tList) {
       System.out.println("the task id is :" + task.getId());
       System.out.println(task.getProcessInstanceId());
       List<ProcessInstance> pdes = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).list();
       if (null != pdes && pdes.size() > 0) {
         for (ProcessInstance pi : pdes) {
           if (null != pi) {
  ExecutionEntity ee = (ExecutionEntity) pi;
  if (null != ee) {
    ActivityImpl ai = ee.getActivity();
    List<PvmTransition> pts = ai.getOutgoingTransitions();
    if (null != pts)
      System.out.println(pts.size());
    else
      System.out.println("PvmTransition list is null");
  }
            }
          }
        }
      }
    }

jbarrez
Star Contributor
Star Contributor
Where are you calling this code from?

If your process is halted in a usertask, the execution rerieved from that task should give the activity back.

steff1
Champ in-the-making
Champ in-the-making
I also had the problem with NullPointerException when calling getActiviti() of a execution entity which I retrieved by a process instance query or a execution query.

This thread shows that a Activity has to be retrieved via a ProcessDefinitionEntity. Here my working unit test.


@Test
    public void getActivityBehaviorViaProcessDefinitionEntity() {
        // start a process
        String processKey = "singleReceiveTaskProcess";
        ProcessInstance processInstance = getActivitiRuntimeService().startProcessInstanceByKey(processKey);


        List<Execution> executions = getActivitiRuntimeService().createExecutionQuery()
                .processInstanceId(processInstance.getId())
                .list();
        assertEquals(1, executions.size());

        Execution execution = executions.get(0);
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
       
        ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) getActivitiRepositoryService() )
                .getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
        ActivityImpl activity = processDefinitionEntity.findActivity(executionEntity.getActivityId());
        assertNotNull(activity);
    }

ggdeveloper
Champ in-the-making
Champ in-the-making
hi,i have the similar problem. i use SpringProcessEngineConfiguration and junit to test my code. My activiti version is 5.7.
I just want to get an ActivityImpl from a task that exists.


/**
  * <pre>
  * Test rollback.
  * </pre>
  *
  * @author 宿晓斐 2011-9-5
  * @throws Exception
  */
@Test
public void testRollback() throws Exception {
  Task mobjTask = taskService.createTaskQuery().taskId("102").singleResult();
  if (mobjTask != null) {
   System.out.println("ready rollback");
   ProcessDefinitionImpl processDefinitionImpl =
     (ProcessDefinitionImpl) repositoryService
       .createProcessDefinitionQuery()
       .processDefinitionId(
         mobjTask.getProcessDefinitionId())
       .singleResult();
   TaskEntity taskEntity = (TaskEntity) mobjTask;
   // this node should not be empty.
   List<PvmTransition> pvmTransitionList =
     taskEntity.getExecution().getActivity()
       .getIncomingTransitions();
   if (pvmTransitionList == null || pvmTransitionList.isEmpty()) {
    throw new ActivitiException("no IncomingTransitions found");
   }
   TransitionImpl transition =
     (TransitionImpl) pvmTransitionList.get(0);
   ActivityImpl toActiviti = transition.getSource();
   if (toActiviti == null) {
    throw new ActivitiException("no toActiviti found");
   }
   TransitionImpl transitionImpl =
     toActiviti.createOutgoingTransition();
   transitionImpl.setDestination(toActiviti);
   taskService.complete(mobjTask.getId());
   System.out.println("roll back completed");
  } else {
   System.out.println("task is null");
  }
 
}


but throw an Excepiton.
i see the error trace and trace code in activity source :

  public ExecutionEntity getExecution() {
    if ( (execution==null) && (executionId!=null) ) {
      this.execution = Context
        .getCommandContext()
        .getExecutionManager()
        .findExecutionById(executionId);
    }
    return execution;
  }
 
It looks like Context or getCommandContext() or  getExecutionManager() is null.
what's happend.
In my mind,when application start s, spring will help us to create these objects and manage them .
why,who can help me,thanks.

trademak
Star Contributor
Star Contributor
Hi,

Please post a fully working unit test so we reproduce the error.

Best regards,

ggdeveloper
Champ in-the-making
Champ in-the-making
Hi,

Please post a fully working unit test so we reproduce the error.

Best regards,
thanks for your help.
My junit  init code is:

public class Demo {

/** The ctx. */
private ClassPathXmlApplicationContext ctx;
 
/** The process engine. */
private ProcessEngine processEngine;

/** The runtime service. */
private RuntimeService runtimeService;

/** The task service. */
private TaskService taskService;

/** The repository service. */
private RepositoryService repositoryService;

/** The history service. */
private HistoryService historyService;

private ExecutionManager executionManager;

/** The ymd. */
public SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");

/**
  * <pre>
  * Before.
  * </pre>
  *
  * @author 宿晓斐 2011-9-2
  */
@Before
public void before() {
  ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
  processEngine = (ProcessEngine) ctx.getBean("processEngine");
  runtimeService = (RuntimeService) ctx.getBean("runtimeService");
  repositoryService =
    (RepositoryService) ctx.getBean("repositoryService");
  taskService = (TaskService) ctx.getBean("taskService");
  historyService = (HistoryService) ctx.getBean("historyService");
  executionManager = (ExecutionManager) ctx.getBean("executionManager");
}
}

and spring config is:

<!– Activiti工作流 配置 start –>

<!– Activiti的数据源等参数配置 –>
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="dataSource" />
  <property name="transactionManager" ref="transactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />
</bean>

<!– Activiti的流程引擎 –>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
  <property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<!– Activiti的资源库服务,用于获取流程定义等内容 –>
<bean id="repositoryService" factory-bean="processEngine"
  factory-method="getRepositoryService" />
 
<!– Activiti的运行时服务,可以用于完成任务等操作 –> 
<bean id="runtimeService" factory-bean="processEngine"
  factory-method="getRuntimeService" />
 
<!– Activiti的任务服务,用于跟任务相关的操作,比如指派处理人等 –>
<bean id="taskService" factory-bean="processEngine"
  factory-method="getTaskService" />
 
<!– Activiti的历史服务,用于查询数据,比如查询已经完成和未完成的任务等 –>
<bean id="historyService" factory-bean="processEngine"
  factory-method="getHistoryService" />

<!– Activiti的管理服务 –>
<bean id="managementService" factory-bean="processEngine"
  factory-method="getManagementService" />
<bean id="executionManager" class="org.activiti.engine.impl.persistence.entity.ExecutionManager" />
  <!– Activiti  配置 end –>

that's all.

jbarrez
Star Contributor
Star Contributor
It seems your 'unit test' is missing the actual test code. Can you add it?

Are you using the services? Your nullpointer seems to indicate you are calling something on an entity object itself instead of going through a service.