Merge branch 'release/V3.2' into merge-3.3/RM-7065_RetentionScheduleInheritance

This commit is contained in:
Roxana Lucanu
2020-01-29 09:36:53 +02:00
4 changed files with 189 additions and 11 deletions

View File

@@ -104,6 +104,7 @@
<property name="recordFolderService" ref="RecordFolderService"/>
<property name="recordService" ref="RecordService"/>
<property name="freezeService" ref="FreezeService"/>
<property name="transactionService" ref="transactionService" />
</bean>
<bean id="DispositionService" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -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)
{

View File

@@ -57,6 +57,9 @@ import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -65,6 +68,7 @@ import org.alfresco.service.cmr.repository.Period;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ParameterCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -115,6 +119,9 @@ public class DispositionServiceImpl extends ServiceBaseImpl
/** Freeze Service */
private FreezeService freezeService;
/** Transaction service */
private TransactionService transactionService;
/** Disposition properties */
private Map<QName, DispositionProperty> dispositionProperties = new HashMap<>(4);
@@ -192,6 +199,14 @@ public class DispositionServiceImpl extends ServiceBaseImpl
this.freezeService = freezeService;
}
/**
* @param transactionService transaction service
*/
public void setTransactionService(TransactionService transactionService)
{
this.transactionService = transactionService;
}
/**
* Behavior to initialize the disposition schedule of a newly filed record.
*
@@ -408,7 +423,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
NodeRef dsNodeRef = getAssociatedDispositionScheduleImpl(nodeRef);
if (dsNodeRef != null)
{
// Cerate disposition schedule object
// Create disposition schedule object
ds = new DispositionScheduleImpl(serviceRegistry, nodeService, dsNodeRef);
}
}
@@ -697,7 +712,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
* @param nodeRef node reference
* @param dispositionActionDefinition disposition action definition
*/
private DispositionAction initialiseDispositionAction(NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition)
private DispositionAction initialiseDispositionAction(final NodeRef nodeRef, DispositionActionDefinition dispositionActionDefinition)
{
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef, ASSOC_NEXT_DISPOSITION_ACTION, ASSOC_NEXT_DISPOSITION_ACTION, 1, true);
if (childAssocs != null && !childAssocs.isEmpty())
@@ -706,7 +721,7 @@ public class DispositionServiceImpl extends ServiceBaseImpl
}
// Create the properties
Map<QName, Serializable> props = new HashMap<>(10);
final Map<QName, Serializable> props = new HashMap<>(10);
Date asOfDate = calculateAsOfDate(nodeRef, dispositionActionDefinition);
@@ -718,14 +733,23 @@ public class DispositionServiceImpl extends ServiceBaseImpl
props.put(PROP_DISPOSITION_AS_OF, asOfDate);
}
// Create a new disposition action object
NodeRef dispositionActionNodeRef = this.nodeService.createNode(
nodeRef,
ASSOC_NEXT_DISPOSITION_ACTION,
ASSOC_NEXT_DISPOSITION_ACTION,
TYPE_DISPOSITION_ACTION,
props).getChildRef();
DispositionAction da = new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef);
DispositionAction da;
// check if current transaction is a READ ONLY one and if true create the node in a READ WRITE transaction
if (AlfrescoTransactionSupport.getTransactionReadState().equals(TxnReadState.TXN_READ_ONLY))
{
da =
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<DispositionAction>()
{
public DispositionAction execute() throws Throwable
{
return createDispositionAction(nodeRef, props);
}
}, false, true);
}
else
{
da = createDispositionAction(nodeRef, props);
}
// Create the events
List<RecordsManagementEvent> events = dispositionActionDefinition.getEvents();
@@ -737,6 +761,24 @@ public class DispositionServiceImpl extends ServiceBaseImpl
return da;
}
/** Creates a new disposition action object
*
* @param nodeRef node reference
* @param props properties of the disposition action to be created
* @return the disposition action object
*/
private DispositionAction createDispositionAction(final NodeRef nodeRef, Map<QName, Serializable> props)
{
NodeRef dispositionActionNodeRef = nodeService.createNode(
nodeRef,
ASSOC_NEXT_DISPOSITION_ACTION,
ASSOC_NEXT_DISPOSITION_ACTION,
TYPE_DISPOSITION_ACTION,
props).getChildRef();
return new DispositionActionImpl(serviceRegistry, dispositionActionNodeRef);
}
/**
* Compute the "disposition as of" date (if necessary) for a disposition action and a node.
*

View File

@@ -0,0 +1,130 @@
/*
* #%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 <http://www.gnu.org/licenses/>.
* #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
* <p>
* relates to https://issues.alfresco.com/jira/browse/RM-7065
*/
public void testRetentionScheduleInheritance_RM7065()
{
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
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
{
dispositionService.getDispositionSchedule(record);
// check for the lifecycle aspect
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<QName, Serializable> cutOff = new HashMap<QName, Serializable>(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<QName, Serializable> retain = new HashMap<QName, Serializable>(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);
}
}