LogEntry entry;
// First pass: Create update logs
while (logEntries.hasNext()) {
entry = (LogEntry) logEntries.next();
WGUpdateLog newLog = null;
WGUpdateLog oldLog = null;
Date currentTime = null;
if (entry.getTarget() != null && !entry.getTarget().equals("#UNKNOWN#")) {
newLog = new WGUpdateLog(entry.getType(), entry.getLogtime(), entry.getLoguser(), entry.getTarget());
wgLogs.add(newLog);
List logsList = (List) wgLogsByTarget.get(entry.getTarget());
if (logsList == null) {
logsList = new ArrayList();
wgLogsByTarget.put(entry.getTarget(), logsList);
}
logsList.add(newLog);
}
}
// Second pass for CS version < 5 to workaround some weaknesses of the CS3/4 history log
if (_ddlVersion < WGDatabase.CSVERSION_WGA5) {
// Determine conflicting log entries, where update and delete is done on the same time and the same document
Iterator wgLogsByTargetIt = wgLogsByTarget.values().iterator();
while (wgLogsByTargetIt.hasNext()) {
List logs = (List) wgLogsByTargetIt.next();
WGUtils.sortByProperty(logs, "date");
Iterator logsIt = logs.iterator();
Date lastTime = null;
List<WGUpdateLog> logsAtSameTime = new ArrayList();
while (logsIt.hasNext()) {
WGUpdateLog log = (WGUpdateLog) logsIt.next();
if (log.getDate().equals(lastTime)) {
logsAtSameTime.add(log);
}
else {
resolveLogConflicts(wgLogs, logsAtSameTime);
logsAtSameTime.clear();
}
lastTime = log.getDate();
}
}
// Order logentries that have the same time in an order that assures dependency documents are created before their dependent documents
Collections.sort(wgLogs, new DocumentDependencyComparator());