From 811fe439eb26c68c3f58d4e2457330da59d965ea Mon Sep 17 00:00:00 2001 From: Jared Ottley Date: Thu, 29 Aug 2013 20:16:27 +0000 Subject: [PATCH] [RM-795] Can't copy/link to record. Reworked Copy policies. The record aspect is now not copied. A new Unique Record Identifier is generated on for the copy. Other record properties are generated when the record is copied into new record folder. Removed old copy behaviour. Behaviour filter is now added to the policy. The filter is used to disable the id check at the end of copy (on commit) so that a new id can be added to the copy. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@54675 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rm-model-context.xml | 1 + .../model/behaviour/RecordCopyBehaviours.java | 80 ++++++++++++------- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index 29f3291417..f1bd9ed043 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -78,6 +78,7 @@ class="org.alfresco.module.org_alfresco_module_rm.model.behaviour.RecordCopyBehaviours" init-method="init"> + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java index b6b7585c79..db54aa0ee2 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordCopyBehaviours.java @@ -18,7 +18,6 @@ */ package org.alfresco.module.org_alfresco_module_rm.model.behaviour; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -26,11 +25,12 @@ import java.util.Map; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementServiceRegistry; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; +import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.repo.copy.AbstractCopyBehaviourCallback; import org.alfresco.repo.copy.CopyBehaviourCallback; import org.alfresco.repo.copy.CopyDetails; import org.alfresco.repo.copy.DoNothingCopyBehaviourCallback; +import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -51,6 +51,9 @@ public class RecordCopyBehaviours implements RecordsManagementModel /** The policy component */ private PolicyComponent policyComponent; + /** The Behaviour Filter */ + private BehaviourFilter behaviourFilter; + /** The rm service registry */ private RecordsManagementServiceRegistry rmServiceRegistry; @@ -67,6 +70,16 @@ public class RecordCopyBehaviours implements RecordsManagementModel this.policyComponent = policyComponent; } + /** + * Set the behaviour Filter + * + * @param behaviourFilter + */ + public void setBehaviourFilter(BehaviourFilter behaviourFilter) + { + this.behaviourFilter = behaviourFilter; + } + /** * Set the rm service registry. * @@ -98,7 +111,19 @@ public class RecordCopyBehaviours implements RecordsManagementModel this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), ASPECT_RECORD_COMPONENT_ID, - new JavaBehaviour(this, "getIdCallback")); + new JavaBehaviour(this, "getDoNothingCopyCallback")); + + //On Copy we need a new ID + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onCopyComplete"), + ASPECT_RECORD_COMPONENT_ID, + new JavaBehaviour(this, "generateId", NotificationFrequency.TRANSACTION_COMMIT)); + + //Don't copy the Aspect Record -- it should be regenerated + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"), + ASPECT_RECORD, + new JavaBehaviour(this, "getDoNothingCopyCallback")); // Move behaviour this.policyComponent.bindClassBehaviour( @@ -108,7 +133,7 @@ public class RecordCopyBehaviours implements RecordsManagementModel this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onMoveNode"), RecordsManagementModel.TYPE_RECORD_FOLDER, - new JavaBehaviour(this, "onMoveRecordFolderNode", NotificationFrequency.FIRST_EVENT)); + new JavaBehaviour(this, "onMoveRecordFolderNode", NotificationFrequency.FIRST_EVENT)); } /** @@ -219,33 +244,28 @@ public class RecordCopyBehaviours implements RecordsManagementModel return new DoNothingCopyBehaviourCallback(); } - public CopyBehaviourCallback getIdCallback(QName classRef, CopyDetails copyDetails) + /** + * Generate and set a new ID for copy of a record + * + * @param classRef + * @param sourceNodeRef + * @param targetNodeRef + * @param copyToNewNode + * @param copyMap + */ + @SuppressWarnings("rawtypes") + public void generateId(QName classRef, NodeRef sourceNodeRef, NodeRef targetNodeRef, boolean copyToNewNode, Map copyMap) { - return new AbstractCopyBehaviourCallback() - { - public ChildAssocCopyAction getChildAssociationCopyAction( - QName classQName, - CopyDetails copyDetails, - CopyChildAssociationDetails childAssocCopyDetails) - { - return null; - } - - public Map getCopyProperties( - QName classQName, - CopyDetails copyDetails, - Map properties) - { - properties.put(PROP_IDENTIFIER, properties.get(PROP_IDENTIFIER) + "1"); - return properties; - } - - public boolean getMustCopy(QName classQName, CopyDetails copyDetails) - { - return true; - } - - }; + final IdentifierService rmIdentifierService = rmServiceRegistry.getIdentifierService(); + final NodeService nodeService = rmServiceRegistry.getNodeService(); + + //Generate the id for the copy + String id = rmIdentifierService.generateIdentifier(nodeService.getType(nodeService.getPrimaryParent(targetNodeRef).getParentRef()), (nodeService.getPrimaryParent(targetNodeRef).getParentRef())); + + //We need to allow the id to be overwritten disable the policy protecting changes to the id + behaviourFilter.disableBehaviour(targetNodeRef, ASPECT_RECORD_COMPONENT_ID); + nodeService.setProperty(targetNodeRef, PROP_IDENTIFIER, id); + behaviourFilter.enableBehaviour(targetNodeRef, ASPECT_RECORD_COMPONENT_ID); } /**