mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126501 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122732 jvonka: (Quick) Shared Links API - 1st cut for find shared links (for current user) - TODO filter by shared by user, option to include/select allowableOperations, ... + more tests :-) RA-777 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126845 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -22,6 +22,7 @@ import org.alfresco.rest.api.model.QuickShareLink;
|
|||||||
import org.alfresco.rest.api.model.QuickShareLinkEmailRequest;
|
import org.alfresco.rest.api.model.QuickShareLinkEmailRequest;
|
||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -86,4 +87,12 @@ public interface QuickShareLinks
|
|||||||
* @param parameters The {@link Parameters} object to get the parameters passed into the request
|
* @param parameters The {@link Parameters} object to get the parameters passed into the request
|
||||||
*/
|
*/
|
||||||
void emailSharedLink(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters);
|
void emailSharedLink(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find (search) for shared links visible to current user
|
||||||
|
*
|
||||||
|
* @param parameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters);
|
||||||
}
|
}
|
@@ -20,6 +20,7 @@ package org.alfresco.rest.api.impl;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.QuickShareModel;
|
import org.alfresco.model.QuickShareModel;
|
||||||
|
import org.alfresco.query.PagingRequest;
|
||||||
import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest;
|
import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||||
@@ -33,9 +34,10 @@ import org.alfresco.rest.api.model.UserInfo;
|
|||||||
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||||
import org.alfresco.rest.framework.core.exceptions.NotFoundException;
|
|
||||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
@@ -47,6 +49,10 @@ import org.alfresco.service.cmr.repository.MimetypeService;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
|
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||||
|
import org.alfresco.service.cmr.search.SearchParameters;
|
||||||
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
@@ -85,6 +91,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
|
|||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private AuthorityService authorityService;
|
private AuthorityService authorityService;
|
||||||
private MimetypeService mimeTypeService;
|
private MimetypeService mimeTypeService;
|
||||||
|
private SearchService searchService;
|
||||||
|
|
||||||
public void setServiceRegistry(ServiceRegistry sr)
|
public void setServiceRegistry(ServiceRegistry sr)
|
||||||
{
|
{
|
||||||
@@ -118,6 +125,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
|
|||||||
this.personService = sr.getPersonService();
|
this.personService = sr.getPersonService();
|
||||||
this.authorityService = sr.getAuthorityService();
|
this.authorityService = sr.getAuthorityService();
|
||||||
this.mimeTypeService = sr.getMimetypeService();
|
this.mimeTypeService = sr.getMimetypeService();
|
||||||
|
this.searchService = sr.getSearchService();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,16 +345,74 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper find (search) method
|
||||||
|
|
||||||
|
public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters)
|
||||||
|
{
|
||||||
|
checkEnabled();
|
||||||
|
|
||||||
|
/*
|
||||||
|
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||||
|
|
||||||
|
String queryString =
|
||||||
|
"ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() +
|
||||||
|
"\" +@\\{http\\://www.alfresco.org/model/content/1.0\\}" + QuickShareModel.PROP_QSHARE_SHAREDBY.getLocalName() + ":\"" + currentUser + "\"";
|
||||||
|
*/
|
||||||
|
|
||||||
|
String queryString =
|
||||||
|
"ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";
|
||||||
|
|
||||||
|
SearchParameters sp = new SearchParameters();
|
||||||
|
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||||
|
sp.setQuery(queryString);
|
||||||
|
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||||
|
|
||||||
|
Paging paging = parameters.getPaging();
|
||||||
|
PagingRequest pagingRequest = Util.getPagingRequest(paging);
|
||||||
|
|
||||||
|
sp.setSkipCount(pagingRequest.getSkipCount());
|
||||||
|
sp.setMaxItems(pagingRequest.getMaxItems());
|
||||||
|
|
||||||
|
// TODO is perf ok with Solr 4 paging/sorting ? (otherwise make this optional via orderBy and leave default sort as undefined)
|
||||||
|
sp.addSort("@" + ContentModel.PROP_MODIFIED, false);
|
||||||
|
|
||||||
|
ResultSet results = searchService.query(sp);
|
||||||
|
|
||||||
|
List<QuickShareLink> qsLinks = new ArrayList<>(results.length());
|
||||||
|
|
||||||
|
for (ResultSetRow row : results)
|
||||||
|
{
|
||||||
|
NodeRef nodeRef = row.getNodeRef();
|
||||||
|
qsLinks.add(getQuickShareInfo(nodeRef, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
results.close();
|
||||||
|
|
||||||
|
return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), new Long(results.getNumberFound()).intValue());
|
||||||
|
}
|
||||||
|
|
||||||
private QuickShareLink getQuickShareInfo(String sharedId, boolean noAuth)
|
private QuickShareLink getQuickShareInfo(String sharedId, boolean noAuth)
|
||||||
{
|
{
|
||||||
checkValidShareId(sharedId);
|
checkValidShareId(sharedId);
|
||||||
|
|
||||||
|
Map<String, Object> map = (Map<String, Object>) quickShareService.getMetaData(sharedId).get("item");
|
||||||
|
NodeRef nodeRef = new NodeRef((String) map.get("nodeRef"));
|
||||||
|
|
||||||
|
return getQuickShareInfo(nodeRef, map, noAuth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, boolean noAuth)
|
||||||
|
{
|
||||||
|
Map<String, Object> map = (Map<String, Object>) quickShareService.getMetaData(nodeRef).get("item");
|
||||||
|
return getQuickShareInfo(nodeRef, map , noAuth);
|
||||||
|
}
|
||||||
|
|
||||||
|
private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth)
|
||||||
|
{
|
||||||
|
String sharedId = (String)map.get("sharedId");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, Object> map = (Map<String, Object>)quickShareService.getMetaData(sharedId).get("item");
|
|
||||||
|
|
||||||
NodeRef nodeRef = new NodeRef((String) map.get("nodeRef"));
|
|
||||||
|
|
||||||
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
|
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
|
||||||
ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);
|
ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@ import org.alfresco.rest.framework.resource.EntityResource;
|
|||||||
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
|
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
|
||||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||||
|
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||||
import org.alfresco.util.ParameterCheck;
|
import org.alfresco.util.ParameterCheck;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
@@ -44,8 +45,11 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@EntityResource(name="shared-links", title = "Shared Links")
|
@EntityResource(name="shared-links", title = "Shared Links")
|
||||||
public class QuickShareLinkEntityResource implements EntityResourceAction.ReadById<QuickShareLink>,
|
public class QuickShareLinkEntityResource implements EntityResourceAction.ReadById<QuickShareLink>,
|
||||||
BinaryResourceAction.Read, EntityResourceAction.Delete,
|
BinaryResourceAction.Read,
|
||||||
EntityResourceAction.Create<QuickShareLink>, InitializingBean
|
EntityResourceAction.Delete,
|
||||||
|
EntityResourceAction.Create<QuickShareLink>,
|
||||||
|
EntityResourceAction.Read<QuickShareLink>,
|
||||||
|
InitializingBean
|
||||||
{
|
{
|
||||||
private QuickShareLinks quickShareLinks;
|
private QuickShareLinks quickShareLinks;
|
||||||
|
|
||||||
@@ -131,4 +135,16 @@ public class QuickShareLinkEntityResource implements EntityResourceAction.ReadBy
|
|||||||
{
|
{
|
||||||
quickShareLinks.emailSharedLink(nodeId, emailRequest, parameters);
|
quickShareLinks.emailSharedLink(nodeId, emailRequest, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find shared links
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@WebApiDescription(title="Find shared links", description = "Find ('search') & return result set of shared links")
|
||||||
|
public CollectionWithPagingInfo<QuickShareLink> readAll(Parameters parameters)
|
||||||
|
{
|
||||||
|
return quickShareLinks.findLinks(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -347,6 +347,98 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests find shared links to file (content)
|
||||||
|
*
|
||||||
|
* Note: relies on search service
|
||||||
|
*
|
||||||
|
* <p>GET:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSharedLinkFind() throws Exception
|
||||||
|
{
|
||||||
|
Paging paging = getPaging(0, 100);
|
||||||
|
|
||||||
|
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 ...
|
||||||
|
|
||||||
|
AuthenticationUtil.setFullyAuthenticatedUser(user1);
|
||||||
|
|
||||||
|
// create doc d1
|
||||||
|
|
||||||
|
String sharedFolderNodeId = getSharedNodeId(user1);
|
||||||
|
|
||||||
|
String contentText = "The quick brown fox jumps over the lazy dog.";
|
||||||
|
|
||||||
|
String docName1 = "content" + RUNID + "_1.txt";
|
||||||
|
NodeRef d1Ref = repoService.createDocument(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, sharedFolderNodeId),
|
||||||
|
docName1, contentText);
|
||||||
|
String d1Id = d1Ref.getId();
|
||||||
|
|
||||||
|
// create doc d2
|
||||||
|
|
||||||
|
String myFolderNodeId = getMyNodeId(user1);
|
||||||
|
|
||||||
|
String docName2 = "content" + RUNID + "_2.txt";
|
||||||
|
NodeRef d2Ref = repoService.createDocument(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, myFolderNodeId),
|
||||||
|
docName2, contentText);
|
||||||
|
String d2Id = d2Ref.getId();
|
||||||
|
|
||||||
|
AuthenticationUtil.clearCurrentSecurityContext();
|
||||||
|
|
||||||
|
// 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.getSharedId();
|
||||||
|
|
||||||
|
// As user 1 ...
|
||||||
|
|
||||||
|
// create shared link
|
||||||
|
body = new HashMap<>();
|
||||||
|
body.put("nodeId", d2Id);
|
||||||
|
response = post(URL_SHARED_LINKS, user1, toJsonAsStringNonNull(body), 201);
|
||||||
|
resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
|
||||||
|
String shared2Id = resp.getSharedId();
|
||||||
|
|
||||||
|
//
|
||||||
|
// find links
|
||||||
|
//
|
||||||
|
|
||||||
|
response = getAll(URL_SHARED_LINKS, user1, paging, 200);
|
||||||
|
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
|
||||||
|
assertEquals(2, sharedLinks.size());
|
||||||
|
assertEquals(shared2Id, sharedLinks.get(0).getSharedId());
|
||||||
|
assertEquals(d2Id, sharedLinks.get(0).getNodeId());
|
||||||
|
assertEquals(shared1Id, sharedLinks.get(1).getSharedId());
|
||||||
|
assertEquals(d1Id, sharedLinks.get(1).getNodeId());
|
||||||
|
|
||||||
|
response = getAll(URL_SHARED_LINKS, user2, paging, 200);
|
||||||
|
sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
|
||||||
|
assertEquals(1, sharedLinks.size());
|
||||||
|
assertEquals(shared1Id, sharedLinks.get(0).getSharedId());
|
||||||
|
assertEquals(d1Id, sharedLinks.get(0).getNodeId());
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
getAll(URL_SHARED_LINKS, user1, paging, 501);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getScope()
|
public String getScope()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user