Package org.activiti.engine

Examples of org.activiti.engine.HistoryService


    ProcessEngineImpl processEngine = initProcessEngine();

    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    ManagementService managementService = processEngine.getManagementService();
    HistoryService historyService = processEngine.getHistoryService();

    // record events
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(TEST_VARIABLE, TEST_VALUE);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables);

    Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult();
    TimeUnit.MILLISECONDS.sleep(50);
    variables = new HashMap<String, Object>();
    variables.put(TASK_TEST_VARIABLE, TASK_TEST_VALUE);
    taskService.complete(task.getId(), variables);

    // transform log events
    List<EventLogEntry> eventLogEntries = managementService.getEventLogEntries(null, null);

    EventLogTransformer transformer = new EventLogTransformer(getTransformers());

    List<SimulationEvent> simulationEvents = transformer.transform(eventLogEntries);

    SimpleEventCalendar eventCalendar = new SimpleEventCalendar(processEngine.getProcessEngineConfiguration().getClock(), new SimulationEventComparator());
    eventCalendar.addEvents(simulationEvents);

    // replay process instance run
    final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, eventCalendar, getReplayHandlers(processInstance.getId()));

    simRun.init(new NoExecutionVariableScope());

    // original process is finished - there should not be any running process instance/task
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // replay process was started
    ProcessInstance replayProcessInstance = runtimeService.createProcessInstanceQuery()
        .processDefinitionKey(USERTASK_PROCESS)
        .singleResult();
    assertNotNull(replayProcessInstance);
    assertTrue(replayProcessInstance.getId().equals(processInstance.getId()) == false);
    assertEquals(TEST_VALUE, runtimeService.getVariable(replayProcessInstance.getId(), TEST_VARIABLE));
    // there should be one task
    assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count());

    simRun.step();

    // userTask was completed - replay process was finished
    assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count());
    assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count());
    HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery()
        .processInstanceId(replayProcessInstance.getId())
        .variableName(TASK_TEST_VARIABLE)
        .singleResult();
    assertNotNull(variableInstance);
    assertEquals(TASK_TEST_VALUE, variableInstance.getValue());
View Full Code Here


    return new ArchivedListQuery();
  }
 
  @Override
  protected Component createDetailComponent(String id) {
    HistoryService historyService = ProcessEngines.getDefaultProcessEngine().getHistoryService();
    HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(id).singleResult();
    taskEventPanel.setTaskId(historicTaskInstance.getId());
    return new HistoricTaskDetailPanel(historicTaskInstance, this);
  }
View Full Code Here

       
        String procId = proc.getId();
        System.out.println("procId="+procId);
       
        long timeout = System.currentTimeMillis()+15*1000;
        HistoryService hstSvc = eng.getHistoryService();
        while (true){
            if (System.currentTimeMillis() > timeout) throw new TimeoutException();
            HistoricProcessInstance hProcInst = hstSvc.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
            if (hProcInst.getEndTime() != null){
                System.out.println(wfn+" ended");
                break;
            }
            Thread.sleep(1000);
View Full Code Here

    task = taskService.createTaskQuery().taskAssignee("user1").singleResult();
    taskService.complete(task.getId());
   
    // 验证历史数据
    HistoryService historyService = activitiRule.getHistoryService();
    List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().list();
    for (HistoricActivityInstance activity : list) {
      System.out.println(activity.getActivityName() + " = " + activity.getEndTime());
    }
  }
View Full Code Here

   
    variableMap = new HashMap<String, Object>();
    variableMap.put("approved", true);
    taskService.complete(task.getId(), variableMap);
   
    HistoryService historyService = activitiRule.getHistoryService();
    long count = historyService.createHistoricProcessInstanceQuery().finished().count();
    assertEquals(1, count);
  }
View Full Code Here

    task = taskService.createTaskQuery().taskAssignee("bb").singleResult();
    variableMap = new HashMap<String, Object>();
    variableMap.put("reApply", false);
    taskService.complete(task.getId(), variableMap);
   
    HistoryService historyService = activitiRule.getHistoryService();
    long count = historyService.createHistoricProcessInstanceQuery().finished().count();
    assertEquals(1, count);
  }
View Full Code Here

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("NoneIntermediateThrowEvent", variableMap);
    assertNotNull(processInstance.getId());
    System.out.println("id " + processInstance.getId() + " "
        + processInstance.getProcessDefinitionId());
   
    HistoryService historyService = activitiRule.getHistoryService();
    long count = historyService.createHistoricProcessInstanceQuery().finished().count();
    assertEquals(1, count);
  }
View Full Code Here

    Map<String, Object> variableMap = new HashMap<String, Object>();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process1", variableMap);
    assertNotNull(processInstance.getId());
    System.out.println("id " + processInstance.getId() + " " + processInstance.getProcessDefinitionId());

    HistoryService historyService = activitiRule.getHistoryService();
    List<HistoricProcessInstance> list2 = historyService.createHistoricProcessInstanceQuery().startedBy("henryyan").list();
    assertEquals(false, list2.isEmpty());

    Task task = taskService.createTaskQuery().taskAssignee("henryyan").singleResult();
    taskService.complete(task.getId());

    List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().finished().list();
    assertEquals(false, list.isEmpty());

    list2 = historyService.createHistoricProcessInstanceQuery().startedBy("henryyan").list();
    assertEquals(false, list2.isEmpty());
  }
View Full Code Here

       
        String procId = proc.getId();
        System.out.println("procId="+procId);
       
        long timeout = System.currentTimeMillis()+15*1000;
        HistoryService hstSvc = eng.getHistoryService();
        while (true){
            if (System.currentTimeMillis() > timeout) throw new TimeoutException();
            HistoricProcessInstance hProcInst = hstSvc.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
            if (hProcInst.getEndTime() != null){
                System.out.println(wfn+" ended");
                break;
            }
            Thread.sleep(1000);
View Full Code Here

   */
  public void autoClaim(String executionId) {

    TaskService taskService = activitiRule.getTaskService();
    RepositoryService repositoryService = activitiRule.getRepositoryService();
    HistoryService historyService = activitiRule.getHistoryService();

    // 查询最新的任务
    List<Task> newTasks = taskService.createTaskQuery().executionId(executionId).list();
    for (Task task : newTasks) {

      // 查询并验证任务是否已经分配到具体人
      if (task.getAssignee() != null) {
        return;
      }

      // 验证任务是分配到组
      ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(task
              .getProcessDefinitionId());

      // 获得当前任务的所有节点
      List<ActivityImpl> activitiList = processDefinition.getActivities();

      for (ActivityImpl activity : activitiList) {
        // 当前节点
        if (task.getTaskDefinitionKey().equals(activity.getId())) {
          ActivityBehavior activityBehavior = activity.getActivityBehavior();

          // 匹配用户任务
          if (activityBehavior instanceof UserTaskActivityBehavior) {
            UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activityBehavior;
            TaskDefinition taskDefinition = userTaskActivityBehavior.getTaskDefinition();
            Set<Expression> candidateUserIdExpressions = taskDefinition.getCandidateUserIdExpressions();
            Set<Expression> candidateGroupIdExpressions = taskDefinition.getCandidateGroupIdExpressions();
            if (!candidateGroupIdExpressions.isEmpty() || !candidateUserIdExpressions.isEmpty()) {

              // 查询历史任务中最新的一条同名记录
              List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery()
                      .taskDefinitionKey(task.getTaskDefinitionKey()).executionId(executionId).orderByHistoricTaskInstanceEndTime().desc().list();

              // 没有历史任务时继续下一个循环
              if (historicTaskInstances.isEmpty()) {
                continue;
View Full Code Here

TOP

Related Classes of org.activiti.engine.HistoryService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.