From f06f2df8b1c1fbc1b105763d8c0a45271d5abbbb Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Wed, 8 Jan 2020 20:38:37 +0200 Subject: [PATCH] RM-7065 ode review comments --- .../action/impl/RetainAction.java | 5 + .../disposition/DispositionServiceImpl.java | 8 +- .../DispositionScheduleInheritanceTest.java | 128 ++++++++++++++++++ 3 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/disposition/DispositionScheduleInheritanceTest.java diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RetainAction.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RetainAction.java index 8116c18715..1820a83421 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RetainAction.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/impl/RetainAction.java @@ -38,6 +38,11 @@ import org.alfresco.service.cmr.repository.NodeRef; */ public class RetainAction extends RMDispositionActionExecuterAbstractBase { + /** + * Action name + */ + public static final String NAME = "retain"; + @Override protected void executeRecordFolderLevelDisposition(Action action, NodeRef recordFolder) { diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java index a5d888fb9f..7b4afd9be1 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/disposition/DispositionServiceImpl.java @@ -737,6 +737,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl } DispositionAction da; + // check if current transaction is a READ ONLY one and if true create the node in a READ WRITE one if (AlfrescoTransactionSupport.getTransactionReadState().equals(TxnReadState.TXN_READ_ONLY)) { da = @@ -747,7 +748,8 @@ public class DispositionServiceImpl extends ServiceBaseImpl return createDispositionAction(nodeRef, props); } }, false, true); - } else + } + else { da = createDispositionAction(nodeRef, props); } @@ -770,14 +772,14 @@ public class DispositionServiceImpl extends ServiceBaseImpl */ private DispositionAction createDispositionAction(final NodeRef nodeRef, Map props) { - NodeRef result = nodeService.createNode( + NodeRef dispositionActionNodeRef = nodeService.createNode( nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, ASSOC_NEXT_DISPOSITION_ACTION, TYPE_DISPOSITION_ACTION, props).getChildRef(); - return new DispositionActionImpl(serviceRegistry, result); + return new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef); } /** diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/disposition/DispositionScheduleInheritanceTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/disposition/DispositionScheduleInheritanceTest.java new file mode 100644 index 0000000000..937ecac430 --- /dev/null +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/disposition/DispositionScheduleInheritanceTest.java @@ -0,0 +1,128 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2020 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.disposition; + +import static org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils.DEFAULT_DISPOSITION_DESCRIPTION; +import static org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils.DEFAULT_DISPOSITION_INSTRUCTIONS; +import static org.alfresco.util.GUID.generate; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; +import org.alfresco.module.org_alfresco_module_rm.action.impl.RetainAction; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; + +/** + * Inherit disposition schedule on record level when moving categories. + * + * @author Roxana Lucanu + * @since 2.5 + */ +public class DispositionScheduleInheritanceTest extends BaseRMTestCase +{ + /** + * Given a root record category with a retention schedule + * and another root record category + * When moving the second record category into the first one (with the disposition) + * Then records under the second record category inherit the retention schedule of the parent record category + *

+ * relates to https://issues.alfresco.com/jira/browse/RM-7065 + */ + public void testRetentionScheduleInheritance_RM3060() + { + doBehaviourDrivenTest(new BehaviourDrivenTest() + { + NodeRef category1; + NodeRef subcategory2; + NodeRef record; + + @Override + public void given() + { + // create root category1 + category1 = filePlanService.createRecordCategory(filePlan, generate()); + + // create record level disposition schedule for category1 + createDispositionSchedule(category1); + + // create subcategory1 under category1 + NodeRef subcategory1 = filePlanService.createRecordCategory(category1, generate()); + + // create root category2 + NodeRef category2 = filePlanService.createRecordCategory(filePlan, generate()); + + // create subcategory2 under category2 + NodeRef subcategory2 = filePlanService.createRecordCategory(category2, generate()); + + // create folder under subcategory2 + folder = recordFolderService.createRecordFolder(subcategory2, generate()); + + // file record in folder and complete it + record = utils.createRecord(folder, generate(), generate()); + utils.completeRecord(record); + } + + @Override + public void when() throws Exception + { + // move subcategory2 under category1 + fileFolderService.move(subcategory2, category1, null); + } + + @Override + public void then() throws Exception + { + assertTrue("Record " + record + " doesn't have the disposition lifecycle aspect.", nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE)); + } + }); + } + + private void createDispositionSchedule(NodeRef category) + { + DispositionSchedule ds = utils.createDispositionSchedule(category, DEFAULT_DISPOSITION_INSTRUCTIONS, DEFAULT_DISPOSITION_DESCRIPTION, true, false, false); + + // CUTOFF immediately + Map cutOff = new HashMap(3); + cutOff.put(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME); + cutOff.put(PROP_DISPOSITION_DESCRIPTION, generate()); + cutOff.put(PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY); + dispositionService.addDispositionActionDefinition(ds, cutOff); + + // RETAIN immediately + Map retain = new HashMap(3); + retain.put(PROP_DISPOSITION_ACTION_NAME, RetainAction.NAME); + retain.put(PROP_DISPOSITION_DESCRIPTION, generate()); + retain.put(PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY); + dispositionService.addDispositionActionDefinition(ds, retain); + } +} \ No newline at end of file