diff --git a/source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java b/source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java index 949b92e82f..a77352090c 100644 --- a/source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java @@ -94,6 +94,9 @@ public class DeletedNodesImpl implements DeletedNodes Map nodeProps = nodeService.getProperties(aNode.getNodeRef()); aNode.setArchivedAt((Date)nodeProps.get(ContentModel.PROP_ARCHIVED_DATE)); aNode.setArchivedByUser(aNode.lookupUserInfo((String)nodeProps.get(ContentModel.PROP_ARCHIVED_BY), mapUserInfo, personService)); + + //Don't show parent id + aNode.setParentId(null); } @Override diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 2318c3069a..e16783298b 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -801,10 +801,14 @@ public class NodesImpl implements Nodes mapUserInfo = new HashMap<>(2); } + Node node; + Map properties = nodeService.getProperties(nodeRef); + PathInfo pathInfo = null; if (includeParam.contains(PARAM_INCLUDE_PATH)) { - pathInfo = lookupPathInfo(nodeRef); + ChildAssociationRef archivedParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC); + pathInfo = lookupPathInfo(nodeRef, archivedParentAssoc); } if (nodeTypeQName == null) @@ -817,9 +821,6 @@ public class NodesImpl implements Nodes parentNodeRef = getParentNodeRef(nodeRef); } - Node node; - Map properties = nodeService.getProperties(nodeRef); - Type type = getType(nodeTypeQName, nodeRef); if (type == null) @@ -898,14 +899,35 @@ public class NodesImpl implements Nodes return node; } - protected PathInfo lookupPathInfo(NodeRef nodeRefIn) + protected PathInfo lookupPathInfo(NodeRef nodeRefIn, ChildAssociationRef archivedParentAssoc) { - final Path nodePath = nodeService.getPath(nodeRefIn); List pathElements = new ArrayList<>(); Boolean isComplete = Boolean.TRUE; - // 2 => as we don't want to include the given node in the path as well. - for (int i = nodePath.size() - 2; i >= 0; i--) + final Path nodePath; + final int pathIndex; + + if (archivedParentAssoc != null) + { + if (permissionService.hasPermission(archivedParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) + && nodeService.exists(archivedParentAssoc.getParentRef())) + { + nodePath = nodeService.getPath(archivedParentAssoc.getParentRef()); + pathIndex = 1;// 1 => we want to include the given node in the path as well. + } + else + { + //We can't return a valid path + return null; + } + } + else + { + nodePath = nodeService.getPath(nodeRefIn); + pathIndex = 2; // 2 => as we don't want to include the given node in the path as well. + } + + for (int i = nodePath.size() - pathIndex; i >= 0; i--) { Element element = nodePath.get(i); if (element instanceof Path.ChildAssocElement) @@ -947,7 +969,7 @@ public class NodesImpl implements Nodes } return new PathInfo(pathStr, isComplete, pathElements); } - + protected Set mapToNodeAspects(List aspectNames) { Set nodeAspects = new HashSet<>(aspectNames.size()); @@ -1586,7 +1608,7 @@ public class NodesImpl implements Nodes } else { - poster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(), + poster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(), activityInfo.getSiteId(), activityInfo.getParentNodeRef(), activityInfo.getNodeRef(), activityInfo.getFileName(), Activities.APP_TOOL, Activities.RESTAPI_CLIENT, activityInfo.getFileInfo()); diff --git a/source/test-java/org/alfresco/rest/DeletedNodesTest.java b/source/test-java/org/alfresco/rest/DeletedNodesTest.java index aeaa3b7c39..9048d8875c 100644 --- a/source/test-java/org/alfresco/rest/DeletedNodesTest.java +++ b/source/test-java/org/alfresco/rest/DeletedNodesTest.java @@ -20,6 +20,7 @@ package org.alfresco.rest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.alfresco.rest.api.Nodes; @@ -30,12 +31,15 @@ import org.alfresco.rest.api.tests.client.RequestContext; import org.alfresco.rest.api.tests.client.data.Document; import org.alfresco.rest.api.tests.client.data.Folder; import org.alfresco.rest.api.tests.client.data.Node; +import org.alfresco.rest.api.tests.client.data.PathInfo; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.junit.Test; import org.springframework.extensions.webscripts.Status; +import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Map; /** * Tests Deleting nodes and recovering @@ -92,23 +96,36 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest assertNotNull(nodes); assertEquals(numOfNodes+3,nodes.size()); - response = getSingle(URL_DELETED_NODES, u1.getId(), document.getId(), 200); + Map params = Collections.singletonMap("include", "path"); + response = getSingle(URL_DELETED_NODES, u1.getId(), document.getId(), params, 200); Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); assertNotNull(node); assertEquals(u1.getId(), node.getArchivedByUser().getId()); assertTrue(node.getArchivedAt().after(now)); + PathInfo path = node.getPath(); + assertNull("Path should be null because its parent has been deleted",path); + assertNull("We don't show the parent id for a deleted node",node.getParentId()); - response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), 200); + response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), params, 200); Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class); assertNotNull(fNode); assertEquals(u1.getId(), fNode.getArchivedByUser().getId()); assertTrue(fNode.getArchivedAt().after(now)); + path = fNode.getPath(); + assertNotNull(path); + assertEquals("/Company Home/Sites/"+tSite.getSiteId()+"/documentLibrary", path.getName()); + assertTrue(path.getIsComplete()); + assertNull("We don't show the parent id for a deleted node",fNode.getParentId()); - response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolderNonSite.getId(), 200); + response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolderNonSite.getId(), params, 200); fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class); assertNotNull(fNode); assertEquals(u1.getId(), fNode.getArchivedByUser().getId()); assertTrue(fNode.getArchivedAt().after(now)); + path = fNode.getPath(); + assertNotNull(path); + assertEquals("/Company Home/User Homes/"+u1.getId(), path.getName()); + assertTrue(path.getIsComplete()); //The list is ordered with the most recently deleted node first checkDeletedNodes(now, createdFolder, createdFolderNonSite, document, nodes); @@ -215,6 +232,7 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest assertEquals("This folder was deleted most recently", createdFolderNonSite.getId(), aNode.getId()); assertEquals(u1.getId(), aNode.getArchivedByUser().getId()); assertTrue(aNode.getArchivedAt().after(now)); + assertNull("We don't show the parent id for a deleted node",aNode.getParentId()); Node folderNode = (Node) nodes.get(1); assertNotNull(folderNode); @@ -222,12 +240,14 @@ public class DeletedNodesTest extends AbstractSingleNetworkSiteTest assertEquals(u1.getId(), folderNode.getArchivedByUser().getId()); assertTrue(folderNode.getArchivedAt().after(now)); assertTrue("This folder was deleted before the non-site folder", folderNode.getArchivedAt().before(aNode.getArchivedAt())); + assertNull("We don't show the parent id for a deleted node",folderNode.getParentId()); aNode = (Node) nodes.get(2); assertNotNull(aNode); assertEquals(document.getId(), aNode.getId()); assertEquals(u1.getId(), aNode.getArchivedByUser().getId()); assertTrue(aNode.getArchivedAt().after(now)); + assertNull("We don't show the parent id for a deleted node",aNode.getParentId()); } }