From 896398c1ff89ce00a712813fb8c6a3c95a06beb8 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 14 Apr 2016 11:28:21 +0300 Subject: [PATCH 1/3] RM-3283 - added extra check for hidden aspect + unit test --- .../type/RecordsManagementContainerType.java | 3 +- .../RecordsManagementContainerTypeTest.java | 99 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java 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 ae0f8fa817..e690e2fe73 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 @@ -136,7 +136,8 @@ public class RecordsManagementContainerType extends BaseBehaviourBean QName childType = nodeService.getType(child); // We only care about "folder" or sub-types - if (dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER)) + if (dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) && + !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) { if (dictionaryService.isSubClass(childType, ContentModel.TYPE_SYSTEM_FOLDER)) { diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java new file mode 100644 index 0000000000..6e2e4ad606 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java @@ -0,0 +1,99 @@ +package org.alfresco.module.org_alfresco_module_rm.model.rma.type; + +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Test; +import org.mockito.InjectMocks; + +/** + * Unit test for RecordsManagementContainerType + * @author Ana Bozianu + * @since 2.4 + */ +public class RecordsManagementContainerTypeTest extends BaseUnitTest +{ + /** test object */ + private @InjectMocks RecordsManagementContainerType recordManagementContainerType; + + /** + * Having the Unfilled Record container and a folder + * When adding a child association between the folder and the container + * Then the folder type shouldn't be renamed + */ + @Test + public void testAddFolderToRMContainer() + { + /* Having a RM container and a folder */ + NodeRef rmContainer = generateRMContainer(); + NodeRef rmFolder = generateFolderNode(false); + + /* + * When adding a child association between the folder and the container + */ + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + /* Then the node type should not be changed to TYPE_RECORD_FOLDER */ + verify(mockedNodeService).setType(rmFolder, TYPE_RECORD_FOLDER); + verify(mockedRecordFolderService).setupRecordFolder(rmFolder); + } + + /** + * Having the Unfilled Record container and a folder having the aspect ASPECT_HIDDEN + * When adding a child association between the folder and the container + * Then the folder type shouldn't be renamed + */ + @Test + public void testAddHiddenFolderToRMContainer() + { + /* Having a RM container and a folder with ASPECT_HIDDEN applied */ + NodeRef rmContainer = generateRMContainer(); + NodeRef rmFolder = generateFolderNode(true); + + /* + * When adding a child association between the folder and the container + */ + ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, ContentModel.ASSOC_CONTAINS, rmFolder); + recordManagementContainerType.onCreateChildAssociation(childAssoc, true); + + /* Then the node type should not be changed to TYPE_RECORD_FOLDER */ + verify(mockedNodeService, never()).setType(rmFolder, TYPE_RECORD_FOLDER); + verify(mockedRecordFolderService, never()).setupRecordFolder(rmFolder); + } + + /** + * Generates a record management container + * @return reference to the generated container + */ + private NodeRef generateRMContainer() + { + 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 node + * @param hasHiddenAspect does the folder node have the aspect ASPECT_HIDDEN + * @return reference to the created folder + */ + private NodeRef generateFolderNode(boolean hasHiddenAspect) + { + 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; + } +} From ec85454dcd7d448ad1b210bdfc0cd999cfdd19de Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 14 Apr 2016 12:25:25 +0300 Subject: [PATCH 2/3] RM-3283 - added missing file header --- .../RecordsManagementContainerTypeTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java index 6e2e4ad606..6f9fd8a661 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerTypeTest.java @@ -1,3 +1,29 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 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.type; import static org.mockito.Mockito.never; From b0b1a19b48d8ecfeeb4fb28ce7a18bee4b7bad78 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 14 Apr 2016 14:25:29 +0300 Subject: [PATCH 3/3] RM-3283 - added comment to explain change --- .../model/rma/type/RecordsManagementContainerType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 e690e2fe73..659b509aa9 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 @@ -135,7 +135,8 @@ public class RecordsManagementContainerType extends BaseBehaviourBean { QName childType = nodeService.getType(child); - // We only care about "folder" or sub-types + // We only care about "folder" or sub-types that are not hidden. + // Some modules use hidden files to store information (see RM-3283) if (dictionaryService.isSubClass(childType, ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) {