/**
* @see org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable, org.olat.core.id.Identity, java.lang.String)
*/
@Override
public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
VFSLeaf currentFile = (VFSLeaf) currentVersion;
VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
if(versionFile == null) {
return false;//cannot do something with the current file
}
VFSContainer versionContainer = versionFile.getParentContainer();
String name = currentFile.getName();
// read from the
Versions v = readVersions(currentFile, versionFile);
if (!(v instanceof VersionsFileImpl)) {
log.error("Wrong implementation of Versions: " + v);
return false;
}
VersionsFileImpl versions = (VersionsFileImpl) v;
String uuid = UUID.randomUUID().toString() + "_" + name;
String versionNr = getNextRevisionNr(versions);
String currentAuthor = versions.getAuthor();
long lastModifiedDate = 0;
if (currentFile instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo();
if(currentAuthor == null) {
currentAuthor = metaInfo.getAuthor();
}
lastModifiedDate = metaInfo.getLastModified();
}
if(lastModifiedDate <= 0) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
lastModifiedDate = cal.getTimeInMillis();
}
RevisionFileImpl newRevision = new RevisionFileImpl();
newRevision.setName(name);
newRevision.setFilename(uuid);
newRevision.setRevisionNr(versionNr);
newRevision.setComment(versions.getComment());
newRevision.setAuthor(currentAuthor);
newRevision.setLastModified(lastModifiedDate);
if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) {
MetaTagged metaTagged = (MetaTagged) currentVersion;
versions.setCreator(metaTagged.getMetaInfo().getAuthor());
}
VFSLeaf target = versionContainer.createChildLeaf(uuid);
if (VFSManager.copyContent(currentFile, target)) {
if (identity != null) {
versions.setAuthor(identity.getName());
}
versions.setComment(comment);