/* * Copyright (C) 2005 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. */ package org.alfresco.repo.version; import java.io.Serializable; import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator; import org.alfresco.repo.action.executer.CreateVersionActionExecuter; import org.alfresco.repo.policy.Behaviour; import org.alfresco.repo.policy.BehaviourDefinition; 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.ActionCondition; import org.alfresco.service.cmr.action.ActionService; 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.namespace.NamespaceService; import org.alfresco.service.namespace.QName; /** * Class containing behaviour for the versionable aspect * * @author Roy Wetherall */ public class VersionableAspect { /** * The policy component */ private PolicyComponent policyComponent; /** * 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; /** * Auto version behaviour */ private Behaviour autoVersionBehaviour; /** * Set the policy component * * @param policyComponent the policy component */ public void setPolicyComponent(PolicyComponent policyComponent) { this.policyComponent = policyComponent; } /** * Set the rule service * * @param ruleService the rule service */ public void setRuleService(RuleService ruleService) { this.ruleService = ruleService; } /** * Set the action service * * @param actionService the action service */ public void setActionService(ActionService actionService) { this.actionService = actionService; } /** * Set the node service * * @param nodeService the node service */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } /** * Initialise the versionable aspect policies */ public void init() { this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), ContentModel.ASPECT_VERSIONABLE, new JavaBehaviour(this, "onAddAspect")); autoVersionBehaviour = new JavaBehaviour(this, "onContentUpdate"); this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"), ContentModel.ASPECT_VERSIONABLE, autoVersionBehaviour); // Register the copy behaviour this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyNode"), ContentModel.ASPECT_VERSIONABLE, new JavaBehaviour(this, "onCopy")); // Register the onCreateVersion behavior for the version aspect //this.policyComponent.bindClassBehaviour( // QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateVersion"), // ContentModel.ASPECT_VERSIONABLE, // new JavaBehaviour(this, "onCreateVersion")); } /** * OnCopy behaviour implementation for the version aspect. *
* Ensures that the propety values of the version aspect are not copied onto * the destination node. * * @see org.alfresco.repo.copy.CopyServicePolicies.OnCopyNodePolicy#onCopyNode(QName, NodeRef, StoreRef, boolean, PolicyScope) */ public void onCopy( QName sourceClassRef, NodeRef sourceNodeRef, StoreRef destinationStoreRef, boolean copyToNewNode, PolicyScope copyDetails) { // Add the version aspect, but do not copy the version label copyDetails.addAspect(ContentModel.ASPECT_VERSIONABLE); copyDetails.addProperty( 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