use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testVariableUpdatesLinkedToActivity.
@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/standalone/history/FullHistoryTest.testVariableUpdatesAreLinkedToActivity.bpmn20.xml" })
public void testVariableUpdatesLinkedToActivity() throws Exception {
ProcessInstance pi = runtimeService.startProcessInstanceByKey("ProcessWithSubProcess");
Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("test", "1");
taskService.complete(task.getId(), variables);
// now we are in the subprocess
task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
variables.clear();
variables.put("test", "2");
taskService.complete(task.getId(), variables);
// now we are ended
testHelper.assertProcessEnded(pi.getId());
// check history
List<HistoricDetail> updates = historyService.createHistoricDetailQuery().variableUpdates().list();
assertEquals(2, updates.size());
Map<String, HistoricVariableUpdate> updatesMap = new HashMap<String, HistoricVariableUpdate>();
HistoricVariableUpdate update = (HistoricVariableUpdate) updates.get(0);
updatesMap.put((String) update.getValue(), update);
update = (HistoricVariableUpdate) updates.get(1);
updatesMap.put((String) update.getValue(), update);
HistoricVariableUpdate update1 = updatesMap.get("1");
HistoricVariableUpdate update2 = updatesMap.get("2");
assertNotNull(update1.getActivityInstanceId());
assertNotNull(update1.getExecutionId());
HistoricActivityInstance historicActivityInstance1 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update1.getActivityInstanceId()).singleResult();
assertEquals(historicActivityInstance1.getExecutionId(), update1.getExecutionId());
assertEquals("usertask1", historicActivityInstance1.getActivityId());
assertNotNull(update2.getActivityInstanceId());
HistoricActivityInstance historicActivityInstance2 = historyService.createHistoricActivityInstanceQuery().activityInstanceId(update2.getActivityInstanceId()).singleResult();
assertEquals("usertask2", historicActivityInstance2.getActivityId());
/*
* This is OK! The variable is set on the root execution, on a execution never run through the activity, where the process instances
* stands when calling the set Variable. But the ActivityId of this flow node is used. So the execution id's doesn't have to be equal.
*
* execution id: On which execution it was set
* activity id: in which activity was the process instance when setting the variable
*/
assertFalse(historicActivityInstance2.getExecutionId().equals(update2.getExecutionId()));
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testHistoricVariableUpdatesAllTypes.
@Test
@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");
ClockUtil.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());
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("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());
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class FullHistoryTest method testErrorMessage.
@Test
public void testErrorMessage() {
Task newTask = taskService.newTask();
taskService.saveTask(newTask);
String variableName = "failingSerializable";
taskService.setVariable(newTask.getId(), variableName, new FailingSerializable());
HistoricDetail result = historyService.createHistoricDetailQuery().disableBinaryFetching().variableUpdates().singleResult();
assertNull(((HistoricVariableUpdate) result).getValue());
assertNotNull(((HistoricVariableUpdate) result).getErrorMessage());
taskService.deleteTask(newTask.getId(), true);
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class HistoricDetailRestServiceQueryTest method testSpinVariableInstanceRetrieval.
@Test
public void testSpinVariableInstanceRetrieval() {
MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate().typedValue(Variables.serializedObjectValue("aSerializedValue").serializationDataFormat("aDataFormat").objectTypeName("aRootType").create());
List<HistoricDetail> details = new ArrayList<HistoricDetail>();
details.add(builder.build());
mockedQuery = setUpMockedDetailsQuery(details);
given().then().expect().statusCode(Status.OK.getStatusCode()).and().body("[0].variableType", equalTo(VariableTypeHelper.toExpectedValueTypeName(ValueType.OBJECT))).body("[0].errorMessage", nullValue()).body("[0].value", equalTo("aSerializedValue")).body("[0].valueInfo." + SerializableValueType.VALUE_INFO_OBJECT_TYPE_NAME, equalTo("aRootType")).body("[0].valueInfo." + SerializableValueType.VALUE_INFO_SERIALIZATION_DATA_FORMAT, equalTo("aDataFormat")).when().get(HISTORIC_DETAIL_RESOURCE_URL);
}
use of org.camunda.bpm.engine.history.HistoricDetail in project camunda-bpm-platform by camunda.
the class HistoricDetailRestServiceImpl method getHistoricDetails.
@Override
public List<HistoricDetailDto> getHistoricDetails(UriInfo uriInfo, Integer firstResult, Integer maxResults, boolean deserializeObjectValues) {
HistoricDetailQueryDto queryDto = new HistoricDetailQueryDto(objectMapper, uriInfo.getQueryParameters());
HistoricDetailQuery query = queryDto.toQuery(processEngine);
query.disableBinaryFetching();
if (!deserializeObjectValues) {
query.disableCustomObjectDeserialization();
}
List<HistoricDetail> queryResult;
if (firstResult != null || maxResults != null) {
queryResult = executePaginatedQuery(query, firstResult, maxResults);
} else {
queryResult = query.list();
}
List<HistoricDetailDto> result = new ArrayList<HistoricDetailDto>();
for (HistoricDetail historicDetail : queryResult) {
HistoricDetailDto dto = HistoricDetailDto.fromHistoricDetail(historicDetail);
result.add(dto);
}
return result;
}
Aggregations