Time for action – querying historical activities

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:

  1. We will create a new Activiti project within the Eclipse IDE.
  2. Within the Activiti project, create a class file HistoricData.
  3. Write the following code in 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());
        
      }
      
      }
    }
  4. Execute the HistoricData.java class so it will display all the process instances that were assigned to the Kermit user, as shown in the following screenshot:
    Time for action – querying historical activities
  5. If we changed the username from kermit to gonzo, the output would be as follows:
    Historic Process Instances for gonzo: traininngProcess:1:3282

What just happened?

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.

FormService

FormService is a part of the Activiti Engine. It is used to access various form data. It is also used to render forms for starting new process instances and completing tasks. Using getStartFormData, we can retrieve all the data necessary for rendering a form to start a new process instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset