From f7622c0231a61648546cfedbc045fee52a75ecc2 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 14 Feb 2017 16:19:45 +0000 Subject: [PATCH 1/2] RM-4681 Add behaviours to restrict where rm items can be created. Record categories can only go in the file plan, or under other record categories. Record folders can only have categories as a primary parent, and holds or transfers as secondary parents. --- .../model/rma/type/RecordCategoryType.java | 7 +++- .../model/rma/type/RecordFolderType.java | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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 4d6d476ebf..b1d7e7a60f 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 @@ -178,13 +178,18 @@ public class RecordCategoryType extends BaseBehaviourBean @Override public Void doWork() { + // Check the parent is either a file plan or a category. + if (!isFilePlan(childAssocRef.getParentRef()) && !isRecordCategory(childAssocRef.getParentRef())) + { + throw new AlfrescoRuntimeException("Operation failed: Record categories must go under file plans or categories."); + } + // setup record category permissions filePlanPermissionService.setupRecordCategoryPermissions(childAssocRef.getChildRef()); return null; } }); - } /** diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java index 2b60c6ff2b..20badd2005 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java @@ -64,6 +64,7 @@ import org.springframework.extensions.surf.util.I18NUtil; ) public class RecordFolderType extends AbstractDisposableItem implements NodeServicePolicies.OnMoveNodePolicy, + NodeServicePolicies.OnCreateNodePolicy, NodeServicePolicies.OnCreateChildAssociationPolicy { /** record service */ @@ -123,6 +124,7 @@ public class RecordFolderType extends AbstractDisposableItem AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { + @Override public Object doWork() { // clean record folder @@ -270,4 +272,40 @@ public class RecordFolderType extends AbstractDisposableItem behaviourFilter.enableBehaviour(); } } + + /** {@inheritDoc}} */ + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + ) + public void onCreateNode(final ChildAssociationRef childAssocRef) + { + // execute behaviour code as system user + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() + { + if (childAssocRef.isPrimary()) + { + // Check the primary parent is a category. + if (!isRecordFolder(childAssocRef.getParentRef())) + { + throw new AlfrescoRuntimeException("Operation failed: Record folders must go under categories."); + } + } + else + { + // Check the secondary parent is a hold or transfer. + if (!isHold(childAssocRef.getParentRef()) && !isTransfer(childAssocRef.getParentRef())) + { + throw new AlfrescoRuntimeException("Operation failed: Record folders can only have secondary parents of holds or transfers."); + } + } + return null; + } + }); + } } From dee7e2d58000d6fceb2b8ecc9def29e81fad0f37 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 15 Feb 2017 04:03:58 +0000 Subject: [PATCH 2/2] RM-4681 Fix typo and add behaviour for moving RM items. --- .../model/rma/type/RecordCategoryType.java | 45 +++++++++-- .../model/rma/type/RecordFolderType.java | 81 +++++++++++-------- 2 files changed, 87 insertions(+), 39 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 b1d7e7a60f..81dc259b95 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 @@ -59,7 +59,8 @@ import org.alfresco.service.namespace.QName; ) public class RecordCategoryType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy, - NodeServicePolicies.OnCreateNodePolicy + NodeServicePolicies.OnCreateNodePolicy, + NodeServicePolicies.OnMoveNodePolicy { /** vital record service */ protected VitalRecordService vitalRecordService; @@ -178,11 +179,7 @@ public class RecordCategoryType extends BaseBehaviourBean @Override public Void doWork() { - // Check the parent is either a file plan or a category. - if (!isFilePlan(childAssocRef.getParentRef()) && !isRecordCategory(childAssocRef.getParentRef())) - { - throw new AlfrescoRuntimeException("Operation failed: Record categories must go under file plans or categories."); - } + checkParentType(childAssocRef); // setup record category permissions filePlanPermissionService.setupRecordCategoryPermissions(childAssocRef.getChildRef()); @@ -218,4 +215,40 @@ public class RecordCategoryType extends BaseBehaviourBean } }; } + + /** Record category move behaviour. {@inheritDoc} */ + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + notificationFrequency = NotificationFrequency.FIRST_EVENT + ) + public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) + { + checkParentType(newChildAssocRef); + } + + /** + * Check the parent of a record category. The parent must be a file plan or another category. + * + * @param childAssocRef The parent-child association. + * @throws UnsupportedOperationException If the parent type is invalid. + */ + private void checkParentType(final ChildAssociationRef childAssocRef) + { + // execute behaviour code as system user + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() + { + // Check the parent is either a file plan or a category. + if (!isFilePlan(childAssocRef.getParentRef()) && !isRecordCategory(childAssocRef.getParentRef())) + { + throw new AlfrescoRuntimeException("Operation failed: Record categories must go under file plans or categories."); + } + return null; + } + }); + } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java index 20badd2005..ddde2471cc 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordFolderType.java @@ -116,41 +116,36 @@ public class RecordFolderType extends AbstractDisposableItem ) public void onMoveNode(ChildAssociationRef oldChildAssocRef, ChildAssociationRef newChildAssocRef) { - if (!nodeService.getType(newChildAssocRef.getParentRef()).equals(TYPE_RECORD_FOLDER)) + checkParentType(newChildAssocRef); + + if (!oldChildAssocRef.getParentRef().equals(newChildAssocRef.getParentRef())) { - if (!oldChildAssocRef.getParentRef().equals(newChildAssocRef.getParentRef())) + final NodeRef newNodeRef = newChildAssocRef.getChildRef(); + + AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { - final NodeRef newNodeRef = newChildAssocRef.getChildRef(); - - AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() + @Override + public Object doWork() { - @Override - public Object doWork() + // clean record folder + cleanDisposableItem(nodeService, newNodeRef); + + // re-initialise the record folder + recordFolderService.setupRecordFolder(newNodeRef); + + // sort out the child records + for (NodeRef record : recordService.getRecords(newNodeRef)) { - // clean record folder - cleanDisposableItem(nodeService, newNodeRef); + // clean record + cleanDisposableItem(nodeService, record); - // re-initialise the record folder - recordFolderService.setupRecordFolder(newNodeRef); - - // sort out the child records - for (NodeRef record : recordService.getRecords(newNodeRef)) - { - // clean record - cleanDisposableItem(nodeService, record); - - // Re-initiate the records in the new folder. - recordService.file(record); - } - - return null; + // Re-initiate the records in the new folder. + recordService.file(record); } - }, AuthenticationUtil.getSystemUserName()); - } - } - else - { - throw new UnsupportedOperationException("Cannot move record folder into another record folder."); + + return null; + } + }, AuthenticationUtil.getSystemUserName()); } } @@ -281,6 +276,17 @@ public class RecordFolderType extends AbstractDisposableItem notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT ) public void onCreateNode(final ChildAssociationRef childAssocRef) + { + checkParentType(childAssocRef); + } + + /** + * Check the parent of a record folder. The primary parent must be a category and a secondary parent may be a hold or a transfer. + * + * @param childAssocRef The parent-child association. + * @throws UnsupportedOperationException If the parent type is invalid. + */ + private void checkParentType(final ChildAssociationRef childAssocRef) { // execute behaviour code as system user AuthenticationUtil.runAsSystem(new RunAsWork() @@ -288,12 +294,19 @@ public class RecordFolderType extends AbstractDisposableItem @Override public Void doWork() { - if (childAssocRef.isPrimary()) + if (nodeService.getType(childAssocRef.getParentRef()).equals(TYPE_RECORD_FOLDER)) + { + // Return slightly more helpful exception in this case. + throw new UnsupportedOperationException("Cannot move record folder into another record folder."); + } + else if (childAssocRef.isPrimary()) { // Check the primary parent is a category. - if (!isRecordFolder(childAssocRef.getParentRef())) + if (!isRecordCategory(childAssocRef.getParentRef())) { - throw new AlfrescoRuntimeException("Operation failed: Record folders must go under categories."); + throw new UnsupportedOperationException( + "Operation failed: Record folders must go under categories, not " + + nodeService.getType(childAssocRef.getParentRef())); } } else @@ -301,7 +314,9 @@ public class RecordFolderType extends AbstractDisposableItem // Check the secondary parent is a hold or transfer. if (!isHold(childAssocRef.getParentRef()) && !isTransfer(childAssocRef.getParentRef())) { - throw new AlfrescoRuntimeException("Operation failed: Record folders can only have secondary parents of holds or transfers."); + throw new UnsupportedOperationException( + "Operation failed: Record folders can only have secondary parents of holds or transfers, not " + + nodeService.getType(childAssocRef.getParentRef())); } } return null;