RM-1623 (Move In-Place Record)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@79188 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2014-08-10 18:43:43 +00:00
parent f894a44844
commit 328bf9f40a
11 changed files with 373 additions and 24 deletions

View File

@@ -39,7 +39,7 @@ import org.apache.commons.logging.LogFactory;
* @since 2.1
*/
public class HideRecordAction extends AuditableActionExecuterAbstractBase
implements RecordsManagementModel
implements RecordsManagementModel
{
/** Logger */

View File

@@ -0,0 +1,143 @@
/*
* 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.dm;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.action.AuditableActionExecuterAbstractBase;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Moves a record within a collaboration site.
* The record can be moved only within the collaboration site where it was declared.
*
* @author Tuna Aksoy
* @since 2.3
*/
public class MoveDmRecordAction extends AuditableActionExecuterAbstractBase implements RecordsManagementModel
{
/** Logger */
private static Log logger = LogFactory.getLog(MoveDmRecordAction.class);
/** Action name */
public static final String NAME = "move-dm-record";
/** Constant for target node reference parameter */
public static final String PARAM_TARGET_NODE_REF = "targetNodeRef";
/** Node service */
private NodeService nodeService;
/** Record service */
private RecordService recordService;
/**
* Gets the node service
*
* @return Node service
*/
protected NodeService getNodeService()
{
return this.nodeService;
}
/**
* Sets the node service
*
* @param nodeService Node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Gets the record service
*
* @return Record service
*/
protected RecordService getRecordService()
{
return this.recordService;
}
/**
* Sets the record service
*
* @param recordService Record service
*/
public void setRecordService(RecordService recordService)
{
this.recordService = recordService;
}
/**
* @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)
{
// Cannot move a document which is not a record
if (!getNodeService().hasAspect(actionedUponNodeRef, ASPECT_RECORD) && logger.isDebugEnabled())
{
logger.debug("Cannot move the document, because '" + actionedUponNodeRef.toString() + "' is not a record.");
}
else
{
// Move the record within the collaboration site
getRecordService().moveRecord(actionedUponNodeRef, getTargetNodeRef(action));
}
}
/**
* Helper method to get the target node reference from the action parameter
*
* @param action The action
* @return Node reference of the target
*/
private NodeRef getTargetNodeRef(Action action)
{
String targetNodeRef = (String) action.getParameterValue(PARAM_TARGET_NODE_REF);
if (StringUtils.isBlank(targetNodeRef))
{
throw new AlfrescoRuntimeException("Could not find target node reference.");
}
return new NodeRef(targetNodeRef);
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
*/
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
// Intentionally empty
}
}

View File

@@ -56,10 +56,10 @@ public interface RecordService
* Disables the property editable check.
*/
void disablePropertyEditableCheck();
/**
* Disables the property editable check for a given node in this transaction only.
*
*
* @param nodeRef node reference
* @since 2.2
*/
@@ -231,4 +231,12 @@ public interface RecordService
* @param folder The folder in which the link will be created
*/
void link(NodeRef nodeRef, NodeRef folder);
/**
* Moves a record within a collaboration site
*
* @param nodeRef The record which should be moved
* @param targetNodeRef The target node reference where it should be moved to
*/
void moveRecord(NodeRef nodeRef, NodeRef targetNodeRef);
}

View File

@@ -80,6 +80,8 @@ import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
@@ -194,6 +196,9 @@ public class RecordServiceImpl extends BaseBehaviourBean
/** Permission service */
private PermissionService permissionService;
/** Site service */
private SiteService siteService;
/** list of available record meta-data aspects and the file plan types the are applicable to */
private Map<QName, Set<QName>> recordMetaDataAspects;
@@ -315,6 +320,14 @@ public class RecordServiceImpl extends BaseBehaviourBean
this.permissionService = permissionService;
}
/**
* @param siteService site service
*/
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
/**
* Init method
*/
@@ -1475,4 +1488,68 @@ public class RecordServiceImpl extends BaseBehaviourBean
nodeService.addChild(folder, nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeService.getProperty(nodeRef, ContentModel.PROP_NAME).toString()));
}
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#moveRecord(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void moveRecord(final NodeRef nodeRef, final NodeRef targetNodeRef)
{
ParameterCheck.mandatory("nodeRef", nodeRef);
ParameterCheck.mandatory("targetNodeRef", targetNodeRef);
NodeRef sourceParentNodeRef = null;
NodeRef originatingLocation = (NodeRef) nodeService.getProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION);
for (ChildAssociationRef parentAssoc : nodeService.getParentAssocs(nodeRef))
{
if (!parentAssoc.isPrimary() && parentAssoc.getParentRef().equals(originatingLocation))
{
sourceParentNodeRef = parentAssoc.getParentRef();
break;
}
}
if (sourceParentNodeRef == null)
{
throw new AlfrescoRuntimeException("Could not find source parent node reference.");
}
SiteInfo sourceSite = siteService.getSite(sourceParentNodeRef);
SiteInfo targetSite = siteService.getSite(targetNodeRef);
if (!sourceSite.equals(targetSite))
{
throw new AlfrescoRuntimeException("The record can only be moved within the same collaboration site.");
}
if (!sourceSite.getSitePreset().equals("site-dashboard"))
{
throw new AlfrescoRuntimeException("Only records within a collaboration site can be moved.");
}
final NodeRef source = sourceParentNodeRef;
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork()
{
try
{
// Move the record
fileFolderService.moveFrom(nodeRef, source, targetNodeRef, null);
// Update the originating location property
nodeService.setProperty(nodeRef, PROP_RECORD_ORIGINATING_LOCATION, targetNodeRef);
}
catch (FileExistsException | FileNotFoundException ex)
{
throw new AlfrescoRuntimeException("Can't move node: " + ex);
}
return null;
}
});
}
}