From 6a13cb0ca2d7022c69a850205cc84170fa34e018 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Tue, 18 Jul 2006 15:44:45 +0000 Subject: [PATCH] Merge V1.3 to HEAD (3087:3098) svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3087 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3098 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3343 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/core-services-context.xml | 7 +- .../messages/version-service.properties | 2 + .../impl/PermissionServiceImpl.java | 7 + .../repo/version/VersionServiceImpl.java | 38 ++-- .../repo/version/VersionServiceImplTest.java | 60 ++++++ .../repo/version/VersionableAspect.java | 185 +++++++----------- 6 files changed, 158 insertions(+), 141 deletions(-) diff --git a/config/alfresco/core-services-context.xml b/config/alfresco/core-services-context.xml index 88749a35c5..d21456287e 100644 --- a/config/alfresco/core-services-context.xml +++ b/config/alfresco/core-services-context.xml @@ -349,15 +349,12 @@ - - + + - - - diff --git a/config/alfresco/messages/version-service.properties b/config/alfresco/messages/version-service.properties index 6d7a741cfb..24462679e1 100644 --- a/config/alfresco/messages/version-service.properties +++ b/config/alfresco/messages/version-service.properties @@ -6,3 +6,5 @@ version_service.err_unsupported=The current implementation of the version servic version_service.err_one_preceeding=The current implementation of the version service only supports one preceeding version. version_service.err_restore_no_version=The node {0} cannot be restore since there is no version information available for this node. version_service.err_revert_mismatch=The version provided to revert to does not come from the nodes version history. +version_service.initial_version=Initial version +version_service.auto_version=Auto version diff --git a/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java b/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java index 9073501937..cb246f5cdf 100644 --- a/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java +++ b/source/java/org/alfresco/repo/security/permissions/impl/PermissionServiceImpl.java @@ -283,6 +283,13 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing { return authorityType; } + + @Override + public String toString() + { + return accessStatus + " " + this.permission + " - " + + this.authority + " (" + this.authorityType + ")"; + } @Override public boolean equals(Object o) diff --git a/source/java/org/alfresco/repo/version/VersionServiceImpl.java b/source/java/org/alfresco/repo/version/VersionServiceImpl.java index 388b9068c0..03a111787f 100644 --- a/source/java/org/alfresco/repo/version/VersionServiceImpl.java +++ b/source/java/org/alfresco/repo/version/VersionServiceImpl.java @@ -802,25 +802,6 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl } return result; - } - - /** - * Checks the given node for the version aspect. Throws an exception if it is not present. - * - * @param nodeRef the node reference - * @throws AspectMissingException - * the version aspect is not present on the node - */ - private void checkForVersionAspect(NodeRef nodeRef) - throws AspectMissingException - { - QName aspectRef = ContentModel.ASPECT_VERSIONABLE; - - if (this.nodeService.hasAspect(nodeRef, aspectRef) == false) - { - // Raise exception to indicate version aspect is not present - throw new AspectMissingException(aspectRef, nodeRef); - } } /** @@ -1089,14 +1070,19 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl public void deleteVersionHistory(NodeRef nodeRef) throws AspectMissingException { - // First check that the versionable aspect is present - checkForVersionAspect(nodeRef); - - // Get the version history node for the node is question and delete it + // Get the version history node for the node is question and delete it NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef); - this.dbNodeService.deleteNode(versionHistoryNodeRef); - // Reset the version label property on the versionable node - this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null); + if (versionHistoryNodeRef != null) + { + // Delete the version history node + this.dbNodeService.deleteNode(versionHistoryNodeRef); + + if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true) + { + // Reset the version label property on the versionable node + this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null); + } + } } } diff --git a/source/java/org/alfresco/repo/version/VersionServiceImplTest.java b/source/java/org/alfresco/repo/version/VersionServiceImplTest.java index 1f78d2876f..b04fe1b1a1 100644 --- a/source/java/org/alfresco/repo/version/VersionServiceImplTest.java +++ b/source/java/org/alfresco/repo/version/VersionServiceImplTest.java @@ -549,4 +549,64 @@ public class VersionServiceImplTest extends BaseVersionStoreTest }); } + + public void testAddRemoveVersionableAspect() + { + HashMap props2 = new HashMap(); + props2.put(ContentModel.PROP_NAME, "test.txt"); + final NodeRef nodeRef = this.dbNodeService.createNode( + rootNodeRef, + ContentModel.ASSOC_CHILDREN, + QName.createQName("{test}MyVersionableNode2"), + TEST_TYPE_QNAME, + props2).getChildRef(); + this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null); + + setComplete(); + endTransaction(); + + TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork() + { + public Object doWork() throws Exception + { + // Check that the version history has been created + VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef); + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + // Remove the versionable aspect + VersionServiceImplTest.this.dbNodeService.removeAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE); + + return null; + } + }); + + TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork() + { + public Object doWork() throws Exception + { + // Check that the version history has been removed + VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef); + assertNull(versionHistory); + + // Re-add the versionable aspect + VersionServiceImplTest.this.dbNodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null); + + return null; + } + }); + + TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork() + { + public Object doWork() throws Exception + { + // Check that the version history has been created + VersionHistory versionHistory = VersionServiceImplTest.this.versionService.getVersionHistory(nodeRef); + assertNotNull(versionHistory); + assertEquals(1, versionHistory.getAllVersions().size()); + + return null; + } + }); + } } diff --git a/source/java/org/alfresco/repo/version/VersionableAspect.java b/source/java/org/alfresco/repo/version/VersionableAspect.java index 475c665dd5..f285d64b3a 100644 --- a/source/java/org/alfresco/repo/version/VersionableAspect.java +++ b/source/java/org/alfresco/repo/version/VersionableAspect.java @@ -17,23 +17,23 @@ package org.alfresco.repo.version; import java.io.Serializable; +import java.util.HashMap; import java.util.Map; +import org.alfresco.i18n.I18NUtil; import org.alfresco.model.ContentModel; -import org.alfresco.repo.action.executer.CreateVersionActionExecuter; import org.alfresco.repo.content.ContentServicePolicies; +import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.Behaviour; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyScope; -import org.alfresco.repo.rule.RuntimeRuleService; -import org.alfresco.service.cmr.action.Action; -import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.rule.Rule; -import org.alfresco.service.cmr.rule.RuleService; +import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; @@ -42,36 +42,27 @@ import org.alfresco.service.namespace.QName; * * @author Roy Wetherall */ -public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy +public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy, + NodeServicePolicies.OnAddAspectPolicy, + NodeServicePolicies.OnRemoveAspectPolicy { - /** - * The policy component - */ + /** The i18n'ized messages */ + private static final String MSG_INITIAL_VERSION = "create_version.initial_version"; + private static final String MSG_AUTO_VERSION = "create_version.auto_version"; + + /** Transaction resource key */ + private static final String KEY_INITIAL_VERSION = "initial_version_"; + + /** The policy component */ private PolicyComponent policyComponent; - /** - * The node service - */ + /** The node service */ private NodeService nodeService; - /** - * The rule service - */ - private RuleService ruleService; - - /** - * The action service - */ - private ActionService actionService; - - /** - * The rule used to create versions - */ - private Rule rule; + /** The Version service */ + private VersionService versionService; - /** - * Auto version behaviour - */ + /** Auto version behaviour */ private Behaviour autoVersionBehaviour; /** @@ -84,25 +75,15 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate this.policyComponent = policyComponent; } - /** - * Set the rule service - * - * @param ruleService the rule service - */ - public void setRuleService(RuleService ruleService) + /** + * Set the version service + * + * @param versionService the version service + */ + public void setVersionService(VersionService versionService) { - this.ruleService = ruleService; - } - - /** - * Set the action service - * - * @param actionService the action service - */ - public void setActionService(ActionService actionService) - { - this.actionService = actionService; - } + this.versionService = versionService; + } /** * Set the node service @@ -122,8 +103,13 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ContentModel.ASPECT_VERSIONABLE, - new JavaBehaviour(this, "onAddAspect")); - autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate"); + new JavaBehaviour(this, "onAddAspect", Behaviour.NotificationFrequency.TRANSACTION_COMMIT)); + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onRemoveAspect"), + ContentModel.ASPECT_VERSIONABLE, + new JavaBehaviour(this, "onRemoveAspect", Behaviour.NotificationFrequency.TRANSACTION_COMMIT)); + + autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.TRANSACTION_COMMIT); this.policyComponent.bindClassBehaviour( ContentServicePolicies.ON_CONTENT_UPDATE, ContentModel.ASPECT_VERSIONABLE, @@ -157,28 +143,7 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate ContentModel.ASPECT_VERSIONABLE, ContentModel.PROP_AUTO_VERSION, this.nodeService.getProperty(sourceNodeRef, ContentModel.PROP_AUTO_VERSION)); - } - - /** - * OnCreateVersion behaviour for the version aspect - *

- * Ensures that the version aspect and it proerties are 'frozen' as part of - * the versioned state. - * - * @param classRef the class reference - * @param versionableNode the versionable node reference - * @param versionProperties the version properties - * @param nodeDetails the details of the node to be versioned - */ - public void onCreateVersion( - QName classRef, - NodeRef versionableNode, - Map versionProperties, - PolicyScope nodeDetails) - { - // Do nothing since we do not what to freeze any of the version - // properties - } + } /** @@ -187,7 +152,6 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate * @param nodeRef * @param aspectTypeQName */ - @SuppressWarnings("unchecked") public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) { if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true) @@ -198,15 +162,29 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate { initialVersion = value.booleanValue(); } - // else this means that the default vlaue has not been set the versionable aspect we applied pre-1.2 + // else this means that the default value has not been set the versionable aspect we applied pre-1.2 if (initialVersion == true) { // Queue create version action - queueCreateVersionAction(nodeRef); + Map versionDetails = new HashMap(1); + versionDetails.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_INITIAL_VERSION)); + this.versionService.createVersion(nodeRef, versionDetails); + + // Keep track of the fact that the initial version has been created + AlfrescoTransactionSupport.bindResource(KEY_INITIAL_VERSION + nodeRef.toString(), nodeRef); } } } + + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy#onRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) + */ + public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName) + { + // When the versionable aspect is removed from a node, then delete the associatied verison history + this.versionService.deleteVersionHistory(nodeRef); + } /** * On content update policy bahaviour @@ -217,21 +195,27 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate { if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true) { - // Determine whether the node is auto versionable or not - boolean autoVersion = false; - Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION); - if (value != null) - { - // If the value is not null then - autoVersion = value.booleanValue(); - } - // else this means that the default value has not been set and the versionable aspect was applied pre-1.1 - - if (autoVersion == true) - { - // Queue create version action - queueCreateVersionAction(nodeRef); - } + // Determine whether we have already created an initial version during this transaction + if (AlfrescoTransactionSupport.getResource(KEY_INITIAL_VERSION + nodeRef.toString()) == null) + { + // Determine whether the node is auto versionable or not + boolean autoVersion = false; + Boolean value = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTO_VERSION); + if (value != null) + { + // If the value is not null then + autoVersion = value.booleanValue(); + } + // else this means that the default value has not been set and the versionable aspect was applied pre-1.1 + + if (autoVersion == true) + { + // Create the auto-version + Map versionProperties = new HashMap(1); + versionProperties.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_AUTO_VERSION)); + this.versionService.createVersion(nodeRef, versionProperties); + } + } } } @@ -251,24 +235,5 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate public void disableAutoVersion() { this.autoVersionBehaviour.disable(); - } - - /** - * Queue create version action - * - * @param nodeRef the node reference - */ - private void queueCreateVersionAction(NodeRef nodeRef) - { - if (this.rule == null) - { - // Create the version action rule - this.rule = this.ruleService.createRule("inbound"); - Action action = this.actionService.createAction(CreateVersionActionExecuter.NAME); - this.rule.addAction(action); - } - - // Stash the rule pending execution at the end of the transaction - ((RuntimeRuleService)this.ruleService).addRulePendingExecution(nodeRef, nodeRef, this.rule, true); - } + } }