From 8bf3cdf913064f5033020a8e580d56cab575c693 Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Wed, 13 Mar 2019 12:04:10 +0000 Subject: [PATCH] RM-6788 adding change to 3.0.1 branch --- .../model/BaseBehaviourBean.java | 29 +++++++++++++++++++ .../model/RecordsManagementModel.java | 5 ++++ .../model/rma/aspect/RecordAspect.java | 15 +--------- .../rma/aspect/RecordAspectUnitTest.java | 18 ++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java index 4e3124b62f..a43be9b58e 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.policy.BehaviourFilter; @@ -142,4 +143,32 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl //no match was found in sub-types of permitted types list throw new IntegrityException(I18NUtil.getMessage(MULTIPLE_CHILDREN_TYPE_ERROR, childType), null); } + + /** + * Helper method to duplicate the bin file of a node and replace the contenturl property with the new reference + * + * @param nodeRef The node to update with a new copy of the bin file + */ + protected void duplicateContentFileIfRequired(NodeRef nodeRef) + { + //Adding fix for RM-6788 where too many duplicates are being made this is a workaround waiting on a full solution + if (!nodeService.hasAspect(nodeRef, ASPECT_ARCHIVED)) + { + //disable versioning and auditing + behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE); + behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE); + try + { + //create a new content URL for the copy/original node + createNewContentURL(nodeRef); + } + finally + { + //enable versioning and auditing + behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE); + behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); + } + } + } + } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java index 0c7202258b..c8f4775bf9 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java @@ -285,4 +285,9 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel QName PROP_COUNT = QName.createQName(RM_URI, "count"); QName ASPECT_SAVED_SEARCH = QName.createQName(RM_URI, "savedSearch"); + + //Workaround for RM-6788 + String GL_URI = "http://www.alfresco.org/model/glacier/1.0"; + QName ASPECT_ARCHIVED = QName.createQName(GL_URI, "archived"); + } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java index 441af631bb..c1529de4f7 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java @@ -401,20 +401,7 @@ public class RecordAspect extends AbstractDisposableItem if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() || !nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) { - //disable versioning and auditing - behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE); - behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE); - try - { - //create a new content URL for the copy/original node - createNewContentURL(nodeRef); - } - finally - { - //enable versioning and auditing - behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE); - behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); - } + duplicateContentFileIfRequired(nodeRef); } return null; diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java index 730da904f3..27d6547e72 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java @@ -29,6 +29,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED; import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; @@ -158,6 +159,23 @@ public class RecordAspectUnitTest verify(mockContentWriter, times(1)).putContent(mockContentReader); } + /** + * This is testing the fix for RM-6788 where archived content couldn't be declared as a record + * This was caused by attempting to copy the bin file and updating the content url of the + * archived piece of content which failed as this is a protected property. This is done if + * the node is/has a copy but the same duplication already happens during archive. + */ + @Test + public void testBinFileNotDuplicatedForArchivedContent() + { + when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF)); + when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null); + when(mockNodeService.hasAspect(NODE_REF, ASPECT_ARCHIVED)).thenReturn(true); + recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); + + verifyBeforeAddAspectMethodsInvocations(0); + } + /** * Helper to verify beforeAddAspect methods invocations *