diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index eb33b725f7..91cb73e5d4 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -650,9 +650,7 @@ public class NodesImpl implements Nodes String path = parameters.getParameter(PARAM_RELATIVE_PATH); NodeRef nodeRef = validateOrLookupNode(nodeId, path); - QName typeQName = getNodeType(nodeRef); - - return getFolderOrDocumentFullInfo(nodeRef, getParentNodeRef(nodeRef), typeQName, parameters); + return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters); } private Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters) @@ -680,11 +678,21 @@ public class NodesImpl implements Nodes pathInfo = lookupPathInfo(nodeRef); } - Type type = getType(nodeTypeQName, nodeRef); + if (nodeTypeQName == null) + { + nodeTypeQName = getNodeType(nodeRef); + } + + if (parentNodeRef == null) + { + parentNodeRef = getParentNodeRef(nodeRef); + } Node node; Map properties = nodeService.getProperties(nodeRef); + Type type = getType(nodeTypeQName, nodeRef); + if (type == null) { // not direct folder (or file) ... @@ -916,9 +924,9 @@ public class NodesImpl implements Nodes final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, path); // check that resolved node is a folder - if (! nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false)) + if (!nodeMatches(parentNodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), null, false)) { - throw new InvalidArgumentException("NodeId of folder is expected: "+parentNodeRef.getId()); + throw new InvalidArgumentException("NodeId of folder is expected: " + parentNodeRef.getId()); } final List selectParam = parameters.getSelectedProperties(); @@ -1040,7 +1048,14 @@ public class NodesImpl implements Nodes } }; - return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst()); + Node sourceEntity = null; + if (parameters.includeSource()) + { + sourceEntity = getFolderOrDocument(parentNodeRef, null, null, selectParam, mapUserInfo); + } + + + return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity); } private Pair parseNodeTypeFilter(String nodeTypeStr) @@ -1553,10 +1568,7 @@ public class NodesImpl implements Nodes setWriterContentType(writer, new ContentInfoWrapper(contentInfo), nodeRef, true); writer.putContent(stream); - return getFolderOrDocumentFullInfo(nodeRef, - getParentNodeRef(nodeRef), - nodeService.getType(nodeRef), - parameters); + return getFolderOrDocumentFullInfo(nodeRef, null, null, parameters); } private void setWriterContentType(ContentWriter writer, ContentInfoWrapper contentInfo, NodeRef nodeRef, boolean guessEncodingIfNull) 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 d6a7d58157..ed7811d322 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -67,6 +67,7 @@ import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.site.SiteVisibility; import org.alfresco.util.TempFileProvider; +import org.json.simple.JSONObject; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -366,7 +367,7 @@ public class NodeApiTest extends AbstractBaseApiTest assertTrue(node.getContent().getSizeInBytes() > 0); // request without select - Map params = new LinkedHashMap<>(); + Map params = new HashMap<>(); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) @@ -378,7 +379,7 @@ public class NodeApiTest extends AbstractBaseApiTest } // request with select - example 1 - params = new LinkedHashMap<>(); + params = new HashMap<>(); params.put("select", "isLink"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -388,7 +389,7 @@ public class NodeApiTest extends AbstractBaseApiTest } // request with select - example 2 - params = new LinkedHashMap<>(); + params = new HashMap<>(); params.put("select", "aspectNames,properties, path,isLink"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -401,7 +402,7 @@ public class NodeApiTest extends AbstractBaseApiTest } // request specific property via select - params = new LinkedHashMap<>(); + params = new HashMap<>(); params.put("select", "cm:lastThumbnailModification"); params.put("orderBy", "isFolder DESC,modifiedAt DESC"); response = getAll(myChildrenUrl, user1, paging, params, 200); @@ -418,7 +419,7 @@ public class NodeApiTest extends AbstractBaseApiTest // filtering, via where clause - folders only - params = new LinkedHashMap<>(); + params = new HashMap<>(); params.put("where", "("+Nodes.PARAM_ISFOLDER+"=true)"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -433,7 +434,7 @@ public class NodeApiTest extends AbstractBaseApiTest assertTrue(folderIds.contains(nodes.get(1).getId())); // filtering, via where clause - content only - params = new LinkedHashMap<>(); + params = new HashMap<>(); params.put("where", "("+Nodes.PARAM_ISFILE+"=true)"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -446,16 +447,45 @@ public class NodeApiTest extends AbstractBaseApiTest params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1); response = getAll(myChildrenUrl, user1, paging, params, 200); - nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); + JSONObject jsonResponse = response.getJsonResponse(); + nodes = jacksonUtil.parseEntries(jsonResponse, Document.class); assertEquals(1, nodes.size()); assertEquals(contentF1_Id, nodes.get(0).getId()); + JSONObject jsonList = (JSONObject)jsonResponse.get("list"); + assertNotNull(jsonList); + JSONObject jsonSrcObj = (JSONObject)jsonResponse.get("source"); + assertNull(jsonSrcObj); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder2); response = getAll(rootChildrenUrl, user1, paging, params, 200); - nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); + jsonResponse = response.getJsonResponse(); + nodes = jacksonUtil.parseEntries(jsonResponse, Document.class); assertEquals(1, nodes.size()); assertEquals(contentF2_Id, nodes.get(0).getId()); + jsonList = (JSONObject)jsonResponse.get("list"); + assertNotNull(jsonList); + jsonSrcObj = (JSONObject)jsonResponse.get("source"); + assertNull(jsonSrcObj); + + // list children via relativePath and also return the source entity + + params = new HashMap<>(); + params.put(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder2); + params.put("includeSource", "true"); + response = getAll(rootChildrenUrl, user1, paging, params, 200); + jsonResponse = response.getJsonResponse(); + nodes = jacksonUtil.parseEntries(jsonResponse, Document.class); + assertEquals(1, nodes.size()); + assertEquals(contentF2_Id, nodes.get(0).getId()); + + jsonList = (JSONObject)jsonResponse.get("list"); + assertNotNull(jsonList); + + Folder src = RestApiUtil.parsePojo("source", jsonList, Folder.class); + assertEquals(folder2_Id, src.getId()); + // -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter. params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER+" DESC,cm" + System.currentTimeMillis() + ":modified DESC"); getAll(myChildrenUrl, user1, paging, params, 400);