From 764b13d4735bc33e7470197e2a3ddc4992e08c93 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 12:41:39 +0200 Subject: [PATCH] RM-4619 - convert the folder nodes before setting identifier --- .../type/RecordsManagementContainerType.java | 35 ++++++++++++++++++- .../rma/type/UnfiledRecordContainerType.java | 9 +++++ .../rma/type/UnfiledRecordFolderType.java | 9 +++++ ...ecordsManagementContainerTypeUnitTest.java | 34 +++++++++--------- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java index ff282ac258..0b9f56ec8a 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java @@ -137,7 +137,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean final NodeRef child = childAssocRef.getChildRef(); if (nodeService.exists(child)) { - QName childType = nodeService.getType(child); + QName childType = convertNodeToFileplanComponent(child, nodeService.getType(child), nodeService.getType(childAssocRef.getParentRef())); // We only care about "folder" or sub-types that are not hidden. // Some modules use hidden files to store information (see RM-3283) @@ -205,4 +205,37 @@ public class RecordsManagementContainerType extends BaseBehaviourBean } }); } + + /** + * Converted the child node to a fileplan component + * The conversion is needed here to be able to generate the identifier + * If there is no conversion rule for the created type nothing happens and the current type is returned + * + * @param child ref to the new child + * @param childType the type of the new child + * @param parentType the type of the parent node + * @return the new type of the child node + */ + protected QName convertNodeToFileplanComponent(final NodeRef child, final QName childType, final QName parentType) + { + if(childType.equals(ContentModel.TYPE_FOLDER)) + { + if(parentType.equals(TYPE_FILE_PLAN)) + { + nodeService.setType(child, TYPE_RECORD_CATEGORY); + return TYPE_RECORD_CATEGORY; + } + if(parentType.equals(TYPE_RECORD_CATEGORY)) + { + nodeService.setType(child, TYPE_RECORD_FOLDER); + return TYPE_RECORD_FOLDER; + } + if(parentType.equals(TYPE_UNFILED_RECORD_CONTAINER) || parentType.equals(TYPE_UNFILED_RECORD_FOLDER)) + { + nodeService.setType(child, TYPE_UNFILED_RECORD_FOLDER); + return TYPE_UNFILED_RECORD_FOLDER; + } + } + return childType; + } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerType.java index d844352e48..a64bbe8e59 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerType.java @@ -76,6 +76,15 @@ public class UnfiledRecordContainerType extends BaseBehaviourBean @Behaviour(kind = BehaviourKind.ASSOCIATION) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode) { + // We need to automatically cast the created folder to record folder if it is a plain folder + // This occurs if the RM folder has been created via IMap, WebDav, etc. Don't check subtypes. + // Some modules use hidden folder subtypes to store information (see RM-3283). + QName childType = nodeService.getType(childAssocRef.getChildRef()); + if (childType.equals(ContentModel.TYPE_FOLDER)) + { + nodeService.setType(childAssocRef.getChildRef(), TYPE_UNFILED_RECORD_FOLDER); + } + // check the created child is of an accepted type validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordFolderType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordFolderType.java index fad07887fe..51f4f62981 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordFolderType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordFolderType.java @@ -55,6 +55,15 @@ public class UnfiledRecordFolderType extends BaseBehaviourBean @Behaviour(kind = BehaviourKind.ASSOCIATION) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean isNewNode) { + // We need to automatically cast the created folder to record folder if it is a plain folder + // This occurs if the RM folder has been created via IMap, WebDav, etc. Don't check subtypes. + // Some modules use hidden folder subtypes to store information (see RM-3283). + QName childType = nodeService.getType(childAssocRef.getChildRef()); + if (childType.equals(ContentModel.TYPE_FOLDER)) + { + nodeService.setType(childAssocRef.getChildRef(), TYPE_UNFILED_RECORD_FOLDER); + } + // check the created child is of an accepted type validateNewChildAssociationSubTypesIncluded(childAssocRef.getChildRef(), ACCEPTED_NON_UNIQUE_CHILD_TYPES); } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java index cb12360323..230cd235ec 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeUnitTest.java @@ -37,6 +37,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.TestModel; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; import org.junit.Test; import org.mockito.InjectMocks; @@ -51,16 +52,18 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest private @InjectMocks RecordsManagementContainerType recordManagementContainerType; /** - * Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN + * Having the Unfilled Record container and a non RM folder subtype node * When adding a child association between the folder and the container * Then the new folder should not be altered + * + * Outlook creates a hidden folder subtype to store attachments and we don't want to change the type of those folders */ @Test - public void testAddHiddenFolderToRMContainer() + public void testAddNonRMFolderSubtypeToRMContainer() { - /* Having a RM container and a folder with ASPECT_HIDDEN applied */ + /* Having a RM container and a non RM folder subtype node */ NodeRef rmContainer = generateRMContainer(); - NodeRef rmFolder = generateFolderNode(true); + NodeRef rmFolder = generateNonRmFolderSubtypeNode(); /* * When adding a child association between the folder and the container @@ -86,22 +89,21 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest } /** - * Generates a folder node - * @param hasHiddenAspect does the folder node have the aspect ASPECT_HIDDEN + * Generates a folder subtype node * @return reference to the created folder */ - private NodeRef generateFolderNode(boolean hasHiddenAspect) + private NodeRef generateNonRmFolderSubtypeNode() { - NodeRef rmFolder = generateNodeRef(); - when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_FOLDER)).thenReturn(true); - when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false); - when(mockedNodeService.getType(rmFolder)).thenReturn(ContentModel.TYPE_FOLDER); - when(mockedNodeService.exists(rmFolder)).thenReturn(true); - when(mockedNodeService.hasAspect(rmFolder, ContentModel.ASPECT_HIDDEN)).thenReturn(hasHiddenAspect); - when(mockedNodeService.hasAspect(rmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); - return rmFolder; + NodeRef folder = generateNodeRef(); + QName folderSubtype = QName.createQName("test", "folderSubtype"); + when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_FOLDER)).thenReturn(true); + when(mockedDictionaryService.isSubClass(folderSubtype, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false); + when(mockedNodeService.getType(folder)).thenReturn(folderSubtype); + when(mockedNodeService.exists(folder)).thenReturn(true); + when(mockedNodeService.hasAspect(folder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + return folder; } - + /** * Generates a folder node * @return reference to the created folder