From 764b13d4735bc33e7470197e2a3ddc4992e08c93 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 12:41:39 +0200 Subject: [PATCH 1/8] 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 From 92fa327f1ed762b541b73838a962a351703d285a Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 16:17:22 +0200 Subject: [PATCH 2/8] RM-4619 - updated unit tests --- .../type/RecordsManagementContainerType.java | 12 +- .../test/integration/issue/RM4619Test.java | 34 ++++- ...ecordsManagementContainerTypeUnitTest.java | 126 +++++++++++++++--- 3 files changed, 143 insertions(+), 29 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 0b9f56ec8a..b507be0558 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 = convertNodeToFileplanComponent(child, nodeService.getType(child), nodeService.getType(childAssocRef.getParentRef())); + QName childType = convertNodeToFileplanComponent(childAssocRef); // We only care about "folder" or sub-types that are not hidden. // Some modules use hidden files to store information (see RM-3283) @@ -211,13 +211,15 @@ public class RecordsManagementContainerType extends BaseBehaviourBean * 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 + * @param childAssocRef reference to the new association * @return the new type of the child node */ - protected QName convertNodeToFileplanComponent(final NodeRef child, final QName childType, final QName parentType) + protected QName convertNodeToFileplanComponent(final ChildAssociationRef childAssocRef) { + NodeRef child = childAssocRef.getChildRef(); + QName childType = nodeService.getType(child); + QName parentType = nodeService.getType(childAssocRef.getParentRef()); + if(childType.equals(ContentModel.TYPE_FOLDER)) { if(parentType.equals(TYPE_FILE_PLAN)) diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java index 6b83327468..c61dec7f92 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java @@ -55,7 +55,8 @@ public class RM4619Test extends BaseRMTestCase public Void run() throws Exception { FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER); - assertEquals(info.getType(), TYPE_RECORD_CATEGORY); + assertEquals(TYPE_RECORD_CATEGORY, info.getType()); + assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); return null; } @@ -75,7 +76,36 @@ public class RM4619Test extends BaseRMTestCase public Void run() throws Exception { FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER); - assertEquals(info.getType(), TYPE_RECORD_FOLDER); + assertEquals(TYPE_RECORD_FOLDER, info.getType()); + assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); + return null; + } + + }, ADMIN_USER); + } + + /** + * Given the RM site is created + * When we create a regular folder in the unfiled record container + * Then the folder is immediately converted to a unfiled record folder + * + * And when we create another regular folder in that unfiled record folder + * Then the folder is also immediately converted to a unfiled record folder + */ + public void testConvertFolderToUnfiledRecordFolder() throws Exception + { + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + FileInfo folder1 = fileFolderService.create(unfiledContainer, GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder1.getType()); + assertNotNull(folder1.getProperties().get(PROP_IDENTIFIER)); + + FileInfo folder2 = fileFolderService.create(folder1.getNodeRef(), GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder2.getType()); + assertNotNull(folder2.getProperties().get(PROP_IDENTIFIER)); return null; } 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 230cd235ec..6d007b3dd2 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 @@ -27,6 +27,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,7 +38,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.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -51,6 +52,21 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest /** test object */ private @InjectMocks RecordsManagementContainerType recordManagementContainerType; + @Before + public void before() throws Exception + { + super.before(); + + when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_FOLDER)).thenReturn(true); + when(mockedDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false); + + when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_FOLDER)).thenReturn(true); + when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false); + + when(mockedDictionaryService.isSubClass(TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER)).thenReturn(true); + when(mockedDictionaryService.isSubClass(TYPE_RECORD_CATEGORY, ContentModel.TYPE_SYSTEM_FOLDER)).thenReturn(false); + } + /** * Having the Unfilled Record container and a non RM folder subtype node * When adding a child association between the folder and the container @@ -63,19 +79,90 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest { /* Having a RM container and a non RM folder subtype node */ NodeRef rmContainer = generateRMContainer(); - NodeRef rmFolder = generateNonRmFolderSubtypeNode(); + NodeRef folder = generateNonRmFolderSubtypeNode(); /* * When adding a child association between the folder and the container */ - ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, folder); recordManagementContainerType.onCreateChildAssociation(childAssoc, true); /* The type should not be changed and no aspects should be added */ verify(mockedNodeService, never()).setType(any(), any()); - verify(mockedNodeService, never()).addAspect(any(), any(), any()); } + /** + * Having the fileplan and a non RM folder node + * When adding a child association between the fileplan and the folder + * Then the new folder should be converted to a record category + */ + @Test + public void testAddFolderInFilePlan() + { + NodeRef fileplan = generateNodeRef(); + when(mockedNodeService.getType(fileplan)).thenReturn(TYPE_FILE_PLAN); + NodeRef folder = generateNonRmFolderNode(); + + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, fileplan, ContentModel.ASSOC_CONTAINS, folder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + verify(mockedNodeService).setType(folder, TYPE_RECORD_CATEGORY); + } + + /** + * Having a record category and a non RM folder node + * When adding a child association between the record category and the folder + * Then the new folder should be converted to a record folder + */ + @Test + public void testAddFolderInRecordCategory() + { + NodeRef category = generateNodeRef(); + when(mockedNodeService.getType(category)).thenReturn(TYPE_RECORD_CATEGORY); + NodeRef folder = generateNonRmFolderNode(); + + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, category, ContentModel.ASSOC_CONTAINS, folder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + verify(mockedNodeService).setType(folder, TYPE_RECORD_FOLDER); + } + + /** + * Having an unfiled record container and a non RM folder node + * When adding a child association between the container and the folder + * Then the new folder should be converted to a unfiled record folder + */ + @Test + public void testAddFolderInUnfiledRecordContainer() + { + NodeRef unfiledRecordContainer = generateNodeRef(); + when(mockedNodeService.getType(unfiledRecordContainer)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER); + NodeRef folder = generateNonRmFolderNode(); + + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, unfiledRecordContainer, ContentModel.ASSOC_CONTAINS, folder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + verify(mockedNodeService).setType(folder, TYPE_UNFILED_RECORD_FOLDER); + } + + /** + * Having an unfiled record folder and a non RM folder node + * When adding a child association between the unfiled record folder and the regular folder + * Then the new folder should be converted to a unfiled record folder + */ + @Test + public void testAddFolderInUnfiledRecordFolder() + { + NodeRef unfiledRecordFolder = generateNodeRef(); + when(mockedNodeService.getType(unfiledRecordFolder)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); + NodeRef folder = generateNonRmFolderNode(); + + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, unfiledRecordFolder, ContentModel.ASSOC_CONTAINS, folder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + verify(mockedNodeService).setType(folder, TYPE_UNFILED_RECORD_FOLDER); + } + /** * Generates a record management container * @return reference to the generated container @@ -84,38 +171,33 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest { NodeRef rmContainer = generateNodeRef(); when(mockedNodeService.getType(rmContainer)).thenReturn(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); - when(mockedDictionaryService.isSubClass(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER, TYPE_FILE_PLAN)).thenReturn(false); return rmContainer; } /** - * Generates a folder subtype node + * Generates a non RM folder subtype node * @return reference to the created folder */ private NodeRef generateNonRmFolderSubtypeNode() { - 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; + NodeRef nonRmFolder = generateNodeRef(); + + when(mockedNodeService.getType(nonRmFolder)).thenReturn(TestModel.NOT_RM_FOLDER_TYPE); + when(mockedNodeService.exists(nonRmFolder)).thenReturn(true); + when(mockedNodeService.hasAspect(nonRmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + return nonRmFolder; } /** - * Generates a folder node + * Generates a non RM folder node * @return reference to the created folder */ private NodeRef generateNonRmFolderNode() { - NodeRef nonRmFolder = generateNodeRef(); - when(mockedDictionaryService.isSubClass(TestModel.NOT_RM_FOLDER_TYPE, ContentModel.TYPE_FOLDER)).thenReturn(true); - when(mockedNodeService.getType(nonRmFolder)).thenReturn(TestModel.NOT_RM_FOLDER_TYPE); - when(mockedNodeService.exists(nonRmFolder)).thenReturn(true); - when(mockedNodeService.hasAspect(nonRmFolder, ContentModel.ASPECT_HIDDEN)).thenReturn(false); - when(mockedNodeService.hasAspect(nonRmFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); - return nonRmFolder; + NodeRef regularFolder = generateNodeRef(); + when(mockedNodeService.getType(regularFolder)).thenReturn(ContentModel.TYPE_FOLDER); + when(mockedNodeService.exists(regularFolder)).thenReturn(true); + when(mockedNodeService.hasAspect(regularFolder, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + return regularFolder; } } From 0b81dd90d69113b62c003132dcabe6d4a64e2daf Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 17:51:16 +0200 Subject: [PATCH 3/8] RM-4619 - after doing the automated conversion the record component identifier is editable --- .../RecordComponentIdentifierAspect.java | 9 +- .../test/integration/issue/RM4619Test.java | 98 ++++++++++++++++--- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java index 112a68efcb..2fda63641b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java @@ -65,7 +65,7 @@ import org.springframework.extensions.surf.util.I18NUtil; public class RecordComponentIdentifierAspect extends BaseBehaviourBean implements NodeServicePolicies.OnUpdatePropertiesPolicy, NodeServicePolicies.BeforeDeleteNodePolicy, - NodeServicePolicies.OnCreateNodePolicy, + NodeServicePolicies.OnAddAspectPolicy, CopyServicePolicies.OnCopyCompletePolicy { /** I18N */ @@ -258,7 +258,7 @@ public class RecordComponentIdentifierAspect extends BaseBehaviourBean notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT ) @Override - public void onCreateNode(final ChildAssociationRef childAssocRef) + public void onAddAspect(final NodeRef nodeRef, final QName aspectTypeQName) { AuthenticationUtil.runAsSystem(new RunAsWork() { @@ -268,10 +268,9 @@ public class RecordComponentIdentifierAspect extends BaseBehaviourBean * When creating a new record the identifier is writable to allow the upload in multiple steps. * On transaction commit make the identifier read only (remove the editable aspect). */ - NodeRef newNode = childAssocRef.getChildRef(); - if(nodeService.exists(newNode)) + if(nodeService.exists(nodeRef)) { - nodeService.setProperty(newNode, RecordsManagementModel.PROP_ID_IS_TEMPORARILY_EDITABLE, false); + nodeService.setProperty(nodeRef, RecordsManagementModel.PROP_ID_IS_TEMPORARILY_EDITABLE, false); } return null; } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java index c61dec7f92..9360f23fe1 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java @@ -28,6 +28,7 @@ package org.alfresco.module.org_alfresco_module_rm.test.integration.issue; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; import org.alfresco.service.cmr.model.FileInfo; +import org.alfresco.service.cmr.repository.NodeRef; import org.springframework.extensions.webscripts.GUID; /** @@ -49,14 +50,30 @@ public class RM4619Test extends BaseRMTestCase */ public void testConvertFolderToCategory() throws Exception { + /* + * Create a folder in the unfiled record container and check it is immediately converted + */ + final NodeRef recordCategory = doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_RECORD_CATEGORY, info.getType()); + assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); + return info.getNodeRef(); + } + }, ADMIN_USER); + + /* + * Check that when the transaction ends the identifier is no longer editable + */ doTestInTransaction(new Test() { @Override public Void run() throws Exception { - FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER); - assertEquals(TYPE_RECORD_CATEGORY, info.getType()); - assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); + assertFalse((Boolean)nodeService.getProperty(recordCategory, PROP_ID_IS_TEMPORARILY_EDITABLE)); return null; } @@ -70,14 +87,30 @@ public class RM4619Test extends BaseRMTestCase */ public void testConvertFolderToRecordFolder() throws Exception { + /* + * Create a folder in a record category and check it is immediately converted + */ + final NodeRef recordFolder = doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_RECORD_FOLDER, info.getType()); + assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); + return info.getNodeRef(); + } + }, ADMIN_USER); + + /* + * Check that when the transaction ends the identifier is no longer editable + */ doTestInTransaction(new Test() { @Override public Void run() throws Exception { - FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER); - assertEquals(TYPE_RECORD_FOLDER, info.getType()); - assertNotNull(info.getProperties().get(PROP_IDENTIFIER)); + assertFalse((Boolean)nodeService.getProperty(recordFolder, PROP_ID_IS_TEMPORARILY_EDITABLE)); return null; } @@ -94,18 +127,59 @@ public class RM4619Test extends BaseRMTestCase */ public void testConvertFolderToUnfiledRecordFolder() throws Exception { + /* + * Create a folder in the unfiled record container and check it is immediately converted + */ + final NodeRef folder1 = doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + FileInfo folder = fileFolderService.create(unfiledContainer, GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder.getType()); + assertNotNull(folder.getProperties().get(PROP_IDENTIFIER)); + return folder.getNodeRef(); + } + }, ADMIN_USER); + + /* + * Check that when the transaction ends the identified is no longer editable + */ doTestInTransaction(new Test() { @Override public Void run() throws Exception { - FileInfo folder1 = fileFolderService.create(unfiledContainer, GUID.generate(), TYPE_FOLDER); - assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder1.getType()); - assertNotNull(folder1.getProperties().get(PROP_IDENTIFIER)); + assertFalse((Boolean)nodeService.getProperty(folder1, PROP_ID_IS_TEMPORARILY_EDITABLE)); + return null; + } + + }, ADMIN_USER); - FileInfo folder2 = fileFolderService.create(folder1.getNodeRef(), GUID.generate(), TYPE_FOLDER); - assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder2.getType()); - assertNotNull(folder2.getProperties().get(PROP_IDENTIFIER)); + /* + * Create a folder in the unfiled record folder and check it is immediately converted + */ + final NodeRef folder2 = doTestInTransaction(new Test() + { + @Override + public NodeRef run() throws Exception + { + FileInfo folder = fileFolderService.create(folder1, GUID.generate(), TYPE_FOLDER); + assertEquals(TYPE_UNFILED_RECORD_FOLDER, folder.getType()); + assertNotNull(folder.getProperties().get(PROP_IDENTIFIER)); + return folder.getNodeRef(); + } + }, ADMIN_USER); + + /* + * Check that when the transaction ends the identified is no longer editable + */ + doTestInTransaction(new Test() + { + @Override + public Void run() throws Exception + { + assertFalse((Boolean)nodeService.getProperty(folder2, PROP_ID_IS_TEMPORARILY_EDITABLE)); return null; } From 2e39b26c6a4ac3b0928ae956cc397cc8947b41ef Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 20:11:01 +0200 Subject: [PATCH 4/8] RM-4619 - add the rm search aspect when a record folder is created via conversion --- .../RecordsManagementSearchBehaviour.java | 29 +++++++++++++++++++ .../test/integration/issue/RM4619Test.java | 2 ++ 2 files changed, 31 insertions(+) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java index ac3ad58ad1..05a215bad9 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java @@ -234,6 +234,11 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel TYPE_RECORD_FOLDER, new JavaBehaviour(this, "recordFolderCreate", NotificationFrequency.TRANSACTION_COMMIT)); + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onSetNodeType"), + TYPE_RECORD_FOLDER, + new JavaBehaviour(this, "convertedToOrFromRecordFolder", NotificationFrequency.TRANSACTION_COMMIT)); + // Vital Records Review Details Rollup this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), @@ -428,6 +433,30 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel }); } + /** + * On update type to or from record folder behaviour implmentation + * @param nodeRef the updated node + * @param oldType the type the node had before update + * @param newType the type the node has after update + */ + public void convertedToOrFromRecordFolder(NodeRef nodeRef, QName oldType, QName newType) + { + AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork() + { + @Override + public Void doWork() throws Exception + { + // If the node has been updated to a record folder + if (newType.equals(TYPE_RECORD_FOLDER) && nodeService.exists(nodeRef)) + { + applySearchAspect(nodeRef); + setupDispositionScheduleProperties(nodeRef); + } + + return null; + } + }); + } /** * Helper method to setup the disposition schedule properties * diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java index 9360f23fe1..9e55647d26 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java @@ -104,6 +104,7 @@ public class RM4619Test extends BaseRMTestCase /* * Check that when the transaction ends the identifier is no longer editable + * And the record folder has the ASPECT_RM_SEARCH aspect */ doTestInTransaction(new Test() { @@ -111,6 +112,7 @@ public class RM4619Test extends BaseRMTestCase public Void run() throws Exception { assertFalse((Boolean)nodeService.getProperty(recordFolder, PROP_ID_IS_TEMPORARILY_EDITABLE)); + assertTrue(nodeService.hasAspect(recordFolder, ASPECT_RM_SEARCH)); return null; } From 29deea36ad020ec78625626ddcbcb8396c1e0693 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 27 Feb 2017 22:23:04 +0200 Subject: [PATCH 5/8] RM-4619 - fixed java7 compilation error --- .../model/behaviour/RecordsManagementSearchBehaviour.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java index 05a215bad9..6835ce016e 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java @@ -434,12 +434,12 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel } /** - * On update type to or from record folder behaviour implmentation + * On update type to or from record folder behaviour implementation * @param nodeRef the updated node * @param oldType the type the node had before update * @param newType the type the node has after update */ - public void convertedToOrFromRecordFolder(NodeRef nodeRef, QName oldType, QName newType) + public void convertedToOrFromRecordFolder(final NodeRef nodeRef, final QName oldType, final QName newType) { AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork() { From 98bce296d23c40ca1f9851e0315bba0fd368f214 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Wed, 1 Mar 2017 20:46:22 +0200 Subject: [PATCH 6/8] Revert "RM-4619 - add the rm search aspect when a record folder is created via conversion" This reverts commit 2e39b26c6a4ac3b0928ae956cc397cc8947b41ef. --- .../RecordsManagementSearchBehaviour.java | 29 ------------------- .../test/integration/issue/RM4619Test.java | 2 -- 2 files changed, 31 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java index 6835ce016e..ac3ad58ad1 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java @@ -234,11 +234,6 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel TYPE_RECORD_FOLDER, new JavaBehaviour(this, "recordFolderCreate", NotificationFrequency.TRANSACTION_COMMIT)); - this.policyComponent.bindClassBehaviour( - QName.createQName(NamespaceService.ALFRESCO_URI, "onSetNodeType"), - TYPE_RECORD_FOLDER, - new JavaBehaviour(this, "convertedToOrFromRecordFolder", NotificationFrequency.TRANSACTION_COMMIT)); - // Vital Records Review Details Rollup this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), @@ -433,30 +428,6 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel }); } - /** - * On update type to or from record folder behaviour implementation - * @param nodeRef the updated node - * @param oldType the type the node had before update - * @param newType the type the node has after update - */ - public void convertedToOrFromRecordFolder(final NodeRef nodeRef, final QName oldType, final QName newType) - { - AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork() - { - @Override - public Void doWork() throws Exception - { - // If the node has been updated to a record folder - if (newType.equals(TYPE_RECORD_FOLDER) && nodeService.exists(nodeRef)) - { - applySearchAspect(nodeRef); - setupDispositionScheduleProperties(nodeRef); - } - - return null; - } - }); - } /** * Helper method to setup the disposition schedule properties * diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java index 9e55647d26..9360f23fe1 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java @@ -104,7 +104,6 @@ public class RM4619Test extends BaseRMTestCase /* * Check that when the transaction ends the identifier is no longer editable - * And the record folder has the ASPECT_RM_SEARCH aspect */ doTestInTransaction(new Test() { @@ -112,7 +111,6 @@ public class RM4619Test extends BaseRMTestCase public Void run() throws Exception { assertFalse((Boolean)nodeService.getProperty(recordFolder, PROP_ID_IS_TEMPORARILY_EDITABLE)); - assertTrue(nodeService.hasAspect(recordFolder, ASPECT_RM_SEARCH)); return null; } From 1b366d5dae2a6f870d30d904750b3eeb0b20eb76 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Wed, 1 Mar 2017 21:32:00 +0200 Subject: [PATCH 7/8] Revert "Revert "RM-4619 - add the rm search aspect when a record folder is created via conversion"" This reverts commit 98bce296d23c40ca1f9851e0315bba0fd368f214. --- .../RecordsManagementSearchBehaviour.java | 29 +++++++++++++++++++ .../test/integration/issue/RM4619Test.java | 2 ++ 2 files changed, 31 insertions(+) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java index ac3ad58ad1..6835ce016e 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/behaviour/RecordsManagementSearchBehaviour.java @@ -234,6 +234,11 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel TYPE_RECORD_FOLDER, new JavaBehaviour(this, "recordFolderCreate", NotificationFrequency.TRANSACTION_COMMIT)); + this.policyComponent.bindClassBehaviour( + QName.createQName(NamespaceService.ALFRESCO_URI, "onSetNodeType"), + TYPE_RECORD_FOLDER, + new JavaBehaviour(this, "convertedToOrFromRecordFolder", NotificationFrequency.TRANSACTION_COMMIT)); + // Vital Records Review Details Rollup this.policyComponent.bindClassBehaviour( QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"), @@ -428,6 +433,30 @@ public class RecordsManagementSearchBehaviour implements RecordsManagementModel }); } + /** + * On update type to or from record folder behaviour implementation + * @param nodeRef the updated node + * @param oldType the type the node had before update + * @param newType the type the node has after update + */ + public void convertedToOrFromRecordFolder(final NodeRef nodeRef, final QName oldType, final QName newType) + { + AuthenticationUtil.runAsSystem(new AuthenticationUtil.RunAsWork() + { + @Override + public Void doWork() throws Exception + { + // If the node has been updated to a record folder + if (newType.equals(TYPE_RECORD_FOLDER) && nodeService.exists(nodeRef)) + { + applySearchAspect(nodeRef); + setupDispositionScheduleProperties(nodeRef); + } + + return null; + } + }); + } /** * Helper method to setup the disposition schedule properties * diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java index 9360f23fe1..9e55647d26 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java @@ -104,6 +104,7 @@ public class RM4619Test extends BaseRMTestCase /* * Check that when the transaction ends the identifier is no longer editable + * And the record folder has the ASPECT_RM_SEARCH aspect */ doTestInTransaction(new Test() { @@ -111,6 +112,7 @@ public class RM4619Test extends BaseRMTestCase public Void run() throws Exception { assertFalse((Boolean)nodeService.getProperty(recordFolder, PROP_ID_IS_TEMPORARILY_EDITABLE)); + assertTrue(nodeService.hasAspect(recordFolder, ASPECT_RM_SEARCH)); return null; } From f1ec66d9ffc075fb7b32cf21f934c884718dacc9 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Fri, 3 Mar 2017 15:13:03 +0200 Subject: [PATCH 8/8] RM-4619 - fixed the reject record issue --- .../model/rma/aspect/RecordComponentIdentifierAspect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java index 2fda63641b..ba91199d44 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordComponentIdentifierAspect.java @@ -268,7 +268,7 @@ public class RecordComponentIdentifierAspect extends BaseBehaviourBean * When creating a new record the identifier is writable to allow the upload in multiple steps. * On transaction commit make the identifier read only (remove the editable aspect). */ - if(nodeService.exists(nodeRef)) + if(nodeService.exists(nodeRef) && nodeService.hasAspect(nodeRef, aspectTypeQName)) { nodeService.setProperty(nodeRef, RecordsManagementModel.PROP_ID_IS_TEMPORARILY_EDITABLE, false); }