mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
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
This commit is contained in:
@@ -349,15 +349,12 @@
|
|||||||
<property name="policyComponent">
|
<property name="policyComponent">
|
||||||
<ref bean="policyComponent" />
|
<ref bean="policyComponent" />
|
||||||
</property>
|
</property>
|
||||||
<property name="ruleService">
|
<property name="versionService">
|
||||||
<ref bean="ruleService"/>
|
<ref bean="versionService"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="nodeService">
|
<property name="nodeService">
|
||||||
<ref bean="nodeService"/>
|
<ref bean="nodeService"/>
|
||||||
</property>
|
</property>
|
||||||
<property name="actionService">
|
|
||||||
<ref bean="actionService"/>
|
|
||||||
</property>
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- -->
|
<!-- -->
|
||||||
|
@@ -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_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_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.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
|
||||||
|
@@ -284,6 +284,13 @@ public class PermissionServiceImpl implements PermissionServiceSPI, Initializing
|
|||||||
return authorityType;
|
return authorityType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return accessStatus + " " + this.permission + " - " +
|
||||||
|
this.authority + " (" + this.authorityType + ")";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
@@ -804,25 +804,6 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
|
|||||||
return result;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.cms.version.VersionService#revert(NodeRef)
|
* @see org.alfresco.cms.version.VersionService#revert(NodeRef)
|
||||||
*/
|
*/
|
||||||
@@ -1089,14 +1070,19 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
|
|||||||
public void deleteVersionHistory(NodeRef nodeRef)
|
public void deleteVersionHistory(NodeRef nodeRef)
|
||||||
throws AspectMissingException
|
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);
|
NodeRef versionHistoryNodeRef = getVersionHistoryNodeRef(nodeRef);
|
||||||
|
|
||||||
|
if (versionHistoryNodeRef != null)
|
||||||
|
{
|
||||||
|
// Delete the version history node
|
||||||
this.dbNodeService.deleteNode(versionHistoryNodeRef);
|
this.dbNodeService.deleteNode(versionHistoryNodeRef);
|
||||||
|
|
||||||
|
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||||
|
{
|
||||||
// Reset the version label property on the versionable node
|
// Reset the version label property on the versionable node
|
||||||
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null);
|
this.nodeService.setProperty(nodeRef, ContentModel.PROP_VERSION_LABEL, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -549,4 +549,64 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAddRemoveVersionableAspect()
|
||||||
|
{
|
||||||
|
HashMap<QName, Serializable> props2 = new HashMap<QName, Serializable>();
|
||||||
|
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<Object>()
|
||||||
|
{
|
||||||
|
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<Object>()
|
||||||
|
{
|
||||||
|
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<Object>()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,23 +17,23 @@
|
|||||||
package org.alfresco.repo.version;
|
package org.alfresco.repo.version;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.i18n.I18NUtil;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.executer.CreateVersionActionExecuter;
|
|
||||||
import org.alfresco.repo.content.ContentServicePolicies;
|
import org.alfresco.repo.content.ContentServicePolicies;
|
||||||
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
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;
|
||||||
import org.alfresco.repo.policy.PolicyScope;
|
import org.alfresco.repo.policy.PolicyScope;
|
||||||
import org.alfresco.repo.rule.RuntimeRuleService;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
|
||||||
import org.alfresco.service.cmr.action.ActionService;
|
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.service.cmr.rule.Rule;
|
import org.alfresco.service.cmr.version.Version;
|
||||||
import org.alfresco.service.cmr.rule.RuleService;
|
import org.alfresco.service.cmr.version.VersionService;
|
||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
@@ -42,36 +42,27 @@ import org.alfresco.service.namespace.QName;
|
|||||||
*
|
*
|
||||||
* @author Roy Wetherall
|
* @author Roy Wetherall
|
||||||
*/
|
*/
|
||||||
public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy
|
public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy,
|
||||||
|
NodeServicePolicies.OnAddAspectPolicy,
|
||||||
|
NodeServicePolicies.OnRemoveAspectPolicy
|
||||||
{
|
{
|
||||||
/**
|
/** The i18n'ized messages */
|
||||||
* The policy component
|
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;
|
private PolicyComponent policyComponent;
|
||||||
|
|
||||||
/**
|
/** The node service */
|
||||||
* The node service
|
|
||||||
*/
|
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
|
|
||||||
/**
|
/** The Version service */
|
||||||
* The rule service
|
private VersionService versionService;
|
||||||
*/
|
|
||||||
private RuleService ruleService;
|
|
||||||
|
|
||||||
/**
|
/** Auto version behaviour */
|
||||||
* The action service
|
|
||||||
*/
|
|
||||||
private ActionService actionService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The rule used to create versions
|
|
||||||
*/
|
|
||||||
private Rule rule;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto version behaviour
|
|
||||||
*/
|
|
||||||
private Behaviour autoVersionBehaviour;
|
private Behaviour autoVersionBehaviour;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,23 +76,13 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the rule service
|
* Set the version service
|
||||||
*
|
*
|
||||||
* @param ruleService the rule service
|
* @param versionService the version service
|
||||||
*/
|
*/
|
||||||
public void setRuleService(RuleService ruleService)
|
public void setVersionService(VersionService versionService)
|
||||||
{
|
{
|
||||||
this.ruleService = ruleService;
|
this.versionService = versionService;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the action service
|
|
||||||
*
|
|
||||||
* @param actionService the action service
|
|
||||||
*/
|
|
||||||
public void setActionService(ActionService actionService)
|
|
||||||
{
|
|
||||||
this.actionService = actionService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,8 +103,13 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
this.policyComponent.bindClassBehaviour(
|
this.policyComponent.bindClassBehaviour(
|
||||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
|
QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
|
||||||
ContentModel.ASPECT_VERSIONABLE,
|
ContentModel.ASPECT_VERSIONABLE,
|
||||||
new JavaBehaviour(this, "onAddAspect"));
|
new JavaBehaviour(this, "onAddAspect", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
|
||||||
autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate");
|
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(
|
this.policyComponent.bindClassBehaviour(
|
||||||
ContentServicePolicies.ON_CONTENT_UPDATE,
|
ContentServicePolicies.ON_CONTENT_UPDATE,
|
||||||
ContentModel.ASPECT_VERSIONABLE,
|
ContentModel.ASPECT_VERSIONABLE,
|
||||||
@@ -159,27 +145,6 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
this.nodeService.getProperty(sourceNodeRef, ContentModel.PROP_AUTO_VERSION));
|
this.nodeService.getProperty(sourceNodeRef, ContentModel.PROP_AUTO_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* OnCreateVersion behaviour for the version aspect
|
|
||||||
* <p>
|
|
||||||
* 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<String, Serializable> versionProperties,
|
|
||||||
PolicyScope nodeDetails)
|
|
||||||
{
|
|
||||||
// Do nothing since we do not what to freeze any of the version
|
|
||||||
// properties
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On add aspect policy behaviour
|
* On add aspect policy behaviour
|
||||||
@@ -187,7 +152,6 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
* @param nodeRef
|
* @param nodeRef
|
||||||
* @param aspectTypeQName
|
* @param aspectTypeQName
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
|
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||||
{
|
{
|
||||||
if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
|
if (aspectTypeQName.equals(ContentModel.ASPECT_VERSIONABLE) == true)
|
||||||
@@ -198,16 +162,30 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
{
|
{
|
||||||
initialVersion = value.booleanValue();
|
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)
|
if (initialVersion == true)
|
||||||
{
|
{
|
||||||
// Queue create version action
|
// Queue create version action
|
||||||
queueCreateVersionAction(nodeRef);
|
Map<String, Serializable> versionDetails = new HashMap<String, Serializable>(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
|
* On content update policy bahaviour
|
||||||
*
|
*
|
||||||
@@ -216,6 +194,9 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
|
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
|
||||||
{
|
{
|
||||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||||
|
{
|
||||||
|
// 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
|
// Determine whether the node is auto versionable or not
|
||||||
boolean autoVersion = false;
|
boolean autoVersion = false;
|
||||||
@@ -229,8 +210,11 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
|
|
||||||
if (autoVersion == true)
|
if (autoVersion == true)
|
||||||
{
|
{
|
||||||
// Queue create version action
|
// Create the auto-version
|
||||||
queueCreateVersionAction(nodeRef);
|
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
|
||||||
|
versionProperties.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_AUTO_VERSION));
|
||||||
|
this.versionService.createVersion(nodeRef, versionProperties);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,23 +236,4 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
|||||||
{
|
{
|
||||||
this.autoVersionBehaviour.disable();
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user