From ed8f24865c3f4c7b3b0d32db20d77e83d3b8e134 Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Mon, 1 Apr 2019 17:54:23 +0100 Subject: [PATCH 1/3] RM-6787 adding fix for version number increasing and bin duplicating more than needed --- .../org_alfresco_module_rm/module-context.xml | 5 + .../rm-model-context.xml | 1 + .../model/rma/aspect/RecordAspect.java | 28 ++--- .../util/ContentBinDuplicationUtility.java | 78 ++++++++++++ .../rma/aspect/RecordAspectUnitTest.java | 47 +------- .../ContentBinDuplicationUtilityUnitTest.java | 113 ++++++++++++++++++ 6 files changed, 217 insertions(+), 55 deletions(-) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml index 63242f2ab1..84b6bb8ba6 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -248,6 +248,11 @@ + + + + + diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index ddd303c982..a3a01f47b0 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -143,6 +143,7 @@ + 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..77cd3101bd 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 @@ -38,6 +38,7 @@ import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; +import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; import org.alfresco.repo.content.ContentServicePolicies; import org.alfresco.repo.copy.CopyBehaviourCallback; import org.alfresco.repo.copy.CopyDetails; @@ -94,6 +95,9 @@ public class RecordAspect extends AbstractDisposableItem /** quickShare service */ private QuickShareService quickShareService; + /** Utility class for duplicating content */ + private ContentBinDuplicationUtility contentBinDuplicationUtility; + /** I18N */ private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content"; @@ -130,6 +134,15 @@ public class RecordAspect extends AbstractDisposableItem this.quickShareService = quickShareService; } + /** + * Setter for content duplication utility class + * @param contentBinDuplicationUtility ContentBinDuplicationUtility + */ + public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility) + { + this.contentBinDuplicationUtility = contentBinDuplicationUtility; + } + /** * Behaviour to ensure renditions have the appropriate extended security. * @@ -401,20 +414,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); - } + contentBinDuplicationUtility.duplicate(nodeRef); } return null; diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java new file mode 100644 index 0000000000..9fcee6bc6a --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java @@ -0,0 +1,78 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.util; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Utility class to duplicate the content of a node without triggering the audit or versioning behaviours + * @author Ross Gale + * @since 2.7.2 + */ +public class ContentBinDuplicationUtility extends ServiceBaseImpl +{ + + /** + * Behaviour filter + */ + protected BehaviourFilter behaviourFilter; + + /** + * Setter for behaviour filter + * @param behaviourFilter + */ + public void setBehaviourFilter(BehaviourFilter behaviourFilter) + { + this.behaviourFilter = behaviourFilter; + } + + /** + * Duplicate the content of a node without triggering the audit or versioning behaviours + * + * @param nodeRef The node with the content to duplicate + */ + public void duplicate(NodeRef nodeRef) + { + //disabling 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/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..35bc440b8a 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 @@ -30,8 +30,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; 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; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -39,7 +37,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; -import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; @@ -70,8 +68,6 @@ public class RecordAspectUnitTest @Mock private NodeService mockNodeService; @Mock - private BehaviourFilter mockBehaviorFilter; - @Mock private ContentService mockContentService; @Mock private ContentReader mockContentReader; @@ -79,6 +75,8 @@ public class RecordAspectUnitTest private ContentWriter mockContentWriter; @Mock private ExtendedSecurityService mockExtendedSecurityService; + @Mock + private ContentBinDuplicationUtility contentBinDuplicationUtility; @Before public void setUp() @@ -96,7 +94,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verifyBeforeAddAspectMethodsInvocations(1); + verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF); } /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ @@ -109,24 +107,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verifyBeforeAddAspectMethodsInvocations(1); - } - - /** Check that no content bin is created if the file does not have content. */ - @Test - public void testBeforeAddAspectOnFileWithNoContent() - { - when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF)); - when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null); - - recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - - verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); - verify(mockContentService, times(1)).getReader(NODE_REF, ContentModel.PROP_CONTENT); - verify(mockContentService, never()).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF); } /** Check that the bin is not duplicated before adding the aspect if the node has no copies. */ @@ -138,7 +119,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verifyBeforeAddAspectMethodsInvocations(0); + verify(contentBinDuplicationUtility, times(0)).duplicate(NODE_REF); } /** Check that the bin is duplicated when copying a record. */ @@ -157,20 +138,4 @@ public class RecordAspectUnitTest verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true); verify(mockContentWriter, times(1)).putContent(mockContentReader); } - - /** - * Helper to verify beforeAddAspect methods invocations - * - * @param wantedNumberOfInvocations wanted number of invocations for each method - */ - private void verifyBeforeAddAspectMethodsInvocations(int wantedNumberOfInvocations) - { - verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); - verify(mockContentService, times(wantedNumberOfInvocations)).getReader(NODE_REF, ContentModel.PROP_CONTENT); - verify(mockContentService, times(wantedNumberOfInvocations)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); - verify(mockContentWriter, times(wantedNumberOfInvocations)).putContent(mockContentReader); - verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); - } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java new file mode 100644 index 0000000000..3f9ab62b1d --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java @@ -0,0 +1,113 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.util; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Test class for the ContentBinDuplicationUtility + * @author Ross Gale + * @since 2.7.2 + */ +public class ContentBinDuplicationUtilityUnitTest +{ + + @Mock + private ContentService contentService; + + @Mock + private BehaviourFilter behaviourFilter; + + @Mock + private ContentReader contentReader; + + @Mock + private ContentWriter contentWriter; + + @InjectMocks + private ContentBinDuplicationUtility contentBinDuplicationUtility; + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + } + + /** + * Tests that the requests are made to disable and re-enable the audit and versioning and to update the content bin + */ + @Test + public void testContentUrlIsUpdated() + { + NodeRef nodeRef = new NodeRef("some://test/noderef"); + when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader); + when(contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter); + contentBinDuplicationUtility.duplicate(nodeRef); + verify(contentWriter, times(1)).putContent(contentReader); + checkBehaviours(1); + } + + /** + * Test content duplication doesn't happen when node has no content + */ + @Test + public void testDuplicationDoesntHappenWithNoContent() + { + NodeRef nodeRef = new NodeRef("some://test/noderef"); + when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null); + contentBinDuplicationUtility.duplicate(nodeRef); + verify(contentWriter, times(0)).putContent(contentReader); + checkBehaviours(1); + } + + /** + * Check that the behaviours are disabled and re-enabled the correct number of times + * @param times the times the behaviours should be called + */ + private void checkBehaviours(int times) + { + verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_AUDITABLE); + verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_VERSIONABLE); + verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_AUDITABLE); + verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_VERSIONABLE); + } +} From 9baac01d03dbaa3560ed0d90a90c3a1af2fe37c9 Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Tue, 2 Apr 2019 11:47:29 +0100 Subject: [PATCH 2/3] RM-6787 updating copy and add behaviors for other aspects to use duplication utility class --- .../rm-version-context.xml | 1 + .../model/rma/aspect/RecordAspect.java | 2 +- .../model/rma/aspect/VersionRecordAspect.java | 18 ++++++- .../util/ContentBinDuplicationUtility.java | 47 +++++++++++++++---- .../util/ServiceBaseImpl.java | 30 +----------- .../rma/aspect/RecordAspectUnitTest.java | 12 ++--- .../ContentBinDuplicationUtilityUnitTest.java | 6 +-- 7 files changed, 65 insertions(+), 51 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml index 91c2f622ea..f9f7a7e409 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml @@ -16,6 +16,7 @@ + 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 77cd3101bd..cf5e19cf26 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 @@ -369,7 +369,7 @@ public class RecordAspect extends AbstractDisposableItem extendedSecurityService.remove(targetNodeRef); //create a new content URL for the copy - createNewContentURL(targetNodeRef); + contentBinDuplicationUtility.duplicate(targetNodeRef); } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java index efab5cc2ea..c41e937aa1 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java @@ -33,6 +33,7 @@ import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; +import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService; import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -64,6 +65,11 @@ public class VersionRecordAspect extends BaseBehaviourBean /** relationship service */ private RelationshipService relationshipService; + /** + * Utility class for duplicating content + */ + private ContentBinDuplicationUtility contentBinDuplicationUtility; + /** * @param recordableVersionService recordable version service */ @@ -80,6 +86,16 @@ public class VersionRecordAspect extends BaseBehaviourBean this.relationshipService = relationshipService; } + /** + * Setter for content duplication utility class + * + * @param contentBinDuplicationUtility ContentBinDuplicationUtility + */ + public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility) + { + this.contentBinDuplicationUtility = contentBinDuplicationUtility; + } + /** * If the record is a version record then delete the associated version entry * @@ -148,7 +164,7 @@ public class VersionRecordAspect extends BaseBehaviourBean if (!nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_RECORD_ORIGINATING_DETAILS)) { //create a new content URL for the version record - createNewContentURL(nodeRef); + contentBinDuplicationUtility.duplicate(nodeRef); } } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java index 9fcee6bc6a..c1d7e879f0 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java @@ -28,6 +28,9 @@ package org.alfresco.module.org_alfresco_module_rm.util; import org.alfresco.model.ContentModel; import org.alfresco.repo.policy.BehaviourFilter; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; /** @@ -35,23 +38,37 @@ import org.alfresco.service.cmr.repository.NodeRef; * @author Ross Gale * @since 2.7.2 */ -public class ContentBinDuplicationUtility extends ServiceBaseImpl +public class ContentBinDuplicationUtility { /** * Behaviour filter */ - protected BehaviourFilter behaviourFilter; + private BehaviourFilter behaviourFilter; + + /** + * Provides methods for accessing and transforming content. + */ + private ContentService contentService; /** * Setter for behaviour filter - * @param behaviourFilter + * @param behaviourFilter BehaviourFilter */ public void setBehaviourFilter(BehaviourFilter behaviourFilter) { this.behaviourFilter = behaviourFilter; } + /** + * Setter for content service + * @param contentService ContentService + */ + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + /** * Duplicate the content of a node without triggering the audit or versioning behaviours * @@ -60,19 +77,31 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl public void duplicate(NodeRef nodeRef) { //disabling versioning and auditing - behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE); - behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE); - + behaviourFilter.disableBehaviour(); try { //create a new content URL for the copy/original node - createNewContentURL(nodeRef); + updateContentProperty(nodeRef); } finally { //enable versioning and auditing - behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE); - behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); + behaviourFilter.enableBehaviour(); + } + } + + /** + * Helper to update the content property for the node + * + * @param nodeRef the node + */ + private void updateContentProperty(NodeRef nodeRef) + { + ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); + if (reader != null) + { + ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); + writer.putContent(reader); } } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java index 8fc5094b05..f7a58ea1ff 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.WeakHashMap; -import org.alfresco.model.ContentModel; + import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; @@ -39,9 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ChildAssociationRef; -import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; @@ -554,30 +552,4 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte result.add(nodeService.getType(nodeRef)); return result; } - - /** - * Helper to update the given content property for the node - * - * @param nodeRef the node - * @param contentProperty the property to be updated - */ - protected void updateContentProperty(NodeRef nodeRef, QName contentProperty) - { - ContentReader reader = contentService.getReader(nodeRef, contentProperty); - if (reader != null) - { - ContentWriter writer = contentService.getWriter(nodeRef, contentProperty, true); - writer.putContent(reader); - } - } - - /** - * Helper to create a new content URL for the node - * - * @param nodeRef the node - */ - protected void createNewContentURL(NodeRef nodeRef) - { - updateContentProperty(nodeRef, ContentModel.PROP_CONTENT); - } } 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 35bc440b8a..84d0559590 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 @@ -76,7 +76,7 @@ public class RecordAspectUnitTest @Mock private ExtendedSecurityService mockExtendedSecurityService; @Mock - private ContentBinDuplicationUtility contentBinDuplicationUtility; + private ContentBinDuplicationUtility mockContentBinDuplicationUtility; @Before public void setUp() @@ -94,7 +94,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF); + verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF); } /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ @@ -107,7 +107,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF); + verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF); } /** Check that the bin is not duplicated before adding the aspect if the node has no copies. */ @@ -119,7 +119,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(contentBinDuplicationUtility, times(0)).duplicate(NODE_REF); + verify(mockContentBinDuplicationUtility, times(0)).duplicate(NODE_REF); } /** Check that the bin is duplicated when copying a record. */ @@ -134,8 +134,6 @@ public class RecordAspectUnitTest recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null); verify(mockExtendedSecurityService, times(1)).remove(COPY_REF); - verify(mockContentService, times(1)).getReader(COPY_REF, ContentModel.PROP_CONTENT); - verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true); - verify(mockContentWriter, times(1)).putContent(mockContentReader); + verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF); } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java index 3f9ab62b1d..c37437433a 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java @@ -105,9 +105,7 @@ public class ContentBinDuplicationUtilityUnitTest */ private void checkBehaviours(int times) { - verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_AUDITABLE); - verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_VERSIONABLE); - verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_AUDITABLE); - verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_VERSIONABLE); + verify(behaviourFilter, times(times)).disableBehaviour(); + verify(behaviourFilter, times(times)).enableBehaviour(); } } From eb9071fb734f0ceaf0445ab75fe863a9e651c59f Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 5 Apr 2019 12:04:27 +0300 Subject: [PATCH 3/3] Revert "Merge remote-tracking branch 'remotes/origin/feature-2.7/RM-6787_ReduceBinDuplication_V3' into feature-2.7/RM-6787_VersionChangeTests_no" This reverts commit b5d1ae792eae2bd5adf4b1211011ace1046d40b7, reversing changes made to d5dfbe7194c9e421b52e08032d192c089191e384. --- .../org_alfresco_module_rm/module-context.xml | 5 - .../rm-model-context.xml | 1 - .../rm-version-context.xml | 1 - .../model/rma/aspect/RecordAspect.java | 30 ++--- .../model/rma/aspect/VersionRecordAspect.java | 18 +-- .../util/ContentBinDuplicationUtility.java | 107 ----------------- .../util/ServiceBaseImpl.java | 30 ++++- .../rma/aspect/RecordAspectUnitTest.java | 51 ++++++-- .../ContentBinDuplicationUtilityUnitTest.java | 111 ------------------ 9 files changed, 89 insertions(+), 265 deletions(-) delete mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java delete mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml index 84b6bb8ba6..63242f2ab1 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -248,11 +248,6 @@ - - - - - diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index a3a01f47b0..ddd303c982 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -143,7 +143,6 @@ - diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml index f9f7a7e409..91c2f622ea 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-version-context.xml @@ -16,7 +16,6 @@ - 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 cf5e19cf26..441af631bb 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 @@ -38,7 +38,6 @@ import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; -import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; import org.alfresco.repo.content.ContentServicePolicies; import org.alfresco.repo.copy.CopyBehaviourCallback; import org.alfresco.repo.copy.CopyDetails; @@ -95,9 +94,6 @@ public class RecordAspect extends AbstractDisposableItem /** quickShare service */ private QuickShareService quickShareService; - /** Utility class for duplicating content */ - private ContentBinDuplicationUtility contentBinDuplicationUtility; - /** I18N */ private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content"; @@ -134,15 +130,6 @@ public class RecordAspect extends AbstractDisposableItem this.quickShareService = quickShareService; } - /** - * Setter for content duplication utility class - * @param contentBinDuplicationUtility ContentBinDuplicationUtility - */ - public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility) - { - this.contentBinDuplicationUtility = contentBinDuplicationUtility; - } - /** * Behaviour to ensure renditions have the appropriate extended security. * @@ -369,7 +356,7 @@ public class RecordAspect extends AbstractDisposableItem extendedSecurityService.remove(targetNodeRef); //create a new content URL for the copy - contentBinDuplicationUtility.duplicate(targetNodeRef); + createNewContentURL(targetNodeRef); } } @@ -414,7 +401,20 @@ public class RecordAspect extends AbstractDisposableItem if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() || !nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) { - contentBinDuplicationUtility.duplicate(nodeRef); + //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); + } } return null; diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java index c41e937aa1..efab5cc2ea 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java @@ -33,7 +33,6 @@ import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship; import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; -import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService; import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; @@ -65,11 +64,6 @@ public class VersionRecordAspect extends BaseBehaviourBean /** relationship service */ private RelationshipService relationshipService; - /** - * Utility class for duplicating content - */ - private ContentBinDuplicationUtility contentBinDuplicationUtility; - /** * @param recordableVersionService recordable version service */ @@ -86,16 +80,6 @@ public class VersionRecordAspect extends BaseBehaviourBean this.relationshipService = relationshipService; } - /** - * Setter for content duplication utility class - * - * @param contentBinDuplicationUtility ContentBinDuplicationUtility - */ - public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility) - { - this.contentBinDuplicationUtility = contentBinDuplicationUtility; - } - /** * If the record is a version record then delete the associated version entry * @@ -164,7 +148,7 @@ public class VersionRecordAspect extends BaseBehaviourBean if (!nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_RECORD_ORIGINATING_DETAILS)) { //create a new content URL for the version record - contentBinDuplicationUtility.duplicate(nodeRef); + createNewContentURL(nodeRef); } } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java deleted file mode 100644 index c1d7e879f0..0000000000 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.module.org_alfresco_module_rm.util; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.policy.BehaviourFilter; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.NodeRef; - -/** - * Utility class to duplicate the content of a node without triggering the audit or versioning behaviours - * @author Ross Gale - * @since 2.7.2 - */ -public class ContentBinDuplicationUtility -{ - - /** - * Behaviour filter - */ - private BehaviourFilter behaviourFilter; - - /** - * Provides methods for accessing and transforming content. - */ - private ContentService contentService; - - /** - * Setter for behaviour filter - * @param behaviourFilter BehaviourFilter - */ - public void setBehaviourFilter(BehaviourFilter behaviourFilter) - { - this.behaviourFilter = behaviourFilter; - } - - /** - * Setter for content service - * @param contentService ContentService - */ - public void setContentService(ContentService contentService) - { - this.contentService = contentService; - } - - /** - * Duplicate the content of a node without triggering the audit or versioning behaviours - * - * @param nodeRef The node with the content to duplicate - */ - public void duplicate(NodeRef nodeRef) - { - //disabling versioning and auditing - behaviourFilter.disableBehaviour(); - try - { - //create a new content URL for the copy/original node - updateContentProperty(nodeRef); - } - finally - { - //enable versioning and auditing - behaviourFilter.enableBehaviour(); - } - } - - /** - * Helper to update the content property for the node - * - * @param nodeRef the node - */ - private void updateContentProperty(NodeRef nodeRef) - { - ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); - if (reader != null) - { - ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); - writer.putContent(reader); - } - } -} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java index f7a58ea1ff..8fc5094b05 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.WeakHashMap; - +import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; @@ -39,7 +39,9 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; @@ -552,4 +554,30 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte result.add(nodeService.getType(nodeRef)); return result; } + + /** + * Helper to update the given content property for the node + * + * @param nodeRef the node + * @param contentProperty the property to be updated + */ + protected void updateContentProperty(NodeRef nodeRef, QName contentProperty) + { + ContentReader reader = contentService.getReader(nodeRef, contentProperty); + if (reader != null) + { + ContentWriter writer = contentService.getWriter(nodeRef, contentProperty, true); + writer.putContent(reader); + } + } + + /** + * Helper to create a new content URL for the node + * + * @param nodeRef the node + */ + protected void createNewContentURL(NodeRef nodeRef) + { + updateContentProperty(nodeRef, ContentModel.PROP_CONTENT); + } } 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 84d0559590..730da904f3 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 @@ -30,6 +30,8 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; 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; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,7 +39,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; -import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; +import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; @@ -68,6 +70,8 @@ public class RecordAspectUnitTest @Mock private NodeService mockNodeService; @Mock + private BehaviourFilter mockBehaviorFilter; + @Mock private ContentService mockContentService; @Mock private ContentReader mockContentReader; @@ -75,8 +79,6 @@ public class RecordAspectUnitTest private ContentWriter mockContentWriter; @Mock private ExtendedSecurityService mockExtendedSecurityService; - @Mock - private ContentBinDuplicationUtility mockContentBinDuplicationUtility; @Before public void setUp() @@ -94,7 +96,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF); + verifyBeforeAddAspectMethodsInvocations(1); } /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ @@ -107,7 +109,24 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF); + verifyBeforeAddAspectMethodsInvocations(1); + } + + /** Check that no content bin is created if the file does not have content. */ + @Test + public void testBeforeAddAspectOnFileWithNoContent() + { + when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF)); + when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null); + + recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); + + verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + verify(mockContentService, times(1)).getReader(NODE_REF, ContentModel.PROP_CONTENT); + verify(mockContentService, never()).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); } /** Check that the bin is not duplicated before adding the aspect if the node has no copies. */ @@ -119,7 +138,7 @@ public class RecordAspectUnitTest recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); - verify(mockContentBinDuplicationUtility, times(0)).duplicate(NODE_REF); + verifyBeforeAddAspectMethodsInvocations(0); } /** Check that the bin is duplicated when copying a record. */ @@ -134,6 +153,24 @@ public class RecordAspectUnitTest recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null); verify(mockExtendedSecurityService, times(1)).remove(COPY_REF); - verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF); + verify(mockContentService, times(1)).getReader(COPY_REF, ContentModel.PROP_CONTENT); + verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true); + verify(mockContentWriter, times(1)).putContent(mockContentReader); + } + + /** + * Helper to verify beforeAddAspect methods invocations + * + * @param wantedNumberOfInvocations wanted number of invocations for each method + */ + private void verifyBeforeAddAspectMethodsInvocations(int wantedNumberOfInvocations) + { + verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + verify(mockContentService, times(wantedNumberOfInvocations)).getReader(NODE_REF, ContentModel.PROP_CONTENT); + verify(mockContentService, times(wantedNumberOfInvocations)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); + verify(mockContentWriter, times(wantedNumberOfInvocations)).putContent(mockContentReader); + verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java deleted file mode 100644 index c37437433a..0000000000 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtilityUnitTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2019 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ - -package org.alfresco.module.org_alfresco_module_rm.util; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.policy.BehaviourFilter; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentService; -import org.alfresco.service.cmr.repository.ContentWriter; -import org.alfresco.service.cmr.repository.NodeRef; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * Test class for the ContentBinDuplicationUtility - * @author Ross Gale - * @since 2.7.2 - */ -public class ContentBinDuplicationUtilityUnitTest -{ - - @Mock - private ContentService contentService; - - @Mock - private BehaviourFilter behaviourFilter; - - @Mock - private ContentReader contentReader; - - @Mock - private ContentWriter contentWriter; - - @InjectMocks - private ContentBinDuplicationUtility contentBinDuplicationUtility; - - @Before - public void setUp() - { - MockitoAnnotations.initMocks(this); - } - - /** - * Tests that the requests are made to disable and re-enable the audit and versioning and to update the content bin - */ - @Test - public void testContentUrlIsUpdated() - { - NodeRef nodeRef = new NodeRef("some://test/noderef"); - when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader); - when(contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter); - contentBinDuplicationUtility.duplicate(nodeRef); - verify(contentWriter, times(1)).putContent(contentReader); - checkBehaviours(1); - } - - /** - * Test content duplication doesn't happen when node has no content - */ - @Test - public void testDuplicationDoesntHappenWithNoContent() - { - NodeRef nodeRef = new NodeRef("some://test/noderef"); - when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null); - contentBinDuplicationUtility.duplicate(nodeRef); - verify(contentWriter, times(0)).putContent(contentReader); - checkBehaviours(1); - } - - /** - * Check that the behaviours are disabled and re-enabled the correct number of times - * @param times the times the behaviours should be called - */ - private void checkBehaviours(int times) - { - verify(behaviourFilter, times(times)).disableBehaviour(); - verify(behaviourFilter, times(times)).enableBehaviour(); - } -}