From abc74f54f6015c3cda0a620497d9531eb41be1ea Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 9 Jan 2017 15:50:56 +0000 Subject: [PATCH] REPO-1780: always use the primary parent ID regardless of context git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@134111 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/impl/NodesImpl.java | 3 +- .../api/tests/NodeAssociationsApiTest.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 8c839dfb90..a3508d1b93 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -1304,7 +1304,8 @@ public class NodesImpl implements Nodes FileInfo fInfo = page.get(index); // minimal info by default (unless "include"d otherwise) - return getFolderOrDocument(fInfo.getNodeRef(), parentNodeRef, fInfo.getType(), includeParam, mapUserInfo); + // (pass in null as parentNodeRef to force loading of primary parent node as parentId) + return getFolderOrDocument(fInfo.getNodeRef(), null, fInfo.getType(), includeParam, mapUserInfo); } @Override diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java index a66c62195f..2151b55b8c 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeAssociationsApiTest.java @@ -34,6 +34,7 @@ import org.alfresco.rest.api.tests.client.HttpResponse; import org.alfresco.rest.api.tests.client.PublicApiClient; import org.alfresco.rest.api.tests.client.PublicApiClient.Paging; import org.alfresco.rest.api.tests.client.data.Association; +import org.alfresco.rest.api.tests.client.data.Document; import org.alfresco.rest.api.tests.client.data.Node; import org.alfresco.rest.api.tests.util.RestApiUtil; import org.alfresco.service.cmr.repository.NodeRef; @@ -1228,6 +1229,59 @@ public class NodeAssociationsApiTest extends AbstractSingleNetworkSiteTest } } + /** + * Regardless of which parent is used to list children of a node, the node information + * should consistently present the primary parent as a node's {@code parentId}. + *

+ * See REPO-1780 + */ + @Test + public void testListChildrenConsistentParentIdWithSecondaryAssociations() throws Exception + { + setRequestContext(user1); + String myNodeId = getMyNodeId(); + + // Create primary folder + String primaryFolderName = "primary folder " + RUNID; + String primaryFolderId = createFolder(myNodeId, primaryFolderName, null).getId(); + + // Create content file + String contentFileName = "content" + RUNID + " in folder"; + String contentId = createTextFile(primaryFolderId, contentFileName, "The quick brown fox jumps over the lazy dog.").getId(); + + // Add a secondary parent for content file + Node n = new Node(); + n.setName("secondary folder " + RUNID); + n.setNodeType(TYPE_CM_FOLDER); + n.setAspectNames(Arrays.asList(ASPECT_CM_PREFERENCES)); + HttpResponse response = post(getNodeChildrenUrl(myNodeId), toJsonAsStringNonNull(n), 201); + String secondaryFolderId = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class).getId(); + AssocChild secChild = new AssocChild(contentId, ASSOC_TYPE_CM_CONTAINS); + post(getNodeSecondaryChildrenUrl(secondaryFolderId), toJsonAsStringNonNull(secChild), 201); + + Paging paging = getPaging(0, 100); + // Order by folders and modified date first + Map orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC"); + + // Retrieve the node via the primary parent + String primaryChildrenUrl = getNodeChildrenUrl(primaryFolderId); + response = getAll(primaryChildrenUrl, paging, orderBy, 200); + List nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); + Document node = nodes.get(0); + assertEquals(contentId, node.getId()); + assertEquals(primaryFolderId, node.getParentId()); + + // Retrieve the node via the secondary parent + String secondaryChildrenUrl = getNodeChildrenUrl(secondaryFolderId); + response = getAll(secondaryChildrenUrl, paging, orderBy, 200); + nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Document.class); + node = nodes.get(0); + assertEquals(contentId, node.getId()); + // The parent ID must STILL be the primary parent, even when the info + // is retrieved via the secondary parent. + assertEquals(primaryFolderId, node.getParentId()); + } + /** * Test ability to delete a node with associations (to and from the node) and then restore it. * Only the primary parent/child assoc(s) for the deleted node(s) is/are restored.