diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java
index fae162b15f..7fa5baa8e9 100644
--- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/TestData.java
@@ -32,7 +32,6 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FILE_PLAN_TYPE;
-import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_CONTAINER_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.HOLD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.TRANSFER_CONTAINER_TYPE;
@@ -146,7 +145,6 @@ public interface TestData
{ UNFILED_RECORD_FOLDER_TYPE },
{ HOLD_TYPE },
{ TRANSFER_TYPE },
- { FOLDER_TYPE },
{ CONTENT_TYPE }
};
}
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java
index 4ea17baa77..1cef0b44e0 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java
@@ -30,6 +30,7 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
import java.util.Arrays;
import java.util.List;
+import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -213,6 +214,14 @@ public class FilePlanType extends BaseBehaviourBean
@Override
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
+ // We need to automatically cast the created folder to category 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 files to store information (see RM-3283)
+ if (nodeService.getType(childAssocRef.getChildRef()).equals(ContentModel.TYPE_FOLDER))
+ {
+ nodeService.setType(childAssocRef.getChildRef(), TYPE_RECORD_CATEGORY);
+ }
+
// check the created child is of an accepted type
validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, 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/RecordCategoryType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java
index 4f3ae15bef..b5f35e7320 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService;
@@ -111,13 +112,22 @@ public class RecordCategoryType extends BaseBehaviourBean
)
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew)
{
- NodeRef nodeRef = childAssocRef.getChildRef();
- NodeRef parentRef = childAssocRef.getParentRef();
- validateNewChildAssociation(parentRef, nodeRef, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
+ QName childType = nodeService.getType(childAssocRef.getChildRef());
+
+ // 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 folders to store information (see RM-3283).
+ if (childType.equals(ContentModel.TYPE_FOLDER))
+ {
+ nodeService.setType(childAssocRef.getChildRef(), TYPE_RECORD_FOLDER);
+ }
+
+ validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES);
+
if (bNew)
{
// setup the record folder
- recordFolderService.setupRecordFolder(nodeRef);
+ recordFolderService.setupRecordFolder(childAssocRef.getChildRef());
}
}
@@ -132,9 +142,9 @@ public class RecordCategoryType extends BaseBehaviourBean
policy = "alf:onCreateChildAssociation",
notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT
)
- public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew)
+ public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, final boolean bNew)
{
- final NodeRef recordCategory = childAssocRef.getChildRef();
+ final NodeRef child = childAssocRef.getChildRef();
behaviourFilter.disableBehaviour();
try
@@ -145,7 +155,7 @@ public class RecordCategoryType extends BaseBehaviourBean
public Void doWork()
{
// setup vital record definition
- vitalRecordService.setupVitalRecordDefinition(recordCategory);
+ vitalRecordService.setupVitalRecordDefinition(child);
return null;
}
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 504acd4d86..8276307e1c 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
@@ -27,7 +27,6 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
-import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
@@ -44,7 +43,6 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
-import org.springframework.extensions.surf.util.I18NUtil;
/**
* rma:recordsManagementContainer behaviour bean.
@@ -152,32 +150,6 @@ public class RecordsManagementContainerType extends BaseBehaviourBean
}
else
{
- // We need to automatically cast the created folder to RM type if it is a plain folder
- // This occurs if the RM folder has been created via IMap, WebDav, etc
- if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT))
- {
- // Throw exception if the type is not cm:folder
- if (!ContentModel.TYPE_FOLDER.equals(childType))
- {
- throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CANNOT_CAST_TO_RM_TYPE));
- }
- // check the type of the parent to determine what 'kind' of artifact to create
- NodeRef parent = childAssocRef.getParentRef();
- QName parentType = nodeService.getType(parent);
-
- if (dictionaryService.isSubClass(parentType, TYPE_FILE_PLAN))
- {
- // create a rma:recordCategoty since we are in the root of the file plan
- nodeService.setType(child, TYPE_RECORD_CATEGORY);
- }
- else
- {
- // create a rma:recordFolder and initialise record folder
- nodeService.setType(child, TYPE_RECORD_FOLDER);
- recordFolderService.setupRecordFolder(child);
- }
- }
-
// Catch all to generate the rm id (assuming it doesn't already have one!)
setIdenifierProperty(child);
}
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
new file mode 100644
index 0000000000..6b83327468
--- /dev/null
+++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java
@@ -0,0 +1,84 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2017 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.test.integration.issue;
+
+import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
+import org.alfresco.service.cmr.model.FileInfo;
+import org.springframework.extensions.webscripts.GUID;
+
+/**
+ * Unit test for RM-4619
+ *
+ * When creating regular folders through clients that are not RM aware
+ * the folders must be converted to the appropriate RM container
+ *
+ * @author Ana Bozianu
+ * @since 2.6
+ */
+public class RM4619Test extends BaseRMTestCase
+{
+
+ /**
+ * Given the RM site is created
+ * When we create a regular folder in the fileplan
+ * Then the folder is immediately converted to a record category
+ */
+ public void testConvertFolderToCategory() throws Exception
+ {
+ doTestInTransaction(new Test()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ FileInfo info = fileFolderService.create(filePlan, GUID.generate(), TYPE_FOLDER);
+ assertEquals(info.getType(), TYPE_RECORD_CATEGORY);
+ return null;
+ }
+
+ }, ADMIN_USER);
+ }
+
+ /**
+ * Given an existing category
+ * When we create a regular folder in the category
+ * Then the folder is immediately converted to a record folder
+ */
+ public void testConvertFolderToRecordFolder() throws Exception
+ {
+ doTestInTransaction(new Test()
+ {
+ @Override
+ public Void run() throws Exception
+ {
+ FileInfo info = fileFolderService.create(rmContainer, GUID.generate(), TYPE_FOLDER);
+ assertEquals(info.getType(), TYPE_RECORD_FOLDER);
+ return null;
+ }
+
+ }, ADMIN_USER);
+ }
+}
diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java
index 607d053242..d5fa40ae74 100644
--- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java
+++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanTypeUnitTest.java
@@ -27,11 +27,13 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.alfresco.model.ContentModel;
+import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java
index e32127ff19..db00723660 100644
--- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java
+++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryTypeUnitTest.java
@@ -27,6 +27,7 @@
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
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 dfc996c23c..cb12360323 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
@@ -26,13 +26,11 @@
*/
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import org.alfresco.error.AlfrescoRuntimeException;
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;
@@ -52,33 +50,10 @@ public class RecordsManagementContainerTypeUnitTest 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
+ * Then the new folder should not be altered
*/
@Test
public void testAddHiddenFolderToRMContainer()
@@ -93,31 +68,9 @@ public class RecordsManagementContainerTypeUnitTest extends BaseUnitTest
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);
- }
-
- /**
- * Trying to create a RM folder and its sub-types via SFDC, IMap, WebDav, etc
- * Check that exception is thrown on creating child associations
- */
- @Test
- public void testRM3450()
- {
- NodeRef rmContainer = generateRMContainer();
- NodeRef nonRmFolder = generateNonRmFolderNode();
-
- ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CONTAINS, rmContainer, TestModel.NOT_RM_FOLDER_TYPE, nonRmFolder);
- try
- {
- recordManagementContainerType.onCreateChildAssociation(childAssoc, true);
- fail("Expected to throw exception on create child association.");
- }
- catch (Throwable e)
- {
- assertTrue(e instanceof AlfrescoRuntimeException);
- }
+ /* 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());
}
/**