mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1541: Unlink Record
* unlink added to Record Service * unit test for Record Service extended to include link and unlink methods * Unlink action added * unit test for Unlink action added git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@91551 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.action.impl;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Unlink from action implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.3
|
||||
*/
|
||||
public class UnlinkFromAction extends RMActionExecuterAbstractBase
|
||||
{
|
||||
/** action name */
|
||||
public static final String NAME = "unlinkFrom";
|
||||
|
||||
/** action parameters */
|
||||
public static final String PARAM_RECORD_FOLDER = "recordFolder";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// check that the actioned upon node reference exists and is of the correct type
|
||||
if (getNodeService().exists(actionedUponNodeRef) &&
|
||||
!getNodeService().hasAspect(actionedUponNodeRef, ContentModel.ASPECT_PENDING_DELETE) &&
|
||||
getRecordService().isRecord(actionedUponNodeRef))
|
||||
{
|
||||
// get the record folder we are unlinking from
|
||||
String recordFolderValue = (String)action.getParameterValue(PARAM_RECORD_FOLDER);
|
||||
if (recordFolderValue == null || recordFolderValue.isEmpty())
|
||||
{
|
||||
// indicate that the record folder is mandatory
|
||||
throw new AlfrescoRuntimeException("Can't unlink, because no record folder was provided.");
|
||||
}
|
||||
NodeRef recordFolder = new NodeRef(recordFolderValue);
|
||||
|
||||
// unlink record from record folder
|
||||
getRecordService().unlink(actionedUponNodeRef, recordFolder);
|
||||
}
|
||||
}
|
||||
}
|
@@ -54,6 +54,8 @@ public interface RecordService
|
||||
|
||||
/**
|
||||
* Disables the property editable check.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
void disablePropertyEditableCheck();
|
||||
|
||||
@@ -61,6 +63,7 @@ public interface RecordService
|
||||
* Disables the property editable check for a given node in this transaction only.
|
||||
*
|
||||
* @param nodeRef node reference
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
void disablePropertyEditableCheck(NodeRef nodeRef);
|
||||
@@ -249,10 +252,20 @@ public interface RecordService
|
||||
void makeRecord(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Creates a link for the specified document in target
|
||||
* Links a record to a record folder
|
||||
*
|
||||
* @param nodeRef The document node reference for which a link will be created
|
||||
* @param folder The folder in which the link will be created
|
||||
* @param record the record to link
|
||||
* @param recordFolder the record folder to link it to
|
||||
*/
|
||||
void link(NodeRef nodeRef, NodeRef folder);
|
||||
void link(NodeRef record, NodeRef recordFolder);
|
||||
|
||||
/**
|
||||
* Unlinks a record from a specified record folder.
|
||||
*
|
||||
* @param record the record to unlink
|
||||
* @param recordFolder the record folder to unlink it from
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
void unlink(NodeRef record, NodeRef recordFolder);
|
||||
}
|
||||
|
@@ -1635,14 +1635,68 @@ public class RecordServiceImpl extends BaseBehaviourBean
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#link(NodeRef, NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void link(NodeRef nodeRef, NodeRef folder)
|
||||
public void link(NodeRef record, NodeRef recordFolder)
|
||||
{
|
||||
ParameterCheck.mandatory("nodeRef", nodeRef);
|
||||
ParameterCheck.mandatory("folder", folder);
|
||||
ParameterCheck.mandatory("record", record);
|
||||
ParameterCheck.mandatory("recordFolder", recordFolder);
|
||||
|
||||
if(isRecord(nodeRef) && isRecordFolder(folder))
|
||||
// ensure we are linking a record to a record folder
|
||||
if(isRecord(record) && isRecordFolder(recordFolder))
|
||||
{
|
||||
nodeService.addChild(folder, nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeService.getProperty(nodeRef, ContentModel.PROP_NAME).toString()));
|
||||
// ensure that we are not linking a record to an exisiting location
|
||||
List<ChildAssociationRef> parents = nodeService.getParentAssocs(record);
|
||||
for (ChildAssociationRef parent : parents)
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
else
|
||||
{
|
||||
// can only link a record to a record folder
|
||||
throw new AlfrescoRuntimeException("Can only link a record to a record folder.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#unlink(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public void unlink(NodeRef record, NodeRef recordFolder)
|
||||
{
|
||||
ParameterCheck.mandatory("record", record);
|
||||
ParameterCheck.mandatory("recordFolder", recordFolder);
|
||||
|
||||
// ensure we are unlinking a record from a record folder
|
||||
if(isRecord(record) && isRecordFolder(recordFolder))
|
||||
{
|
||||
// check that we are not trying to unlink the primary parent
|
||||
NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
|
||||
if (primaryParent.equals(recordFolder))
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Can't unlink a record from it's owning record folder.");
|
||||
}
|
||||
|
||||
// remove the link
|
||||
nodeService.removeChild(recordFolder, record);
|
||||
}
|
||||
else
|
||||
{
|
||||
// can only unlink a record from a record folder
|
||||
throw new AlfrescoRuntimeException("Can only unlink a record from a record folder.");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user