Merged HEAD (5.2) to 5.2.N (5.2.1)

126515 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      122947 jvonka: (Quick) Shared Links API - updates
      - test for get rendition content via share link (no auth)
      - add optional filter (sharedByUser) to find links
      RA-830, RA-777


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126859 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:56:20 +00:00
parent d2fa56e4b1
commit e48ed0687b
6 changed files with 147 additions and 83 deletions

View File

@@ -31,7 +31,7 @@ import org.alfresco.service.cmr.security.NoSuchPersonException;
public interface People
{
public static String DEFAULT_USER = "-me-";
String DEFAULT_USER = "-me-";
String validatePerson(String personId);
String validatePerson(String personId, boolean validateIsCurrentUser);

View File

@@ -97,4 +97,9 @@ public interface QuickShareLinks
* @return
*/
CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters);
/**
* API Constants - query parameters, etc
*/
String PARAM_SHAREDBY = "sharedByUser";
}

View File

@@ -386,8 +386,6 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
// Helper find (search) method
private static final String PARAM_SHAREDBY = "sharedByUser/id";
private final static Set<String> FIND_SHARED_LINKS_QUERY_PROPERTIES =
new HashSet<>(Arrays.asList(new String[] {PARAM_SHAREDBY}));

View File

@@ -26,9 +26,8 @@
package org.alfresco.rest.api.tests;
import static org.alfresco.rest.api.tests.util.RestApiUtil.parsePaging;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsString;
import static org.junit.Assert.*;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.tenant.TenantUtil;
@@ -45,6 +44,7 @@ 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.Rendition;
import org.alfresco.rest.api.tests.util.MultiPartBuilder;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.site.SiteVisibility;
@@ -344,4 +344,59 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
}
return ResourceUtils.getFile(url);
}
protected static final long PAUSE_TIME = 5000; //millisecond
protected static final int MAX_RETRY = 10;
protected Rendition createAndGetRendition(String userId, String sourceNodeId, String renditionId) throws Exception
{
Rendition renditionRequest = new Rendition();
renditionRequest.setId(renditionId);
int retryCount = 0;
while (retryCount < MAX_RETRY)
{
try
{
HttpResponse res = post(getRenditionsUrl(sourceNodeId), userId, toJsonAsString(renditionRequest), 202);
assertNull(res.getJsonResponse());
break;
}
catch (AssertionError ex)
{
// If no transformer is currently available,
// wait for 'PAUSE_TIME' and try again.
retryCount++;
Thread.sleep(PAUSE_TIME);
}
}
retryCount = 0;
while (retryCount < MAX_RETRY)
{
try
{
HttpResponse response = getSingle(getRenditionsUrl(sourceNodeId), userId, renditionId, 200);
Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
return rendition;
}
catch (AssertionError ex)
{
// If the asynchronous create rendition action is not finished yet,
// wait for 'PAUSE_TIME' and try again.
retryCount++;
Thread.sleep(PAUSE_TIME);
}
}
return null;
}
private String getRenditionsUrl(String nodeId)
{
return "nodes/" + nodeId + "/renditions";
}
}

View File

@@ -68,9 +68,6 @@ import java.util.UUID;
*/
public class RenditionsTest extends AbstractBaseApiTest
{
private static final long PAUSE_TIME = 5000; //millisecond
private static final int MAX_RETRY = 10;
/**
* User one from network one
*/
@@ -177,7 +174,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertTrue(expectedPaging.getTotalItems() >= 5);
// Create 'doclib' rendition
createAndGetRendition(contentNodeId, docLib.getId());
createAndGetRendition(userOneN1.getId(), contentNodeId, docLib.getId());
// List all available renditions (includes those that have been created and those that are yet to be created)
paging = getPaging(0, 50);
@@ -273,7 +270,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertNull("Shouldn't have returned the size, as the rendition hasn't been created yet.", contentInfo.getSizeInBytes());
// Create and get 'doclib' rendition
rendition = createAndGetRendition(contentNodeId, "doclib");
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "doclib");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
contentInfo = rendition.getContent();
@@ -350,7 +347,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertEquals(RenditionStatus.NOT_CREATED, rendition.getStatus());
// Create and get 'imgpreview' rendition
rendition = createAndGetRendition(contentNodeId, "imgpreview");
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "imgpreview");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
ContentInfo contentInfo = rendition.getContent();
@@ -497,7 +494,7 @@ public class RenditionsTest extends AbstractBaseApiTest
assertTrue(contentType.startsWith(MimetypeMap.MIMETYPE_IMAGE_PNG));
// Create and get 'doclib' rendition
rendition = createAndGetRendition(contentNodeId, "doclib");
rendition = createAndGetRendition(userOneN1.getId(), contentNodeId, "doclib");
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
@@ -588,52 +585,6 @@ public class RenditionsTest extends AbstractBaseApiTest
}, user, testSite.getNetworkId());
}
private Rendition createAndGetRendition(String sourceNodeId, String renditionId) throws Exception
{
Rendition renditionRequest = new Rendition();
renditionRequest.setId(renditionId);
int retryCount = 0;
while (retryCount < MAX_RETRY)
{
try
{
HttpResponse res = post(getRenditionsUrl(sourceNodeId), userOneN1.getId(), toJsonAsString(renditionRequest), 202);
assertNull(res.getJsonResponse());
break;
}
catch (AssertionError ex)
{
// If no transformer is currently available,
// wait for 'PAUSE_TIME' and try again.
retryCount++;
Thread.sleep(PAUSE_TIME);
}
}
retryCount = 0;
while (retryCount < MAX_RETRY)
{
try
{
HttpResponse response = getSingle(getRenditionsUrl(sourceNodeId), userOneN1.getId(), renditionId, 200);
Rendition rendition = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Rendition.class);
assertNotNull(rendition);
assertEquals(RenditionStatus.CREATED, rendition.getStatus());
return rendition;
}
catch (AssertionError ex)
{
// If the asynchronous create rendition action is not finished yet,
// wait for 'PAUSE_TIME' and try again.
retryCount++;
Thread.sleep(PAUSE_TIME);
}
}
return null;
}
private Rendition getRendition(List<Rendition> renditions, String renditionName)
{
for (Rendition rn : renditions)

View File

@@ -21,6 +21,9 @@ package org.alfresco.rest.api.tests;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.People;
import org.alfresco.rest.api.QuickShareLinks;
import org.alfresco.rest.api.impl.QuickShareLinksImpl;
import org.alfresco.rest.api.model.QuickShareLink;
import org.alfresco.rest.api.nodes.NodesEntityResource;
@@ -29,6 +32,7 @@ import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
import org.alfresco.rest.api.tests.client.data.Document;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.Rendition;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
@@ -212,7 +216,20 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
assertEquals("attachment; filename=\"" + docName1 + "\"; filename*=UTF-8''" + docName1 + "", response.getHeaders().get("Content-Disposition"));
// TODO unauth access to get shared-link rendition content
// -ve test - try to get non-existent rendition content
getSingle(QuickShareLinkEntityResource.class, null, sharedId + "/renditions/doclib/content", null, 404);
// create rendition
Rendition rendition = createAndGetRendition(user2, d1Id, "doclib");
assertNotNull(rendition);
assertEquals(Rendition.RenditionStatus.CREATED, rendition.getStatus());
// unauth access to get shared link file rendition content
response = getSingle(QuickShareLinkEntityResource.class, null, sharedId + "/renditions/doclib/content", null, 200);
String docName = "doclib";
assertEquals(MimetypeMap.MIMETYPE_IMAGE_PNG+";charset=UTF-8", response.getHeaders().get("Content-Type"));
assertEquals("attachment; filename=\"" + docName + "\"; filename*=UTF-8''" + docName + "", response.getHeaders().get("Content-Disposition"));
// -ve delete tests
@@ -283,10 +300,11 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// (else need to verify test mechanism for enterprise admin via jmx ... etc)
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
quickShareLinks.setEnabled(false);
// -ve - disabled service tests
try
{
quickShareLinks.setEnabled(false);
// -ve - disabled service tests
body.put("nodeId", "dummy");
post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 501);
@@ -294,6 +312,10 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
getSingle(QuickShareLinkEntityResource.class, null, "dummy/content", null, 501);
delete(URL_SHARED_LINKS, user1, "dummy", 501);
}
finally
{
quickShareLinks.setEnabled(true);
}
}
/**
@@ -309,44 +331,47 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
{
Paging paging = getPaging(0, 100);
// Get all shared links visible to user 1 (note: for now assumes clean repo)
HttpResponse response = getAll(URL_SHARED_LINKS, user1, paging, 200);
List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(0, sharedLinks.size());
// As user 1 ...
// create doc d1
String sharedFolderNodeId = getSharedNodeId(user1);
// create doc d1 - in "My" folder
String myFolderNodeId = getMyNodeId(user1);
String content1Text = "The quick brown fox jumps over the lazy dog 1.";
String docName1 = "content" + RUNID + "_1.txt";
Document doc1 = createTextFile(sharedFolderNodeId, user1, docName1, content1Text);
Document doc1 = createTextFile(user1, myFolderNodeId, docName1, content1Text);
String d1Id = doc1.getId();
// create doc d2
String myFolderNodeId = getMyNodeId(user1);
String content2Text = "The quick brown fox jumps over the lazy dog 1.";
// create doc d2 - in "Shared" folder
String sharedFolderNodeId = getSharedNodeId(user1);
String content2Text = "The quick brown fox jumps over the lazy dog 2.";
String docName2 = "content" + RUNID + "_2.txt";
Document doc2 = createTextFile(myFolderNodeId, user1, docName2, content2Text);
Document doc2 = createTextFile(user1, sharedFolderNodeId, docName2, content1Text);
String d2Id = doc2.getId();
// As user 2 ...
// create shared link
Map<String, String> body = new HashMap<>();
body.put("nodeId", d1Id);
response = post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 201);
QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared1Id = resp.getId();
// As user 1 ...
// create shared link
// create shared link to doc 1
Map<String, String> body = new HashMap<>();
body.put("nodeId", d1Id);
response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201);
QuickShareLink resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared1Id = resp.getId();
// As user 2 ...
// create shared link to doc 2
body = new HashMap<>();
body.put("nodeId", d2Id);
response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201);
response = post(URL_SHARED_LINKS, user2, toJsonAsStringNonNull(body), 201);
resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
String shared2Id = resp.getId();
//
// find links
//
@@ -362,20 +387,50 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
response = getAll(URL_SHARED_LINKS, user2, paging, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
// find my links
Map<String, String> params = new HashMap<>();
params.put("where", "("+ QuickShareLinks.PARAM_SHAREDBY+"='"+People.DEFAULT_USER+"')");
response = getAll(URL_SHARED_LINKS, user1, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared1Id, sharedLinks.get(0).getId());
assertEquals(d1Id, sharedLinks.get(0).getNodeId());
// find links shared by a given user
params = new HashMap<>();
params.put("where", "("+ QuickShareLinks.PARAM_SHAREDBY+"='"+user2+"')");
response = getAll(URL_SHARED_LINKS, user1, paging, params, 200);
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
assertEquals(1, sharedLinks.size());
assertEquals(shared2Id, sharedLinks.get(0).getId());
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
// delete the shared links
delete(URL_SHARED_LINKS, user1, shared1Id, 204);
delete(URL_SHARED_LINKS, user2, shared2Id, 204);
// TODO if and when these tests are optionally runnable via remote env then we could skip this part of the test
// (else need to verify test mechanism for enterprise admin via jmx ... etc)
QuickShareLinksImpl quickShareLinks = applicationContext.getBean("quickShareLinks", QuickShareLinksImpl.class);
quickShareLinks.setEnabled(false);
// -ve - disabled service tests
try
{
quickShareLinks.setEnabled(false);
// -ve - disabled service tests
getAll(URL_SHARED_LINKS, user1, paging, 501);
}
finally
{
quickShareLinks.setEnabled(true);
}
}
@Override