diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.desc.xml new file mode 100644 index 0000000000..a0695cc07e --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.desc.xml @@ -0,0 +1,9 @@ + + ThumbnailsDefinitions + Get the thumbnails definitions for a content resource + /api/node/{store_type}/{store_id}/{id}/content{property}/thumbnaildefinitions + /api/path/{store_type}/{store_id}/{id}/content{property}/thumbnaildefinitions + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.js new file mode 100644 index 0000000000..960e4e72cb --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.js @@ -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(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.json.ftl new file mode 100644 index 0000000000..705e7d0483 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnaildefinitions.get.json.ftl @@ -0,0 +1,8 @@ +<#escape x as jsonUtils.encodeJSONString(x)> +[ + <#list thumbnailDefinitions as def> + "${def}" + <#if def_has_next>, + +] + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml index ef63a79f36..e840a9208a 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnails.get.desc.xml @@ -4,6 +4,6 @@ /api/node/{store_type}/{store_id}/{id}/content{property}/thumbnails /api/path/{store_type}/{store_id}/{id}/content{property}/thumbnails - guest + user required \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java b/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java index 4ac880c2db..7a0d007341 100644 --- a/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java @@ -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"; } - - }