mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V1.3 to HEAD (3247:3249, 3250:3280, 3281:3324)
svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3247 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3249 . svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3250 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3280 . svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3281 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3324 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3411 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -373,6 +373,9 @@ public class VersionServiceImpl extends AbstractVersionServiceImpl
|
||||
ContentModel.PROP_VERSION_LABEL,
|
||||
version.getVersionLabel());
|
||||
|
||||
// Invoke the policy behaviour
|
||||
invokeAfterCreateVersion(nodeRef, version);
|
||||
|
||||
// Return the data object representing the newly created version
|
||||
return version;
|
||||
}
|
||||
|
@@ -46,11 +46,37 @@ public interface VersionServicePolicies
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* After create version policy interface
|
||||
*
|
||||
*/
|
||||
public interface AfterCreateVersionPolicy extends ClassPolicy
|
||||
{
|
||||
/**
|
||||
* Called after the version has been created
|
||||
*
|
||||
* @param versionableNode the node that has been versioned
|
||||
* @param version the created version
|
||||
*/
|
||||
public void afterCreateVersion(NodeRef versionableNode, Version version);
|
||||
}
|
||||
|
||||
/**
|
||||
* On create version policy interface
|
||||
*/
|
||||
public interface OnCreateVersionPolicy extends ClassPolicy
|
||||
{
|
||||
/**
|
||||
* Called during the creation of the version to determine what the versioning policy for a
|
||||
* perticular type may be.
|
||||
* WARNING: implementing behaviour for this policy effects the versioning behaviour of the
|
||||
* type the behaviour is registered against.
|
||||
*
|
||||
* @param classRef
|
||||
* @param versionableNode
|
||||
* @param versionProperties
|
||||
* @param nodeDetails
|
||||
*/
|
||||
public void onCreateVersion(
|
||||
QName classRef,
|
||||
NodeRef versionableNode,
|
||||
|
@@ -46,14 +46,15 @@ import org.alfresco.service.namespace.QName;
|
||||
public class VersionableAspect implements ContentServicePolicies.OnContentUpdatePolicy,
|
||||
NodeServicePolicies.OnAddAspectPolicy,
|
||||
NodeServicePolicies.OnRemoveAspectPolicy,
|
||||
NodeServicePolicies.OnDeleteNodePolicy
|
||||
NodeServicePolicies.OnDeleteNodePolicy,
|
||||
VersionServicePolicies.AfterCreateVersionPolicy
|
||||
{
|
||||
/** 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_";
|
||||
private static final String KEY_VERSIONED_NODEREFS = "versioned_noderefs";
|
||||
|
||||
/** The policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
@@ -114,6 +115,10 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"),
|
||||
ContentModel.ASPECT_VERSIONABLE,
|
||||
new JavaBehaviour(this, "onDeleteNode", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "afterCreateVersion"),
|
||||
ContentModel.ASPECT_VERSIONABLE,
|
||||
new JavaBehaviour(this, "afterCreateVersion", Behaviour.NotificationFrequency.EVERY_EVENT));
|
||||
|
||||
autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.TRANSACTION_COMMIT);
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
@@ -189,9 +194,6 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,12 +212,13 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
*
|
||||
* @param nodeRef the node reference
|
||||
*/
|
||||
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
|
||||
@SuppressWarnings("unchecked")
|
||||
public void onContentUpdate(NodeRef nodeRef, boolean newContent)
|
||||
{
|
||||
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)
|
||||
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
|
||||
{
|
||||
Map<NodeRef, NodeRef> versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
|
||||
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
|
||||
{
|
||||
// Determine whether the node is auto versionable or not
|
||||
boolean autoVersion = false;
|
||||
@@ -237,22 +240,19 @@ public class VersionableAspect implements ContentServicePolicies.OnContentUpdate
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable the auto version behaviour
|
||||
*
|
||||
* @see org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy#onCreateVersion(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.util.Map, org.alfresco.repo.policy.PolicyScope)
|
||||
*/
|
||||
public void enableAutoVersion()
|
||||
{
|
||||
this.autoVersionBehaviour.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the auto version behaviour
|
||||
*
|
||||
*/
|
||||
public void disableAutoVersion()
|
||||
{
|
||||
this.autoVersionBehaviour.disable();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void afterCreateVersion(NodeRef versionableNode, Version version)
|
||||
{
|
||||
Map<NodeRef, NodeRef> versionedNodeRefs = (Map<NodeRef, NodeRef>)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
|
||||
if (versionedNodeRefs == null)
|
||||
{
|
||||
versionedNodeRefs = new HashMap<NodeRef, NodeRef>();
|
||||
AlfrescoTransactionSupport.bindResource(KEY_VERSIONED_NODEREFS, versionedNodeRefs);
|
||||
}
|
||||
versionedNodeRefs.put(versionableNode, versionableNode);
|
||||
}
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import org.alfresco.repo.policy.ClassPolicyDelegate;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.policy.PolicyScope;
|
||||
import org.alfresco.repo.version.VersionServicePolicies;
|
||||
import org.alfresco.repo.version.VersionServicePolicies.AfterCreateVersionPolicy;
|
||||
import org.alfresco.repo.version.VersionServicePolicies.BeforeCreateVersionPolicy;
|
||||
import org.alfresco.repo.version.VersionServicePolicies.CalculateVersionLabelPolicy;
|
||||
import org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy;
|
||||
@@ -68,6 +69,7 @@ public abstract class AbstractVersionServiceImpl
|
||||
* Policy delegates
|
||||
*/
|
||||
private ClassPolicyDelegate<BeforeCreateVersionPolicy> beforeCreateVersionDelegate;
|
||||
private ClassPolicyDelegate<AfterCreateVersionPolicy> afterCreateVersionDelegate;
|
||||
private ClassPolicyDelegate<OnCreateVersionPolicy> onCreateVersionDelegate;
|
||||
private ClassPolicyDelegate<CalculateVersionLabelPolicy> calculateVersionLabelDelegate;
|
||||
|
||||
@@ -108,6 +110,7 @@ public abstract class AbstractVersionServiceImpl
|
||||
{
|
||||
// Register the policies
|
||||
this.beforeCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.BeforeCreateVersionPolicy.class);
|
||||
this.afterCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.AfterCreateVersionPolicy.class);
|
||||
this.onCreateVersionDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.OnCreateVersionPolicy.class);
|
||||
this.calculateVersionLabelDelegate = this.policyComponent.registerClassPolicy(VersionServicePolicies.CalculateVersionLabelPolicy.class);
|
||||
}
|
||||
@@ -127,6 +130,22 @@ public abstract class AbstractVersionServiceImpl
|
||||
this.beforeCreateVersionDelegate.get(nodeAspectQNames).beforeCreateVersion(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the after create version policy bahaviour
|
||||
*
|
||||
* @param nodeRef the nodeRef versioned
|
||||
* @param version the created version
|
||||
*/
|
||||
protected void invokeAfterCreateVersion(NodeRef nodeRef, Version version)
|
||||
{
|
||||
// invoke for node type
|
||||
QName nodeTypeQName = nodeService.getType(nodeRef);
|
||||
this.afterCreateVersionDelegate.get(nodeTypeQName).afterCreateVersion(nodeRef, version);
|
||||
// invoke for node aspects
|
||||
Set<QName> nodeAspectQNames = nodeService.getAspects(nodeRef);
|
||||
this.afterCreateVersionDelegate.get(nodeAspectQNames).afterCreateVersion(nodeRef, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the on create version policy behaviour
|
||||
*
|
||||
|
Reference in New Issue
Block a user