use of org.activiti.engine.history.HistoricDetail 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);
}
use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.
the class TaskServiceTest method testGetVariableByHistoricActivityInstance.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testGetVariableByHistoricActivityInstance() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().singleResult();
taskService.setVariable(task.getId(), "variable1", "value1");
taskService.setVariable(task.getId(), "variable1", "value2");
HistoricActivityInstance historicActivitiInstance = historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstance.getId()).activityId("theTask").singleResult();
assertNotNull(historicActivitiInstance);
List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().variableUpdates().activityInstanceId(historicActivitiInstance.getId()).orderByTime().asc().list();
assertEquals(2, resultSet.size());
assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(0)).getVariableName());
assertEquals("value1", ((HistoricVariableUpdate) resultSet.get(0)).getValue());
assertEquals("variable1", ((HistoricVariableUpdate) resultSet.get(1)).getVariableName());
assertEquals("value2", ((HistoricVariableUpdate) resultSet.get(1)).getValue());
}
use of org.activiti.engine.history.HistoricDetail in project Activiti by Activiti.
the class TaskServiceTest method checkHistoricVariableUpdateEntity.
private void checkHistoricVariableUpdateEntity(String variableName, String processInstanceId) {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
boolean deletedVariableUpdateFound = false;
List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().processInstanceId(processInstanceId).list();
for (HistoricDetail currentHistoricDetail : resultSet) {
assertTrue(currentHistoricDetail instanceof HistoricDetailVariableInstanceUpdateEntity);
HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = (HistoricDetailVariableInstanceUpdateEntity) currentHistoricDetail;
if (historicVariableUpdate.getName().equals(variableName)) {
if (historicVariableUpdate.getValue() == null) {
if (deletedVariableUpdateFound) {
fail("Mismatch: A HistoricVariableUpdateEntity with a null value already found");
} else {
deletedVariableUpdateFound = true;
}
}
}
}
assertTrue(deletedVariableUpdateFound);
}
}
use of org.activiti.engine.history.HistoricDetail in project carbon-business-process by wso2.
the class HistoricDetailService method getVariableFromRequest.
public RestVariable getVariableFromRequest(boolean includeBinary, String detailId) {
Object value = null;
HistoricVariableUpdate variableUpdate = null;
HistoryService historyService = BPMNOSGIService.getHistoryService();
HistoricDetail detailObject = historyService.createHistoricDetailQuery().id(detailId).singleResult();
if (detailObject instanceof HistoricVariableUpdate) {
variableUpdate = (HistoricVariableUpdate) detailObject;
value = variableUpdate.getValue();
}
if (value == null) {
throw new ActivitiObjectNotFoundException("Historic detail '" + detailId + "' doesn't have a variable value.", VariableInstanceEntity.class);
} else {
return new RestResponseFactory().createRestVariable(variableUpdate.getVariableName(), value, null, detailId, RestResponseFactory.VARIABLE_HISTORY_DETAIL, includeBinary, uriInfo.getBaseUri().toString());
}
}
Aggregations