diff --git a/source/java/org/alfresco/rest/api/Nodes.java b/source/java/org/alfresco/rest/api/Nodes.java
index 10ca0acb53..fdf66fc345 100644
--- a/source/java/org/alfresco/rest/api/Nodes.java
+++ b/source/java/org/alfresco/rest/api/Nodes.java
@@ -117,7 +117,7 @@ public interface Nodes
Node createNode(String parentFolderNodeId, Node nodeInfo, Parameters parameters);
/**
- * Move node
+ * Move or Copy node
*
* @param sourceNodeId
* @param parentFolderNodeId
@@ -125,18 +125,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.
diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java
index 88b7fd5041..d6266e78a1 100644
--- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java
+++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java
@@ -487,7 +487,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());
}
}
@@ -534,6 +534,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();
@@ -629,7 +634,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();
@@ -1109,7 +1114,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
@@ -1388,26 +1393,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)
@@ -1424,25 +1432,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);
}
}
diff --git a/source/java/org/alfresco/rest/api/model/NodeTarget.java b/source/java/org/alfresco/rest/api/model/NodeTarget.java
index afe2c2cca9..a00dc4df94 100644
--- a/source/java/org/alfresco/rest/api/model/NodeTarget.java
+++ b/source/java/org/alfresco/rest/api/model/NodeTarget.java
@@ -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
POST:
@@ -1231,6 +1235,41 @@ public class NodeApiTest extends AbstractBaseApiTest assertEquals(newD2Name, documentResp.getName()); assertEquals(target, documentResp.getParentId()); + + // -ve tests + + // missing target + NodeTarget tgt = new NodeTarget(); + tgt.setName("new name"); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 400); + + // name already exists + tgt = new NodeTarget(); + tgt.setName(newD2Name); + tgt.setTargetParentId(target); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 409); + + // unknown source nodeId + tgt = new NodeTarget(); + tgt.setTargetParentId(target); + post("nodes/"+UUID.randomUUID().toString()+"/copy", user1, toJsonAsStringNonNull(tgt), null, 404); + + // unknown target nodeId + tgt = new NodeTarget(); + tgt.setTargetParentId(UUID.randomUUID().toString()); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 404); + + // target is not a folder + tgt = new NodeTarget(); + tgt.setTargetParentId(d2Id); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 400); + + String rootNodeId = getRootNodeId(user1); + + // no (write/create) permissions to copy to target + tgt = new NodeTarget(); + tgt.setTargetParentId(rootNodeId); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 403); } /** * Tests create folder.