From c52e2a7cf55eb567b6b0b781dc359e828263d721 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 30 Jan 2017 12:05:48 +0200 Subject: [PATCH] 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) {