Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

122127 jvonka: Nodes (FileFolder) API - update/add -ve tests for move & copy operations
   - also fix-up error messages to show nodeId (rather than full nodeRef)
   RA-684, RA-806


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126450 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 10:57:11 +00:00
parent df9a17f35f
commit ac73cc618d
5 changed files with 120 additions and 67 deletions

View File

@@ -110,7 +110,7 @@ public interface Nodes
Node createNode(String parentFolderNodeId, Node nodeInfo, Parameters parameters);
/**
* Move node
* Move or Copy node
*
* @param sourceNodeId
* @param parentFolderNodeId
@@ -118,18 +118,7 @@ public interface Nodes
* @param parameters
* @return
*/
Node moveNode(String sourceNodeId, String parentFolderNodeId, String name, Parameters parameters);
/**
* Copy node
*
* @param sourceNodeId
* @param parentFolderNodeId
* @param name
* @param parameters
* @return
*/
Node copyNode(String sourceNodeId, String parentFolderNodeId, String name, Parameters parameters);
Node moveOrCopyNode(String sourceNodeId, String parentFolderNodeId, String name, Parameters parameters, boolean isCopy);
/**
* Update node meta-data.

View File

@@ -480,7 +480,7 @@ public class NodesImpl implements Nodes
}
else
{
throw new InvalidArgumentException("Node is not a file");
throw new InvalidArgumentException("Node is not a file: "+nodeRef.getId());
}
}
@@ -527,6 +527,11 @@ public class NodesImpl implements Nodes
{
NodeRef parentNodeRef;
if ((nodeId == null) || (nodeId.isEmpty()))
{
throw new InvalidArgumentException("Missing nodeId");
}
if (nodeId.equals(PATH_ROOT))
{
parentNodeRef = repositoryHelper.getCompanyHome();
@@ -622,7 +627,7 @@ public class NodesImpl implements Nodes
catch (FileNotFoundException fnfe)
{
// convert checked exception
throw new EntityNotFoundException(fnfe.getMessage()+" ["+parentNodeRef.getId()+","+path+"]");
throw new EntityNotFoundException(parentNodeRef.getId());
}
return fileInfo.getNodeRef();
@@ -1102,7 +1107,7 @@ public class NodesImpl implements Nodes
{
if (nodeInfo.getNodeRef() != null)
{
throw new InvalidArgumentException("Unexpected id when trying to create a new node: "+nodeInfo.getNodeRef());
throw new InvalidArgumentException("Unexpected id when trying to create a new node: "+nodeInfo.getNodeRef().getId());
}
// check that requested parent node exists and it's type is a (sub-)type of folder
@@ -1381,26 +1386,29 @@ public class NodesImpl implements Nodes
return getFolderOrDocument(nodeRef.getId(), parameters);
}
public Node moveNode(String sourceNodeId, String parentFolderNodeId, String name, Parameters parameters)
public Node moveOrCopyNode(String sourceNodeId, String targetParentId, String name, Parameters parameters, boolean isCopy)
{
final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
if ((sourceNodeId == null) || (sourceNodeId.isEmpty()))
{
throw new InvalidArgumentException("Missing sourceNodeId");
}
if ((targetParentId == null) || (targetParentId.isEmpty()))
{
throw new InvalidArgumentException("Missing targetParentId");
}
final NodeRef parentNodeRef = validateOrLookupNode(targetParentId, null);
final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId, null);
FileInfo fi = moveOrCopy(sourceNodeRef, parentNodeRef, name, false);
FileInfo fi = moveOrCopyImpl(sourceNodeRef, parentNodeRef, name, isCopy);
return getFolderOrDocument(fi.getNodeRef().getId(), parameters);
}
public Node copyNode(String sourceNodeId, String parentFolderNodeId, String name, Parameters parameters)
protected FileInfo moveOrCopyImpl(NodeRef nodeRef, NodeRef parentNodeRef, String name, boolean isCopy)
{
final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null);
final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId, null);
String targetParentId = parentNodeRef.getId();
FileInfo fi = moveOrCopy(sourceNodeRef, parentNodeRef, name, true);
return getFolderOrDocument(fi.getNodeRef().getId(), parameters);
}
protected FileInfo moveOrCopy(NodeRef nodeRef, NodeRef parentNodeRef, String name, boolean isCopy)
{
try
{
if (isCopy)
@@ -1417,25 +1425,25 @@ public class NodesImpl implements Nodes
}
catch (InvalidNodeRefException inre)
{
throw new EntityNotFoundException(inre.getMessage());
throw new EntityNotFoundException(targetParentId);
}
catch (FileNotFoundException fnfe)
{
// convert checked exception
throw new EntityNotFoundException(fnfe.getMessage());
throw new EntityNotFoundException(targetParentId);
}
catch (FileExistsException fee)
{
// duplicate - name clash
throw new ConstraintViolatedException(fee.getMessage());
throw new ConstraintViolatedException("Name already exists in target parent: "+name);
}
catch (FileFolderServiceImpl.InvalidTypeException ite)
{
throw new InvalidArgumentException(ite.getMessage());
throw new InvalidArgumentException("Invalid type of target parent: "+targetParentId);
}
catch (CyclicChildRelationshipException ccre)
{
throw new InvalidArgumentException(ccre.getMessage());
throw new InvalidArgumentException("Parent/child cycle detected: "+targetParentId);
}
}

View File

@@ -1,9 +1,26 @@
/*
* Copyright (C) 2005-2015 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.rest.api.model;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* A target object.
*
* @author Gethin James
*/
public class NodeTarget extends Target

View File

@@ -127,14 +127,14 @@ public class NodesEntityResource implements
@WebApiDescription(title = "Copy Node", description="Copy one or more nodes (files or folders) to a new target folder, with option to rename.")
public Node copyById(String nodeId, NodeTarget target, Parameters parameters)
{
return nodes.copyNode(nodeId, target.getTargetParentId(), target.getName(), parameters);
return nodes.moveOrCopyNode(nodeId, target.getTargetParentId(), target.getName(), parameters, true);
}
@Operation("move")
@WebApiDescription(title = "Move Node", description="Moves one or more nodes (files or folders) to a new target folder, with option to rename.")
public Node moveById(String nodeId, NodeTarget target, Parameters parameters)
{
return nodes.moveNode(nodeId, target.getTargetParentId(), target.getName(), parameters);
return nodes.moveOrCopyNode(nodeId, target.getTargetParentId(), target.getName(), parameters, false);
}
}