Prevent incompatiable disposition schedules from being linked together

* the unpredicatable behaviour was caused by this incompatibility and the resulting uncertaintity over which level of dispostion would 'win'
  * RM-1963: It is not possible to cut off record scheduled for cut off if it's linked to a folder with disposition schedule with cut off step set on folder.
  * RM-1962: The disposition schedule steps are not working as expected on a record linked to a folder with disposition schedule on it's own.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@97948 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2015-02-25 00:25:33 +00:00
parent 890dd9417c
commit af6f894ed0
7 changed files with 439 additions and 22 deletions

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.module.org_alfresco_module_rm.record;
import org.alfresco.error.AlfrescoRuntimeException;
/**
* Record link exception class
*
* @author Roy Wetherall
* @since 2.3
*/
public class RecordLinkRuntimeException extends AlfrescoRuntimeException
{
private static final long serialVersionUID = 5202539484220535897L;
public RecordLinkRuntimeException(String msgId, Throwable cause)
{
super(msgId, cause);
}
public RecordLinkRuntimeException(String msgId, Object[] msgParams, Throwable cause)
{
super(msgId, msgParams, cause);
}
public RecordLinkRuntimeException(String msgId, Object[] msgParams)
{
super(msgId, msgParams);
}
public RecordLinkRuntimeException(String msgId)
{
super(msgId);
}
}

View File

@@ -43,6 +43,8 @@ import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnFi
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule;
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
@@ -221,6 +223,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
/** Relationship service */
private RelationshipService relationshipService;
/** Disposition service */
private DispositionService dispositionService;
/** records management container type */
private RecordsManagementContainerType recordsManagementContainerType;
@@ -362,6 +367,17 @@ public class RecordServiceImpl extends BaseBehaviourBean
this.relationshipService = relationshipService;
}
/**
* @param dispositionService disposition service
*/
public void setDispositionService(DispositionService dispositionService)
{
this.dispositionService = dispositionService;
}
/**
* @param recordsManagementContainerType records management container type
*/
public void setRecordsManagementContainerType(RecordsManagementContainerType recordsManagementContainerType)
{
this.recordsManagementContainerType = recordsManagementContainerType;
@@ -518,18 +534,33 @@ public class RecordServiceImpl extends BaseBehaviourBean
Set<NodeRef> newRecords = transactionalResourceHelper.getSet(KEY_NEW_RECORDS);
newRecords.add(nodeRef);
}
else
{
// if we are linking a record
NodeRef parentNodeRef = childAssocRef.getParentRef();
if (isRecord(nodeRef) && isRecordFolder(parentNodeRef))
{
// validate the link conditions
validateLinkConditions(nodeRef, parentNodeRef);
}
}
// create and file the content as a record
file(nodeRef);
}
}
}
catch (RecordLinkRuntimeException e)
{
// rethrow exception
throw e;
}
catch (AlfrescoRuntimeException e)
{
// do nothing but log error
if (logger.isDebugEnabled())
if (logger.isWarnEnabled())
{
logger.debug("Unable to file pending record.", e);
logger.warn("Unable to file pending record.", e);
}
}
finally
@@ -1685,7 +1716,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
{
ParameterCheck.mandatory("record", record);
ParameterCheck.mandatory("recordFolder", recordFolder);
// ensure we are linking a record to a record folder
if(isRecord(record) && isRecordFolder(recordFolder))
{
@@ -1696,24 +1727,51 @@ public class RecordServiceImpl extends BaseBehaviourBean
if (parent.getParentRef().equals(recordFolder))
{
// we can not link a record to the same location more than once
throw new AlfrescoRuntimeException("Can not link a record to the same record folder more than once");
throw new RecordLinkRuntimeException("Can not link a record to the same record folder more than once");
}
}
}
// validate link conditions
validateLinkConditions(record, recordFolder);
// get the current name of the record
String name = nodeService.getProperty(record, ContentModel.PROP_NAME).toString();
// create a secondary link to the record folder
nodeService.addChild(
recordFolder,
record,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name));
recordFolder,
record,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name));
}
else
{
// can only link a record to a record folder
throw new AlfrescoRuntimeException("Can only link a record to a record folder.");
throw new RecordLinkRuntimeException("Can only link a record to a record folder.");
}
}
/**
*
* @param record
* @param recordFolder
*/
private void validateLinkConditions(NodeRef record, NodeRef recordFolder)
{
// ensure that the linking record folders have compatible disposition schedules
DispositionSchedule recordDispositionSchedule = dispositionService.getDispositionSchedule(record);
if (recordDispositionSchedule != null)
{
DispositionSchedule recordFolderDispositionSchedule = dispositionService.getDispositionSchedule(recordFolder);
if (recordFolderDispositionSchedule != null)
{
if (recordDispositionSchedule.isRecordLevelDisposition() != recordFolderDispositionSchedule.isRecordLevelDisposition())
{
// we can't link a record to an incompatible disposition schedule
throw new RecordLinkRuntimeException("Can not link a record to a record folder with an incompatible disposition schedule. "
+ "They must either both be record level or record folder level dispositions.");
}
}
}
}
@@ -1733,7 +1791,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
if (primaryParent.equals(recordFolder))
{
throw new AlfrescoRuntimeException("Can't unlink a record from it's owning record folder.");
throw new RecordLinkRuntimeException("Can't unlink a record from it's owning record folder.");
}
// remove the link
@@ -1742,7 +1800,7 @@ public class RecordServiceImpl extends BaseBehaviourBean
else
{
// can only unlink a record from a record folder
throw new AlfrescoRuntimeException("Can only unlink a record from a record folder.");
throw new RecordLinkRuntimeException("Can only unlink a record from a record folder.");
}
}