From c84c951c521b3339dedac000a12f45ab5e74a7a0 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 26 Jan 2017 12:05:17 +0200 Subject: [PATCH 01/10] RM-4619 - moved the conversion to the specific types before the type check --- .../model/rma/type/FilePlanType.java | 15 +++++++++- .../model/rma/type/RecordCategoryType.java | 22 ++++++++++++--- .../type/RecordsManagementContainerType.java | 28 ------------------- 3 files changed, 32 insertions(+), 33 deletions(-) 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..2f88fe7d37 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; @@ -208,11 +209,23 @@ public class FilePlanType extends BaseBehaviourBean */ @Behaviour ( - kind = BehaviourKind.ASSOCIATION + kind = BehaviourKind.ASSOCIATION, + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT ) @Override public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) { + NodeRef child = childAssocRef.getChildRef(); + + // 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 + // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) + if (nodeService.getType(child) == ContentModel.TYPE_FOLDER && + !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) + { + nodeService.setType(child, 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..531c2047eb 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; @@ -107,18 +108,31 @@ public class RecordCategoryType extends BaseBehaviourBean @Override @Behaviour ( - kind = BehaviourKind.ASSOCIATION + kind = BehaviourKind.ASSOCIATION, + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT ) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) { - NodeRef nodeRef = childAssocRef.getChildRef(); + NodeRef child = childAssocRef.getChildRef(); NodeRef parentRef = childAssocRef.getParentRef(); - validateNewChildAssociation(parentRef, nodeRef, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); + QName childType = nodeService.getType(child); + + // 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 + // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) + if ( childType == ContentModel.TYPE_FOLDER && + !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) + { + nodeService.setType(child, TYPE_RECORD_FOLDER); + } + if (bNew) { // setup the record folder - recordFolderService.setupRecordFolder(nodeRef); + recordFolderService.setupRecordFolder(child); } + + validateNewChildAssociation(parentRef, child, 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/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); } From ca8892195533e6354a89715d9712f3bec7dd5ce7 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Thu, 26 Jan 2017 12:16:54 +0200 Subject: [PATCH 02/10] RM-4619 - fixed unit tests --- .../model/rma/type/FilePlanTypeUnitTest.java | 25 ++++++++ .../rma/type/RecordCategoryTypeUnitTest.java | 25 ++++++++ ...ecordsManagementContainerTypeUnitTest.java | 57 ++----------------- 3 files changed, 55 insertions(+), 52 deletions(-) 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..d25d6ecb19 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; @@ -180,6 +182,29 @@ public class FilePlanTypeUnitTest extends BaseUnitTest filePlanType.onCreateChildAssociation(childAssoc, true); } + /** + * Given that we try to add "cm:folder" type to a record category, + * Then operation is successful and the folder is automatically converted to a record folder + */ + @Test + public void testConversionToRecordFolder() throws Exception + { + NodeRef fileplan = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN); + NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); + ChildAssociationRef childAssocRef = generateChildAssociationRef(fileplan, nodeRef); + + try + { + filePlanType.onCreateChildAssociation(childAssocRef, true); + } + catch(IntegrityException ex) + { + // this will throw an exception because unit tests can't detect type change + } + + verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_CATEGORY); + } + /** * Helper method that creates a child of the fileplan container with the provided type * @param childType the node type of the child to be created 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..ffd6256a2d 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; @@ -108,4 +109,28 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); recordCategoryType.onCreateChildAssociation(childAssocRef, true); } + + /** + * Given that we try to add "cm:folder" type to a record category, + * Then operation is successful and the folder is automatically converted to a record folder + */ + @Test + public void testConversionToRecordFolder() throws Exception + { + NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY); + NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); + ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); + + try + { + recordCategoryType.onCreateChildAssociation(childAssocRef, true); + } + catch(IntegrityException ex) + { + // this will throw an exception because unit tests can't detect type change + } + + verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_FOLDER); + verify(mockedRecordFolderService).setupRecordFolder(nodeRef); + } } 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()); } /** From 088c8701410e5060ad54918807795818007691e2 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Sun, 29 Jan 2017 17:37:05 +0200 Subject: [PATCH 03/10] RM-4619 - moved code to existing onCommit method --- .../model/rma/type/RecordCategoryType.java | 27 +++++++++---------- .../rma/type/RecordCategoryTypeUnitTest.java | 3 +-- 2 files changed, 14 insertions(+), 16 deletions(-) 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 531c2047eb..f4a6ceb359 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 @@ -108,23 +108,12 @@ public class RecordCategoryType extends BaseBehaviourBean @Override @Behaviour ( - kind = BehaviourKind.ASSOCIATION, - notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + kind = BehaviourKind.ASSOCIATION ) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) { NodeRef child = childAssocRef.getChildRef(); NodeRef parentRef = childAssocRef.getParentRef(); - QName childType = nodeService.getType(child); - - // 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 - // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) - if ( childType == ContentModel.TYPE_FOLDER && - !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) - { - nodeService.setType(child, TYPE_RECORD_FOLDER); - } if (bNew) { @@ -148,7 +137,17 @@ public class RecordCategoryType extends BaseBehaviourBean ) public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) { - final NodeRef recordCategory = childAssocRef.getChildRef(); + final NodeRef child = childAssocRef.getChildRef(); + QName childType = nodeService.getType(child); + + // 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 + // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) + if ( childType == ContentModel.TYPE_FOLDER && + !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) + { + nodeService.setType(child, TYPE_RECORD_FOLDER); + } behaviourFilter.disableBehaviour(); try @@ -159,7 +158,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/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 ffd6256a2d..df9f2e1826 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 @@ -123,7 +123,7 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest try { - recordCategoryType.onCreateChildAssociation(childAssocRef, true); + recordCategoryType.onCreateChildAssociationOnCommit(childAssocRef, true); } catch(IntegrityException ex) { @@ -131,6 +131,5 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest } verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_FOLDER); - verify(mockedRecordFolderService).setupRecordFolder(nodeRef); } } From 6ff8dd5846bb80078d48c8171524e0f84e976340 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 12:05:48 +0200 Subject: [PATCH 04/10] RM-4619 - added cm:folder as accepted type and do the conversion onCommit - request doesn't have full info --- .../model/rma/type/FilePlanType.java | 27 ++++++++---- .../model/rma/type/RecordCategoryType.java | 41 +++++++++---------- .../rm/rest/api/impl/RMNodesImpl.java | 9 +--- .../model/rma/type/FilePlanTypeUnitTest.java | 2 +- 4 files changed, 41 insertions(+), 38 deletions(-) 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 2f88fe7d37..38076241c7 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 @@ -67,7 +67,7 @@ public class FilePlanType extends BaseBehaviourBean NodeServicePolicies.BeforeDeleteNodePolicy { private final static List ACCEPTED_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD_CONTAINER, TYPE_TRANSFER_CONTAINER, TYPE_UNFILED_RECORD_CONTAINER); - private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY); + private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER); private static final String BEHAVIOUR_NAME = "onDeleteFilePlan"; /** file plan service */ @@ -209,25 +209,38 @@ public class FilePlanType extends BaseBehaviourBean */ @Behaviour ( - kind = BehaviourKind.ASSOCIATION, - notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + kind = BehaviourKind.ASSOCIATION ) @Override public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) + { + // check the created child is of an accepted type + validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); + } + + /** + * On transaction commit + * + * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) + */ + @Behaviour + ( + kind = BehaviourKind.ASSOCIATION, + policy = "alf:onCreateChildAssociation", + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + ) + public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) { NodeRef child = childAssocRef.getChildRef(); // 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 // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) - if (nodeService.getType(child) == ContentModel.TYPE_FOLDER && + if (nodeService.getType(child).equals(ContentModel.TYPE_FOLDER) && !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) { nodeService.setType(child, 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 f4a6ceb359..3dc8d4d04a 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 @@ -65,7 +65,7 @@ public class RecordCategoryType extends BaseBehaviourBean NodeServicePolicies.OnCreateNodePolicy { private final static List ACCEPTED_UNIQUE_CHILD_TYPES = new ArrayList(); - private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, TYPE_RECORD_FOLDER); + private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, TYPE_RECORD_FOLDER, ContentModel.TYPE_FOLDER); /** vital record service */ protected VitalRecordService vitalRecordService; @@ -112,16 +112,7 @@ public class RecordCategoryType extends BaseBehaviourBean ) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) { - NodeRef child = childAssocRef.getChildRef(); - NodeRef parentRef = childAssocRef.getParentRef(); - - if (bNew) - { - // setup the record folder - recordFolderService.setupRecordFolder(child); - } - - validateNewChildAssociation(parentRef, child, ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); + validateNewChildAssociation(childAssocRef.getParentRef(), childAssocRef.getChildRef(), ACCEPTED_UNIQUE_CHILD_TYPES, ACCEPTED_NON_UNIQUE_CHILD_TYPES); } /** @@ -135,19 +126,10 @@ 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 child = childAssocRef.getChildRef(); - QName childType = nodeService.getType(child); - - // 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 - // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) - if ( childType == ContentModel.TYPE_FOLDER && - !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) - { - nodeService.setType(child, TYPE_RECORD_FOLDER); - } + final QName childType = nodeService.getType(child); behaviourFilter.disableBehaviour(); try @@ -157,6 +139,21 @@ public class RecordCategoryType extends BaseBehaviourBean @Override public Void doWork() { + // 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 + // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) + if ( childType.equals(ContentModel.TYPE_FOLDER) && + !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) + { + nodeService.setType(child, TYPE_RECORD_FOLDER); + } + + if (bNew) + { + // setup the record folder + recordFolderService.setupRecordFolder(child); + } + // setup vital record definition vitalRecordService.setupVitalRecordDefinition(child); diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java index e9b7f71de9..81e839c120 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java @@ -138,14 +138,7 @@ public class RMNodesImpl extends NodesImpl implements RMNodes if (type == null) { - if (filePlanService.isFilePlanComponent(nodeRef)) - { - node = new FileplanComponentNode(originalNode); - } - else - { - throw new InvalidParameterException("The provided node is not a fileplan component"); - } + node = new FileplanComponentNode(originalNode); } else { 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 d25d6ecb19..af6a035acc 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 @@ -195,7 +195,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest try { - filePlanType.onCreateChildAssociation(childAssocRef, true); + filePlanType.onCreateChildAssociationOnCommit(childAssocRef, true); } catch(IntegrityException ex) { From e1b0e994a1a0acbce41ac7caa94b1ef11e3c2599 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 12:54:37 +0200 Subject: [PATCH 05/10] RM-4619 - added the fileplan component check back but in different place --- .../rm-public-rest-context.xml | 3 +- .../rm/rest/api/impl/RMNodesImpl.java | 6 ++++ .../rm/rest/api/impl/RecordsImpl.java | 22 +++++++++---- .../impl/RMNodesImplRelativePathUnitTest.java | 5 +++ .../rm/rest/api/impl/RMNodesImplUnitTest.java | 4 +-- .../rm/rest/api/impl/RecordsImplUnitTest.java | 33 ++++++++++--------- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index 34da746fb3..9c37e9482f 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -93,7 +93,8 @@ - + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java index 81e839c120..b581ff89b2 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java @@ -61,6 +61,7 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.alfresco.util.ParameterCheck; @@ -277,6 +278,11 @@ public class RMNodesImpl extends NodesImpl implements RMNodes } } + if(!filePlanService.isFilePlanComponent(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId))) + { + throw new InvalidParameterException("The provided node is not a fileplan component"); + } + return super.validateNode(nodeId); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java index 2938feee94..5bc3500ab9 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java @@ -36,6 +36,7 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -67,7 +68,8 @@ public class RecordsImpl implements Records, InitializingBean protected FileFolderService fileFolderService; protected DictionaryService dictionaryService; protected AuthenticationUtil authenticationUtil; - protected RMNodes nodes; + protected RMNodes rmNodes; + protected Nodes nodes; public void setRecordService(RecordService recordService) { @@ -99,7 +101,12 @@ public class RecordsImpl implements Records, InitializingBean this.authenticationUtil = authenticationUtil; } - public void setNodes(RMNodes nodes) + public void setRmNodes(RMNodes rmNodes) + { + this.rmNodes = rmNodes; + } + + public void setNodes(Nodes nodes) { this.nodes = nodes; } @@ -108,6 +115,7 @@ public class RecordsImpl implements Records, InitializingBean public Node declareFileAsRecord(String fileId, Parameters parameters) { // Get file to be declared + // Use nodes instead of rmNodes because the file is not a record yet NodeRef fileNodeRef = nodes.validateNode(fileId) ; // Get fileplan @@ -127,7 +135,7 @@ public class RecordsImpl implements Records, InitializingBean recordService.createRecord(filePlan, fileNodeRef, !hideRecord); // Get information about the new record - return nodes.getFolderOrDocument(fileId, parameters); + return rmNodes.getFolderOrDocument(fileId, parameters); } @Override @@ -139,7 +147,7 @@ public class RecordsImpl implements Records, InitializingBean } // Get record - NodeRef record = nodes.validateNode(recordId); + NodeRef record = rmNodes.validateNode(recordId); // Get record folder to file/link the record to String parentContainerId = target.getTargetParentId(); @@ -155,7 +163,7 @@ public class RecordsImpl implements Records, InitializingBean } }); } - NodeRef parentRecordFolder = nodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT); + NodeRef parentRecordFolder = rmNodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT); // Check if the target is a record folder if(!dictionaryService.isSubClass(nodeService.getType(parentRecordFolder), RecordsManagementModel.TYPE_RECORD_FOLDER)) @@ -186,7 +194,7 @@ public class RecordsImpl implements Records, InitializingBean } // Get the record info - return nodes.getFolderOrDocument(recordId, parameters); + return rmNodes.getFolderOrDocument(recordId, parameters); } @Override @@ -194,7 +202,7 @@ public class RecordsImpl implements Records, InitializingBean { ParameterCheck.mandatory("recordService", recordService); ParameterCheck.mandatory("filePlanService", filePlanService); - ParameterCheck.mandatory("nodes", nodes); + ParameterCheck.mandatory("nodes", rmNodes); ParameterCheck.mandatory("nodeService", nodeService); ParameterCheck.mandatory("fileFolderService", fileFolderService); ParameterCheck.mandatory("dictionaryService", dictionaryService); diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java index 0a0db60ae7..796242aa56 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java @@ -85,6 +85,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest * Given any parent node */ NodeRef parentNode = AlfMock.generateNodeRef(mockedNodeService); + when(mockedFilePlanService.isFilePlanComponent(parentNode)).thenReturn(true); /* * When trying to create a node in the parent node with no relative path @@ -112,6 +113,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest * Given a parent node and an existing path c1/f1 under it */ NodeRef parentNode = AlfMock.generateNodeRef(mockedNodeService); + when(mockedFilePlanService.isFilePlanComponent(parentNode)).thenReturn(true); String category = "c1"; NodeRef categoryNode = AlfMock.generateNodeRef(mockedNodeService); @@ -154,6 +156,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest String category1 = "c1"; NodeRef categoryNode1 = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getChildByName(fileplanNodeRef, ContentModel.ASSOC_CONTAINS, category1)).thenReturn(categoryNode1); + when(mockedFilePlanService.isFilePlanComponent(fileplanNodeRef)).thenReturn(true); // create c2 String category2 = "c2"; @@ -200,6 +203,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest */ NodeRef unfiledRecordContainer = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getType(unfiledRecordContainer)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER); + when(mockedFilePlanService.isFilePlanComponent(unfiledRecordContainer)).thenReturn(true); /* * When trying to create a content node in the relative path f1/f2/f3 @@ -255,6 +259,7 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest */ NodeRef fileplanNodeRef = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getType(fileplanNodeRef)).thenReturn(TYPE_FILE_PLAN); + when(mockedFilePlanService.isFilePlanComponent(fileplanNodeRef)).thenReturn(true); /* * When trying to create a folder node in the relative path c1/c2/c3 diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java index e174775483..ddd5db3af7 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java @@ -318,10 +318,9 @@ public class RMNodesImplUnitTest extends BaseUnitTest setupCompanyHomeAndPrimaryParent(nodeRef); when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(false); - List includeParamList = new ArrayList(); try { - rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null); + rmNodesImpl.validateNode(nodeRef.getId()); fail("Expected exception since the requested node is not a fileplan component."); } catch(InvalidParameterException ex) @@ -628,6 +627,7 @@ public class RMNodesImplUnitTest extends BaseUnitTest public void testValidateNode() throws Exception { NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService); + when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true); NodeRef validateOrLookupNode = rmNodesImpl.validateNode(nodeRef.getId()); assertEquals(nodeRef, validateOrLookupNode); } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java index c10b272441..e3c57b407a 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java @@ -40,6 +40,7 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock; import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; +import org.alfresco.rest.api.Nodes; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rm.rest.api.RMNodes; import org.alfresco.rm.rest.api.Records; @@ -77,7 +78,9 @@ public class RecordsImplUnitTest @Mock protected AuthenticationUtil mockedAuthenticationUtil; @Mock - protected RMNodes mockedNodes; + protected RMNodes mockedRMNodes; + @Mock + protected Nodes mockedNodes; @InjectMocks private RecordsImpl recordsImpl; @@ -119,7 +122,7 @@ public class RecordsImplUnitTest * Then a record is created under the existing fileplan from the provided file */ verify(mockedRecordService).createRecord(fileplan, mockedFile, false); - verify(mockedNodes).getFolderOrDocument(mockedFile.getId(), params); + verify(mockedRMNodes).getFolderOrDocument(mockedFile.getId(), params); } /** @@ -134,7 +137,7 @@ public class RecordsImplUnitTest * Given a record */ NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); /* * When trying to filing a record providing a blank destination path @@ -157,7 +160,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -169,7 +172,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedRMNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -185,7 +188,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the destination folder */ - verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); + verify(mockedRMNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -203,7 +206,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -220,7 +223,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into String relativePath = "category/recordFolder"; NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedRMNodes.getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -236,7 +239,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the destination folder relative to the fileplan */ - verify(mockedNodes).getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT); + verify(mockedRMNodes).getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -254,7 +257,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -270,7 +273,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into String relativePath = "category/recordFolder"; NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedRMNodes.getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -287,7 +290,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the correct destination folder */ - verify(mockedNodes).getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT); + verify(mockedRMNodes).getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -304,7 +307,7 @@ public class RecordsImplUnitTest */ // mock the record to link NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -316,7 +319,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedRMNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); /* @@ -331,7 +334,7 @@ public class RecordsImplUnitTest /* * Then the record is linked to the destination folder */ - verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); + verify(mockedRMNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); verify(mockedRecordService).link(mockedRecord, mockedTargetRecordFolder); } } From 40b61c5c6249b6b0f717061809abcb62fbdad2c0 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 14:35:23 +0200 Subject: [PATCH 06/10] RM-4619 - doing the conversion at first event --- .../model/rma/type/FilePlanType.java | 35 +++++-------------- .../model/rma/type/RecordCategoryType.java | 34 +++++++++--------- .../model/rma/type/FilePlanTypeUnitTest.java | 2 +- .../rma/type/RecordCategoryTypeUnitTest.java | 2 +- 4 files changed, 28 insertions(+), 45 deletions(-) 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 38076241c7..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 @@ -67,7 +67,7 @@ public class FilePlanType extends BaseBehaviourBean NodeServicePolicies.BeforeDeleteNodePolicy { private final static List ACCEPTED_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD_CONTAINER, TYPE_TRANSFER_CONTAINER, TYPE_UNFILED_RECORD_CONTAINER); - private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, ContentModel.TYPE_FOLDER); + private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY); private static final String BEHAVIOUR_NAME = "onDeleteFilePlan"; /** file plan service */ @@ -214,35 +214,18 @@ 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); } - /** - * On transaction commit - * - * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateChildAssociationPolicy#onCreateChildAssociation(org.alfresco.service.cmr.repository.ChildAssociationRef, boolean) - */ - @Behaviour - ( - kind = BehaviourKind.ASSOCIATION, - policy = "alf:onCreateChildAssociation", - notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT - ) - public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, boolean bNew) - { - NodeRef child = childAssocRef.getChildRef(); - - // 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 - // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) - if (nodeService.getType(child).equals(ContentModel.TYPE_FOLDER) && - !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) - { - nodeService.setType(child, TYPE_RECORD_CATEGORY); - } - } - /** * @see org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy#onCreateNode(org.alfresco.service.cmr.repository.ChildAssociationRef) */ 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 3dc8d4d04a..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 @@ -65,7 +65,7 @@ public class RecordCategoryType extends BaseBehaviourBean NodeServicePolicies.OnCreateNodePolicy { private final static List ACCEPTED_UNIQUE_CHILD_TYPES = new ArrayList(); - private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, TYPE_RECORD_FOLDER, ContentModel.TYPE_FOLDER); + private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY, TYPE_RECORD_FOLDER); /** vital record service */ protected VitalRecordService vitalRecordService; @@ -112,7 +112,23 @@ public class RecordCategoryType extends BaseBehaviourBean ) public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean bNew) { + 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(childAssocRef.getChildRef()); + } } /** @@ -129,7 +145,6 @@ public class RecordCategoryType extends BaseBehaviourBean public void onCreateChildAssociationOnCommit(ChildAssociationRef childAssocRef, final boolean bNew) { final NodeRef child = childAssocRef.getChildRef(); - final QName childType = nodeService.getType(child); behaviourFilter.disableBehaviour(); try @@ -139,21 +154,6 @@ public class RecordCategoryType extends BaseBehaviourBean @Override public Void doWork() { - // 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 - // Ignore hidden files. Some modules use hidden files to store information (see RM-3283) - if ( childType.equals(ContentModel.TYPE_FOLDER) && - !nodeService.hasAspect(child, ContentModel.ASPECT_HIDDEN)) - { - nodeService.setType(child, TYPE_RECORD_FOLDER); - } - - if (bNew) - { - // setup the record folder - recordFolderService.setupRecordFolder(child); - } - // setup vital record definition vitalRecordService.setupVitalRecordDefinition(child); 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 af6a035acc..d25d6ecb19 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 @@ -195,7 +195,7 @@ public class FilePlanTypeUnitTest extends BaseUnitTest try { - filePlanType.onCreateChildAssociationOnCommit(childAssocRef, true); + filePlanType.onCreateChildAssociation(childAssocRef, true); } catch(IntegrityException ex) { 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 df9f2e1826..2560615bca 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 @@ -123,7 +123,7 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest try { - recordCategoryType.onCreateChildAssociationOnCommit(childAssocRef, true); + recordCategoryType.onCreateChildAssociation(childAssocRef, true); } catch(IntegrityException ex) { From 257880cb62036f33c1b1c74274b68b7e8859de5a Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 16:53:58 +0200 Subject: [PATCH 07/10] Revert "RM-4619 - added the fileplan component check back but in different place" This reverts commit e1b0e994a1a0acbce41ac7caa94b1ef11e3c2599. --- .../rm-public-rest-context.xml | 3 +- .../rm/rest/api/impl/RMNodesImpl.java | 6 ---- .../rm/rest/api/impl/RecordsImpl.java | 22 ++++--------- .../impl/RMNodesImplRelativePathUnitTest.java | 5 --- .../rm/rest/api/impl/RMNodesImplUnitTest.java | 4 +-- .../rm/rest/api/impl/RecordsImplUnitTest.java | 33 +++++++++---------- 6 files changed, 25 insertions(+), 48 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml index 9c37e9482f..34da746fb3 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-rest-context.xml @@ -93,8 +93,7 @@ - - + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java index b581ff89b2..81e839c120 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java @@ -61,7 +61,6 @@ import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.alfresco.util.ParameterCheck; @@ -278,11 +277,6 @@ public class RMNodesImpl extends NodesImpl implements RMNodes } } - if(!filePlanService.isFilePlanComponent(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId))) - { - throw new InvalidParameterException("The provided node is not a fileplan component"); - } - return super.validateNode(nodeId); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java index 5bc3500ab9..2938feee94 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RecordsImpl.java @@ -36,7 +36,6 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; import org.alfresco.repo.node.integrity.IntegrityException; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.model.Node; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; import org.alfresco.rest.framework.resource.parameters.Parameters; @@ -68,8 +67,7 @@ public class RecordsImpl implements Records, InitializingBean protected FileFolderService fileFolderService; protected DictionaryService dictionaryService; protected AuthenticationUtil authenticationUtil; - protected RMNodes rmNodes; - protected Nodes nodes; + protected RMNodes nodes; public void setRecordService(RecordService recordService) { @@ -101,12 +99,7 @@ public class RecordsImpl implements Records, InitializingBean this.authenticationUtil = authenticationUtil; } - public void setRmNodes(RMNodes rmNodes) - { - this.rmNodes = rmNodes; - } - - public void setNodes(Nodes nodes) + public void setNodes(RMNodes nodes) { this.nodes = nodes; } @@ -115,7 +108,6 @@ public class RecordsImpl implements Records, InitializingBean public Node declareFileAsRecord(String fileId, Parameters parameters) { // Get file to be declared - // Use nodes instead of rmNodes because the file is not a record yet NodeRef fileNodeRef = nodes.validateNode(fileId) ; // Get fileplan @@ -135,7 +127,7 @@ public class RecordsImpl implements Records, InitializingBean recordService.createRecord(filePlan, fileNodeRef, !hideRecord); // Get information about the new record - return rmNodes.getFolderOrDocument(fileId, parameters); + return nodes.getFolderOrDocument(fileId, parameters); } @Override @@ -147,7 +139,7 @@ public class RecordsImpl implements Records, InitializingBean } // Get record - NodeRef record = rmNodes.validateNode(recordId); + NodeRef record = nodes.validateNode(recordId); // Get record folder to file/link the record to String parentContainerId = target.getTargetParentId(); @@ -163,7 +155,7 @@ public class RecordsImpl implements Records, InitializingBean } }); } - NodeRef parentRecordFolder = rmNodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT); + NodeRef parentRecordFolder = nodes.getOrCreatePath(parentContainerId, target.getRelativePath(), ContentModel.TYPE_CONTENT); // Check if the target is a record folder if(!dictionaryService.isSubClass(nodeService.getType(parentRecordFolder), RecordsManagementModel.TYPE_RECORD_FOLDER)) @@ -194,7 +186,7 @@ public class RecordsImpl implements Records, InitializingBean } // Get the record info - return rmNodes.getFolderOrDocument(recordId, parameters); + return nodes.getFolderOrDocument(recordId, parameters); } @Override @@ -202,7 +194,7 @@ public class RecordsImpl implements Records, InitializingBean { ParameterCheck.mandatory("recordService", recordService); ParameterCheck.mandatory("filePlanService", filePlanService); - ParameterCheck.mandatory("nodes", rmNodes); + ParameterCheck.mandatory("nodes", nodes); ParameterCheck.mandatory("nodeService", nodeService); ParameterCheck.mandatory("fileFolderService", fileFolderService); ParameterCheck.mandatory("dictionaryService", dictionaryService); diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java index 796242aa56..0a0db60ae7 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplRelativePathUnitTest.java @@ -85,7 +85,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest * Given any parent node */ NodeRef parentNode = AlfMock.generateNodeRef(mockedNodeService); - when(mockedFilePlanService.isFilePlanComponent(parentNode)).thenReturn(true); /* * When trying to create a node in the parent node with no relative path @@ -113,7 +112,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest * Given a parent node and an existing path c1/f1 under it */ NodeRef parentNode = AlfMock.generateNodeRef(mockedNodeService); - when(mockedFilePlanService.isFilePlanComponent(parentNode)).thenReturn(true); String category = "c1"; NodeRef categoryNode = AlfMock.generateNodeRef(mockedNodeService); @@ -156,7 +154,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest String category1 = "c1"; NodeRef categoryNode1 = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getChildByName(fileplanNodeRef, ContentModel.ASSOC_CONTAINS, category1)).thenReturn(categoryNode1); - when(mockedFilePlanService.isFilePlanComponent(fileplanNodeRef)).thenReturn(true); // create c2 String category2 = "c2"; @@ -203,7 +200,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest */ NodeRef unfiledRecordContainer = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getType(unfiledRecordContainer)).thenReturn(TYPE_UNFILED_RECORD_CONTAINER); - when(mockedFilePlanService.isFilePlanComponent(unfiledRecordContainer)).thenReturn(true); /* * When trying to create a content node in the relative path f1/f2/f3 @@ -259,7 +255,6 @@ public class RMNodesImplRelativePathUnitTest extends BaseUnitTest */ NodeRef fileplanNodeRef = AlfMock.generateNodeRef(mockedNodeService); when(mockedNodeService.getType(fileplanNodeRef)).thenReturn(TYPE_FILE_PLAN); - when(mockedFilePlanService.isFilePlanComponent(fileplanNodeRef)).thenReturn(true); /* * When trying to create a folder node in the relative path c1/c2/c3 diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java index ddd5db3af7..e174775483 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RMNodesImplUnitTest.java @@ -318,9 +318,10 @@ public class RMNodesImplUnitTest extends BaseUnitTest setupCompanyHomeAndPrimaryParent(nodeRef); when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(false); + List includeParamList = new ArrayList(); try { - rmNodesImpl.validateNode(nodeRef.getId()); + rmNodesImpl.getFolderOrDocument(nodeRef, null, null, includeParamList, null); fail("Expected exception since the requested node is not a fileplan component."); } catch(InvalidParameterException ex) @@ -627,7 +628,6 @@ public class RMNodesImplUnitTest extends BaseUnitTest public void testValidateNode() throws Exception { NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService); - when(mockedFilePlanService.isFilePlanComponent(nodeRef)).thenReturn(true); NodeRef validateOrLookupNode = rmNodesImpl.validateNode(nodeRef.getId()); assertEquals(nodeRef, validateOrLookupNode); } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java index e3c57b407a..c10b272441 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/rm/rest/api/impl/RecordsImplUnitTest.java @@ -40,7 +40,6 @@ import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock; import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; -import org.alfresco.rest.api.Nodes; import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rm.rest.api.RMNodes; import org.alfresco.rm.rest.api.Records; @@ -78,9 +77,7 @@ public class RecordsImplUnitTest @Mock protected AuthenticationUtil mockedAuthenticationUtil; @Mock - protected RMNodes mockedRMNodes; - @Mock - protected Nodes mockedNodes; + protected RMNodes mockedNodes; @InjectMocks private RecordsImpl recordsImpl; @@ -122,7 +119,7 @@ public class RecordsImplUnitTest * Then a record is created under the existing fileplan from the provided file */ verify(mockedRecordService).createRecord(fileplan, mockedFile, false); - verify(mockedRMNodes).getFolderOrDocument(mockedFile.getId(), params); + verify(mockedNodes).getFolderOrDocument(mockedFile.getId(), params); } /** @@ -137,7 +134,7 @@ public class RecordsImplUnitTest * Given a record */ NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); /* * When trying to filing a record providing a blank destination path @@ -160,7 +157,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -172,7 +169,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -188,7 +185,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the destination folder */ - verify(mockedRMNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); + verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -206,7 +203,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -223,7 +220,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into String relativePath = "category/recordFolder"; NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedNodes.getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -239,7 +236,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the destination folder relative to the fileplan */ - verify(mockedRMNodes).getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT); + verify(mockedNodes).getOrCreatePath(fileplan.getId(), relativePath, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -257,7 +254,7 @@ public class RecordsImplUnitTest */ // mock the record to file NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -273,7 +270,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into String relativePath = "category/recordFolder"; NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedNodes.getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); when(mockedDictionaryService.isSubClass(TYPE_RECORD_FOLDER, TYPE_RECORD_FOLDER)).thenReturn(true); @@ -290,7 +287,7 @@ public class RecordsImplUnitTest /* * Then the record is moved under the correct destination folder */ - verify(mockedRMNodes).getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT); + verify(mockedNodes).getOrCreatePath(mockedTargetCategory.getId(), relativePath, TYPE_CONTENT); verify(mockedFileFolderService).moveFrom(mockedRecord, mockedPrimaryParent, mockedTargetRecordFolder, null); } @@ -307,7 +304,7 @@ public class RecordsImplUnitTest */ // mock the record to link NodeRef mockedRecord = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); + when(mockedNodes.validateNode(mockedRecord.getId())).thenReturn(mockedRecord); // mock the current primary parent NodeRef mockedPrimaryParent = AlfMock.generateNodeRef(mockedNodeService); @@ -319,7 +316,7 @@ public class RecordsImplUnitTest // mock the target record folder to file the record into NodeRef mockedTargetRecordFolder = AlfMock.generateNodeRef(mockedNodeService); - when(mockedRMNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); + when(mockedNodes.getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT)).thenReturn(mockedTargetRecordFolder); when(mockedNodeService.getType(mockedTargetRecordFolder)).thenReturn(TYPE_RECORD_FOLDER); /* @@ -334,7 +331,7 @@ public class RecordsImplUnitTest /* * Then the record is linked to the destination folder */ - verify(mockedRMNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); + verify(mockedNodes).getOrCreatePath(mockedTargetRecordFolder.getId(), null, TYPE_CONTENT); verify(mockedRecordService).link(mockedRecord, mockedTargetRecordFolder); } } From 5fc0cc504528a10a52a53fdf81bc3ff6446574d0 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 17:03:41 +0200 Subject: [PATCH 08/10] RM-4619 - moved the fileplan component check back --- .../java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java index 81e839c120..e9b7f71de9 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/rm/rest/api/impl/RMNodesImpl.java @@ -138,7 +138,14 @@ public class RMNodesImpl extends NodesImpl implements RMNodes if (type == null) { - node = new FileplanComponentNode(originalNode); + if (filePlanService.isFilePlanComponent(nodeRef)) + { + node = new FileplanComponentNode(originalNode); + } + else + { + throw new InvalidParameterException("The provided node is not a fileplan component"); + } } else { From 5b041f31f24ca7f13f2728a91a9ca37f34066262 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 22:51:31 +0200 Subject: [PATCH 09/10] RM-4619 - removed folder from the invalit type list --- .../test/java/org/alfresco/rest/rm/community/base/TestData.java | 2 -- 1 file changed, 2 deletions(-) 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 } }; } From 161ec4eaeec5776bd4d80a0e5be92dabdc2b7104 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 7 Feb 2017 16:24:10 +0200 Subject: [PATCH 10/10] RM-4619 - replaced unit tests with integration tests --- .../test/integration/issue/RM4619Test.java | 84 +++++++++++++++++++ .../model/rma/type/FilePlanTypeUnitTest.java | 23 ----- .../rma/type/RecordCategoryTypeUnitTest.java | 23 ----- 3 files changed, 84 insertions(+), 46 deletions(-) create mode 100644 rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/issue/RM4619Test.java 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 d25d6ecb19..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 @@ -182,29 +182,6 @@ public class FilePlanTypeUnitTest extends BaseUnitTest filePlanType.onCreateChildAssociation(childAssoc, true); } - /** - * Given that we try to add "cm:folder" type to a record category, - * Then operation is successful and the folder is automatically converted to a record folder - */ - @Test - public void testConversionToRecordFolder() throws Exception - { - NodeRef fileplan = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN); - NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); - ChildAssociationRef childAssocRef = generateChildAssociationRef(fileplan, nodeRef); - - try - { - filePlanType.onCreateChildAssociation(childAssocRef, true); - } - catch(IntegrityException ex) - { - // this will throw an exception because unit tests can't detect type change - } - - verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_CATEGORY); - } - /** * Helper method that creates a child of the fileplan container with the provided type * @param childType the node type of the child to be created 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 2560615bca..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 @@ -109,27 +109,4 @@ public class RecordCategoryTypeUnitTest extends BaseUnitTest ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); recordCategoryType.onCreateChildAssociation(childAssocRef, true); } - - /** - * Given that we try to add "cm:folder" type to a record category, - * Then operation is successful and the folder is automatically converted to a record folder - */ - @Test - public void testConversionToRecordFolder() throws Exception - { - NodeRef recordCategoryNodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_RECORD_CATEGORY); - NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER, true); - ChildAssociationRef childAssocRef = generateChildAssociationRef(recordCategoryNodeRef, nodeRef); - - try - { - recordCategoryType.onCreateChildAssociation(childAssocRef, true); - } - catch(IntegrityException ex) - { - // this will throw an exception because unit tests can't detect type change - } - - verify(mockedNodeService).setType(nodeRef, TYPE_RECORD_FOLDER); - } }