use of org.activiti.engine.history.HistoricVariableUpdate in project Activiti by Activiti.
the class TaskServiceTest method testGetVariableByHistoricActivityInstance.
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testGetVariableByHistoricActivityInstance() {
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.FULL)) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertThat(processInstance).isNotNull();
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();
assertThat(historicActivitiInstance).isNotNull();
List<HistoricDetail> resultSet = historyService.createHistoricDetailQuery().variableUpdates().activityInstanceId(historicActivitiInstance.getId()).list();
assertThat(resultSet).hasSize(2);
assertThat(resultSet).extracting(h -> ((HistoricVariableUpdate) h).getValue()).containsExactlyInAnyOrder("value1", "value2");
assertThat(resultSet).extracting(h -> ((HistoricVariableUpdate) h).getVariableName()).containsOnly("variable1");
}
}
use of org.activiti.engine.history.HistoricVariableUpdate in project alfresco-repository by Alfresco.
the class ActivitiPropertyConverter method convertHistoricDetails.
/**
* Convert a list of {@link HistoricDetail} to a map with key-value pairs.
* @param details the histroicDetails. Should be a list of {@link HistoricVariableUpdate}s.
*/
public Map<String, Object> convertHistoricDetails(List<HistoricDetail> details) {
HashMap<String, HistoricVariableUpdate> updateMap = new HashMap<String, HistoricVariableUpdate>();
HistoricVariableUpdate previous = null;
HistoricVariableUpdate current = null;
boolean isMoreRecent = false;
for (HistoricDetail detail : details) {
current = (HistoricVariableUpdate) detail;
previous = updateMap.get(current.getVariableName());
if (previous == null) {
isMoreRecent = true;
} else {
// Check if this update is more recent that the one already present in the map
if (current.getTime().equals(previous.getTime())) {
if (current.getRevision() == previous.getRevision()) {
// Revert to comparison of the ID
isMoreRecent = Long.valueOf(current.getId()).longValue() > Long.valueOf(previous.getId()).longValue();
} else {
isMoreRecent = current.getRevision() > previous.getRevision();
}
} else {
isMoreRecent = current.getTime().after(previous.getTime());
}
}
// Add to the map if value is more recent than existing value or is the first value for this update
if (isMoreRecent) {
updateMap.put(current.getVariableName(), current);
}
}
HashMap<String, Object> variables = new HashMap<String, Object>();
for (Entry<String, HistoricVariableUpdate> entry : updateMap.entrySet()) {
variables.put(entry.getKey(), entry.getValue().getValue());
}
return variables;
}
Aggregations