org.activiti.engine.history.HistoricVariableInstance Java Examples

The following examples show how to use org.activiti.engine.history.HistoricVariableInstance. 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: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimpleNoWaitState() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(4, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(2, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #2
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
    assertEquals(2, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("myVar", historicVariable.getName());
    assertEquals("test101112", historicVariable.getTextValue());

    HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
    assertEquals("myVar1", historicVariable1.getName());
    assertEquals("test789", historicVariable1.getTextValue());

    assertEquals(18, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(7, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #3
Source File: ProcessInstanceLogQueryAndByteArrayTypeVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testIncludeVariableUpdates() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
        .processInstanceId(processInstanceId).variableName("var").singleResult();
    assertEquals(historicVariableInstance.getValue(), LARGE_STRING_VALUE);
    
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId)
      .includeVariableUpdates()
      .singleResult();
    List<HistoricData> events = log.getHistoricData();
    assertEquals(1, events.size());
    
    for (HistoricData event : events) {
      assertTrue(event instanceof HistoricVariableUpdate);
      assertEquals(((HistoricDetailVariableInstanceUpdateEntity) event).getValue(), LARGE_STRING_VALUE);
    }
  }
}
 
Example #4
Source File: HistoricVariableInstanceQueryImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public List<HistoricVariableInstance> executeList(CommandContext commandContext, Page page) {
    checkQueryOk();
    ensureVariablesInitialized();

    List<HistoricVariableInstance> historicVariableInstances = commandContext
            .getHistoricVariableInstanceEntityManager()
            .findHistoricVariableInstancesByQueryCriteria(this, page);

    if (!excludeVariableInitialization) {
        for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
            if (historicVariableInstance instanceof HistoricVariableInstanceEntity) {
                HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
                if (variableEntity.getVariableType() != null) {
                    variableEntity.getValue();

                    // make sure JPA entities are cached for later retrieval
                    if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
                        ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
                    }
                }
            }
        }
    }
    return historicVariableInstances;
}
 
Example #5
Source File: ScriptExecutionListenerTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = { "org/activiti/examples/bpmn/executionlistener/ScriptExecutionListenerTest.bpmn20.xml" })
public void testScriptExecutionListener() {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("scriptExecutionListenerProcess");

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstance.getId()).list();
    Map<String, Object> varMap = new HashMap<String, Object>();
    for (HistoricVariableInstance historicVariableInstance : historicVariables) {
      varMap.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());
    }

    assertTrue(varMap.containsKey("foo"));
    assertEquals("FOO", varMap.get("foo"));
    assertTrue(varMap.containsKey("var1"));
    assertEquals("test", varMap.get("var1"));
    assertFalse(varMap.containsKey("bar"));
    assertTrue(varMap.containsKey("myVar"));
    assertEquals("BAR", varMap.get("myVar"));
  }
}
 
Example #6
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimple() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
   TaskQuery taskQuery = taskService.createTaskQuery();
   Task userTask = taskQuery.singleResult();
   assertEquals("userTask1", userTask.getName());
   
   taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));
   
   assertProcessEnded(processInstance.getId());
   
   List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
   assertEquals(1, variables.size());
   
   HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
   assertEquals("test456", historicVariable.getTextValue());
   
   assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
   assertEquals(3, historyService.createHistoricDetailQuery().count());
	}
}
 
Example #7
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testSimpleNoWaitState() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
   assertProcessEnded(processInstance.getId());
   
   List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
   assertEquals(1, variables.size());
   
   HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
   assertEquals("test456", historicVariable.getTextValue());
   
   assertEquals(4, historyService.createHistoricActivityInstanceQuery().count());
   assertEquals(2, historyService.createHistoricDetailQuery().count());
	}
}
 
Example #8
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelNoWaitState() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(7, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(2, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #9
Source File: HistoricVariableInstanceQueryImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public List<HistoricVariableInstance> executeList(CommandContext commandContext, Page page) {
  checkQueryOk();
  ensureVariablesInitialized();

  List<HistoricVariableInstance> historicVariableInstances = commandContext.getHistoricVariableInstanceEntityManager().findHistoricVariableInstancesByQueryCriteria(this, page);

  if (excludeVariableInitialization == false) {
    for (HistoricVariableInstance historicVariableInstance : historicVariableInstances) {
      if (historicVariableInstance instanceof HistoricVariableInstanceEntity) {
        HistoricVariableInstanceEntity variableEntity = (HistoricVariableInstanceEntity) historicVariableInstance;
        if (variableEntity != null && variableEntity.getVariableType() != null) {
          variableEntity.getValue();

          // make sure JPA entities are cached for later retrieval
          if (JPAEntityVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName()) || JPAEntityListVariableType.TYPE_NAME.equals(variableEntity.getVariableType().getTypeName())) {
            ((CacheableVariable) variableEntity.getVariableType()).setForceCacheable(true);
          }
        }
      }
    }
  }
  return historicVariableInstances;
}
 
Example #10
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testParallelNoWaitState() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
   assertProcessEnded(processInstance.getId());
   
   List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().list();
   assertEquals(1, variables.size());
   
   HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
   assertEquals("test456", historicVariable.getTextValue());
   
   assertEquals(7, historyService.createHistoricActivityInstanceQuery().count());
   assertEquals(2, historyService.createHistoricDetailQuery().count());
	}
}
 
Example #11
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testTwoSubProcessInParallelWithinSubProcess() {
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoSubProcessInParallelWithinSubProcess");
   assertProcessEnded(processInstance.getId());
   
   List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc().list();
   assertEquals(2, variables.size());
   
   HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
   assertEquals("myVar", historicVariable.getName());
   assertEquals("test101112", historicVariable.getTextValue());
   
   HistoricVariableInstanceEntity historicVariable1 = (HistoricVariableInstanceEntity) variables.get(1);
   assertEquals("myVar1", historicVariable1.getName());
   assertEquals("test789", historicVariable1.getTextValue());
   
   assertEquals(18, historyService.createHistoricActivityInstanceQuery().count());
   assertEquals(7, historyService.createHistoricDetailQuery().count());
	}
}
 
Example #12
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testRestrictByExecutionId() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task userTask = taskQuery.singleResult();
    assertEquals("userTask1", userTask.getName());

    taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().executionId(processInstance.getId()).list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(3, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #13
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testRestrictByExecutionId() {
  if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc");
    TaskQuery taskQuery = taskService.createTaskQuery();
    Task userTask = taskQuery.singleResult();
    assertEquals("userTask1", userTask.getName());

    taskService.complete(userTask.getId(), CollectionUtil.singletonMap("myVar", "test789"));

    assertProcessEnded(processInstance.getId());

    List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().executionId(processInstance.getId()).list();
    assertEquals(1, variables.size());

    HistoricVariableInstanceEntity historicVariable = (HistoricVariableInstanceEntity) variables.get(0);
    assertEquals("test456", historicVariable.getTextValue());

    assertEquals(5, historyService.createHistoricActivityInstanceQuery().count());
    assertEquals(3, historyService.createHistoricDetailQuery().count());
  }
}
 
Example #14
Source File: ActivitiTaskFormService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public List<ProcessInstanceVariableRepresentation> getProcessInstanceVariables(String taskId) {
  HistoricTaskInstance task = permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), taskId);
  List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(task.getProcessInstanceId()).list();

  // Get all process-variables to extract values from
  Map<String, ProcessInstanceVariableRepresentation> processInstanceVariables = new HashMap<String, ProcessInstanceVariableRepresentation>();

  for (HistoricVariableInstance historicVariableInstance : historicVariables) {
      ProcessInstanceVariableRepresentation processInstanceVariableRepresentation = new ProcessInstanceVariableRepresentation(
              historicVariableInstance.getVariableName(), historicVariableInstance.getVariableTypeName(), historicVariableInstance.getValue());
      processInstanceVariables.put(historicVariableInstance.getId(), processInstanceVariableRepresentation);
  }

  List<ProcessInstanceVariableRepresentation> processInstanceVariableRepresenations = 
      new ArrayList<ProcessInstanceVariableRepresentation>(processInstanceVariables.values());
  return processInstanceVariableRepresenations;
}
 
Example #15
Source File: HistoricJPAVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testGetJPAEntityAsHistoricVariable() {
  setupJPAEntities();
  // -----------------------------------------------------------------------------
  // Simple test, Start process with JPA entities as variables
  // -----------------------------------------------------------------------------
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);

  // Start the process with the JPA-entities as variables. They will be stored
  // in the DB.
  this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();

  for (Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
    taskService.complete(task.getId());
  }

  // Get JPAEntity Variable by HistoricVariableInstanceQuery
  HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess")
      .singleResult();

  Object value = historicVariableInstance.getValue();
  assertTrue(value instanceof FieldAccessJPAEntity);
  assertEquals(((FieldAccessJPAEntity) value).getValue(), simpleEntityFieldAccess.getValue());
}
 
Example #16
Source File: HistoricJPAVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testGetJPAEntityAsHistoricVariable() {
	setupJPAEntities();
	// -----------------------------------------------------------------------------
	// Simple test, Start process with JPA entities as variables
	// -----------------------------------------------------------------------------
	Map<String, Object> variables = new HashMap<String, Object>();
	variables.put("simpleEntityFieldAccess", simpleEntityFieldAccess);

	// Start the process with the JPA-entities as variables. They will be stored in the DB.
	this.processInstanceId = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables).getId();

	for (Task task : taskService.createTaskQuery().includeTaskLocalVariables().list()) {
		taskService.complete(task.getId());
	}
	
	// Get JPAEntity Variable by HistoricVariableInstanceQuery
	HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
			.processInstanceId(processInstanceId).variableName("simpleEntityFieldAccess").singleResult();
	
	Object value = historicVariableInstance.getValue();
	assertTrue(value instanceof FieldAccessJPAEntity);
	assertEquals(((FieldAccessJPAEntity)value).getValue(), simpleEntityFieldAccess.getValue());
}
 
Example #17
Source File: ProcessInstanceLogQueryAndByteArrayTypeVariableTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testIncludeVariableUpdates() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
    
    HistoricVariableInstance historicVariableInstance = historyService.createHistoricVariableInstanceQuery()
        .processInstanceId(processInstanceId).variableName("var").singleResult();
    assertEquals(historicVariableInstance.getValue(), LARGE_STRING_VALUE);
    
    ProcessInstanceHistoryLog log = historyService.createProcessInstanceHistoryLogQuery(processInstanceId)
      .includeVariableUpdates()
      .singleResult();
    List<HistoricData> events = log.getHistoricData();
    assertEquals(1, events.size());
    
    for (HistoricData event : events) {
      assertTrue(event instanceof HistoricVariableUpdate);
      assertEquals(((HistoricDetailVariableInstanceUpdateEntity) event).getValue(), LARGE_STRING_VALUE);
    }
  }
}
 
Example #18
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={
  "org/activiti5/engine/test/api/runtime/variableScope.bpmn20.xml"
})
public void testHistoricVariableQueryByExecutionIdsForScope(){
  Map<String, Object> processVars = new HashMap<String, Object>();
  processVars.put("processVar", "processVar");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
  
  Set<String> executionIds = new HashSet<String>();
  List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
  for (Execution execution : executions){
    if (!processInstance.getId().equals(execution.getId())){
      executionIds.add(execution.getId());
      runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
    }
  }
  
  List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  for (Task task : tasks){
    taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
  }
  
  Set<String> processInstanceIds = new HashSet<String>();
  processInstanceIds.add(processInstance.getId());
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(processInstanceIds).list();
  assertEquals(historicVariableInstances.size(), 1);
  assertEquals(historicVariableInstances.get(0).getVariableName(), "processVar");
  assertEquals(historicVariableInstances.get(0).getValue() , "processVar");
  
  historicVariableInstances = historyService.createHistoricVariableInstanceQuery().executionIds(executionIds).excludeTaskVariables().list();
  assertEquals(historicVariableInstances.size(), 2);
  assertEquals(historicVariableInstances.get(0).getVariableName(), "executionVar");
  assertEquals(historicVariableInstances.get(0).getValue() , "executionVar");
  assertEquals(historicVariableInstances.get(1).getVariableName(), "executionVar");
  assertEquals(historicVariableInstances.get(1).getValue() , "executionVar");
}
 
Example #19
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricVariableQueryByTaskIds() {
  deployTwoTasksTestProcess();
  // Generate data
  String processInstanceId = runtimeService.startProcessInstanceByKey("twoTasksProcess").getId();
  List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstanceId).list();
  taskService.setVariableLocal(tasks.get(0).getId(), "taskVar1", "hello1");
  taskService.setVariableLocal(tasks.get(1).getId(), "taskVar2", "hello2");
  
  Set<String> taskIds = new HashSet<String>();
  taskIds.add(tasks.get(0).getId());
  taskIds.add(tasks.get(1).getId());
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().taskIds(taskIds).list();
  assertEquals(2, historyService.createHistoricVariableInstanceQuery().taskIds(taskIds).count());
  assertEquals(2, historicVariableInstances.size());
  assertEquals("taskVar1", historicVariableInstances.get(0).getVariableName());
  assertEquals("hello1", historicVariableInstances.get(0).getValue());
  assertEquals("taskVar2", historicVariableInstances.get(1).getVariableName());
  assertEquals("hello2", historicVariableInstances.get(1).getValue());
  
  taskIds = new HashSet<String>();
  taskIds.add(tasks.get(0).getId());
  historicVariableInstances = historyService.createHistoricVariableInstanceQuery().taskIds(taskIds).list();
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().taskIds(taskIds).count());
  assertEquals(1, historicVariableInstances.size());
  assertEquals("taskVar1", historicVariableInstances.get(0).getVariableName());
  assertEquals("hello1", historicVariableInstances.get(0).getValue());
}
 
Example #20
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources={
  "org/activiti5/engine/test/api/runtime/variableScope.bpmn20.xml"
})
public void testHistoricVariableQueryByTaskIdsForScope() {
  Map<String, Object> processVars = new HashMap<String, Object>();
  processVars.put("processVar", "processVar");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variableScopeProcess", processVars);
  
  Set<String> executionIds = new HashSet<String>();
  List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list();
  for (Execution execution : executions){
    if (!processInstance.getId().equals(execution.getId())){
      executionIds.add(execution.getId());
      runtimeService.setVariableLocal(execution.getId(), "executionVar", "executionVar");
    }
  }
  
  List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
  Set<String> taskIds = new HashSet<String>();
  for (Task task : tasks){
    taskService.setVariableLocal(task.getId(), "taskVar", "taskVar");
    taskIds.add(task.getId());
  }
  
  List<HistoricVariableInstance> historicVariableInstances = historyService.createHistoricVariableInstanceQuery().taskIds(taskIds).list();
  assertEquals(historicVariableInstances.size(), 2);
  assertEquals(historicVariableInstances.get(0).getVariableName(), "taskVar");
  assertEquals(historicVariableInstances.get(0).getValue() , "taskVar");
  assertEquals(historicVariableInstances.get(1).getVariableName(), "taskVar");
  assertEquals(historicVariableInstances.get(1).getValue() , "taskVar");
}
 
Example #21
Source File: HistoricVariableInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = "org/activiti5/engine/test/history/HistoricVariableInstanceTest.testSimple.bpmn20.xml")
public void testNativeHistoricVariableInstanceQuery() {
	
	if(processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
	
   assertEquals("ACT_HI_VARINST", managementService.getTableName(HistoricVariableInstance.class));
   assertEquals("ACT_HI_VARINST", managementService.getTableName(HistoricVariableInstanceEntity.class));
	
   String tableName = managementService.getTableName(HistoricVariableInstance.class);
   String baseQuerySql = "SELECT * FROM " + tableName;
	
   Map<String, Object> variables = new HashMap<String, Object>();
   variables.put("var1", "value1");
   variables.put("var2", "value2");
   ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProc", variables);
   assertNotNull(processInstance);
	
   assertEquals(3, historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).list().size());
	
   String sqlWithConditions = baseQuerySql + " where NAME_ = #{name}";
   assertEquals("test123", historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions)
       .parameter("name", "myVar").singleResult().getValue());
	
   sqlWithConditions = baseQuerySql + " where NAME_ like #{name}";
   assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions)
       .parameter("name", "var%").list().size());
	
   // paging
   assertEquals(3, historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).listPage(0, 3).size());
   assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql(baseQuerySql).listPage(1, 3).size());
   assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql(sqlWithConditions)
       .parameter("name", "var%").listPage(0, 2).size());
	}

}
 
Example #22
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 #23
Source File: StandaloneTaskTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testHistoricVariableOkOnUpdate() {
   if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.AUDIT)) {
 		// 1. create a task
 		Task task = taskService.newTask();
 		task.setName("test execution");
 		task.setOwner("josOwner");
 		task.setAssignee("JosAssignee");
 		taskService.saveTask(task);
 		 
 		// 2. set task variables
 		Map<String, Object> taskVariables = new HashMap<String, Object>();
 		taskVariables.put("finishedAmount", 0);
 		taskService.setVariables(task.getId(), taskVariables);
 		 
 		// 3. complete this task with a new variable
 		Map<String, Object> finishVariables = new HashMap<String, Object>();
 		finishVariables.put("finishedAmount", 40);
 		taskService.complete(task.getId(), finishVariables);
 		 
 		// 4. get completed variable
 		List<HistoricVariableInstance> hisVarList = historyService.createHistoricVariableInstanceQuery().taskId(task.getId()).list();
 		assertEquals(1, hisVarList.size());
 		assertEquals(40, hisVarList.get(0).getValue());
 		
 		// Cleanup
 		historyService.deleteHistoricTaskInstance(task.getId());
   }
}
 
Example #24
Source File: FullHistoryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources="org/activiti5/standalone/history/FullHistoryTest.testVariableUpdates.bpmn20.xml")
public void testHistoricVariableInstanceQuery() {
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("process", "one");
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
  runtimeService.trigger(processInstance.getProcessInstanceId());
  
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("process").count());
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count());    
  
  Map<String, Object> variables2 = new HashMap<String, Object>();
  variables2.put("process", "two");
  ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("receiveTask", variables2);
  runtimeService.trigger(processInstance2.getProcessInstanceId());
  
  assertEquals(2, historyService.createHistoricVariableInstanceQuery().variableName("process").count());
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").count());    
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "two").count());        
  
  HistoricVariableInstance historicProcessVariable = historyService.createHistoricVariableInstanceQuery().variableValueEquals("process", "one").singleResult();
  assertEquals("process", historicProcessVariable.getVariableName());
  assertEquals("one", historicProcessVariable.getValue());
  
  Map<String, Object> variables3 = new HashMap<String, Object>();
  variables3.put("long", 1000l);
  variables3.put("double", 25.43d);
  ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("receiveTask", variables3);
  runtimeService.trigger(processInstance3.getProcessInstanceId());
  
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("long").count());
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("long", 1000l).count());    
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableName("double").count());
  assertEquals(1, historyService.createHistoricVariableInstanceQuery().variableValueEquals("double",  25.43d).count());    

}
 
Example #25
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public HistoricVariableInstanceResponse createHistoricVariableInstanceResponse(HistoricVariableInstance variableInstance, RestUrlBuilder urlBuilder) {
  HistoricVariableInstanceResponse result = new HistoricVariableInstanceResponse();
  result.setId(variableInstance.getId());
  result.setProcessInstanceId(variableInstance.getProcessInstanceId());
  if (variableInstance.getProcessInstanceId() != null) {
    result.setProcessInstanceUrl(urlBuilder.buildUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, variableInstance.getProcessInstanceId()));
  }
  result.setTaskId(variableInstance.getTaskId());
  result.setVariable(createRestVariable(variableInstance.getVariableName(), variableInstance.getValue(), null, variableInstance.getId(), VARIABLE_HISTORY_VARINSTANCE, false, urlBuilder));
  return result;
}
 
Example #26
Source File: ListenerTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"diagrams/chapter7/listener/listener.bpmn"})
public void testListener() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("endListener", new ProcessEndExecutionListener());
    variables.put("assignmentDelegate", new TaskAssigneeListener());
    variables.put("name", "Henry Yan");

    identityService.setAuthenticatedUserId("henryyan");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("listener", variables);

    // 校验是否执行了启动监听
    String processInstanceId = processInstance.getId();
    assertTrue((Boolean) runtimeService.getVariable(processInstanceId, "setInStartListener"));

    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).taskAssignee("jenny").singleResult();
    String setInTaskCreate = (String) taskService.getVariable(task.getId(), "setInTaskCreate");
    assertEquals("create, Hello, Henry Yan", setInTaskCreate);
    taskService.complete(task.getId());

    // 流程结束后查询变量
    List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
    boolean hasVariableOfEndListener = false;
    for (HistoricVariableInstance variableInstance : list) {
        if (variableInstance.getVariableName().equals("setInEndListener")) {
            hasVariableOfEndListener = true;
        }
    }
    assertTrue(hasVariableOfEndListener);
}
 
Example #27
Source File: WorkflowRestImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get all items from the process package variable
 */
public CollectionWithPagingInfo<Item> getItemsFromProcess(String processId, Paging paging)
{
    ActivitiScriptNode packageScriptNode = null;
    try 
    {
        HistoricVariableInstance variableInstance = activitiProcessEngine.getHistoryService()
                .createHistoricVariableInstanceQuery()
                .processInstanceId(processId)
                .variableName(BPM_PACKAGE)
                .singleResult();
        
        if (variableInstance != null)
        {
            packageScriptNode = (ActivitiScriptNode) variableInstance.getValue();
        }
        else
        {
            throw new EntityNotFoundException(processId);
        }
    } 
    catch (ActivitiObjectNotFoundException e)
    {
        throw new EntityNotFoundException(processId);
    }
    
    List<Item> page = new ArrayList<Item>();
    if (packageScriptNode != null)
    {
        List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
        for (ChildAssociationRef childAssociationRef : documentList)
        {
            Item item = createItemForNodeRef(childAssociationRef.getChildRef());
            page.add(item);
        }
    }
    
    return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
 
Example #28
Source File: ListenerTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"diagrams/chapter7/listener/listener.bpmn"})
public void testListener() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("endListener", new ProcessEndExecutionListener());
    variables.put("assignmentDelegate", new TaskAssigneeListener());
    variables.put("name", "Henry Yan");

    identityService.setAuthenticatedUserId("henryyan");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("listener", variables);

    // 校验是否执行了启动监听
    String processInstanceId = processInstance.getId();
    assertTrue((Boolean) runtimeService.getVariable(processInstanceId, "setInStartListener"));

    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).taskAssignee("jenny").singleResult();
    String setInTaskCreate = (String) taskService.getVariable(task.getId(), "setInTaskCreate");
    assertEquals("create, Hello, Henry Yan", setInTaskCreate);
    taskService.complete(task.getId());

    // 流程结束后查询变量
    List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
    boolean hasVariableOfEndListener = false;
    for (HistoricVariableInstance variableInstance : list) {
        if (variableInstance.getVariableName().equals("setInEndListener")) {
            hasVariableOfEndListener = true;
        }
    }
    assertTrue(hasVariableOfEndListener);
}
 
Example #29
Source File: HistoricVariableInstanceEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryLikeByQueryVariableValueIgnoreCase() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var%", "%\\%%").singleResult();
      assertNotNull(historicVariable);
      assertEquals(processInstance1.getId(), historicVariable.getProcessInstanceId());
      
      historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("var_", "%\\_%").singleResult();
      assertNotNull(historicVariable);
      assertEquals(processInstance2.getId(), historicVariable.getProcessInstanceId());
  }
}
 
Example #30
Source File: HistoricVariableInstanceEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryLikeByQueryVariableValue() {
  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
      HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var%", "%\\%%").singleResult();
      assertNotNull(historicVariable);
      assertEquals(processInstance1.getId(), historicVariable.getProcessInstanceId());
      
      historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("var_", "%\\_%").singleResult();
      assertNotNull(historicVariable);
      assertEquals(processInstance2.getId(), historicVariable.getProcessInstanceId());
  }
}