Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

127312 jkaabimofrad: SFS-577, SFS-581: Fixed the shared-link no-auth APIs issue with multi-tenancy.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127316 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-23 10:11:10 +00:00
parent 1fcd057a28
commit 0c017176a3
7 changed files with 239 additions and 16 deletions

View File

@@ -157,6 +157,16 @@ public interface Nodes
*/
BinaryResource getContent(String fileNodeId, Parameters parameters, boolean recordActivity);
/**
* Download file content.
*
* @param nodeRef the content nodeRef
* @param parameters
* @param recordActivity true, if an activity post is required.
* @return
*/
BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity);
/**
* Uploads file content (updates existing node with new content).
*
@@ -215,7 +225,7 @@ public interface Nodes
String PATH_SHARED = "-shared-";
String OP_CREATE = "create";
String OP_DELETE= "delete";
String OP_DELETE = "delete";
String OP_UPDATE = "update";
String PARAM_RELATIVE_PATH = "relativePath";
@@ -244,6 +254,4 @@ public interface Nodes
String PARAM_VERSION_MAJOR = "majorVersion"; // true if major, false if minor
String PARAM_VERSION_COMMENT = "comment";
String PARAM_RENDITIONS = "renditions";
}

View File

@@ -23,6 +23,7 @@ import org.alfresco.rest.api.model.Rendition;
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.service.cmr.repository.NodeRef;
/**
* Renditions API
@@ -31,6 +32,8 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
*/
public interface Renditions
{
String PARAM_STATUS = "status";
/**
* Lists all available renditions includes those that have been created and those that are yet to be created.
*
@@ -70,5 +73,13 @@ public interface Renditions
*/
BinaryResource getContent(String nodeId, String renditionId, Parameters parameters);
String PARAM_STATUS = "status";
/**
* Downloads rendition.
*
* @param sourceNodeRef the source nodeRef
* @param renditionId the rendition id
* @param parameters the {@link Parameters} object to get the parameters passed into the request
* @return the rendition stream
*/
BinaryResource getContent(NodeRef sourceNodeRef, String renditionId, Parameters parameters);
}

View File

@@ -1950,15 +1950,20 @@ public class NodesImpl implements Nodes
public BinaryResource getContent(String fileNodeId, Parameters parameters, boolean recordActivity)
{
final NodeRef nodeRef = validateNode(fileNodeId);
return getContent(nodeRef, parameters, recordActivity);
}
if (! nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false))
@Override
public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity)
{
if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false))
{
throw new InvalidArgumentException("NodeId of content is expected: "+nodeRef.getId());
throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
}
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
ContentData cd = (ContentData)nodeProps.get(ContentModel.PROP_CONTENT);
String name = (String)nodeProps.get(ContentModel.PROP_NAME);
ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
String name = (String) nodeProps.get(ContentModel.PROP_NAME);
org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
String mimeType = null;
@@ -1982,7 +1987,7 @@ public class NodesImpl implements Nodes
}
else
{
logger.warn("Ignored attachment=false for "+fileNodeId+" since "+mimeType+" is not in the whitelist for non-attach content types");
logger.warn("Ignored attachment=false for "+nodeRef.getId()+" since "+mimeType+" is not in the whitelist for non-attach content types");
}
}
}
@@ -1990,7 +1995,7 @@ public class NodesImpl implements Nodes
if (recordActivity)
{
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
postActivity(Activity_Type.DOWNLOADED, activityInfo, true);
}

View File

@@ -230,15 +230,13 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
throw new InvalidNodeRefException(nodeRef);
}
String nodeId = nodeRef.getId();
if (renditionId != null)
{
return renditions.getContent(nodeId, renditionId, parameters);
return renditions.getContent(nodeRef, renditionId, parameters);
}
else
{
return nodes.getContent(nodeId, parameters, false);
return nodes.getContent(nodeRef, parameters, false);
}
}
}, networkTenantDomain);

View File

@@ -21,6 +21,7 @@ package org.alfresco.rest.api.impl;
import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
import org.alfresco.repo.thumbnail.ThumbnailHelper;
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
@@ -96,6 +97,7 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
private NamespaceService namespaceService;
private ServiceRegistry serviceRegistry;
private ResourceLoader resourceLoader;
private TenantService tenantService;
public void setNodes(Nodes nodes)
{
@@ -123,12 +125,18 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
this.resourceLoader = resourceLoader;
}
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void init()
{
PropertyCheck.mandatory(this, "nodes", nodes);
PropertyCheck.mandatory(this, "thumbnailService", thumbnailService);
PropertyCheck.mandatory(this, "scriptThumbnailService", scriptThumbnailService);
PropertyCheck.mandatory(this, "serviceRegistry", serviceRegistry);
PropertyCheck.mandatory(this, "tenantService", tenantService);
this.nodeService = serviceRegistry.getNodeService();
this.actionService = serviceRegistry.getActionService();
@@ -288,7 +296,13 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
public BinaryResource getContent(String nodeId, String renditionId, Parameters parameters)
{
final NodeRef sourceNodeRef = validateSourceNode(nodeId);
final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, renditionId, parameters);
return getContent(sourceNodeRef, renditionId, parameters);
}
@Override
public BinaryResource getContent(NodeRef sourceNodeRef, String renditionId, Parameters parameters)
{
NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, renditionId, parameters);
// By default set attachment header (with rendition Id) unless attachment=false
boolean attach = true;
@@ -382,7 +396,8 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware
{
return null;
}
return nodeRefRendition.getChildRef();
return tenantService.getName(nodeRef, nodeRefRendition.getChildRef());
}
protected Rendition toApiRendition(NodeRef renditionNodeRef)