From ce95d147e120165238f1bafe4bfb33f7ae7ef166 Mon Sep 17 00:00:00 2001 From: Jamal Kaabi-Mofrad Date: Tue, 31 May 2016 10:08:07 +0000 Subject: [PATCH] Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 127427 jkaabimofrad: RA-1052: Modified the upload API so that the failure of the async request to create a rendition wouldn't fail the upload. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127445 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/impl/NodesImpl.java | 20 +++++++++++++++---- .../rest/api/tests/RenditionsTest.java | 20 +++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index af8ef3018e..13f66f9749 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -2229,8 +2229,6 @@ public class NodesImpl implements Nodes try { - List thumbnailDefs = getThumbnailDefs(renditionNames); - // Map the given properties, if any. if (qnameStrProps.size() > 0) { @@ -2265,9 +2263,23 @@ public class NodesImpl implements Nodes } // Create a new file. - Node fileNode = createNewFile(parentNodeRef, fileName, nodeTypeQName, content, properties, parameters); + final Node fileNode = createNewFile(parentNodeRef, fileName, nodeTypeQName, content, properties, parameters); - requestRenditions(thumbnailDefs, fileNode); + // RA-1052 + try + { + List thumbnailDefs = getThumbnailDefs(renditionNames); + requestRenditions(thumbnailDefs, fileNode); + } + catch (Exception ex) + { + // Note: The log level is not 'error' as it could easily fill out the log file, especially in the Cloud. + if (logger.isDebugEnabled()) + { + // Don't throw the exception as we don't want the the upload to fail, just log it. + logger.debug("Asynchronous request to create a rendition upon upload failed: " + ex.getMessage()); + } + } return fileNode; diff --git a/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java b/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java index f0ec3a6c72..0a6f82d857 100644 --- a/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java @@ -529,23 +529,31 @@ public class RenditionsTest extends AbstractBaseApiTest assertEquals(RenditionStatus.CREATED, rendition.getStatus()); */ - // -ve - currently we do not support multiple rendition requests on create + + /* + * Per RA-1052, the failure of the async request to create a rendition + * should NOT fail the upload. + */ + + // Currently we do not support multiple rendition requests on create reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_PDF)) + .setAutoRename(true) .setRenditions(Arrays.asList(new String[]{"doclib,imgpreview"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 400); + post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); - // -ve + // Unknown rendition reqBody = MultiPartBuilder.create() .setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_PDF)) + .setAutoRename(true) .setRenditions(Arrays.asList(new String[]{"unknown"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 404); + post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); - // -ve + // ThumbnailService is disabled ThumbnailService thumbnailService = applicationContext.getBean("thumbnailService", ThumbnailService.class); thumbnailService.setThumbnailsEnabled(false); try @@ -558,7 +566,7 @@ public class RenditionsTest extends AbstractBaseApiTest .setRenditions(Arrays.asList(new String[]{"doclib"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 501); + post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); } finally {