From a5dc916a7eb83015237f20b6a5077b7c751fa705 Mon Sep 17 00:00:00 2001 From: cagache Date: Thu, 7 Feb 2019 17:54:46 +0200 Subject: [PATCH 01/10] MNT-20145 Don't delete the content url if the file has copies or it is a copy --- .../content/ContentDestructionComponent.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java index fb77f3efb6..5bdfd1dc33 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java @@ -33,6 +33,7 @@ import java.util.Set; import org.alfresco.model.ContentModel; import org.alfresco.model.RenditionModel; +import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.service.cmr.dictionary.DictionaryService; @@ -214,16 +215,22 @@ public class ContentDestructionComponent // get content data ContentData dataContent = (ContentData)entry.getValue(); - // if enabled cleanse content - if (isCleansingEnabled()) - { - // register for cleanse then immediate destruction - getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl()); - } - else - { - // register for immediate destruction - getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true); + // destroy the nodes content properties only if it doesn't have copies or it is a copy + // destroy the nodes content properties only if the versionedNodeRef is deleted + if (getNodeService().getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() && + getNodeService().getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() && + getNodeService().getProperty(nodeRef, RecordableVersionModel.PROP_VERSIONED_NODEREF) == null) + { // if enabled cleanse content + if (isCleansingEnabled()) + { + // register for cleanse then immediate destruction + getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl()); + } + else + { + // register for immediate destruction + getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true); + } } // clear the property From 5b477a7b64dbe951d8d56e6df3ea33740e130c8f Mon Sep 17 00:00:00 2001 From: cagache Date: Wed, 13 Feb 2019 16:00:05 +0200 Subject: [PATCH 02/10] added IT for delete classified content with copies --- .../content/ContentDestructionComponent.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java index 5bdfd1dc33..07226abc96 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java @@ -215,12 +215,11 @@ public class ContentDestructionComponent // get content data ContentData dataContent = (ContentData)entry.getValue(); - // destroy the nodes content properties only if it doesn't have copies or it is a copy - // destroy the nodes content properties only if the versionedNodeRef is deleted + // destroy the node's content properties only if it doesn't have copies or it is a copy if (getNodeService().getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() && - getNodeService().getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() && - getNodeService().getProperty(nodeRef, RecordableVersionModel.PROP_VERSIONED_NODEREF) == null) - { // if enabled cleanse content + getNodeService().getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) + { + // if enabled cleanse content if (isCleansingEnabled()) { // register for cleanse then immediate destruction From 3c47771450039ea740f3b8d8b04b973daaddf007 Mon Sep 17 00:00:00 2001 From: cagache Date: Thu, 14 Feb 2019 12:55:10 +0200 Subject: [PATCH 03/10] added behaviour to duplicate the bin before declaring a version record --- .../rm-version-context.xml | 1 + .../model/rma/aspect/VersionRecordAspect.java | 43 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 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..94ddc06345 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/VersionRecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/VersionRecordAspect.java index 9437c6c6ef..a22ce023c0 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 @@ -34,12 +34,17 @@ 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.version.RecordableVersionService; import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.model.FileFolderService; +import org.alfresco.service.cmr.repository.ContentReader; +import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.namespace.QName; /** * rmv:versionRecord behaviour bean @@ -52,14 +57,18 @@ import org.alfresco.service.cmr.version.Version; defaultType = "rmv:versionRecord" ) public class VersionRecordAspect extends BaseBehaviourBean - implements NodeServicePolicies.BeforeDeleteNodePolicy + implements NodeServicePolicies.BeforeAddAspectPolicy, + NodeServicePolicies.BeforeDeleteNodePolicy { /** recordable version service */ private RecordableVersionService recordableVersionService; /** relationship service */ private RelationshipService relationshipService; - + + /** File folder service */ + private FileFolderService fileFolderService; + /** * @param recordableVersionService recordable version service */ @@ -75,7 +84,16 @@ public class VersionRecordAspect extends BaseBehaviourBean { this.relationshipService = relationshipService; } - + + /** + * + * @param fileFolderService file folder service + */ + public void setFileFolderService(FileFolderService fileFolderService) + { + this.fileFolderService = fileFolderService; + } + /** * If the record is a version record then delete the associated version entry * @@ -129,4 +147,23 @@ public class VersionRecordAspect extends BaseBehaviourBean }); } } + + /** + * Behaviour to duplicate the bin before declaring a version record + * + * @see org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy#beforeAddAspect(org.alfresco.service.cmr.repository.NodeRef, + * org.alfresco.service.namespace.QName) + */ + @Override + @Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT) + public void beforeAddAspect(NodeRef nodeRef, QName qName) + { + //create a new content URL for the version record + ContentReader reader = fileFolderService.getReader(nodeRef); + if (reader != null) + { + ContentWriter writer = fileFolderService.getWriter(nodeRef); + writer.putContent(reader); + } + } } From 01f7bc013d4da7a73162ff96245fd818bd952c47 Mon Sep 17 00:00:00 2001 From: cagache Date: Thu, 14 Feb 2019 16:22:57 +0200 Subject: [PATCH 04/10] fixed failing tests --- .../version/RecordableVersionsBaseTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java index c75997e0e1..6fda8324da 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java @@ -238,7 +238,16 @@ public abstract class RecordableVersionsBaseTest extends BaseRMTestCase implemen if (frozenProperties.containsKey(beforePropertyName)) { Serializable frozenValue = frozenProperties.get(beforePropertyName); - assertEquals("Frozen property " + beforePropertyName.getLocalName() + " value is incorrect.", entry.getValue(), frozenValue); + if(beforePropertyName.equals(ContentModel.PROP_CONTENT)) + { + assertTrue("Frozen property " + beforePropertyName.getLocalName() + " value is incorrect.", + entry.getValue() != frozenValue); + } + else + { + assertEquals("Frozen property " + beforePropertyName.getLocalName() + " value is incorrect.", + entry.getValue(), frozenValue); + } cloneFrozenProperties.remove(beforePropertyName); } else if (!PROP_FILE_PLAN.equals(beforePropertyName) && From 54010f6ab9c4c7df02b162b2ee8d965c29a99079 Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 15 Feb 2019 16:41:18 +0200 Subject: [PATCH 05/10] MNT-20145 Duplicate the content url when declaring node as record, version as record, classifying or securing if the node has copies or it is a copy --- .../rm-model-context.xml | 1 - .../rm-service-context.xml | 1 + .../rm-version-context.xml | 1 - .../content/ContentDestructionComponent.java | 23 ++++------ .../model/rma/aspect/RecordAspect.java | 44 +++++++++---------- .../model/rma/aspect/VersionRecordAspect.java | 22 +--------- .../util/ServiceBaseImpl.java | 29 +++++++++++- 7 files changed, 61 insertions(+), 60 deletions(-) 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 4cb71d28e0..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-service-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 01ac11f766..8ae5ad48fa 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -45,6 +45,7 @@ + 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 94ddc06345..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/content/ContentDestructionComponent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java index 07226abc96..6c714ae61c 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java @@ -215,21 +215,16 @@ public class ContentDestructionComponent // get content data ContentData dataContent = (ContentData)entry.getValue(); - // destroy the node's content properties only if it doesn't have copies or it is a copy - if (getNodeService().getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() && - getNodeService().getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) + // if enabled cleanse content + if (isCleansingEnabled()) { - // if enabled cleanse content - if (isCleansingEnabled()) - { - // register for cleanse then immediate destruction - getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl()); - } - else - { - // register for immediate destruction - getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true); - } + // register for cleanse then immediate destruction + getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl()); + } + else + { + // register for immediate destruction + getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true); } // clear the property 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 b59181191b..fbc4725afe 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 @@ -51,13 +51,9 @@ import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.quickshare.QuickShareService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentData; -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.ScriptService; import org.alfresco.service.namespace.QName; @@ -98,9 +94,6 @@ public class RecordAspect extends AbstractDisposableItem /** quickShare service */ private QuickShareService quickShareService; - /** File folder service */ - private FileFolderService fileFolderService; - /** I18N */ private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content"; @@ -137,15 +130,6 @@ public class RecordAspect extends AbstractDisposableItem this.quickShareService = quickShareService; } - /** - * - * @param fileFolderService file folder service - */ - public void setFileFolderService(FileFolderService fileFolderService) - { - this.fileFolderService = fileFolderService; - } - /** * Behaviour to ensure renditions have the appropriate extended security. * @@ -376,12 +360,7 @@ public class RecordAspect extends AbstractDisposableItem extendedSecurityService.remove(targetNodeRef); //create a new content URL for the copy - ContentReader reader = fileFolderService.getReader(targetNodeRef); - if (reader != null) - { - ContentWriter writer = fileFolderService.getWriter(targetNodeRef); - writer.putContent(reader); - } + createNewContentURL(targetNodeRef); } } @@ -402,6 +381,7 @@ public class RecordAspect extends AbstractDisposableItem /** * Behaviour to remove the shared link before declare a record + * and to create new bin if the node is a copy or has copies * * @see org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy#beforeAddAspect(org.alfresco.service.cmr.repository.NodeRef, * org.alfresco.service.namespace.QName) @@ -421,6 +401,26 @@ public class RecordAspect extends AbstractDisposableItem quickShareService.unshareContent(sharedId); } + // if the node has a copy or is a copy of an existing node + if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() || + !nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) + { + //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); + } + } + return null; } }, AuthenticationUtil.getSystemUserName()); 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 a22ce023c0..f4712a8995 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 @@ -39,9 +39,6 @@ import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.service.cmr.model.FileFolderService; -import org.alfresco.service.cmr.repository.ContentReader; -import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.version.Version; import org.alfresco.service.namespace.QName; @@ -66,9 +63,6 @@ public class VersionRecordAspect extends BaseBehaviourBean /** relationship service */ private RelationshipService relationshipService; - /** File folder service */ - private FileFolderService fileFolderService; - /** * @param recordableVersionService recordable version service */ @@ -85,15 +79,6 @@ public class VersionRecordAspect extends BaseBehaviourBean this.relationshipService = relationshipService; } - /** - * - * @param fileFolderService file folder service - */ - public void setFileFolderService(FileFolderService fileFolderService) - { - this.fileFolderService = fileFolderService; - } - /** * If the record is a version record then delete the associated version entry * @@ -159,11 +144,6 @@ public class VersionRecordAspect extends BaseBehaviourBean public void beforeAddAspect(NodeRef nodeRef, QName qName) { //create a new content URL for the version record - ContentReader reader = fileFolderService.getReader(nodeRef); - if (reader != null) - { - ContentWriter writer = fileFolderService.getWriter(nodeRef); - writer.putContent(reader); - } + createNewContentURL(nodeRef); } } 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 8f45c69441..5eccd498e5 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 @@ -36,8 +36,11 @@ import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.model.FileFolderService; 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.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.namespace.QName; @@ -73,7 +76,10 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte protected AuthenticationUtil authenticationUtil; /** transactional resource helper */ - protected TransactionalResourceHelper transactionalResourceHelper; + protected TransactionalResourceHelper transactionalResourceHelper; + + /** File folder service */ + protected FileFolderService fileFolderService; /** * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) @@ -124,6 +130,16 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte this.transactionalResourceHelper = transactionalResourceHelper; } + /** + * Set the file folder service + * + * @param fileFolderService file folder service + */ + public void setFileFolderService(FileFolderService fileFolderService) + { + this.fileFolderService = fileFolderService; + } + /** * Helper to get internal node service. *

@@ -537,4 +553,15 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte result.add(nodeService.getType(nodeRef)); return result; } + + protected void createNewContentURL(NodeRef nodeRef) + { + //create a new content URL for the copy + ContentReader reader = fileFolderService.getReader(nodeRef); + if (reader != null) + { + ContentWriter writer = fileFolderService.getWriter(nodeRef); + writer.putContent(reader); + } + } } From b6d6094ebeea6a6ca6b3accfb0ddfa4d14defe7d Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 15 Feb 2019 17:11:04 +0200 Subject: [PATCH 06/10] added javadoc and removed unused imports --- .../content/ContentDestructionComponent.java | 1 - .../org_alfresco_module_rm/util/ServiceBaseImpl.java | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java index 6c714ae61c..fb77f3efb6 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/content/ContentDestructionComponent.java @@ -33,7 +33,6 @@ import java.util.Set; import org.alfresco.model.ContentModel; import org.alfresco.model.RenditionModel; -import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.service.cmr.dictionary.DictionaryService; 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 5eccd498e5..bccb9b0c2b 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 @@ -74,7 +74,7 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte /** authentication helper */ protected AuthenticationUtil authenticationUtil; - + /** transactional resource helper */ protected TransactionalResourceHelper transactionalResourceHelper; @@ -554,9 +554,14 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte return result; } + /** + * Helper to create a new content URL for the node + * + * @param nodeRef the node + */ protected void createNewContentURL(NodeRef nodeRef) { - //create a new content URL for the copy + //create a new content URL for the node ContentReader reader = fileFolderService.getReader(nodeRef); if (reader != null) { From ab762cf8f512c579355470414079dd4ba5dfb840 Mon Sep 17 00:00:00 2001 From: cagache Date: Mon, 18 Feb 2019 10:57:16 +0200 Subject: [PATCH 07/10] addressed code review comments --- .../rm-service-context.xml | 2 +- .../model/rma/aspect/RecordAspect.java | 8 +--- .../util/ServiceBaseImpl.java | 39 ++++++++++++------- .../version/RecordableVersionsBaseTest.java | 2 +- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 8ae5ad48fa..de5519decd 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -45,7 +45,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 fbc4725afe..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 @@ -335,11 +335,7 @@ public class RecordAspect extends AbstractDisposableItem /** * On copy complete behaviour for record aspect. * - * @param classRef - * @param sourceNodeRef - * @param targetNodeRef - * @param copyToNewNode - * @param copyMap + * @see org.alfresco.repo.copy.CopyServicePolicies.OnCopyCompletePolicy#onCopyComplete(QName, NodeRef, NodeRef, boolean, Map) */ @Override @Behaviour @@ -405,7 +401,7 @@ public class RecordAspect extends AbstractDisposableItem if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() || !nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty()) { - //disabling versioning and auditing + //disable versioning and auditing behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE); behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE); try 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 bccb9b0c2b..77b7ab0d79 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 @@ -28,9 +28,11 @@ package org.alfresco.module.org_alfresco_module_rm.util; import java.util.Map; +import java.util.Optional; 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; @@ -40,6 +42,7 @@ import org.alfresco.service.cmr.model.FileFolderService; 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; @@ -78,8 +81,8 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte /** transactional resource helper */ protected TransactionalResourceHelper transactionalResourceHelper; - /** File folder service */ - protected FileFolderService fileFolderService; + /** Content service */ + protected ContentService contentService; /** * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) @@ -131,13 +134,13 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte } /** - * Set the file folder service + * Set the content service * - * @param fileFolderService file folder service + * @param contentService content service */ - public void setFileFolderService(FileFolderService fileFolderService) + public void setContentService(ContentService contentService) { - this.fileFolderService = fileFolderService; + this.contentService = contentService; } /** @@ -554,6 +557,22 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte 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 * @@ -561,12 +580,6 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte */ protected void createNewContentURL(NodeRef nodeRef) { - //create a new content URL for the node - ContentReader reader = fileFolderService.getReader(nodeRef); - if (reader != null) - { - ContentWriter writer = fileFolderService.getWriter(nodeRef); - writer.putContent(reader); - } + updateContentProperty(nodeRef, ContentModel.PROP_CONTENT); } } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java index 6fda8324da..2727c0b730 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/version/RecordableVersionsBaseTest.java @@ -240,7 +240,7 @@ public abstract class RecordableVersionsBaseTest extends BaseRMTestCase implemen Serializable frozenValue = frozenProperties.get(beforePropertyName); if(beforePropertyName.equals(ContentModel.PROP_CONTENT)) { - assertTrue("Frozen property " + beforePropertyName.getLocalName() + " value is incorrect.", + assertTrue("Content property value should be different.", entry.getValue() != frozenValue); } else From a5629acc2ab10e74a34280aa271c426884846d34 Mon Sep 17 00:00:00 2001 From: cagache Date: Mon, 18 Feb 2019 15:16:48 +0200 Subject: [PATCH 08/10] added unit tests --- .../util/ServiceBaseImpl.java | 2 - .../rma/aspect/RecordAspectUnitTest.java | 139 ++++++++++++++++++ 2 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java 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 77b7ab0d79..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 @@ -28,7 +28,6 @@ package org.alfresco.module.org_alfresco_module_rm.util; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.WeakHashMap; @@ -38,7 +37,6 @@ import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.service.cmr.dictionary.DictionaryService; -import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentReader; 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 new file mode 100644 index 0000000000..78c6263dbf --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java @@ -0,0 +1,139 @@ +/* + * #%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.model.rma.aspect; + +import static java.util.Arrays.asList; + +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; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.alfresco.model.ContentModel; +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; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +/** + * Unit tests for the {@link RecordAspect}. + * + * @author Claudia Agache + */ +public class RecordAspectUnitTest +{ + private static final NodeRef NODE_REF = new NodeRef("node://Ref/"); + private static final NodeRef COPY_REF = new NodeRef("node://Copy/"); + private static final AssociationRef SOURCE_ASSOC_REF = new AssociationRef(COPY_REF, ContentModel.ASSOC_ORIGINAL, + NODE_REF); + private static final AssociationRef TARGET_ASSOC_REF = new AssociationRef(NODE_REF, ContentModel.ASSOC_ORIGINAL, + COPY_REF); + + @InjectMocks + private RecordAspect recordAspect; + @Mock + private NodeService mockNodeService; + @Mock + private BehaviourFilter mockBehaviorFilter; + @Mock + private ContentService mockContentService; + @Mock + private ContentReader mockContentReader; + @Mock + private ContentWriter mockContentWriter; + + @Before + public void setUp() + { + initMocks(this); + } + + /** Check that the bin is duplicated before adding the aspect if the file has a copy. */ + @Test + public void testDuplicateBinForFileWithCopy() + { + when(mockNodeService.getSourceAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(SOURCE_ASSOC_REF)); + when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader); + when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter); + + 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, times(1)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); + verify(mockContentWriter, times(1)).putContent(mockContentReader); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + } + + /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ + @Test + public void testDuplicateBinForCopy() + { + when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF)); + when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader); + when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter); + + 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, times(1)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); + verify(mockContentWriter, times(1)).putContent(mockContentReader); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); + verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + } + + /** Check that no content bin is created if the file does not have content. */ + @Test + public void testFileWithNoContent() + { + 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)); + } +} From db47a2f6f2921e6cafda06454d17e152b57cd502 Mon Sep 17 00:00:00 2001 From: cagache Date: Mon, 18 Feb 2019 17:08:05 +0200 Subject: [PATCH 09/10] addressed code review comments --- .../rma/aspect/RecordAspectUnitTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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 78c6263dbf..b11aa53026 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 @@ -37,6 +37,7 @@ import static org.mockito.Mockito.when; 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.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ContentReader; @@ -75,6 +76,8 @@ public class RecordAspectUnitTest private ContentReader mockContentReader; @Mock private ContentWriter mockContentWriter; + @Mock + private ExtendedSecurityService mockExtendedSecurityService; @Before public void setUp() @@ -84,7 +87,7 @@ public class RecordAspectUnitTest /** Check that the bin is duplicated before adding the aspect if the file has a copy. */ @Test - public void testDuplicateBinForFileWithCopy() + public void testDuplicateBinBeforeAddingAspectForFileWithCopy() { when(mockNodeService.getSourceAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(SOURCE_ASSOC_REF)); when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader); @@ -103,7 +106,7 @@ public class RecordAspectUnitTest /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ @Test - public void testDuplicateBinForCopy() + public void testDuplicateBinBeforeAddingAspectForCopy() { when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF)); when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader); @@ -136,4 +139,21 @@ public class RecordAspectUnitTest verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); } + + /** Check that the bin is duplicated when copying a record. */ + @Test + public void testDuplicateBinWhenCopyingRecord() + { + when(mockNodeService.exists(COPY_REF)).thenReturn(true); + when(mockNodeService.hasAspect(COPY_REF, ASPECT_RECORD)).thenReturn(true); + when(mockContentService.getReader(COPY_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader); + when(mockContentService.getWriter(COPY_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter); + + 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); + } } From fb02ac0afa14090394f98a29504676e658228e08 Mon Sep 17 00:00:00 2001 From: cagache Date: Tue, 19 Feb 2019 09:37:36 +0200 Subject: [PATCH 10/10] addressed code review comments --- .../rma/aspect/RecordAspectUnitTest.java | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) 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 b11aa53026..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 @@ -27,6 +27,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_RECORD; import static org.mockito.Matchers.eq; @@ -95,13 +96,7 @@ public class RecordAspectUnitTest 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, times(1)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); - verify(mockContentWriter, times(1)).putContent(mockContentReader); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + verifyBeforeAddAspectMethodsInvocations(1); } /** Check that the bin is duplicated before adding the aspect if the file is a copy. */ @@ -114,18 +109,12 @@ public class RecordAspectUnitTest 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, times(1)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true); - verify(mockContentWriter, times(1)).putContent(mockContentReader); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE)); - verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE)); + verifyBeforeAddAspectMethodsInvocations(1); } /** Check that no content bin is created if the file does not have content. */ @Test - public void testFileWithNoContent() + 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); @@ -140,6 +129,18 @@ public class RecordAspectUnitTest 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. */ + @Test + public void testNotDuplicateBinForFileWithNoCopies() + { + when(mockNodeService.getSourceAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(emptyList()); + when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(emptyList()); + + recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD); + + verifyBeforeAddAspectMethodsInvocations(0); + } + /** Check that the bin is duplicated when copying a record. */ @Test public void testDuplicateBinWhenCopyingRecord() @@ -156,4 +157,20 @@ 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)); + } }