use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricDetailQueryById.
@Test
public void testHistoricDetailQueryById() {
Task newTask = taskService.newTask();
taskService.saveTask(newTask);
String variableName = "someName";
String variableValue = "someValue";
taskService.setVariable(newTask.getId(), variableName, variableValue);
HistoricDetail result = historyService.createHistoricDetailQuery().singleResult();
HistoricDetail resultById = historyService.createHistoricDetailQuery().detailId(result.getId()).singleResult();
assertNotNull(resultById);
assertEquals(result.getId(), resultById.getId());
assertEquals(variableName, ((HistoricVariableUpdate) resultById).getVariableName());
assertEquals(variableValue, ((HistoricVariableUpdate) resultById).getValue());
assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate) resultById).getVariableTypeName());
assertEquals(ValueType.STRING.getName(), ((HistoricVariableUpdate) resultById).getTypeName());
taskService.deleteTask(newTask.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricDetail 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());
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricDetailQueryMixed.
@Test
@Deployment
public void testHistoricDetailQueryMixed() throws Exception {
Map<String, String> formProperties = new HashMap<String, String>();
formProperties.put("formProp1", "activiti rocks!");
formProperties.put("formProp2", "12345");
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("historicDetailMixed").singleResult();
ProcessInstance processInstance = formService.submitStartFormData(procDef.getId(), formProperties);
List<HistoricDetail> details = historyService.createHistoricDetailQuery().processInstanceId(processInstance.getId()).orderByVariableName().asc().list();
assertEquals(4, details.size());
assertTrue(details.get(0) instanceof HistoricFormProperty);
HistoricFormProperty formProp1 = (HistoricFormProperty) details.get(0);
assertEquals("formProp1", formProp1.getPropertyId());
assertEquals("activiti rocks!", formProp1.getPropertyValue());
assertTrue(details.get(1) instanceof HistoricFormProperty);
HistoricFormProperty formProp2 = (HistoricFormProperty) details.get(1);
assertEquals("formProp2", formProp2.getPropertyId());
assertEquals("12345", formProp2.getPropertyValue());
assertTrue(details.get(2) instanceof HistoricVariableUpdate);
HistoricVariableUpdate varUpdate1 = (HistoricVariableUpdate) details.get(2);
assertEquals("variable1", varUpdate1.getVariableName());
assertEquals("activiti rocks!", varUpdate1.getValue());
// This variable should be of type LONG since this is defined in the process-definition
assertTrue(details.get(3) instanceof HistoricVariableUpdate);
HistoricVariableUpdate varUpdate2 = (HistoricVariableUpdate) details.get(3);
assertEquals("variable2", varUpdate2.getVariableName());
assertEquals(12345L, varUpdate2.getValue());
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class UserOperationIdTest method testSetTaskVariablesInServiceTask.
@Test
public void testSetTaskVariablesInServiceTask() {
// given
BpmnModelInstance bpmnModelInstance = Bpmn.createExecutableProcess(PROCESS_KEY).startEvent().userTask().serviceTask().camundaExpression("${execution.setVariable('foo', 'bar')}").endEvent().done();
testRule.deploy(bpmnModelInstance);
identityService.setAuthenticatedUserId("demo");
runtimeService.startProcessInstanceByKey(PROCESS_KEY);
Task task = taskService.createTaskQuery().singleResult();
// when
taskService.complete(task.getId());
// then
HistoricDetail historicDetail = historyService.createHistoricDetailQuery().singleResult();
// no user operation log id is set for this update, as it is not written as part of the user operation
assertNull(historicDetail.getUserOperationId());
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class HistoricDetailManager method deleteHistoricDetailsByTaskId.
public void deleteHistoricDetailsByTaskId(String taskId) {
if (isHistoryEnabled()) {
// delete entries in DB
List<HistoricDetail> historicDetails = findHistoricDetailsByTaskId(taskId);
for (HistoricDetail historicDetail : historicDetails) {
((HistoricDetailEventEntity) historicDetail).delete();
}
// delete entries in Cache
List<HistoricDetailEventEntity> cachedHistoricDetails = getDbEntityManager().getCachedEntitiesByType(HistoricDetailEventEntity.class);
for (HistoricDetailEventEntity historicDetail : cachedHistoricDetails) {
// make sure we only delete the right ones (as we cannot make a proper query in the cache)
if (taskId.equals(historicDetail.getTaskId())) {
historicDetail.delete();
}
}
}
}
Aggregations