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)
126380 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 120084 jkaabimofrad: RA-640, RA-681: made "update node content" API to return the default JSON representation of the file node. Also added a test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126726 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -125,8 +125,7 @@ public interface Nodes
|
||||
// TODO update REST fwk - to optionally support "attachment" (Content-Disposition) header
|
||||
BinaryResource getContent(String fileNodeId, Parameters parameters);
|
||||
|
||||
// TODO update REST fwk - to optionally support return of json
|
||||
void updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters);
|
||||
Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters);
|
||||
|
||||
/**
|
||||
* Uploads file content and meta-data into the repository.
|
||||
|
@@ -35,6 +35,7 @@ import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.rest.antlr.WhereClauseParser;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.ContentInfo;
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
@@ -45,7 +46,6 @@ import org.alfresco.rest.framework.core.exceptions.ApiException;
|
||||
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
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.RequestEntityTooLargeException;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
@@ -93,12 +93,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.Content;
|
||||
import org.springframework.extensions.webscripts.servlet.FormData;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -1001,10 +998,20 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
}
|
||||
|
||||
if (isContent) {
|
||||
if (isContent)
|
||||
{
|
||||
// add empty file
|
||||
ContentWriter writer = sr.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
String mimeType = sr.getMimetypeService().guessMimetype(nodeName);
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
String mimeType;
|
||||
ContentInfo contentInfo = nodeInfo.getContent();
|
||||
if (contentInfo != null && contentInfo.getMimeType() != null)
|
||||
{
|
||||
mimeType = contentInfo.getMimeType();
|
||||
}
|
||||
else
|
||||
{
|
||||
mimeType = mimetypeService.guessMimetype(nodeName);
|
||||
}
|
||||
writer.setMimetype(mimeType);
|
||||
writer.putContent("");
|
||||
}
|
||||
@@ -1159,34 +1166,34 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters)
|
||||
public Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters)
|
||||
{
|
||||
final NodeRef nodeRef = validateNode(fileNodeId);
|
||||
|
||||
if (! nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null))
|
||||
if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null))
|
||||
{
|
||||
throw new InvalidArgumentException("NodeId of content is expected: "+nodeRef);
|
||||
throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef);
|
||||
}
|
||||
|
||||
ContentWriter writer = sr.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
|
||||
String mimeType = contentInfo.getMimeType();
|
||||
if (mimeType == null)
|
||||
{
|
||||
String fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
String fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
writer.guessMimetype(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.setMimetype(mimeType);
|
||||
}
|
||||
|
||||
writer.guessEncoding();
|
||||
|
||||
writer.putContent(stream);
|
||||
|
||||
// TODO - hmm - we may wish to return json info !!
|
||||
return;
|
||||
return getFolderOrDocumentFullInfo(nodeRef,
|
||||
getParentNodeRef(nodeRef),
|
||||
nodeService.getType(nodeRef),
|
||||
parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1389,9 +1396,8 @@ public class NodesImpl implements Nodes
|
||||
protected void write(NodeRef nodeRef, Content content, String fileName, boolean applyMimeType, boolean guessEncoding)
|
||||
{
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
InputStream is;
|
||||
String mimeType = content.getMimetype();
|
||||
// Per RA-637 requirement the mimeType provided by the client takes precedent, however,
|
||||
// Per RA-637 requirement the mimeType provided by the client takes precedence, however,
|
||||
// if the mimeType is null, then it will be retrieved or guessed.
|
||||
if (mimeType == null || !applyMimeType)
|
||||
{
|
||||
@@ -1405,28 +1411,17 @@ public class NodesImpl implements Nodes
|
||||
mimeType = mimetypeService.guessMimetype(fileName);
|
||||
}
|
||||
}
|
||||
writer.setMimetype(mimeType);
|
||||
|
||||
if (guessEncoding)
|
||||
{
|
||||
is = new BufferedInputStream(content.getInputStream());
|
||||
is.mark(1024);
|
||||
|
||||
writer.setEncoding(guessEncoding(is, mimeType));
|
||||
try
|
||||
{
|
||||
is.reset();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("Failed to reset input stream", e);
|
||||
}
|
||||
writer.guessEncoding();
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.setEncoding(content.getEncoding());
|
||||
is = content.getInputStream();
|
||||
}
|
||||
writer.setMimetype(mimeType);
|
||||
writer.putContent(is);
|
||||
writer.putContent(content.getInputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1448,22 +1443,6 @@ public class NodesImpl implements Nodes
|
||||
versionService.ensureVersioningEnabled(nodeRef, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guesses the character encoding of the given inputStream.
|
||||
*/
|
||||
protected String guessEncoding(InputStream in, String mimeType)
|
||||
{
|
||||
String encoding = "UTF-8";
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
Charset charset = mimetypeService.getContentCharsetFinder().getCharset(in, mimeType);
|
||||
encoding = charset.name();
|
||||
}
|
||||
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the given node metadata asynchronously.
|
||||
*/
|
||||
|
@@ -52,7 +52,7 @@ import java.io.InputStream;
|
||||
@EntityResource(name="nodes", title = "Nodes")
|
||||
public class NodesEntityResource implements
|
||||
EntityResourceAction.ReadById<Node>, EntityResourceAction.Delete, EntityResourceAction.Update<Node>,
|
||||
BinaryResourceAction.Read, BinaryResourceAction.Update, InitializingBean
|
||||
BinaryResourceAction.Read, BinaryResourceAction.Update<Node>, InitializingBean
|
||||
{
|
||||
private Nodes nodes;
|
||||
|
||||
@@ -93,9 +93,9 @@ public class NodesEntityResource implements
|
||||
@Override
|
||||
@WebApiDescription(title = "Upload content", description = "Upload content")
|
||||
@BinaryProperties({"content"})
|
||||
public void updateProperty(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters)
|
||||
public Node updateProperty(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters)
|
||||
{
|
||||
nodes.updateContent(fileNodeId, contentInfo, stream, parameters);
|
||||
return nodes.updateContent(fileNodeId, contentInfo, stream, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -79,7 +79,7 @@ public interface BinaryResourceAction
|
||||
/**
|
||||
* HTTP PUT - Updates a binary resource if it exists, error if not
|
||||
*/
|
||||
public static interface Update extends ResourceAction
|
||||
public static interface Update<E> extends ResourceAction
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ public interface BinaryResourceAction
|
||||
* @param contentInfo Basic information about the content stream
|
||||
* @param params {@link Parameters}
|
||||
*/
|
||||
public void updateProperty (String entityId, BasicContentInfo contentInfo, InputStream stream, Parameters params);
|
||||
public E updateProperty (String entityId, BasicContentInfo contentInfo, InputStream stream, Parameters params);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@ import java.util.Locale;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.web.scripts.BufferedRequest;
|
||||
import org.alfresco.rest.framework.core.ResourceInspector;
|
||||
import org.alfresco.rest.framework.core.ResourceLocator;
|
||||
import org.alfresco.rest.framework.core.ResourceMetadata;
|
||||
@@ -196,10 +195,8 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
BinaryResourceAction.Update binUpdater = (BinaryResourceAction.Update) resource.getResource();
|
||||
binUpdater.updateProperty(params.getEntityId(),params.getContentInfo(), params.getStream(), params);
|
||||
//Don't pass anything to the callback - its just successful
|
||||
return null;
|
||||
BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
|
||||
default:
|
||||
throw new UnsupportedResourceOperationException("PUT not supported for Actions");
|
||||
}
|
||||
|
Reference in New Issue
Block a user