From 6db7101fdbb8d317d9c3d1e13ea3354b3ecff9d8 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 17 Jan 2013 16:18:53 +0100 Subject: [PATCH] OO-467: on second thoughts, the low level check of the max number of versions must detect if the versioning is deactivated and don't add a revision in this case --- .../util/vfs/version/FolderVersioningConfigurator.java | 3 ++- .../olat/core/util/vfs/version/SimpleVersionConfig.java | 2 +- .../olat/core/util/vfs/version/VersionsFileManager.java | 8 ++++++-- .../org/olat/core/util/vfs/version/VersionsManager.java | 8 ++++++++ .../olat/core/util/vfs/version/VersionManagerTest.java | 4 +--- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/olat/core/util/vfs/version/FolderVersioningConfigurator.java b/src/main/java/org/olat/core/util/vfs/version/FolderVersioningConfigurator.java index 2b1a48a6cc5..97bfd3b0e4b 100644 --- a/src/main/java/org/olat/core/util/vfs/version/FolderVersioningConfigurator.java +++ b/src/main/java/org/olat/core/util/vfs/version/FolderVersioningConfigurator.java @@ -34,9 +34,10 @@ import org.olat.core.util.vfs.VFSContainer; public interface FolderVersioningConfigurator { /** + * The absolut limit for this instance * @return -1 for versioning without limit, 0 for no versioning, 1 - n is the maximum number of revision per file */ - public int versionAllowed(); + public int getMaxNumOfVersionsAllowed(); /** * @param relPath diff --git a/src/main/java/org/olat/core/util/vfs/version/SimpleVersionConfig.java b/src/main/java/org/olat/core/util/vfs/version/SimpleVersionConfig.java index a575dedf95e..3b9deab1640 100644 --- a/src/main/java/org/olat/core/util/vfs/version/SimpleVersionConfig.java +++ b/src/main/java/org/olat/core/util/vfs/version/SimpleVersionConfig.java @@ -130,7 +130,7 @@ public class SimpleVersionConfig implements GenericEventListener, FolderVersioni } @Override - public int versionAllowed() { + public int getMaxNumOfVersionsAllowed() { return getVersionAllowed(); } diff --git a/src/main/java/org/olat/core/util/vfs/version/VersionsFileManager.java b/src/main/java/org/olat/core/util/vfs/version/VersionsFileManager.java index dc1c3f9618d..340396e2c58 100644 --- a/src/main/java/org/olat/core/util/vfs/version/VersionsFileManager.java +++ b/src/main/java/org/olat/core/util/vfs/version/VersionsFileManager.java @@ -555,6 +555,11 @@ public class VersionsFileManager extends VersionsManager implements Initializabl */ @Override public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) { + int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed(); + if(maxNumOfVersions == 0) { + return true;//deactivated, return all ok + } + VFSLeaf currentFile = (VFSLeaf) currentVersion; VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true); @@ -615,8 +620,7 @@ public class VersionsFileManager extends VersionsManager implements Initializabl if (identity != null) { versions.setAuthor(identity.getName()); } - - int maxNumOfVersions = versioningConfigurator.versionAllowed(); + if(maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) { List<VFSRevision> revisions = versions.getRevisions(); int numOfVersionsToDelete = Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1); diff --git a/src/main/java/org/olat/core/util/vfs/version/VersionsManager.java b/src/main/java/org/olat/core/util/vfs/version/VersionsManager.java index 4049f5b6809..b2c4bc35376 100644 --- a/src/main/java/org/olat/core/util/vfs/version/VersionsManager.java +++ b/src/main/java/org/olat/core/util/vfs/version/VersionsManager.java @@ -92,6 +92,14 @@ public abstract class VersionsManager extends BasicManager { */ public abstract boolean addVersion(Versionable currentVersion, Identity author, String comment, InputStream newVersion); + /** + * Add a new revision to the files. The method check the number of revisions against the absolute + * maximum limit for the instance. + * @param currentVersion + * @param author + * @param comment + * @return + */ public abstract boolean addToRevisions(Versionable currentVersion, Identity author, String comment); /** diff --git a/src/test/java/org/olat/core/util/vfs/version/VersionManagerTest.java b/src/test/java/org/olat/core/util/vfs/version/VersionManagerTest.java index d37232e9b28..c5b474c79a2 100644 --- a/src/test/java/org/olat/core/util/vfs/version/VersionManagerTest.java +++ b/src/test/java/org/olat/core/util/vfs/version/VersionManagerTest.java @@ -208,9 +208,7 @@ public class VersionManagerTest extends OlatTestCase { Versions versions = VersionsFileManager.getInstance().createVersionsFor((VFSLeaf)retrievedFile); List<VFSRevision> revisions = versions.getRevisions(); assertNotNull(revisions); - assertEquals(1, revisions.size()); - - assertEquals("Version 5", versions.getComment()); + assertTrue(revisions.isEmpty()); } @Test -- GitLab