use of teamdash.wbs.ChangeHistory in project processdash by dtuma.
the class WorkflowMappingAltererProjectDir method saveWorkflows.
@Override
public void saveWorkflows(WorkflowWBSModel workflows) throws IOException, LockFailureException {
// save the workflows
RobustFileWriter out = new RobustFileWriter(workflowFile(), "UTF-8");
BufferedWriter buf = new BufferedWriter(out);
workflows.getAsXML(buf);
buf.flush();
out.close();
// add an entry to the change history file
File changeHistoryFile = new File(dir.getDirectory(), TeamProject.CHANGE_HISTORY_FILE);
ChangeHistory changeHistory = new ChangeHistory(changeHistoryFile);
changeHistory.addEntry(userName);
changeHistory.write(changeHistoryFile);
// flush data to the server
if (dir.flushData() == false)
throw new IOException("Unable to save data");
// save a data backup with the new contents
dir.doBackup("saved_mappings");
}
use of teamdash.wbs.ChangeHistory in project processdash by dtuma.
the class ProjectHistoryLocal method getZipFileVersionUid.
private String getZipFileVersionUid(File oneFile) throws IOException {
// only examine backups created by a save operation
Matcher m = SAVED_ZIP_FILENAME_PAT.matcher(oneFile.getName());
if (!m.matches())
return null;
// entry in that file identifies its version.
try {
InputStream changeHist = getFileFromZip(oneFile, WBSFilenameConstants.CHANGE_HISTORY_FILE);
if (changeHist != null) {
Element xml = XMLUtils.parse(changeHist).getDocumentElement();
ChangeHistory zipHist = new ChangeHistory(xml);
Entry zipHistEntry = zipHist.getLastEntry();
if (zipHistEntry != null)
return zipHistEntry.getUid();
}
} catch (SAXException se) {
}
// extract the user name and save date from the ZIP filename.
long zipDate;
try {
zipDate = SAVE_DATE_FMT.parse(m.group(1)).getTime();
} catch (ParseException pe) {
return null;
}
String safeZipUser = m.group(2);
// look through the change entries for one that could correspond to this
// ZIP backup file.
String bestMatch = null;
long bestDelta = DateUtils.DAY;
for (Entry e : versions) {
// if this ZIP file was saved by a different person, skip it.
String safeVersionUser = FileUtils.makeSafe(e.getUser());
if (!safeZipUser.equalsIgnoreCase(safeVersionUser))
continue;
// compare the change history timestamp with the ZIP file timestamp.
// If they match, return this date.
long oneDelta = Math.abs(e.getTimestamp().getTime() - zipDate);
if (oneDelta < 2000)
return e.getUid();
// The ZIP file timestamp does not include a time zone offset, so
// the two values above could differ if the file was saved by a
// user in a different timezone. If the values differ by an amount
// that looks like a time zone delta, consider this to be a match.
// (Usually this would be an even number of hours; but since some
// time zones have a 30 minute offset, we allow for that.)
long oneDiff = oneDelta % (30 * DateUtils.MINUTES);
if (oneDiff > 2000)
continue;
// separation of exactly "n" hours, select the closest save time.
if (bestDelta > oneDelta) {
bestMatch = e.getUid();
bestDelta = oneDelta;
}
}
return bestMatch;
}
use of teamdash.wbs.ChangeHistory in project processdash by dtuma.
the class ProjectHistoryLocal method refresh.
public void refresh() throws IOException {
versions = new ChangeHistory(dir).getEntries();
List<Entry> firstEntries = null;
if (versions.size() > 1)
firstEntries = new ArrayList(versions.subList(0, 2));
findZipFiles(dir);
for (Iterator i = versions.iterator(); i.hasNext(); ) {
Entry e = (Entry) i.next();
if (!zipFiles.containsKey(e.getUid()))
i.remove();
}
if (firstEntries != null && !versions.isEmpty() && versions.get(0) == firstEntries.get(1))
versions.add(0, firstEntries.get(0));
}
use of teamdash.wbs.ChangeHistory in project processdash by dtuma.
the class ProjectHistoryBridgedAbstract method initTimeDelta.
protected void initTimeDelta(ManifestEntry changeHist) {
// these back to UTC timestamps.
if (timeDelta == 0 && changeHist != null) {
try {
Element xml = parseXml(changeHist.getStream());
ChangeHistory changes = new ChangeHistory(xml);
Entry lastChange = changes.getLastEntry();
long lastTimestamp = lastChange.getTimestamp().getTime();
timeDelta = changeHist.lastMod - lastTimestamp;
// the file modification time can normally differ from the
// change timestamp by a second or two; but we are only
// interested in the delta caused by time zone differences.
// round the delta to an even half-hour interval.
double fraction = timeDelta / (30.0 * DateUtils.MINUTES);
timeDelta = (int) Math.round(fraction) * 30 * DateUtils.MINUTES;
} catch (Exception e) {
}
}
}
Aggregations