mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
118825 jkaabimofrad: RA-655: manual merge of SFS module to FILE-FOLDER-API. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126351 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,10 +19,17 @@
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.rest.api.tests.RepoService.SiteInformation;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestSite;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -75,9 +82,14 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
}
|
||||
|
||||
protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, int expectedStatus) throws Exception
|
||||
{
|
||||
return getAll(url, runAsUser, paging, null, expectedStatus);
|
||||
}
|
||||
|
||||
protected HttpResponse getAll(String url, String runAsUser, PublicApiClient.Paging paging, Map<String, String> otherParams, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
Map<String, String> params = (paging == null) ? null : createParams(paging, null);
|
||||
Map<String, String> params = (paging == null) ? null : createParams(paging, otherParams);
|
||||
|
||||
HttpResponse response = publicApiClient.get(getScope(), url, null, null, null, params);
|
||||
checkStatus(expectedStatus, response.getStatusCode());
|
||||
@@ -85,6 +97,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return response;
|
||||
}
|
||||
|
||||
protected HttpResponse getAll(Class<?> entityResource, String runAsUser, PublicApiClient.Paging paging, Map<String, String> otherParams, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
|
||||
HttpResponse response = publicApiClient.get(entityResource, null, null, otherParams);
|
||||
checkStatus(expectedStatus, response.getStatusCode());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
protected HttpResponse getSingle(String url, String runAsUser, String entityId, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
@@ -95,6 +117,16 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return response;
|
||||
}
|
||||
|
||||
protected HttpResponse getSingle(Class<?> entityResource, String runAsUser, String entityId, Map<String, String> params, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
|
||||
HttpResponse response = publicApiClient.get(entityResource, entityId, null, params);
|
||||
checkStatus(expectedStatus, response.getStatusCode());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
protected HttpResponse put(String url, String runAsUser, String entityId, String body, String queryString, int expectedStatus) throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(runAsUser));
|
||||
@@ -125,6 +157,23 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
|
||||
return person.getId();
|
||||
}
|
||||
|
||||
protected TestSite createSite(final TestNetwork testNetwork, TestPerson user, final SiteVisibility siteVisibility)
|
||||
{
|
||||
final String siteName = "RandomSite" + System.currentTimeMillis();
|
||||
final TestSite site = TenantUtil.runAsUserTenant(new TenantUtil.TenantRunAsWork<TestSite>()
|
||||
{
|
||||
@Override
|
||||
public TestSite doWork() throws Exception
|
||||
{
|
||||
SiteInformation siteInfo = new SiteInformation(siteName, siteName, siteName, siteVisibility);
|
||||
return repoService.createSite(testNetwork, siteInfo);
|
||||
}
|
||||
}, user.getId(), testNetwork.getId());
|
||||
assertNotNull(site);
|
||||
|
||||
return site;
|
||||
}
|
||||
|
||||
protected void checkStatus(int expectedStatus, int actualStatus)
|
||||
{
|
||||
if (expectedStatus > 0 && expectedStatus != actualStatus)
|
||||
|
485
source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java
Normal file
485
source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.PathInfo;
|
||||
import org.alfresco.rest.api.model.PathInfo.ElementInfo;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestSite;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ExpectedPaging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.data.SiteRole;
|
||||
import org.alfresco.rest.api.tests.util.JacksonUtil;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* API tests for:
|
||||
* <ul>
|
||||
* <li> {@literal host:port/alfresco/api/{networkId}/public/alfresco/versions/1/nodes/{nodeId}} </li>
|
||||
* <li> {@literal host:port/alfresco/api/{networkId}/public/alfresco/versions/1/nodes/{nodeId}/children} </li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class NodeApiTest extends AbstractBaseApiTest
|
||||
{
|
||||
/**
|
||||
* User one from network one
|
||||
*/
|
||||
private TestPerson userOneN1;
|
||||
/**
|
||||
* User two from network one
|
||||
*/
|
||||
private TestPerson userTwoN1;
|
||||
/**
|
||||
* Private site of user one from network one
|
||||
*/
|
||||
private TestSite userOneN1Site;
|
||||
private String user1;
|
||||
private String user2;
|
||||
private List<String> users = new ArrayList<>();
|
||||
|
||||
protected MutableAuthenticationService authenticationService;
|
||||
protected PersonService personService;
|
||||
protected Repository repositoryHelper;
|
||||
protected JacksonUtil jacksonUtil;
|
||||
protected PermissionService permissionService;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
repositoryHelper = applicationContext.getBean("repositoryHelper", Repository.class);
|
||||
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
|
||||
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
|
||||
|
||||
user1 = createUser("user1" + System.currentTimeMillis());
|
||||
user2 = createUser("user2" + System.currentTimeMillis());
|
||||
// We just need to clean the on-premise-users,
|
||||
// so the tests for the specific network would work.
|
||||
users.add(user1);
|
||||
users.add(user2);
|
||||
|
||||
TestNetwork networkOne = getTestFixture().getRandomNetwork();
|
||||
userOneN1 = networkOne.createUser();
|
||||
userTwoN1 = networkOne.createUser();
|
||||
|
||||
userOneN1Site = createSite(networkOne, userOneN1, SiteVisibility.PRIVATE);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
for (final String user : users)
|
||||
{
|
||||
transactionHelper.doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (personService.personExists(user))
|
||||
{
|
||||
authenticationService.deleteAuthentication(user);
|
||||
personService.deletePerson(user);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
users.clear();
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDocLibChildren() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userOneN1.getId());
|
||||
|
||||
NodeRef docLibNodeRef = userOneN1Site.getContainerNodeRef(("documentLibrary"));
|
||||
|
||||
String folder1 = "folder" + System.currentTimeMillis() + "_1";
|
||||
repoService.addToDocumentLibrary(userOneN1Site, folder1, ContentModel.TYPE_FOLDER);
|
||||
|
||||
String folder2 = "folder" + System.currentTimeMillis() + "_2";
|
||||
repoService.addToDocumentLibrary(userOneN1Site, folder2, ContentModel.TYPE_FOLDER);
|
||||
|
||||
String content1 = "content" + System.currentTimeMillis() + "_1";
|
||||
repoService.addToDocumentLibrary(userOneN1Site, content1, ContentModel.TYPE_CONTENT);
|
||||
|
||||
String content2 = "content" + System.currentTimeMillis() + "_2";
|
||||
repoService.addToDocumentLibrary(userOneN1Site, content2, ContentModel.TYPE_CONTENT);
|
||||
|
||||
String forum1 = "forum" + System.currentTimeMillis() + "_1";
|
||||
repoService.createObjectOfCustomType(docLibNodeRef, forum1, ForumModel.TYPE_TOPIC.toString());
|
||||
|
||||
Paging paging = getPaging(0, 100);
|
||||
HttpResponse response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, 200);
|
||||
List<Node> nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size()); // forum is part of the default ignored types
|
||||
// Paging
|
||||
ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
|
||||
assertEquals(4, expectedPaging.getCount().intValue());
|
||||
assertEquals(0, expectedPaging.getSkipCount().intValue());
|
||||
assertEquals(100, expectedPaging.getMaxItems().intValue());
|
||||
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
|
||||
|
||||
// Order by folders and modified date first
|
||||
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
|
||||
response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
assertTrue(nodes.get(0).getIsFolder());
|
||||
assertEquals(folder1, nodes.get(1).getName());
|
||||
assertTrue(nodes.get(1).getIsFolder());
|
||||
assertEquals(content2, nodes.get(2).getName());
|
||||
assertFalse(nodes.get(2).getIsFolder());
|
||||
assertEquals(content1, nodes.get(3).getName());
|
||||
assertFalse(nodes.get(3).getIsFolder());
|
||||
|
||||
// Order by folders last and modified date first
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder ASC,modifiedAt DESC");
|
||||
response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(content2, nodes.get(0).getName());
|
||||
assertEquals(content1, nodes.get(1).getName());
|
||||
assertEquals(folder2, nodes.get(2).getName());
|
||||
assertEquals(folder1, nodes.get(3).getName());
|
||||
|
||||
// Order by folders and modified date last
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder,modifiedAt");
|
||||
response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(4, nodes.size());
|
||||
assertEquals(content1, nodes.get(0).getName());
|
||||
assertEquals(content2, nodes.get(1).getName());
|
||||
assertEquals(folder1, nodes.get(2).getName());
|
||||
assertEquals(folder2, nodes.get(3).getName());
|
||||
|
||||
// Order by folders and modified date first
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
|
||||
// SkipCount=0,MaxItems=2
|
||||
paging = getPaging(0, 2);
|
||||
response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
assertEquals(folder1, nodes.get(1).getName());
|
||||
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
|
||||
assertEquals(2, expectedPaging.getCount().intValue());
|
||||
assertEquals(0, expectedPaging.getSkipCount().intValue());
|
||||
assertEquals(2, expectedPaging.getMaxItems().intValue());
|
||||
assertTrue(expectedPaging.getHasMoreItems().booleanValue());
|
||||
|
||||
// SkipCount=2,MaxItems=4
|
||||
paging = getPaging(2, 4);
|
||||
response = getAll(getChildrenUrl(docLibNodeRef), userOneN1.getId(), paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Node.class);
|
||||
assertEquals(2, nodes.size());
|
||||
assertEquals(content2, nodes.get(0).getName());
|
||||
assertEquals(content1, nodes.get(1).getName());
|
||||
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
|
||||
assertEquals(2, expectedPaging.getCount().intValue());
|
||||
assertEquals(2, expectedPaging.getSkipCount().intValue());
|
||||
assertEquals(4, expectedPaging.getMaxItems().intValue());
|
||||
assertFalse(expectedPaging.getHasMoreItems().booleanValue());
|
||||
|
||||
// userTwoN1 tries to access userOneN1's docLib
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userTwoN1.getId());
|
||||
paging = getPaging(0, Integer.MAX_VALUE);
|
||||
getAll(getChildrenUrl(docLibNodeRef), userTwoN1.getId(), paging, 403);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMyFilesChildren() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
NodeRef myFilesNodeRef = repositoryHelper.getUserHome(personService.getPerson(user1));
|
||||
|
||||
String folder1 = "folder" + System.currentTimeMillis() + "_1";
|
||||
repoService.createFolder(myFilesNodeRef, folder1);
|
||||
|
||||
String folder2 = "folder" + System.currentTimeMillis() + "_2";
|
||||
repoService.createFolder(myFilesNodeRef, folder2);
|
||||
|
||||
String content1 = "content" + System.currentTimeMillis() + "_1";
|
||||
NodeRef contentNodeRef = repoService.createDocument(myFilesNodeRef, content1, "The quick brown fox jumps over the lazy dog.");
|
||||
repoService.getNodeService().setProperty(contentNodeRef, ContentModel.PROP_OWNER, user1);
|
||||
repoService.getNodeService().setProperty(contentNodeRef, ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA,
|
||||
(Serializable) Collections.singletonList("doclib:1444660852296"));
|
||||
|
||||
Paging paging = getPaging(0, Integer.MAX_VALUE);
|
||||
HttpResponse response = getAll(getChildrenUrl(myFilesNodeRef), user1, paging, 200);
|
||||
List<Document> nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
|
||||
assertEquals(3, nodes.size());
|
||||
|
||||
// Order by folders and modified date first
|
||||
Map<String, String> orderBy = Collections.singletonMap("orderBy", "isFolder DESC,modifiedAt DESC");
|
||||
response = getAll(getChildrenUrl(myFilesNodeRef), user1, paging, orderBy, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
|
||||
assertEquals(3, nodes.size());
|
||||
assertEquals(folder2, nodes.get(0).getName());
|
||||
assertEquals(folder1, nodes.get(1).getName());
|
||||
Document node = (Document) nodes.get(2);
|
||||
assertEquals(content1, node.getName());
|
||||
assertEquals("cm:content", node.getNodeType());
|
||||
assertEquals(contentNodeRef.getId(), node.getNodeRef().getId());
|
||||
UserInfo createdByUser = node.getCreatedByUser();
|
||||
assertEquals(user1, createdByUser.getUserName());
|
||||
assertEquals(user1 + " " + user1, createdByUser.getDisplayName());
|
||||
UserInfo modifiedByUser = node.getModifiedByUser();
|
||||
assertEquals(user1, modifiedByUser.getUserName());
|
||||
assertEquals(user1 + " " + user1, modifiedByUser.getDisplayName());
|
||||
assertEquals(MimetypeMap.MIMETYPE_BINARY, node.getContent().getMimeType());
|
||||
assertNotNull(node.getContent().getMimeTypeName());
|
||||
assertNotNull(node.getContent().getEncoding());
|
||||
assertTrue(node.getContent().getSizeInBytes() > 0);
|
||||
|
||||
// Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter.
|
||||
orderBy = Collections.singletonMap("orderBy", "isFolder DESC,cm" + System.currentTimeMillis() + ":modified DESC");
|
||||
getAll(getChildrenUrl(myFilesNodeRef), user1, paging, orderBy, 400);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user2);
|
||||
// user2 tries to access user1's home folder
|
||||
getAll(getChildrenUrl(myFilesNodeRef), user2, paging, 403);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
// request property via select
|
||||
Map<String, String> params = new LinkedHashMap<>();
|
||||
params.put("select", "cm_lastThumbnailModification");// TODO replace the underscore with colon when the framework is fixed.
|
||||
params.put("orderBy", "isFolder DESC,modifiedAt DESC");
|
||||
response = getAll(getChildrenUrl(myFilesNodeRef), user1, paging, params, 200);
|
||||
nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class);
|
||||
assertEquals(3, nodes.size());
|
||||
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(0).getProperties());
|
||||
assertNull("There shouldn't be a 'properties' object in the response.", nodes.get(1).getProperties());
|
||||
assertNotNull("There should be a 'properties' object in the response.", nodes.get(2).getProperties());
|
||||
Set<Entry<String, Object>> props = nodes.get(2).getProperties().entrySet();
|
||||
assertEquals(1, props.size());
|
||||
Entry<String, Object> entry = props.iterator().next();
|
||||
assertEquals("cm:lastThumbnailModification", entry.getKey());
|
||||
assertEquals("doclib:1444660852296", ((List<?>) entry.getValue()).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPathElements_DocLib() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userOneN1.getId());
|
||||
userOneN1Site.inviteToSite(userTwoN1.getEmail(), SiteRole.SiteConsumer);
|
||||
|
||||
NodeRef docLibNodeRef = userOneN1Site.getContainerNodeRef(("documentLibrary"));
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A
|
||||
String folderA = "folder" + System.currentTimeMillis() + "_A";
|
||||
NodeRef folderA_Ref = repoService.createFolder(docLibNodeRef, folderA);
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B
|
||||
String folderB = "folder" + System.currentTimeMillis() + "_B";
|
||||
NodeRef folderB_Ref = repoService.createFolder(folderA_Ref, folderB);
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
|
||||
String folderC = "folder" + System.currentTimeMillis() + "_C";
|
||||
NodeRef folderC_Ref = repoService.createFolder(folderB_Ref, folderC);
|
||||
|
||||
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C/content<timestamp>
|
||||
String content = "content" + System.currentTimeMillis();
|
||||
NodeRef contentNodeRef = repoService.createDocument(folderC_Ref, content, "The quick brown fox jumps over the lazy dog.");
|
||||
|
||||
// Revoke folderB inherited permissions
|
||||
permissionService.setInheritParentPermissions(folderB_Ref, false);
|
||||
// Grant userTwoN1 permission for folderC
|
||||
permissionService.setPermission(folderC_Ref, userTwoN1.getId(), PermissionService.CONSUMER, true);
|
||||
|
||||
//...nodes/nodeId?select=path
|
||||
Map<String, String> params = Collections.singletonMap("select", "path");
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, userOneN1.getId(), contentNodeRef.getId(), params, 200);
|
||||
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
PathInfo path = node.getPath();
|
||||
assertNotNull(path);
|
||||
assertTrue(path.getIsComplete());
|
||||
assertNotNull(path.getName());
|
||||
// the path should only include the parents (not the requested node)
|
||||
assertFalse(path.getName().endsWith(content));
|
||||
assertTrue(path.getName().startsWith("/Company Home"));
|
||||
List<ElementInfo> pathElements = path.getElements();
|
||||
assertEquals(7, pathElements.size());
|
||||
assertEquals("Company Home", pathElements.get(0).getName());
|
||||
assertEquals("Sites", pathElements.get(1).getName());
|
||||
assertEquals(userOneN1Site.getSiteId(), pathElements.get(2).getName());
|
||||
assertEquals("documentLibrary", pathElements.get(3).getName());
|
||||
assertEquals(folderA, pathElements.get(4).getName());
|
||||
assertEquals(folderB, pathElements.get(5).getName());
|
||||
assertEquals(folderC, pathElements.get(6).getName());
|
||||
|
||||
// Try the above tests with userTwoN1 (site consumer)
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userTwoN1.getId());
|
||||
response = getSingle(NodesEntityResource.class, userTwoN1.getId(), contentNodeRef.getId(), params, 200);
|
||||
node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
path = node.getPath();
|
||||
assertNotNull(path);
|
||||
assertFalse("The path is not complete as the user doesn't have permission to access the full path.", path.getIsComplete());
|
||||
assertNotNull(path.getName());
|
||||
// site consumer (userTwoN1) dose not have access to the folderB
|
||||
assertFalse("site consumer (userTwoN1) dose not have access to the folderB", path.getName().contains(folderB));
|
||||
assertFalse(path.getName().startsWith("/Company Home"));
|
||||
// Go up as far as they can, before getting access denied (i.e. "/folderC")
|
||||
assertTrue(path.getName().endsWith(folderC));
|
||||
pathElements = path.getElements();
|
||||
assertEquals(1, pathElements.size());
|
||||
assertEquals(folderC, pathElements.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPathElements_MyFiles() throws Exception
|
||||
{
|
||||
final String userNodeAlias = "-my-";
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, user1, userNodeAlias, null, 200);
|
||||
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
|
||||
NodeRef myFilesNodeRef = node.getNodeRef();
|
||||
assertNotNull(myFilesNodeRef);
|
||||
assertEquals(user1, node.getName());
|
||||
assertTrue(node.getIsFolder());
|
||||
|
||||
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A
|
||||
String folderA = "folder" + System.currentTimeMillis() + "_A";
|
||||
NodeRef folderA_Ref = repoService.createFolder(myFilesNodeRef, folderA);
|
||||
|
||||
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B
|
||||
String folderB = "folder" + System.currentTimeMillis() + "_B";
|
||||
NodeRef folderB_Ref = repoService.createFolder(folderA_Ref, folderB);
|
||||
|
||||
// /Company Home/User Homes/user<timestamp>/folder<timestamp>_A/folder<timestamp>_B/folder<timestamp>_C
|
||||
String folderC = "folder" + System.currentTimeMillis() + "_C";
|
||||
NodeRef folderC_Ref = repoService.createFolder(folderB_Ref, folderC);
|
||||
|
||||
//...nodes/nodeId?select=pathInfo
|
||||
Map<String, String> params = Collections.singletonMap("select", "path");
|
||||
response = getSingle(NodesEntityResource.class, user1, folderC_Ref.getId(), params, 200);
|
||||
node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
|
||||
PathInfo pathInfo = node.getPath();
|
||||
assertNotNull(pathInfo);
|
||||
assertTrue(pathInfo.getIsComplete());
|
||||
assertNotNull(pathInfo.getName());
|
||||
// the pathInfo should only include the parents (not the requested node)
|
||||
assertFalse(pathInfo.getName().endsWith(folderC));
|
||||
assertTrue(pathInfo.getName().startsWith("/Company Home"));
|
||||
List<ElementInfo> pathElements = pathInfo.getElements();
|
||||
assertEquals(5, pathElements.size());
|
||||
assertEquals("Company Home", pathElements.get(0).getName());
|
||||
assertNotNull(pathElements.get(0).getId());
|
||||
assertEquals("User Homes", pathElements.get(1).getName());
|
||||
assertNotNull(pathElements.get(1).getId());
|
||||
assertEquals(user1, pathElements.get(2).getName());
|
||||
assertNotNull(pathElements.get(2).getId());
|
||||
assertEquals(folderA, pathElements.get(3).getName());
|
||||
assertNotNull(pathElements.get(3).getId());
|
||||
assertEquals(folderB, pathElements.get(4).getName());
|
||||
assertNotNull(pathElements.get(4).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNodeWithKnownAlias() throws Exception
|
||||
{
|
||||
final String rootNodeAlias = "-root-";
|
||||
HttpResponse response = getSingle(NodesEntityResource.class, user1, rootNodeAlias, null, 200);
|
||||
Node node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
|
||||
assertEquals("Company Home", node.getName());
|
||||
assertNotNull(node.getNodeRef());
|
||||
PathInfo pathInfo = node.getPath();
|
||||
// empty JSON object ("path":{})
|
||||
assertNotNull(pathInfo);
|
||||
// as this is the root node, there will be no name or path elements.
|
||||
assertNull(pathInfo.getIsComplete());
|
||||
assertNull(pathInfo.getName());
|
||||
assertNull(pathInfo.getElements());
|
||||
|
||||
// unknown alias
|
||||
getSingle(NodesEntityResource.class, user1, "testSomeUndefinedAlias", null, 404);
|
||||
|
||||
final String userNodeAlias = "-my-";
|
||||
response = getSingle(NodesEntityResource.class, user1, userNodeAlias, null, 200);
|
||||
node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class);
|
||||
NodeRef myFilesNodeRef = node.getNodeRef();
|
||||
assertNotNull(myFilesNodeRef);
|
||||
assertEquals(user1, node.getName());
|
||||
assertTrue(node.getIsFolder());
|
||||
pathInfo = node.getPath();
|
||||
assertNotNull(pathInfo);
|
||||
assertTrue(pathInfo.getIsComplete());
|
||||
|
||||
//Delete user1's home
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
repoService.getNodeService().deleteNode(myFilesNodeRef);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||
getSingle(NodesEntityResource.class, user1, userNodeAlias, null, 404); // Not found
|
||||
}
|
||||
|
||||
private String getChildrenUrl(NodeRef nodeRef)
|
||||
{
|
||||
return "nodes/" + nodeRef.getId() + "/children";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.api.tests.util;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class JacksonUtil
|
||||
{
|
||||
private JacksonHelper jsonHelper;
|
||||
|
||||
public JacksonUtil(JacksonHelper jsonHelper)
|
||||
{
|
||||
this.jsonHelper = jsonHelper;
|
||||
}
|
||||
|
||||
public <T> List<T> parseEntries(JSONObject jsonObject, Class<T> clazz) throws IOException
|
||||
{
|
||||
assertNotNull(jsonObject);
|
||||
assertNotNull(clazz);
|
||||
|
||||
List<T> models = new ArrayList<>();
|
||||
|
||||
JSONObject jsonList = (JSONObject) jsonObject.get("list");
|
||||
assertNotNull(jsonList);
|
||||
|
||||
JSONArray jsonEntries = (JSONArray) jsonList.get("entries");
|
||||
assertNotNull(jsonEntries);
|
||||
|
||||
for (Object entry : jsonEntries)
|
||||
{
|
||||
JSONObject jsonEntry = (JSONObject) entry;
|
||||
T pojoModel = parseEntry(jsonEntry, clazz);
|
||||
models.add(pojoModel);
|
||||
}
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
public <T> T parseEntry(JSONObject jsonObject, Class<T> clazz) throws IOException
|
||||
{
|
||||
assertNotNull(jsonObject);
|
||||
assertNotNull(clazz);
|
||||
|
||||
JSONObject entry = (JSONObject) jsonObject.get("entry");
|
||||
T pojoModel = jsonHelper.construct(new StringReader(entry.toJSONString()), clazz);
|
||||
assertNotNull(pojoModel);
|
||||
|
||||
return pojoModel;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user