mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REPO-1742 : changes after review
This commit is contained in:
@@ -1311,48 +1311,50 @@ public class NodesImpl implements Nodes
|
||||
FileInfo fInfo = page.get(index);
|
||||
|
||||
// minimal info by default (unless "include"d otherwise)
|
||||
// (pass in null as parentNodeRef to force loading of primary
|
||||
// parent node as parentId)
|
||||
|
||||
// (pass in null as parentNodeRef to force loading of primary
|
||||
// parent node as parentId)
|
||||
Node node = getFolderOrDocument(fInfo.getNodeRef(), null, fInfo.getType(), includeParam, mapUserInfo);
|
||||
if (node.getPath() != null)
|
||||
{
|
||||
NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId,null);
|
||||
try
|
||||
{
|
||||
// get the path elements
|
||||
List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, node.getNodeRef());
|
||||
|
||||
int sizePathInfos = pathInfos.size();
|
||||
|
||||
if (sizePathInfos > 1)
|
||||
{
|
||||
// remove the current child
|
||||
pathInfos.remove(sizePathInfos - 1);
|
||||
|
||||
// build the path string
|
||||
StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
|
||||
for (String fileInfo : pathInfos)
|
||||
{
|
||||
sb.append("/");
|
||||
sb.append(fileInfo);
|
||||
}
|
||||
|
||||
node.getPath().setRelativePath(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
}
|
||||
calculateRelativePath(parentFolderNodeId, node);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
private void calculateRelativePath(String parentFolderNodeId, Node node)
|
||||
{
|
||||
NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId, null);
|
||||
try
|
||||
{
|
||||
// get the path elements
|
||||
List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, node.getNodeRef());
|
||||
|
||||
int sizePathInfos = pathInfos.size();
|
||||
|
||||
if (sizePathInfos > 1)
|
||||
{
|
||||
// remove the current child
|
||||
pathInfos.remove(sizePathInfos - 1);
|
||||
|
||||
// build the path string
|
||||
StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
|
||||
for (String fileInfo : pathInfos)
|
||||
{
|
||||
sb.append("/");
|
||||
sb.append(fileInfo);
|
||||
}
|
||||
|
||||
node.getPath().setRelativePath(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
|
@@ -4346,51 +4346,52 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
|
||||
/**
|
||||
* Test upload using relativePath
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testUploadUsingRelativePath() throws Exception{
|
||||
public void testUploadUsingRelativePath() throws Exception
|
||||
{
|
||||
setRequestContext(user1);
|
||||
|
||||
// user1 creates a private site and adds user2 as a site consumer
|
||||
String site1Title = "site-testGetPathElements_DocLib-" + RUNID;
|
||||
String site1Id = createSite(site1Title, SiteVisibility.PRIVATE).getId();
|
||||
addSiteMember(site1Id, user2, SiteRole.SiteConsumer);
|
||||
|
||||
|
||||
String site1DocLibNodeId = getSiteContainerNodeId(site1Id, "documentLibrary");
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
|
||||
|
||||
// /Company
|
||||
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
|
||||
String folderA = "folder" + RUNID + "_A";
|
||||
String folderA_Id = createFolder(site1DocLibNodeId, folderA).getId();
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
|
||||
// /Company
|
||||
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
|
||||
String folderB = "folder" + RUNID + "_B";
|
||||
String folderB_Id = createFolder(folderA_Id, folderB).getId();
|
||||
NodeRef folderB_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderB_Id);
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
|
||||
// /Company
|
||||
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
|
||||
String folderC = "folder" + RUNID + "_C";
|
||||
String folderC_Id = createFolder(folderB_Id, folderC).getId();
|
||||
NodeRef folderC_Ref = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, folderC_Id);
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
|
||||
// /Company
|
||||
// Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
|
||||
String content = "content" + RUNID;
|
||||
String content_Id = createTextFile(folderC_Id, content, "The quick brown fox jumps over the lazy dog.").getId();
|
||||
|
||||
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("include", "path");
|
||||
params.put("relativePath", folderA + "/" + folderB + "/" + folderC);
|
||||
|
||||
//call get with relativePathParam
|
||||
|
||||
// call get with relativePathParam
|
||||
HttpResponse response = getAll(getNodeChildrenUrl(site1DocLibNodeId), null, params, 200);
|
||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
|
||||
assertEquals(1, nodes.size());
|
||||
assertEquals("/" + folderA + "/" + folderB + "/" + folderC,((Node)(nodes.get(0))).getPath().getRelativePath());
|
||||
}
|
||||
|
||||
assertEquals(1, nodes.size());
|
||||
assertEquals("/" + folderA + "/" + folderB + "/" + folderC, ((Node) (nodes.get(0))).getPath().getRelativePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update permission on a node
|
||||
@@ -4821,7 +4822,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user