org.activiti.engine.history.HistoricActivityInstance Java Examples

The following examples show how to use org.activiti.engine.history.HistoricActivityInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelSubProcess.bpmn20.xml" })
public void testParallelSubProcessHistory() {
  runtimeService.startProcessInstanceByKey("miParallelSubprocess");
  for (Task task : taskService.createTaskQuery().list()) {
    taskService.complete(task.getId());
  }

  // Validate history
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("miSubProcess").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance hai : historicActivityInstances) {
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #2
Source File: TaskServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
  public void testGetVariableByHistoricActivityInstance() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
      ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
      assertNotNull(processInstance);
      Task task = taskService.createTaskQuery().singleResult();

      taskService.setVariable(task.getId(), "variable1", "value1");
      taskService.setVariable(task.getId(), "variable1", "value2");

      HistoricActivityInstance historicActivitiInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId())
              .activityId("theTask").singleResult();
      assertNotNull(historicActivitiInstance);

      List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().variableUpdates().activityInstanceId(historicActivitiInstance.getId())
              .orderByTime().asc().list();

      assertEquals(2, resultSet.size());
      assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(0)).getVariableName());
      assertEquals("value1", ((HistoricVariableUpdate) resultSet.get(0)).getValue());
      assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(1)).getVariableName());
      assertEquals("value2", ((HistoricVariableUpdate) resultSet.get(1)).getValue());
    }
}
 
Example #3
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelScriptTasks.bpmn20.xml"})
public void testParallelScriptTasksHistory() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("sum", 0);
  vars.put("nrOfLoops", 4);
  runtimeService.startProcessInstanceByKey("miParallelScriptTask", vars);
  
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").list();
    assertEquals(4, historicActivityInstances.size());
    for (HistoricActivityInstance hai : historicActivityInstances) {
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getStartTime());
    }
  }
}
 
Example #4
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelScriptTasks.bpmn20.xml" })
public void testParallelScriptTasksHistory() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("sum", 0);
  vars.put(NR_OF_LOOPS_KEY, 4);
  runtimeService.startProcessInstanceByKey("miParallelScriptTask", vars);

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").list();
    assertEquals(4, historicActivityInstances.size());
    for (HistoricActivityInstance hai : historicActivityInstances) {
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #5
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/bpmn/multiinstance/MultiInstanceTest.testParallelSubProcess.bpmn20.xml"})
public void testParallelSubProcessHistory() {
  runtimeService.startProcessInstanceByKey("miParallelSubprocess");
  for (Task task : taskService.createTaskQuery().list()) {
    taskService.complete(task.getId());
  }
  
  // Validate history
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery().activityId("miSubProcess").list();
    assertEquals(2, historicActivityInstances.size());
    for (HistoricActivityInstance hai : historicActivityInstances) {
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #6
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/history/calledProcess.bpmn20.xml",
        "org/activiti5/engine/test/history/HistoricActivityInstanceTest.testCallSimpleSubProcess.bpmn20.xml"
      })
public void testHistoricActivityInstanceCalledProcessId() {    
  runtimeService.startProcessInstanceByKey("callSimpleSubProcess");

  HistoricActivityInstance historicActivityInstance = historyService
    .createHistoricActivityInstanceQuery()
    .activityId("callSubProcess")
    .singleResult();
  
  HistoricProcessInstance oldInstance = historyService.createHistoricProcessInstanceQuery().processDefinitionKey("calledProcess").singleResult();
  
  assertEquals(oldInstance.getId(), historicActivityInstance.getCalledProcessInstanceId());
}
 
Example #7
Source File: ParallelGatewayTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testHistoryTables() {
 
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("testHistoryRecords");
  
  List<HistoricActivityInstance> history = historyService
  		.createHistoricActivityInstanceQuery()
  		.processInstanceId(pi.getId()). list();
  
  for (HistoricActivityInstance h: history) {
  	if (h.getActivityId().equals("parallelgateway2")) {
  		  assertNotNull(h.getEndTime());
  	}
  }
  
}
 
Example #8
Source File: AbstractActivitiTestCase.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void assertHistoricActivitiesDeleteReason(ProcessInstance processInstance, String expectedDeleteReason, String ... activityIds) {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    for (String activityId : activityIds) {
      List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
          .activityId(activityId).processInstanceId(processInstance.getId()).list();
      assertTrue("Could not find historic activities", historicActivityInstances.size() > 0);
      for (HistoricActivityInstance historicActivityInstance : historicActivityInstances) {
        assertNotNull(historicActivityInstance.getEndTime());
        if (expectedDeleteReason == null) {
          assertNull(historicActivityInstance.getDeleteReason()); 
        } else {
          assertTrue(historicActivityInstance.getDeleteReason().startsWith(expectedDeleteReason));
        }
      }
    }
  }
}
 
Example #9
Source File: ProcessInstanceHighlightsResource.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
/**
 * getHighLightedFlows
 *
 * @param processDefinition
 * @param processInstanceId
 * @return
 */
private List<String> getHighLightedFlows(ProcessDefinitionEntity processDefinition, String processInstanceId) {

    List<String> highLightedFlows = new ArrayList<String>();

    List<HistoricActivityInstance> historicActivityInstances = historyService.createHistoricActivityInstanceQuery()
            .processInstanceId(processInstanceId)
            //order by startime asc is not correct. use default order is correct.
            //.orderByHistoricActivityInstanceStartTime().asc()/*.orderByActivityId().asc()*/
            .list();

    LinkedList<HistoricActivityInstance> hisActInstList = new LinkedList<HistoricActivityInstance>();
    hisActInstList.addAll(historicActivityInstances);

    getHighlightedFlows(processDefinition.getActivities(), hisActInstList, highLightedFlows);

    return highLightedFlows;
}
 
Example #10
Source File: AsyncExclusiveJobsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/** 
 * Test for https://activiti.atlassian.net/browse/ACT-4035.
 */
@Deployment
public void testExclusiveJobs() {
	
	if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
	
		// The process has two script tasks in parallel, both exclusive.
		// They should be executed with at least 6 seconds in between (as they both sleep for 6 seconds)
		runtimeService.startProcessInstanceByKey("testExclusiveJobs");
		waitForJobExecutorToProcessAllJobs(20000L, 500L);
		
		HistoricActivityInstance scriptTaskAInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskA").singleResult();
		HistoricActivityInstance scriptTaskBInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskB").singleResult();
		
		long endTimeA = scriptTaskAInstance.getEndTime().getTime();
		long endTimeB = scriptTaskBInstance.getEndTime().getTime();
		long endTimeDifference = 0;
		if (endTimeB > endTimeA) {
			endTimeDifference = endTimeB - endTimeA;
		} else {
			endTimeDifference = endTimeA - endTimeB;
		}
		assertTrue(endTimeDifference > 6000); // > 6000 -> jobs were executed in parallel
	}
	
}
 
Example #11
Source File: MultiInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/multiinstance/MultiInstanceTest.testSequentialScriptTasks.bpmn20.xml" })
public void testSequentialScriptTasksHistory() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("sum", 0);
  vars.put(NR_OF_LOOPS_KEY, 7);
  runtimeService.startProcessInstanceByKey("miSequentialScriptTask", vars);

  // Validate history
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricActivityInstance> historicInstances = historyService.createHistoricActivityInstanceQuery().activityType("scriptTask").orderByActivityId().asc().list();
    assertEquals(7, historicInstances.size());
    for (int i = 0; i < 7; i++) {
      HistoricActivityInstance hai = historicInstances.get(i);
      assertEquals("scriptTask", hai.getActivityType());
      assertNotNull(hai.getStartTime());
      assertNotNull(hai.getEndTime());
    }
  }
}
 
Example #12
Source File: TerminateEndEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void assertHistoricActivitiesDeleteReason(ProcessInstance processInstance, String expectedDeleteReason, String ... activityIds) {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    for (String activityId : activityIds) {
      List<HistoricActivityInstance> historicActiviyInstances = historyService.createHistoricActivityInstanceQuery()
          .activityId(activityId).processInstanceId(processInstance.getId()).list();
      assertTrue(historicActiviyInstances.size() > 0);
      for (HistoricActivityInstance historicActiviyInstance : historicActiviyInstances) {
        assertNotNull(historicActiviyInstance.getEndTime());
        if (expectedDeleteReason == null) {
          assertNull(historicActiviyInstance.getDeleteReason()); 
        } else {
          assertTrue(historicActiviyInstance.getDeleteReason().startsWith(expectedDeleteReason));
        }
      }
    }
  }
}
 
Example #13
Source File: CompensateEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationStepEndRecorded.bpmn20.xml"})
public void testCompensationStepEndTimeRecorded() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationStepEndRecordedProcess");
  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());

  if (!processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    return;
  }
  final HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().activityId("compensationScriptTask");
  assertEquals(1, query.count());
  final HistoricActivityInstance compensationScriptTask = query.singleResult();
  assertNotNull(compensationScriptTask);
  assertNotNull(compensationScriptTask.getEndTime());
  assertNotNull(compensationScriptTask.getDurationInMillis());
}
 
Example #14
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public HistoricActivityInstanceResponse createHistoricActivityInstanceResponse(HistoricActivityInstance activityInstance, RestUrlBuilder urlBuilder) {
  HistoricActivityInstanceResponse result = new HistoricActivityInstanceResponse();
  result.setActivityId(activityInstance.getActivityId());
  result.setActivityName(activityInstance.getActivityName());
  result.setActivityType(activityInstance.getActivityType());
  result.setAssignee(activityInstance.getAssignee());
  result.setCalledProcessInstanceId(activityInstance.getCalledProcessInstanceId());
  result.setDurationInMillis(activityInstance.getDurationInMillis());
  result.setEndTime(activityInstance.getEndTime());
  result.setExecutionId(activityInstance.getExecutionId());
  result.setId(activityInstance.getId());
  result.setProcessDefinitionId(activityInstance.getProcessDefinitionId());
  result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, activityInstance.getProcessDefinitionId()));
  result.setProcessInstanceId(activityInstance.getProcessInstanceId());
  result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, activityInstance.getId()));
  result.setStartTime(activityInstance.getStartTime());
  result.setTaskId(activityInstance.getTaskId());
  result.setTenantId(activityInstance.getTenantId());
  return result;
}
 
Example #15
Source File: ProcessCustomService.java    From maven-framework-project with MIT License 6 votes vote down vote up
/** 
 * 查询指定任务节点的最新记录 
 *  
 * @param processInstance 
 *            流程实例 
 * @param activityId 
 * @return 
 */  
private static HistoricActivityInstance findHistoricUserTask(  
        ProcessInstance processInstance, String activityId) {  
    HistoricActivityInstance rtnVal = null;  
    // 查询当前流程实例审批结束的历史节点  
    List<HistoricActivityInstance> historicActivityInstances = historyService  
            .createHistoricActivityInstanceQuery().activityType("userTask")  
            .processInstanceId(processInstance.getId()).activityId(  
                    activityId).finished()  
            .orderByHistoricActivityInstanceEndTime().desc().list();  
    if (historicActivityInstances.size() > 0) {  
        rtnVal = historicActivityInstances.get(0);  
    }  
  
    return rtnVal;  
}
 
Example #16
Source File: AsyncExclusiveJobsTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/** 
 * Test for https://activiti.atlassian.net/browse/ACT-4035.
 */
@Deployment
public void testExclusiveJobs() {
	
	if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
	
		// The process has two script tasks in parallel, both exclusive.
		// They should be executed with at least 6 seconds in between (as they both sleep for 6 seconds)
		runtimeService.startProcessInstanceByKey("testExclusiveJobs");
		waitForJobExecutorToProcessAllJobs(20000L, 500L);
		
		HistoricActivityInstance scriptTaskAInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskA").singleResult();
		HistoricActivityInstance scriptTaskBInstance = historyService.createHistoricActivityInstanceQuery().activityId("scriptTaskB").singleResult();
		
		long endTimeA = scriptTaskAInstance.getEndTime().getTime();
		long endTimeB = scriptTaskBInstance.getEndTime().getTime();
		long endTimeDifference = 0;
		if (endTimeB > endTimeA) {
			endTimeDifference = endTimeB - endTimeA;
		} else {
			endTimeDifference = endTimeA - endTimeB;
		}
		assertTrue(endTimeDifference > 6000); // > 6000 -> jobs were executed in parallel
	}
	
}
 
Example #17
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceNoop() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("noopProcess");
  
  HistoricActivityInstance historicActivityInstance = historyService
    .createHistoricActivityInstanceQuery()
    .activityId("noop")
    .singleResult();
  
  assertEquals("noop", historicActivityInstance.getActivityId());
  assertEquals("serviceTask", historicActivityInstance.getActivityType());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertEquals(processInstance.getId(), historicActivityInstance.getExecutionId());
  assertNotNull(historicActivityInstance.getStartTime());
  assertNotNull(historicActivityInstance.getEndTime());
  assertTrue(historicActivityInstance.getDurationInMillis() >= 0);
}
 
Example #18
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Test to validate fix for ACT-1549: endTime of joining parallel gateway is not set
 */
@Deployment
public void testParallelJoinEndTime() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("forkJoin");

  List<Task> tasksToComplete = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  assertEquals(2, tasksToComplete.size());

  // Complete both tasks, second task-complete should end the fork-gateway
  // and set time
  taskService.complete(tasksToComplete.get(0).getId());
  taskService.complete(tasksToComplete.get(1).getId());

  List<HistoricActivityInstance> historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("join").processInstanceId(processInstance.getId()).list();

  assertNotNull(historicActivityInstance);

  // History contains 2 entries for parallel join (one for each path
  // arriving in the join), should contain end-time
  assertEquals(2, historicActivityInstance.size());
  assertNotNull(historicActivityInstance.get(0).getEndTime());
  assertNotNull(historicActivityInstance.get(1).getEndTime());
}
 
Example #19
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceProperties() {
  // Start process instance
  runtimeService.startProcessInstanceByKey("taskAssigneeProcess");

  // Get task list
  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("theTask").singleResult();

  Task task = taskService.createTaskQuery().singleResult();
  assertEquals(task.getId(), historicActivityInstance.getTaskId());
  assertEquals("kermit", historicActivityInstance.getAssignee());
}
 
Example #20
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceForEventsQuery() {
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("eventProcess");
  assertEquals(1, taskService.createTaskQuery().count());
  runtimeService.signalEventReceived("signal");
  assertProcessEnded(pi.getId());

  assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("noop").list().size());
  assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("userTask").list().size());
  assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").list().size());
  assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("start").list().size());
  assertEquals(1, historyService.createHistoricActivityInstanceQuery().activityId("end").list().size());

  // TODO: Discuss if boundary events will occur in the log!
  // assertEquals(1,
  // historyService.createHistoricActivityInstanceQuery().activityId("boundaryEvent").list().size());

  HistoricActivityInstance intermediateEvent = historyService.createHistoricActivityInstanceQuery().activityId("intermediate-event").singleResult();
  assertNotNull(intermediateEvent.getStartTime());
  assertNotNull(intermediateEvent.getEndTime());

  HistoricActivityInstance startEvent = historyService.createHistoricActivityInstanceQuery().activityId("start").singleResult();
  assertNotNull(startEvent.getStartTime());
  assertNotNull(startEvent.getEndTime());

  HistoricActivityInstance endEvent = historyService.createHistoricActivityInstanceQuery().activityId("end").singleResult();
  assertNotNull(endEvent.getStartTime());
  assertNotNull(endEvent.getEndTime());
}
 
Example #21
Source File: ProcessExtensionServiceImpl.java    From activiti-demo with Apache License 2.0 5 votes vote down vote up
private ActivityImpl filterNewestActivity(ProcessInstance processInstance,
                                          List<ActivityImpl> tempList){
    while (tempList.size()>0){
        ActivityImpl activity_1 = tempList.get(0);
        HistoricActivityInstance activityInstance_1 = findHistoricUserTask(processInstance,activity_1.getId());

        if(activityInstance_1==null){
            tempList.remove(activity_1);
            continue;
        }

        if(tempList.size()>1){
            ActivityImpl activity_2 = tempList.get(1);
            HistoricActivityInstance activityInstance_2 = findHistoricUserTask(processInstance,activity_2.getId());

            if(activityInstance_2==null){
                tempList.remove(activity_2);
                continue;
            }

            if(activityInstance_1.getEndTime().before(activityInstance_2.getEndTime())){
                tempList.remove(activity_1);
            }else {
                tempList.remove(activity_2);
            }
        }else {
            break;
        }
    }

    if(tempList.size()>0){
        return  tempList.get(0);
    }
    return null;
}
 
Example #22
Source File: ProcessInstanceHighlightsResource.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Check out the outgoing transition connected to firstActInst from startEventActList
 *
 * @param startEventActList
 * @param firstActInst
 * @return
 */
private PvmTransition getStartTransaction(List<ActivityImpl> startEventActList, HistoricActivityInstance firstActInst) {
    for (ActivityImpl startEventAct : startEventActList) {
        for (PvmTransition trans : startEventAct.getOutgoingTransitions()) {
            if (trans.getDestination().getId().equals(firstActInst.getActivityId())) {
                return trans;
            }
        }
    }
    return null;
}
 
Example #23
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 测试前加签
 */
@Test
public void testInsertTasksBefore() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//在前面加两个节点
	ActivityImpl[] as = tfcs.insertTasksBefore("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	Assert.assertEquals(as[0].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[1].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step2", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	//完成step2
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了step3
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2-1,step2-2,step2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}
 
Example #24
Source File: CallActivityTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testNotInheritVariablesSubprocess() throws Exception {
  BpmnModel mainBpmnModel = loadBPMNModel(NOT_INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
  BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);

  processEngine.getRepositoryService()
      .createDeployment()
      .name("childProcessDeployment")
      .addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
  
  processEngine.getRepositoryService()
      .createDeployment()
      .name("mainProcessDeployment")
      .addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();
  
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("var1", "String test value");
  variables.put("var2", true);
  variables.put("var3", 12345);
  variables.put("var4", 67890);

  ProcessInstance mainProcessInstance = runtimeService.startProcessInstanceByKey("mainProcess", variables);

  HistoricActivityInstanceQuery activityInstanceQuery = historyService.createHistoricActivityInstanceQuery();
  activityInstanceQuery.processInstanceId(mainProcessInstance.getId());
  activityInstanceQuery.activityId("childProcessCall");
  HistoricActivityInstance activityInstance = activityInstanceQuery.singleResult();
  String calledInstanceId = activityInstance.getCalledProcessInstanceId();

  HistoricVariableInstanceQuery variableInstanceQuery = historyService.createHistoricVariableInstanceQuery();
  variableInstanceQuery.processInstanceId(calledInstanceId);
  List<HistoricVariableInstance> variableInstances = variableInstanceQuery.list();

  assertEquals(0, variableInstances.size());
}
 
Example #25
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test to validate fix for ACT-1399: Boundary-event and event-based auditing
 */
@Deployment
public void testBoundaryEvent() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("boundaryEventProcess");
  // Complete the task with the boundary-event on it
  Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
  assertNotNull(task);
  taskService.complete(task.getId());

  assertEquals(0L, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());

  // Check if there is NO historic activity instance for a boundary-event
  // that has not triggered
  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("boundary").processInstanceId(processInstance.getId()).singleResult();

  assertNull(historicActivityInstance);

  // Now check the history when the boundary-event is fired
  processInstance = runtimeService.startProcessInstanceByKey("boundaryEventProcess");

  task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

  Execution signalExecution = runtimeService.createExecutionQuery().signalEventSubscriptionName("alert").singleResult();
  runtimeService.signalEventReceived("alert", signalExecution.getId());
  assertEquals(0L, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count());

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("boundary").processInstanceId(processInstance.getId()).singleResult();

  assertNotNull(historicActivityInstance);
  assertNotNull(historicActivityInstance.getStartTime());
  assertNotNull(historicActivityInstance.getEndTime());
}
 
Example #26
Source File: HistoricActivityInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testHistoricActivityInstanceReceive() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveProcess");

  HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNull(historicActivityInstance.getEndTime());
  assertNull(historicActivityInstance.getDurationInMillis());
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertNotNull(historicActivityInstance.getStartTime());

  Execution execution = runtimeService.createExecutionQuery().onlyChildExecutions().processInstanceId(processInstance.getId()).singleResult();
  runtimeService.trigger(execution.getId());

  historicActivityInstance = historyService.createHistoricActivityInstanceQuery().activityId("receive").singleResult();

  assertEquals("receive", historicActivityInstance.getActivityId());
  assertEquals("receiveTask", historicActivityInstance.getActivityType());
  assertNotNull(historicActivityInstance.getEndTime());
  assertTrue(historicActivityInstance.getDurationInMillis() >= 0);
  assertNotNull(historicActivityInstance.getProcessDefinitionId());
  assertEquals(processInstance.getId(), historicActivityInstance.getProcessInstanceId());
  assertNotNull(historicActivityInstance.getStartTime());
}
 
Example #27
Source File: CompensateEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment
public void testCompensateWithSubprocess() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensateProcess");
  
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
    HistoricActivityInstance historicActivityInstance = historyService.createHistoricActivityInstanceQuery()
        .processInstanceId(processInstance.getId()).activityId("bookHotel").singleResult();
    assertNotNull(historicActivityInstance.getEndTime());
  }
  
  // Triggering the task will trigger the compensation subprocess
  Task afterBookHotelTask = taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .taskDefinitionKey("afterBookHotel").singleResult();
  taskService.complete(afterBookHotelTask.getId());
  
  Task compensationTask1 = taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .taskDefinitionKey("compensateTask1").singleResult();
  assertNotNull(compensationTask1);
  
  Task compensationTask2 = taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .taskDefinitionKey("compensateTask2").singleResult();
  assertNotNull(compensationTask2);
  
  taskService.complete(compensationTask1.getId());
  taskService.complete(compensationTask2.getId());
  
  Task compensationTask3 = taskService.createTaskQuery().processInstanceId(processInstance.getId())
      .taskDefinitionKey("compensateTask3").singleResult();
  assertNotNull(compensationTask3);
  taskService.complete(compensationTask3.getId());
  
  assertProcessEnded(processInstance.getId());
}
 
Example #28
Source File: CompensateEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/compensate/CompensateEventTest.testCompensationStepEndRecorded.bpmn20.xml" })
public void testCompensationStepEndTimeRecorded() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("compensationStepEndRecordedProcess");
  assertProcessEnded(processInstance.getId());
  assertEquals(0, runtimeService.createProcessInstanceQuery().count());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    final HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery().activityId("compensationScriptTask");
    assertEquals(1, query.count());
    final HistoricActivityInstance compensationScriptTask = query.singleResult();
    assertNotNull(compensationScriptTask);
    assertNotNull(compensationScriptTask.getEndTime());
    assertNotNull(compensationScriptTask.getDurationInMillis());
  }
}
 
Example #29
Source File: ActivitiHistoryGraphBuilder.java    From lemon with Apache License 2.0 5 votes vote down vote up
public HistoricActivityInstance findVisitedHistoricActivityInstance(
        String activityId) {
    for (int i = visitedHistoricActivityInstances.size() - 1; i >= 0; i--) {
        HistoricActivityInstance historicActivityInstance = visitedHistoricActivityInstances
                .get(i);

        if (activityId.equals(historicActivityInstance.getActivityId())) {
            return historicActivityInstance;
        }
    }

    return null;
}
 
Example #30
Source File: ActivitiesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public CollectionWithPagingInfo<Activity> getActivities(String processId, Parameters parameters)
{
    Paging paging = parameters.getPaging();
    String status = parameters.getParameter("status");
    
    validateIfUserAllowedToWorkWithProcess(processId);

    HistoricActivityInstanceQuery query = activitiProcessEngine
            .getHistoryService()
            .createHistoricActivityInstanceQuery();
    
    if (STATUS_ACTIVE.equals(status)) query.unfinished();
    else if (STATUS_COMPLETED.equals(status)) query.finished();
    
    query.processInstanceId(processId);
    
    query.orderByExecutionId().asc();
    
    List<HistoricActivityInstance> activities = query.listPage(paging.getSkipCount(), paging.getMaxItems());

    List<Activity> page = new ArrayList<Activity>(activities.size());
    for (HistoricActivityInstance activityInstance: activities) 
    {
        Activity activity = new Activity(activityInstance);
        page.add(activity);
    }
    
    return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}