diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 3484ba57f1..9d26b6dfb8 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -1540,11 +1540,6 @@ public class NodesImpl implements Nodes // check that requested parent node exists and it's type is a (sub-)type of folder NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, null); - if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false)) - { - throw new InvalidArgumentException("NodeId of folder is expected: "+parentNodeRef.getId()); - } - // node name - mandatory String nodeName = nodeInfo.getName(); if ((nodeName == null) || nodeName.isEmpty()) 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 77cbf16464..213b592d3c 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -1823,9 +1823,11 @@ public class NodeApiTest extends AbstractBaseApiTest obj.setName("c1"); obj.setNodeType(TYPE_CM_CONTENT); + // assoc type => cm:contains response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String c1Id = nodeResp.getId(); + assertEquals(fId, nodeResp.getParentId()); obj = new Node(); obj.setName("c2"); @@ -1834,9 +1836,11 @@ public class NodeApiTest extends AbstractBaseApiTest assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE); obj.setAssociation(assoc); + // assoc type => cm:preferenceImage response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); String c2Id = nodeResp.getId(); + assertEquals(fId, nodeResp.getParentId()); response = getAll(getNodeChildrenUrl(fId), user1, null, null, 200); nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class); @@ -1859,6 +1863,43 @@ public class NodeApiTest extends AbstractBaseApiTest assertEquals(1, nodes.size()); assertEquals(c2Id, nodes.get(0).getId()); assertTrue(nodes.get(0).getAssociation().getIsPrimary()); + + // + // test that we can also create children below content + // + + obj = new Node(); + obj.setName("c3"); + obj.setNodeType(TYPE_CM_CONTENT); + nodeUpdate.setAspectNames(Collections.singletonList(ASPECT_CM_PREFERENCES)); + + // assoc type => cm:contains + response = post(getNodeChildrenUrl(fId), user1, toJsonAsStringNonNull(obj), 201); + nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); + String c3Id = nodeResp.getId(); + + obj = new Node(); + obj.setName("c4"); + obj.setNodeType(TYPE_CM_CONTENT); + assoc = new Association(); + assoc.setAssocType(ASSOC_TYPE_CM_PREFERENCE_IMAGE); + obj.setAssociation(assoc); + + // assoc type => cm:preferenceImage + response = post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 201); + nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class); + assertEquals(c3Id, nodeResp.getParentId()); + + // -ve test + obj = new Node(); + obj.setName("c5"); + obj.setNodeType(TYPE_CM_CONTENT); + assoc = new Association(); + assoc.setAssocType(ASSOC_TYPE_CM_CONTAINS); + obj.setAssociation(assoc); + + // assoc type => cm:contains (requires parent to be a folder !) + post(getNodeChildrenUrl(c3Id), user1, toJsonAsStringNonNull(obj), 422); } finally {