Thumbnail Service: support for asyn creation of thumbnails (unit test's included)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9428 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-06-09 10:10:16 +00:00
parent 8072997657
commit 98df967450
6 changed files with 103 additions and 34 deletions

View File

@@ -161,30 +161,6 @@ public class StreamContent extends AbstractWebScript
mergeScriptModelIntoTemplateModel(returnModel, model);
}
// Get the content parameters from the model
NodeRef nodeRef = (NodeRef)model.get("contentNode");
if (nodeRef == null)
{
throw new WebScriptException("The content node was not specified so the content cannot be streamed to the client");
}
QName propertyQName = null;
String contentProperty = (String)model.get("contentProperty");
if (contentProperty == null)
{
// default to the standard content property
propertyQName = ContentModel.PROP_CONTENT;
}
else
{
propertyQName = QName.createQName(contentProperty);
}
Boolean attachBoolean = (Boolean)model.get("attach");
boolean attach = false;
if (attachBoolean != null)
{
attach = attachBoolean.booleanValue();
}
// is a redirect to a status specific template required?
if (status.getRedirect())
{
@@ -193,7 +169,31 @@ public class StreamContent extends AbstractWebScript
sendStatus(req, res, status, cache, format, templateModel);
}
else
{
{
// Get the content parameters from the model
NodeRef nodeRef = (NodeRef)model.get("contentNode");
if (nodeRef == null)
{
throw new WebScriptException("The content node was not specified so the content cannot be streamed to the client");
}
QName propertyQName = null;
String contentProperty = (String)model.get("contentProperty");
if (contentProperty == null)
{
// default to the standard content property
propertyQName = ContentModel.PROP_CONTENT;
}
else
{
propertyQName = QName.createQName(contentProperty);
}
Boolean attachBoolean = (Boolean)model.get("attach");
boolean attach = false;
if (attachBoolean != null)
{
attach = attachBoolean.booleanValue();
}
// Stream the content
streamContent(req, res, nodeRef, propertyQName, attach);
}

View File

@@ -37,6 +37,7 @@ import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.GUID;
import org.apache.tools.ant.taskdefs.Sleep;
import org.json.JSONObject;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -128,6 +129,55 @@ public class ThumbnailServiceTest extends BaseWebScriptTest
}
public void testCreateAsyncThumbnail() throws Exception
{
// Check for pdfToSWF transformation before doing test
if (this.contentService.getTransformer(MimetypeMap.MIMETYPE_PDF, MimetypeMap.MIMETYPE_FLASH) != null)
{
String url = "/api/node/" + pdfNode.getStoreRef().getProtocol() + "/" + pdfNode.getStoreRef().getIdentifier() + "/" + pdfNode.getId() + "/content/thumbnails?as=true";
JSONObject tn = new JSONObject();
tn.put("thumbnailName", "webpreview");
MockHttpServletResponse response = this.postRequest(url, 200, tn.toString(), "application/json");
assertEquals("", response.getContentAsString().trim());
getWait(pdfNode, "webpreview");
}
// Do a image transformation (medium)
String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails?as=true";
JSONObject tn = new JSONObject();
tn.put("thumbnailName", "medium");
MockHttpServletResponse response = this.postRequest(url, 200, tn.toString(), "application/json");
assertEquals("", response.getContentAsString().trim());
getWait(jpgNode, "medium");
}
private void getWait(NodeRef node, String thumbnailName)
throws Exception
{
String url = "/api/node/" + node.getStoreRef().getProtocol() + "/" + node.getStoreRef().getIdentifier() + "/" + node.getId() + "/content/thumbnails/" + thumbnailName;
while (true)
{
MockHttpServletResponse response = getRequest(url, 0);
if (response.getStatus() == 200)
{
break;
}
else if (response.getStatus() == 500)
{
System.out.println("Error during getWait: " + response.getContentAsString());
fail("A 500 status was found whilst waiting for the thumbnail to be processed");
}
else
{
Thread.sleep(100);
}
}
}
}