Thumbnail Service: can now get a list of thumbnail definitions that can be applied to a given content property

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10437 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2008-08-20 10:27:56 +00:00
parent f4da392bc3
commit b5caf3fdef
5 changed files with 92 additions and 3 deletions

View File

@@ -0,0 +1,9 @@
<webscript>
<shortname>ThumbnailsDefinitions</shortname>
<description>Get the thumbnails definitions for a content resource</description>
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnaildefinitions</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnaildefinitions</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,23 @@
function main()
{
// Get the node from the URL
var pathSegments = url.match.split("/");
var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/"));
var node = search.findNode(pathSegments[2], reference);
// 404 if the node to thumbnail is not found
if (node == null)
{
status.setCode(status.STATUS_NOT_FOUND, "The node could not be found");
return;
}
// Get the thumbnail definitions
var thumbnailDefinitions = node.getThumbnailDefintions();
// Add them to the model
model.node = node;
model.thumbnailDefinitions = thumbnailDefinitions;
}
main();

View File

@@ -0,0 +1,8 @@
<#escape x as jsonUtils.encodeJSONString(x)>
[
<#list thumbnailDefinitions as def>
"${def}"
<#if def_has_next>,</#if>
</#list>
]
</#escape>

View File

@@ -4,6 +4,6 @@
<url>/api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails</url>
<url>/api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails</url>
<format default="json"/>
<authentication>guest</authentication>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -142,6 +142,57 @@ public class ThumbnailServiceTest extends BaseWebScriptTest
}
public void testThumbnailDefinitions() 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/thumbnaildefinitions";
MockHttpServletResponse response = this.getRequest(url, 200);
JSONArray array = new JSONArray(response.getContentAsString());
assertNotNull(array);
assertFalse(array.length() == 0);
boolean hasMedium = false;
boolean hasWebPreview = false;
for (int i = 0; i < array.length(); i++)
{
if (array.getString(i).equals("medium") == true)
{
hasMedium = true;
}
else if (array.getString(i).equals("webpreview") == true)
{
hasWebPreview = true;
}
}
assertTrue(hasMedium);
assertTrue(hasWebPreview);
}
String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnaildefinitions";
MockHttpServletResponse response = this.getRequest(url, 200);
JSONArray array = new JSONArray(response.getContentAsString());
assertNotNull(array);
assertFalse(array.length() == 0);
boolean hasMedium = false;
boolean hasWebPreview = false;
for (int i = 0; i < array.length(); i++)
{
if (array.getString(i).equals("medium") == true)
{
hasMedium = true;
}
else if (array.getString(i).equals("webpreview") == true)
{
hasWebPreview = true;
}
}
assertTrue(hasMedium);
assertFalse(hasWebPreview);
}
public void testCreateAsyncThumbnail() throws Exception
{
// Check for pdfToSWF transformation before doing test
@@ -221,6 +272,4 @@ public class ThumbnailServiceTest extends BaseWebScriptTest
{
return "/api/node/" + nodeRef.getStoreRef().getProtocol() + "/" + nodeRef.getStoreRef().getIdentifier() + "/" + nodeRef.getId() + "/content/thumbnails";
}
}