Search in sources :

Example 1 with HistoricVariableInstanceQuery

use of org.activiti.engine.history.HistoricVariableInstanceQuery in project Activiti by Activiti.

the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.

@Deployment
public void testHistoricVariableUpdatesAllTypes() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("aVariable", "initial value");
    Date startedDate = sdf.parse("01/01/2001 01:23:45 000");
    // In the javaDelegate, the current time is manipulated
    Date updatedDate = sdf.parse("01/01/2001 01:23:46 000");
    processEngineConfiguration.getClock().setCurrentTime(startedDate);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("HistoricVariableUpdateProcess", variables);
    List<HistoricDetail> details = historyService.createHistoricDetailQuery().variableUpdates().processInstanceId(processInstance.getId()).orderByVariableName().asc().orderByTime().asc().list();
    // 8 variable updates should be present, one performed when starting process
    // the other 7 are set in VariableSetter serviceTask
    assertEquals(9, details.size());
    // Since we order by varName, first entry should be aVariable update from startTask
    HistoricVariableUpdate startVarUpdate = (HistoricVariableUpdate) details.get(0);
    assertEquals("aVariable", startVarUpdate.getVariableName());
    assertEquals("initial value", startVarUpdate.getValue());
    assertEquals(0, startVarUpdate.getRevision());
    assertEquals(processInstance.getId(), startVarUpdate.getProcessInstanceId());
    // Date should the the one set when starting
    assertEquals(startedDate, startVarUpdate.getTime());
    HistoricVariableUpdate updatedStringVariable = (HistoricVariableUpdate) details.get(1);
    assertEquals("aVariable", updatedStringVariable.getVariableName());
    assertEquals("updated value", updatedStringVariable.getValue());
    assertEquals(processInstance.getId(), updatedStringVariable.getProcessInstanceId());
    // Date should be the updated date
    assertEquals(updatedDate, updatedStringVariable.getTime());
    HistoricVariableUpdate intVariable = (HistoricVariableUpdate) details.get(2);
    assertEquals("bVariable", intVariable.getVariableName());
    assertEquals(123, intVariable.getValue());
    assertEquals(processInstance.getId(), intVariable.getProcessInstanceId());
    assertEquals(updatedDate, intVariable.getTime());
    HistoricVariableUpdate longVariable = (HistoricVariableUpdate) details.get(3);
    assertEquals("cVariable", longVariable.getVariableName());
    assertEquals(12345L, longVariable.getValue());
    assertEquals(processInstance.getId(), longVariable.getProcessInstanceId());
    assertEquals(updatedDate, longVariable.getTime());
    HistoricVariableUpdate doubleVariable = (HistoricVariableUpdate) details.get(4);
    assertEquals("dVariable", doubleVariable.getVariableName());
    assertEquals(1234.567, doubleVariable.getValue());
    assertEquals(processInstance.getId(), doubleVariable.getProcessInstanceId());
    assertEquals(updatedDate, doubleVariable.getTime());
    HistoricVariableUpdate shortVariable = (HistoricVariableUpdate) details.get(5);
    assertEquals("eVariable", shortVariable.getVariableName());
    assertEquals((short) 12, shortVariable.getValue());
    assertEquals(processInstance.getId(), shortVariable.getProcessInstanceId());
    assertEquals(updatedDate, shortVariable.getTime());
    HistoricVariableUpdate dateVariable = (HistoricVariableUpdate) details.get(6);
    assertEquals("fVariable", dateVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), dateVariable.getValue());
    assertEquals(processInstance.getId(), dateVariable.getProcessInstanceId());
    assertEquals(updatedDate, dateVariable.getTime());
    HistoricVariableUpdate serializableVariable = (HistoricVariableUpdate) details.get(7);
    assertEquals("gVariable", serializableVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), serializableVariable.getValue());
    assertEquals(processInstance.getId(), serializableVariable.getProcessInstanceId());
    assertEquals(updatedDate, serializableVariable.getTime());
    HistoricVariableUpdate byteArrayVariable = (HistoricVariableUpdate) details.get(8);
    assertEquals("hVariable", byteArrayVariable.getVariableName());
    assertEquals(";-)", new String((byte[]) byteArrayVariable.getValue()));
    assertEquals(processInstance.getId(), byteArrayVariable.getProcessInstanceId());
    assertEquals(updatedDate, byteArrayVariable.getTime());
    // end process instance
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    taskService.complete(tasks.get(0).getId());
    assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertEquals(8, historicProcessVariableQuery.count());
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertEquals("aVariable", historicVariable.getVariableName());
    assertEquals("updated value", historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(1);
    assertEquals("bVariable", historicVariable.getVariableName());
    assertEquals(123, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(2);
    assertEquals("cVariable", historicVariable.getVariableName());
    assertEquals(12345L, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(3);
    assertEquals("dVariable", historicVariable.getVariableName());
    assertEquals(1234.567, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(4);
    assertEquals("eVariable", historicVariable.getVariableName());
    assertEquals((short) 12, historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(5);
    assertEquals("fVariable", historicVariable.getVariableName());
    assertEquals(sdf.parse("01/01/2001 01:23:45 678"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(6);
    assertEquals("gVariable", historicVariable.getVariableName());
    assertEquals(new SerializableVariable("hello hello"), historicVariable.getValue());
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
    historicVariable = historicVariables.get(7);
    assertEquals("hVariable", historicVariable.getVariableName());
    assertEquals(";-)", ";-)", new String((byte[]) historicVariable.getValue()));
    assertEquals(processInstance.getId(), historicVariable.getProcessInstanceId());
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) Date(java.util.Date) SerializableVariable(org.activiti.engine.test.history.SerializableVariable) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimpleDateFormat(java.text.SimpleDateFormat) Deployment(org.activiti.engine.test.Deployment)

Example 2 with HistoricVariableInstanceQuery

use of org.activiti.engine.history.HistoricVariableInstanceQuery in project Activiti by Activiti.

the class CallActivityTest method testInheritVariablesSubprocess.

public void testInheritVariablesSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(INHERIT_VARIABLES_MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(INHERIT_VARIABLES_CHILD_PROCESS_RESOURCE);
    processEngine.getRepositoryService().createDeployment().name("mainProcessDeployment").addBpmnModel("mainProcess.bpmn20.xml", mainBpmnModel).deploy();
    processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).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();
    List<HistoricVariableInstance> variableInstances = variableInstanceQuery.processInstanceId(calledInstanceId).list();
    assertEquals(4, variableInstances.size());
    for (HistoricVariableInstance variable : variableInstances) {
        assertEquals(variables.get(variable.getVariableName()), variable.getValue());
    }
}
Also used : HistoricActivityInstanceQuery(org.activiti.engine.history.HistoricActivityInstanceQuery) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 3 with HistoricVariableInstanceQuery

use of org.activiti.engine.history.HistoricVariableInstanceQuery in project Activiti by Activiti.

the class CallActivityTest method testNotInheritVariablesSubprocess.

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());
}
Also used : HistoricActivityInstanceQuery(org.activiti.engine.history.HistoricActivityInstanceQuery) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance)

Example 4 with HistoricVariableInstanceQuery

use of org.activiti.engine.history.HistoricVariableInstanceQuery in project Activiti by Activiti.

the class FullHistoryTest method testVariableUpdates.

@Deployment
public void testVariableUpdates() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("number", "one");
    variables.put("character", "a");
    variables.put("bytes", ":-(".getBytes());
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("receiveTask", variables);
    runtimeService.setVariable(processInstance.getId(), "number", "two");
    runtimeService.setVariable(processInstance.getId(), "bytes", ":-)".getBytes());
    // Start-task should be added to history
    HistoricActivityInstance historicStartEvent = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theStart").singleResult();
    assertNotNull(historicStartEvent);
    HistoricActivityInstance waitStateActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("waitState").singleResult();
    assertNotNull(waitStateActivity);
    HistoricActivityInstance serviceTaskActivity = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("serviceTask").singleResult();
    assertNotNull(serviceTaskActivity);
    List<HistoricDetail> historicDetails = historyService.createHistoricDetailQuery().orderByVariableName().asc().orderByVariableRevision().asc().list();
    assertEquals(10, historicDetails.size());
    HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(0);
    assertEquals("bytes", historicVariableUpdate.getVariableName());
    assertEquals(":-(", new String((byte[]) historicVariableUpdate.getValue()));
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(1);
    assertEquals("bytes", historicVariableUpdate.getVariableName());
    assertEquals(":-)", new String((byte[]) historicVariableUpdate.getValue()));
    assertEquals(1, historicVariableUpdate.getRevision());
    assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(2);
    assertEquals("character", historicVariableUpdate.getVariableName());
    assertEquals("a", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(3);
    assertEquals("number", historicVariableUpdate.getVariableName());
    assertEquals("one", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable is updated when process was in waitstate
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(4);
    assertEquals("number", historicVariableUpdate.getVariableName());
    assertEquals("two", historicVariableUpdate.getValue());
    assertEquals(1, historicVariableUpdate.getRevision());
    assertEquals(waitStateActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from process-start execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(5);
    assertEquals("zVar1", historicVariableUpdate.getVariableName());
    assertEquals("Event: start", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(historicStartEvent.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from transition take execution listener
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(6);
    assertEquals("zVar2", historicVariableUpdate.getVariableName());
    assertEquals("Event: take", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertNull(historicVariableUpdate.getActivityInstanceId());
    // Variable set from activity start execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(7);
    assertEquals("zVar3", historicVariableUpdate.getVariableName());
    assertEquals("Event: start", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from activity end execution listener on the servicetask
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(8);
    assertEquals("zVar4", historicVariableUpdate.getVariableName());
    assertEquals("Event: end", historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // Variable set from service-task
    historicVariableUpdate = (HistoricVariableUpdate) historicDetails.get(9);
    assertEquals("zzz", historicVariableUpdate.getVariableName());
    assertEquals(123456789L, historicVariableUpdate.getValue());
    assertEquals(0, historicVariableUpdate.getRevision());
    assertEquals(serviceTaskActivity.getId(), historicVariableUpdate.getActivityInstanceId());
    // trigger receive task
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
    // check for historic process variables set
    HistoricVariableInstanceQuery historicProcessVariableQuery = historyService.createHistoricVariableInstanceQuery().orderByVariableName().asc();
    assertEquals(8, historicProcessVariableQuery.count());
    List<HistoricVariableInstance> historicVariables = historicProcessVariableQuery.list();
    // Variable status when process is finished
    HistoricVariableInstance historicVariable = historicVariables.get(0);
    assertEquals("bytes", historicVariable.getVariableName());
    assertEquals(":-)", new String((byte[]) historicVariable.getValue()));
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(1);
    assertEquals("character", historicVariable.getVariableName());
    assertEquals("a", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(2);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    assertNotSame(historicVariable.getCreateTime(), historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(3);
    assertEquals("zVar1", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(4);
    assertEquals("zVar2", historicVariable.getVariableName());
    assertEquals("Event: take", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(5);
    assertEquals("zVar3", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(6);
    assertEquals("zVar4", historicVariable.getVariableName());
    assertEquals("Event: end", historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historicVariables.get(7);
    assertEquals("zzz", historicVariable.getVariableName());
    assertEquals(123456789L, historicVariable.getValue());
    assertNotNull(historicVariable.getCreateTime());
    assertNotNull(historicVariable.getLastUpdatedTime());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLike("number", "tw%").singleResult();
    assertNotNull(historicVariable);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW%").singleResult();
    assertNotNull(historicVariable);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historyService.createHistoricVariableInstanceQuery().variableValueLikeIgnoreCase("number", "TW2%").singleResult();
    assertNull(historicVariable);
}
Also used : HistoricVariableUpdate(org.activiti.engine.history.HistoricVariableUpdate) HistoricDetail(org.activiti.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.activiti.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.activiti.engine.history.HistoricActivityInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

HashMap (java.util.HashMap)4 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)4 HistoricVariableInstanceQuery (org.activiti.engine.history.HistoricVariableInstanceQuery)4 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)4 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)2 HistoricDetail (org.activiti.engine.history.HistoricDetail)2 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)2 HistoricVariableUpdate (org.activiti.engine.history.HistoricVariableUpdate)2 Deployment (org.activiti.engine.test.Deployment)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Task (org.activiti.engine.task.Task)1 SerializableVariable (org.activiti.engine.test.history.SerializableVariable)1