From 256ba70e5c0254ffc0d2a920599c19af4c25fda0 Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Tue, 10 May 2016 12:11:52 +0000 Subject: [PATCH] Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 126115 jvonka: RA-1028: Fix copy bug - if same parent & name (ie. nothing copied) then return 409 rather than 201 - see also SFS-554 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126635 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- source/java/org/alfresco/rest/api/impl/NodesImpl.java | 8 +++++++- .../org/alfresco/rest/api/tests/NodeApiTest.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index bc03c0f4c2..15127ae42e 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -1900,7 +1900,13 @@ public class NodesImpl implements Nodes if (isCopy) { // copy - return fileFolderService.copy(nodeRef, parentNodeRef, name); + FileInfo newFileInfo = fileFolderService.copy(nodeRef, parentNodeRef, name); + if (newFileInfo.getNodeRef().equals(nodeRef)) + { + // copy did not happen - eg. same parent folder and name (name can be null or same) + throw new FileExistsException(nodeRef, ""); + } + return newFileInfo; } else { diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index 9e73a16aa7..14d0dd0a9a 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -1476,12 +1476,17 @@ public class NodeApiTest extends AbstractBaseApiTest tgt.setName("new name"); post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 400); - // name already exists + // name already exists - different parent tgt = new NodeTarget(); tgt.setName(newD2Name); tgt.setTargetParentId(targetId); post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 409); + // name already exists - same parent + tgt = new NodeTarget(); + tgt.setTargetParentId(sourceId); + post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 409); + // unknown source nodeId tgt = new NodeTarget(); tgt.setTargetParentId(targetId);