From 010ba4a86c4cf136e681337be3caeda40ff4c0e6 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 7 Feb 2015 10:29:39 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud) 96317: Merged 5.0.N (5.0.1) to HEAD-BUG-FIX (5.1/Cloud) 96272: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.1) 96106: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.5) 96045: Merged DEV to V4.1-BUG-FIX (4.1.10) 94227 : MNT-12569: Problems with org/alfresco/repository/thumbnail scripts - Added a test 94339 : MNT-12569: Problems with org/alfresco/repository/thumbnail scripts - Implemented 'PUT' method git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@96483 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/thumbnail/thumbnail.put.js | 45 +++++++++++++++++++ .../thumbnail/thumbnail.put.json.ftl | 3 ++ .../thumbnail/ThumbnailServiceTest.java | 26 +++++++++++ 3 files changed, 74 insertions(+) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.js create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.json.ftl diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.js new file mode 100644 index 0000000000..9a9326e554 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.js @@ -0,0 +1,45 @@ +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 thumbnail source node could not be found"); + return; + } + + // 400 if the node is not a subtype of cm:content + if (!node.isSubType("cm:content")) + { + status.setCode(status.STATUS_BAD_REQUEST, "The thumbnail source node is not a subtype of cm:content"); + return; + } + + // Get the thumbnail name from the JSON content + var thumbnailName = url.templateArgs.thumbnailname; + + // 404 if no thumbnail name found + if (thumbnailName == null) + { + status.setCode(status.STATUS_NOT_FOUND, "Thumbnail name was not provided"); + return; + } + + // Get the thumbnail + var thumbnail = node.getThumbnail(thumbnailName); + + if (thumbnail != null) + { + thumbnail.update(); + } + else + { + status.setCode(status.STATUS_NOT_FOUND, "Thumbnail with name '" + thumbnailName + "' not found"); + } +} + +main(); \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.json.ftl new file mode 100644 index 0000000000..294abc0699 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/thumbnail/thumbnail.put.json.ftl @@ -0,0 +1,3 @@ +{ + "Status Code": ${status.code} +} \ No newline at end of file diff --git a/source/test-java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java b/source/test-java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java index 7641d24096..722f50071e 100644 --- a/source/test-java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java +++ b/source/test-java/org/alfresco/repo/web/scripts/thumbnail/ThumbnailServiceTest.java @@ -42,6 +42,7 @@ import org.json.JSONArray; import org.json.JSONObject; import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest; +import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest; import org.springframework.extensions.webscripts.TestWebScriptServer.Response; /** @@ -212,6 +213,31 @@ public class ThumbnailServiceTest extends BaseWebScriptTest assertEquals(0, getArr.length()); } + public void testUpdateThumbnail() throws Exception + { + // Do a image transformation + String url = "/api/node/" + jpgNode.getStoreRef().getProtocol() + "/" + jpgNode.getStoreRef().getIdentifier() + "/" + jpgNode.getId() + "/content/thumbnails"; + JSONObject tn = new JSONObject(); + tn.put("thumbnailName", "doclib"); + Response response = sendRequest(new PostRequest(url, tn.toString(), "application/json"), 200); + System.out.println(response.getContentAsString()); + + // Check getAll whilst we are here + Response getAllResp = sendRequest(new GetRequest(getThumbnailsURL(jpgNode)), 200); + JSONArray getArr = new JSONArray(getAllResp.getContentAsString()); + assertNotNull(getArr); + assertEquals(1, getArr.length()); + assertEquals("doclib", getArr.getJSONObject(0).get("thumbnailName")); + //Now we know that thumbnail was created + + + sendRequest(new GetRequest(getThumbnailsURL(jpgNode) + "/incorrectname"), 404); + //Request for update of thumbnail, that is absent + sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/incorrectname", "", "application/json"), 404); + //Request for update of correct thumbnail + sendRequest(new PutRequest(getThumbnailsURL(jpgNode) + "/doclib", "", "application/json"), 200); + } + public void testThumbnailDefinitions() throws Exception { // Check for pdfToSWF transformation before doing test