Search in sources :

Example 21 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class RestartProcessInstancesCmd method collectInitialVariables.

protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) {
    HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService();
    HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance);
    HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery().variableUpdates().executionId(processInstance.getId()).activityInstanceId(startActivityInstance.getId());
    List<HistoricDetail> historicDetails = query.sequenceCounter(1).list();
    VariableMap variables = new VariableMapImpl();
    for (HistoricDetail detail : historicDetails) {
        HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail;
        variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue());
    }
    return variables;
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) HistoricDetailQueryImpl(org.camunda.bpm.engine.impl.HistoricDetailQueryImpl) HistoryService(org.camunda.bpm.engine.HistoryService) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance)

Example 22 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class FullHistoryTest method testHistoricVariableUpdateStandaloneTaskDefinitionProperties.

@Test
public void testHistoricVariableUpdateStandaloneTaskDefinitionProperties() {
    // given
    String taskId = "myTask";
    Task task = taskService.newTask(taskId);
    taskService.saveTask(task);
    taskService.setVariable(taskId, "aVariable", "anotherValue");
    String firstVariable = runtimeService.createVariableInstanceQuery().variableName("aVariable").singleResult().getId();
    // when
    HistoricVariableUpdate instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(firstVariable).singleResult();
    // then
    assertNull(instance.getProcessDefinitionKey());
    assertNull(instance.getProcessDefinitionId());
    assertNull(instance.getCaseDefinitionKey());
    assertNull(instance.getCaseDefinitionId());
    taskService.deleteTask(taskId, true);
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) Task(org.camunda.bpm.engine.task.Task) Test(org.junit.Test)

Example 23 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class FullHistoryTest method testHistoricVariableUpdateProcessDefinitionProperty.

@Test
@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testHistoricVariableUpdateProcessDefinitionProperty() {
    // given
    String key = "oneTaskProcess";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key);
    String processInstanceId = processInstance.getId();
    String taskId = taskService.createTaskQuery().singleResult().getId();
    runtimeService.setVariable(processInstanceId, "aVariable", "aValue");
    taskService.setVariableLocal(taskId, "aLocalVariable", "anotherValue");
    String firstVariable = runtimeService.createVariableInstanceQuery().variableName("aVariable").singleResult().getId();
    String secondVariable = runtimeService.createVariableInstanceQuery().variableName("aLocalVariable").singleResult().getId();
    // when (1)
    HistoricVariableUpdate instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(firstVariable).singleResult();
    // then (1)
    assertNotNull(instance.getProcessDefinitionKey());
    assertEquals(key, instance.getProcessDefinitionKey());
    assertNotNull(instance.getProcessDefinitionId());
    assertEquals(processInstance.getProcessDefinitionId(), instance.getProcessDefinitionId());
    assertNull(instance.getCaseDefinitionKey());
    assertNull(instance.getCaseDefinitionId());
    // when (2)
    instance = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(secondVariable).singleResult();
    // then (2)
    assertNotNull(instance.getProcessDefinitionKey());
    assertEquals(key, instance.getProcessDefinitionKey());
    assertNotNull(instance.getProcessDefinitionId());
    assertEquals(processInstance.getProcessDefinitionId(), instance.getProcessDefinitionId());
    assertNull(instance.getCaseDefinitionKey());
    assertNull(instance.getCaseDefinitionId());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 24 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class FullHistoryTest method testVariableUpdates.

@Test
@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());
    testHelper.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()));
    historicVariable = historicVariables.get(1);
    assertEquals("character", historicVariable.getVariableName());
    assertEquals("a", historicVariable.getValue());
    historicVariable = historicVariables.get(2);
    assertEquals("number", historicVariable.getVariableName());
    assertEquals("two", historicVariable.getValue());
    historicVariable = historicVariables.get(3);
    assertEquals("zVar1", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    historicVariable = historicVariables.get(4);
    assertEquals("zVar2", historicVariable.getVariableName());
    assertEquals("Event: take", historicVariable.getValue());
    historicVariable = historicVariables.get(5);
    assertEquals("zVar3", historicVariable.getVariableName());
    assertEquals("Event: start", historicVariable.getValue());
    historicVariable = historicVariables.get(6);
    assertEquals("zVar4", historicVariable.getVariableName());
    assertEquals("Event: end", historicVariable.getValue());
    historicVariable = historicVariables.get(7);
    assertEquals("zzz", historicVariable.getVariableName());
    assertEquals(123456789L, historicVariable.getValue());
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) HashMap(java.util.HashMap) HistoricVariableInstanceQuery(org.camunda.bpm.engine.history.HistoricVariableInstanceQuery) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) HistoricActivityInstance(org.camunda.bpm.engine.history.HistoricActivityInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 25 with HistoricVariableUpdate

use of org.camunda.bpm.engine.history.HistoricVariableUpdate in project camunda-bpm-platform by camunda.

the class CustomHistoryTest method testReceivesVariableUpdates.

@Deployment(resources = "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml")
public void testReceivesVariableUpdates() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // when
    String value = "a Variable Value";
    runtimeService.setVariable(instance.getId(), "aStringVariable", value);
    runtimeService.setVariable(instance.getId(), "aBytesVariable", value.getBytes());
    // then the historic variable instances and their values exist
    assertEquals(2, historyService.createHistoricVariableInstanceQuery().count());
    HistoricVariableInstance historicStringVariable = historyService.createHistoricVariableInstanceQuery().variableName("aStringVariable").singleResult();
    assertNotNull(historicStringVariable);
    assertEquals(value, historicStringVariable.getValue());
    HistoricVariableInstance historicBytesVariable = historyService.createHistoricVariableInstanceQuery().variableName("aBytesVariable").singleResult();
    assertNotNull(historicBytesVariable);
    assertTrue(Arrays.equals(value.getBytes(), (byte[]) historicBytesVariable.getValue()));
    // then the historic variable updates and their values exist
    assertEquals(2, historyService.createHistoricDetailQuery().variableUpdates().count());
    HistoricVariableUpdate historicStringVariableUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(historicStringVariable.getId()).singleResult();
    assertNotNull(historicStringVariableUpdate);
    assertEquals(value, historicStringVariableUpdate.getValue());
    HistoricVariableUpdate historicByteVariableUpdate = (HistoricVariableUpdate) historyService.createHistoricDetailQuery().variableUpdates().variableInstanceId(historicBytesVariable.getId()).singleResult();
    assertNotNull(historicByteVariableUpdate);
    assertTrue(Arrays.equals(value.getBytes(), (byte[]) historicByteVariableUpdate.getValue()));
}
Also used : HistoricVariableUpdate(org.camunda.bpm.engine.history.HistoricVariableUpdate) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

HistoricVariableUpdate (org.camunda.bpm.engine.history.HistoricVariableUpdate)29 Test (org.junit.Test)19 Deployment (org.camunda.bpm.engine.test.Deployment)13 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)10 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)10 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)8 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)8 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)8 MockHistoricVariableUpdateBuilder (org.camunda.bpm.engine.rest.helper.MockHistoricVariableUpdateBuilder)7 HistoricActivityInstance (org.camunda.bpm.engine.history.HistoricActivityInstance)6 HashMap (java.util.HashMap)5 Task (org.camunda.bpm.engine.task.Task)5 ObjectValue (org.camunda.bpm.engine.variable.value.ObjectValue)5 FileValue (org.camunda.bpm.engine.variable.value.FileValue)4 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Response (com.jayway.restassured.response.Response)2 HistoryService (org.camunda.bpm.engine.HistoryService)2 HistoricVariableInstanceQuery (org.camunda.bpm.engine.history.HistoricVariableInstanceQuery)2 MockObjectValue (org.camunda.bpm.engine.rest.helper.MockObjectValue)2