From dc067d1878d4968bdba1c405d3dcb51673a15494 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Fri, 3 Jun 2016 15:19:29 +0000 Subject: [PATCH] Merged HEAD (5.2) to 5.2.N (5.2.1) 127617 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2) 127512 jkaabimofrad: REPO-47: Per peer review, changed the upload API to throw an exception when requesting multiple renditions. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127724 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/rest/api/impl/NodesImpl.java | 69 +++++++++++-------- .../rest/api/tests/RenditionsTest.java | 2 +- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 9d26b6dfb8..081dbb1dc2 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -129,8 +129,6 @@ import org.alfresco.service.cmr.version.VersionService; import org.alfresco.service.cmr.version.VersionType; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; -import org.alfresco.service.namespace.QNamePattern; -import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.Pair; import org.alfresco.util.PropertyCheck; import org.apache.commons.lang.StringUtils; @@ -152,6 +150,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -2447,8 +2446,8 @@ public class NodesImpl implements Nodes // if requested, make (get or create) path parentNodeRef = getOrCreatePath(parentNodeRef, relativePath); - - QName assocTypeQName = ContentModel.ASSOC_CONTAINS; + final QName assocTypeQName = ContentModel.ASSOC_CONTAINS; + final Set renditions = getRequestedRenditions(renditionNames); try { @@ -2491,7 +2490,7 @@ public class NodesImpl implements Nodes // RA-1052 try { - List thumbnailDefs = getThumbnailDefs(renditionNames); + List thumbnailDefs = getThumbnailDefs(renditions); requestRenditions(thumbnailDefs, fileNode); } catch (Exception ex) @@ -2568,11 +2567,11 @@ public class NodesImpl implements Nodes return null; } - private List getThumbnailDefs(String renditionsParam) + private List getThumbnailDefs(Set renditionNames) { List thumbnailDefs = null; - if (renditionsParam != null) + if (renditionNames != null) { // If thumbnail generation has been configured off, then don't bother. if (!thumbnailService.getThumbnailsEnabled()) @@ -2580,37 +2579,53 @@ public class NodesImpl implements Nodes throw new DisabledServiceException("Thumbnail generation has been disabled."); } - String[] renditionNames = renditionsParam.split(","); - - // Temporary - pending future improvements to thumbnail service to minimise chance of - // missing/failed thumbnails (when requested/generated 'concurrently') - if (renditionNames.length > 1) - { - throw new InvalidArgumentException("Please specify one rendition entity id only"); - } - - thumbnailDefs = new ArrayList<>(renditionNames.length); + thumbnailDefs = new ArrayList<>(renditionNames.size()); ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry(); for (String renditionName : renditionNames) { - renditionName = renditionName.trim(); - if (!renditionName.isEmpty()) + // Use the thumbnail registry to get the details of the thumbnail + ThumbnailDefinition thumbnailDef = registry.getThumbnailDefinition(renditionName); + if (thumbnailDef == null) { - // Use the thumbnail registry to get the details of the thumbnail - ThumbnailDefinition thumbnailDef = registry.getThumbnailDefinition(renditionName); - if (thumbnailDef == null) - { - throw new NotFoundException(renditionName + " is not registered."); - } - - thumbnailDefs.add(thumbnailDef); + throw new NotFoundException(renditionName + " is not registered."); } + + thumbnailDefs.add(thumbnailDef); + } } return thumbnailDefs; } + private Set getRequestedRenditions(String renditionsParam) + { + if (renditionsParam == null) + { + return null; + } + + String[] renditionNames = renditionsParam.split(","); + + // Temporary - pending future improvements to thumbnail service to minimise chance of + // missing/failed thumbnails (when requested/generated 'concurrently') + if (renditionNames.length > 1) + { + throw new InvalidArgumentException("Please specify one rendition entity id only"); + } + + Set renditions = new LinkedHashSet<>(renditionNames.length); + for (String name : renditionNames) + { + name = name.trim(); + if (!name.isEmpty()) + { + renditions.add(name.trim()); + } + } + return renditions; + } + private void requestRenditions(List thumbnailDefs, Node fileNode) { if (thumbnailDefs != null) 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 c4be39ff57..d685d700b4 100644 --- a/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/RenditionsTest.java @@ -546,7 +546,7 @@ public class RenditionsTest extends AbstractBaseApiTest .setRenditions(Arrays.asList(new String[]{"doclib,imgpreview"})) .build(); - post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 201); + post(getNodeChildrenUrl(folder_Id), userId, reqBody.getBody(), null, reqBody.getContentType(), 400); // Unknown rendition reqBody = MultiPartBuilder.create()