ALF-11259 Disable the VersionableAspect before updating the version label property on a node, when deleting the current version (plus test)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31631 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-11-02 02:58:45 +00:00
parent 053f4e691a
commit 0484671e8f
3 changed files with 75 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
import org.alfresco.repo.policy.PolicyScope; import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.version.common.VersionHistoryImpl; import org.alfresco.repo.version.common.VersionHistoryImpl;
@@ -1368,6 +1369,9 @@ public class Version2ServiceImpl extends VersionServiceImpl implements VersionSe
if (headVersion != null) if (headVersion != null)
{ {
// Reset the version label property on the versionable node to new head version // Reset the version label property on the versionable node to new head version
// Disable the VersionableAspect for this change though, we don't want
// to have this create a new version for the property change!
policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel()); this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, headVersion.getVersionLabel());
} }
else else

View File

@@ -1193,9 +1193,14 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(2, versionHistory.getAllVersions().size()); assertEquals(2, versionHistory.getAllVersions().size());
// Check version labels, should be 0.2 and 0.1 as property changes
// are minor updates, and we had no initial label set
Version[] versions = versionHistory.getAllVersions().toArray(new Version[2]);
assertEquals("0.2", versions[0].getVersionLabel());
assertEquals("0.1", versions[1].getVersionLabel());
return null; return null;
} }
}); });
List<String> excludedOnUpdateProps = new ArrayList<String>(1); List<String> excludedOnUpdateProps = new ArrayList<String>(1);
@@ -1222,6 +1227,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
}); });
// Now lets have a look and make sure we have the correct number of entries in the version history // Now lets have a look and make sure we have the correct number of entries in the version history
// (The property changes were excluded so there should have been no changes)
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception
@@ -1250,7 +1256,6 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
}); });
// test auto-version props on - with a non-excluded prop change // test auto-version props on - with a non-excluded prop change
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception
@@ -1266,6 +1271,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
}); });
// Now lets have a look and make sure we have the correct number of entries in the version history // Now lets have a look and make sure we have the correct number of entries in the version history
// (We should have gained one more)
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object execute() throws Exception public Object execute() throws Exception
@@ -1274,9 +1280,70 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
assertNotNull(versionHistory); assertNotNull(versionHistory);
assertEquals(3, versionHistory.getAllVersions().size()); assertEquals(3, versionHistory.getAllVersions().size());
// Check the versions,
Version[] versions = versionHistory.getAllVersions().toArray(new Version[3]);
assertEquals("0.3", versions[0].getVersionLabel());
assertEquals("0.2", versions[1].getVersionLabel());
assertEquals("0.1", versions[2].getVersionLabel());
return null; return null;
} }
});
// Delete version 0.2, auto changes won't affect this
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{
VersionHistory versionHistory = versionService.getVersionHistory(versionableNode);
Version[] versions = versionHistory.getAllVersions().toArray(new Version[3]);
Version v = versions[1];
assertEquals("0.2", v.getVersionLabel());
versionService.deleteVersion(versionableNode, v);
return null;
}
});
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{
VersionHistory versionHistory = versionService.getVersionHistory(versionableNode);
assertNotNull(versionHistory);
assertEquals(2, versionHistory.getAllVersions().size());
// Check the versions, will now have a gap
Version[] versions = versionHistory.getAllVersions().toArray(new Version[2]);
assertEquals("0.3", versions[0].getVersionLabel());
assertEquals("0.1", versions[1].getVersionLabel());
return null;
}
});
// Delete the head version, will revert back to 0.1
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{
Version v = versionService.getCurrentVersion(versionableNode);
assertEquals("0.3", v.getVersionLabel());
versionService.deleteVersion(versionableNode, v);
return null;
}
});
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
{
public Object execute() throws Exception
{
VersionHistory versionHistory = versionService.getVersionHistory(versionableNode);
assertNotNull(versionHistory);
assertEquals(1, versionHistory.getAllVersions().size());
// Check the version
Version[] versions = versionHistory.getAllVersions().toArray(new Version[1]);
assertEquals("0.1", versions[0].getVersionLabel());
return null;
}
}); });
} }

View File

@@ -35,6 +35,7 @@ import org.alfresco.repo.copy.DefaultCopyBehaviourCallback;
import org.alfresco.repo.dictionary.DictionaryDAO; import org.alfresco.repo.dictionary.DictionaryDAO;
import org.alfresco.repo.dictionary.DictionaryListener; import org.alfresco.repo.dictionary.DictionaryListener;
import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
import org.alfresco.repo.policy.Behaviour; import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
@@ -219,7 +220,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
onUpdatePropertiesBehaviour = new JavaBehaviour(this, "onUpdateProperties", Behaviour.NotificationFrequency.TRANSACTION_COMMIT); onUpdatePropertiesBehaviour = new JavaBehaviour(this, "onUpdateProperties", Behaviour.NotificationFrequency.TRANSACTION_COMMIT);
this.policyComponent.bindClassBehaviour( this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), OnUpdatePropertiesPolicy.QNAME,
ContentModel.ASPECT_VERSIONABLE, ContentModel.ASPECT_VERSIONABLE,
onUpdatePropertiesBehaviour); onUpdatePropertiesBehaviour);