Question

I am using Activiti 5.12. As provided, in its user guide, REST API to get he details of a process instance is : GET /process-instance/{processInstanceId}

Its response is something like this :

{
"id": "2",
"processDefinitionId": "financialReport:1",
"businessKey": "55",
"startTime": "2010-10-13T14:54:26.750+02:00",
"startActivityId": "startFinancialAnalysis",
"startUserId": "kermit",
"completed": false,
"tasks": [
    {
        "taskId": "3",
        "taskName": "Analyze report",
        "owner": null,
        "assignee": "Kermit",
        "startTime": "2010-10-13T14:53:26.750+02:00",
        "completed": false
    }
],
"activities": [
    {
        "activityId": "4",
        "activityName": "Get report",
        "activityType": "ServiceTask",
        "startTime": "2010-10-13T14:53:25.950+02:00",
        "completed": true,
        "duration": 200
    }
],
"variables": [
    {
        "variableName": "reportName",
        "variableValue": "classified.pdf"
    }
],
"historyVariables": [
    {
        "variableName": "reportName",
        "variableValue": "classified.pdf",
        "variableType": "String",
        "revision": 1,
        "time": "2010-10-13T14:53:26.750+02:00"
    }
]
}

A JAVA API for the same is also provided, which is : ProcessEngines.getProcessEngine(configuredProcessEngineName).getHistoryService().createHistoricProcessInstanceQuery().processInstanceId("somevalue").singleResult()

This Java API does not work, as teh return type HistoricProcessInstance does not have the method to get the task list.

My objective is to get the current state of a process instance, i.e which task it's presently at.

The REST API lists all tasks that process instance has carried out and the last task of the list is the one it's currently executing, as its property completed is false.

I want to achieve the same from java code.

Can you please help me out. Any alternative way to get to my objective is also fine with me.

Was it helpful?

Solution

You can use another query of HistoricService API:

List<HistoricTaskIntance> taskList = getHistoryService()
  .createHistoricTaskInstanceQuery()
  .processInstanceId(processInstanceId)
  .list()

The current task status can be defined by HistoricTaskInstance.getEndTime() that will return null for open tasks.

OTHER TIPS

I have tried this way out.

SELECT NAME_ FROM act_hi_taskinst where PROC_INST_ID_= 1000  and END_TIME_ IS NULL;"

act_hi_taskinst contains history tasks for each and every instance.

If the process with instance id is completed then you wont get any result, so you can check that condition before moving forward.

I have run this piece of SQL Statement to get the required task name.

The answer given by @Mike also meets the objective. Even here also you have to check whether process is incomplete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top