Using HistoryService, we can get historical data such as names of the finished process instances and when a process started and was completed.
We will follow the ensuing steps to fetch some historical data from the database for a specific task:
HistoricData
.HistoricData
:package com.activiti; import java.security.Identity; import java.util.HashMap; import java.util.List; import java.util.Map; import org.activiti.engine.HistoryService; import org.activiti.engine.IdentityService; import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.ProcessEngines; import org.activiti.engine.TaskService; import org.activiti.engine.history.HistoricActivityInstance; import org.activiti.engine.identity.Group; import org.activiti.engine.identity.GroupQuery; import org.activiti.engine.identity.User; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; public class HistoricData { public static void main(String ar[]) { ProcessEngine processEngine = ProcessEngineConfiguration .createStandaloneProcessEngineConfiguration() .setJdbcDriver("com.mysql.jdbc.Driver") .setJdbcUrl("jdbc:mysql://localhost:3306/activiti_book") .setJdbcPassword("root").setJdbcUsername("root") .buildProcessEngine(); HistoryService history=processEngine.getHistoryService(); List<HistoricActivityInstance> processinstance=history.createHistoricActivityInstanceQuery().taskAssignee("kermit").list(); for(HistoricActivityInstance pi:processinstance) { System.out.println("Historic Process Instances for kermit:"+pi.getProcessDefinitionId()); } } }
HistoricData.java
class so it will display all the process instances that were assigned to the Kermit user, as shown in the following screenshot:kermit
to gonzo
, the output would be as follows:Historic Process Instances for gonzo: traininngProcess:1:3282
We learned the types of historical data that are maintained by the Activiti Engine. Now we know how to use HistoryService for different purposes. We executed a task to get a list of the process instances that were assigned to a specific user.