From 0995ee28240870f0c982bb62b948f1a463277214 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Tue, 11 Feb 2014 20:46:44 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 57480: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 57290: Merged V4.1-BUG-FIX (4.1.7) to V4.2-BUG-FIX (4.2.1) 57279: Fix for MNT-9801. I have very slightly refactored the configuration of thumbnails. Rather than inject system.thumbnail.generate into both CreateThumbnail- and UpdateThumbnailActionExecuter, I am now injecting it into the ThumbnailService centrally. I left the old injector methods for backwards compatibility, but deprecated them. Now all requests to create a thumbnail via the ScriptNode API pre-check that thumbnail generation is enabled. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61822 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/thumbnail-service-context.xml | 12 +- .../org/alfresco/repo/jscript/ScriptNode.java | 115 +++++++++--------- .../CreateThumbnailActionExecuter.java | 14 ++- .../repo/thumbnail/ThumbnailServiceImpl.java | 7 ++ .../UpdateThumbnailActionExecuter.java | 14 ++- .../cmr/thumbnail/ThumbnailService.java | 14 +++ 6 files changed, 103 insertions(+), 73 deletions(-) diff --git a/config/alfresco/thumbnail-service-context.xml b/config/alfresco/thumbnail-service-context.xml index 2624153ecf..ce5ed21afc 100644 --- a/config/alfresco/thumbnail-service-context.xml +++ b/config/alfresco/thumbnail-service-context.xml @@ -48,6 +48,10 @@ + + + ${system.thumbnail.generate} + - - ${system.thumbnail.generate} - @@ -266,10 +266,6 @@ - - - ${system.thumbnail.generate} - diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index 19b27425c6..3615dc4281 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -2866,71 +2866,76 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider */ public ScriptThumbnail createThumbnail(String thumbnailName, boolean async) { + final ThumbnailService thumbnailService = services.getThumbnailService(); + ScriptThumbnail result = null; - // Use the thumbnail registy to get the details of the thumbail - ThumbnailRegistry registry = this.services.getThumbnailService().getThumbnailRegistry(); - ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName); - if (details == null) + // If thumbnail generation has been configured off, then don't bother with any of this. + if ( thumbnailService.getThumbnailsEnabled()) { - // Throw exception - throw new ScriptException("The thumbnail name '" + thumbnailName + "' is not registered"); - } - - // If there's nothing currently registered to generate thumbnails for the - // specified mimetype, then log a message and bail out - String nodeMimeType = getMimetype(); - Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); - ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value); - if (!ContentData.hasContent(contentData) || - !services.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT).exists()) - { - if (logger.isDebugEnabled()) - logger.debug("Unable to create thumbnail '" + details.getName() + "' as there is no content"); - return null; - } - if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details)) - { - logger.info("Unable to create thumbnail '" + details.getName() + "' for " + - nodeMimeType + " as no transformer is currently available."); - return null; - } - - // Have the thumbnail created - if (async == false) - { - try + // Use the thumbnail registy to get the details of the thumbail + ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry(); + ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName); + if (details == null) { - // Create the thumbnail - NodeRef thumbnailNodeRef = this.services.getThumbnailService().createThumbnail( - this.nodeRef, - ContentModel.PROP_CONTENT, - details.getMimetype(), - details.getTransformationOptions(), - details.getName()); - - // Create the thumbnail script object - result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope); + // Throw exception + throw new ScriptException("The thumbnail name '" + thumbnailName + "' is not registered"); } - catch (AlfrescoRuntimeException e) + + // If there's nothing currently registered to generate thumbnails for the + // specified mimetype, then log a message and bail out + String nodeMimeType = getMimetype(); + Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); + ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value); + if (!ContentData.hasContent(contentData) || + !services.getContentService().getReader(nodeRef, ContentModel.PROP_CONTENT).exists()) { - Throwable rootCause = e.getRootCause(); - if (rootCause instanceof UnimportantTransformException) + if (logger.isDebugEnabled()) + logger.debug("Unable to create thumbnail '" + details.getName() + "' as there is no content"); + return null; + } + if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details)) + { + logger.info("Unable to create thumbnail '" + details.getName() + "' for " + + nodeMimeType + " as no transformer is currently available."); + return null; + } + + // Have the thumbnail created + if (async == false) + { + try { - logger.debug("Unable to create thumbnail '" + details.getName() + "' as "+rootCause.getMessage()); - return null; + // Create the thumbnail + NodeRef thumbnailNodeRef = thumbnailService.createThumbnail( + this.nodeRef, + ContentModel.PROP_CONTENT, + details.getMimetype(), + details.getTransformationOptions(), + details.getName()); + + // Create the thumbnail script object + result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope); } - throw e; + catch (AlfrescoRuntimeException e) + { + Throwable rootCause = e.getRootCause(); + if (rootCause instanceof UnimportantTransformException) + { + logger.debug("Unable to create thumbnail '" + details.getName() + "' as "+rootCause.getMessage()); + return null; + } + throw e; + } + } + else + { + Action action = ThumbnailHelper.createCreateThumbnailAction(details, services); + + // Queue async creation of thumbnail + this.services.getActionService().executeAction(action, this.nodeRef, true, true); } } - else - { - Action action = ThumbnailHelper.createCreateThumbnailAction(details, services); - - // Queue async creation of thumbnail - this.services.getActionService().executeAction(action, this.nodeRef, true, true); - } - return result; } diff --git a/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java b/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java index 923d72c65a..07d780e409 100644 --- a/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java +++ b/source/java/org/alfresco/repo/thumbnail/CreateThumbnailActionExecuter.java @@ -58,9 +58,6 @@ public class CreateThumbnailActionExecuter extends ActionExecuterAbstractBase /** Node Service */ private NodeService nodeService; - /** Property turns on and off all thumbnail creation */ - private boolean generateThumbnails = true; - // Size limitations (in KBytes) indexed by mimetype for thumbnail creation private HashMap mimetypeMaxSourceSizeKBytes; @@ -101,10 +98,17 @@ public class CreateThumbnailActionExecuter extends ActionExecuterAbstractBase /** * Enable thumbnail creation at all regardless of mimetype. * @param generateThumbnails a {@code false} value turns off all thumbnail creation. + * @deprecated Use {@link ThumbnailServiceImpl#setThumbnailsEnabled(boolean)} instead. */ public void setGenerateThumbnails(boolean generateThumbnails) { - this.generateThumbnails = generateThumbnails; + if (logger.isDebugEnabled()) + { + logger.debug("Thumbnail generation is " + + (generateThumbnails ? "enabled" : "disabled") + + "via deprecated method in " + this.getClass().getSimpleName()); + } + this.thumbnailService.setThumbnailsEnabled(generateThumbnails); } /** @@ -114,7 +118,7 @@ public class CreateThumbnailActionExecuter extends ActionExecuterAbstractBase protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { // Check if thumbnailing is generally disabled - if (!generateThumbnails) + if (!thumbnailService.getThumbnailsEnabled()) { if (logger.isDebugEnabled()) { diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java index 991caf2ad4..7a26173bed 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java @@ -91,6 +91,9 @@ public class ThumbnailServiceImpl implements ThumbnailService, /** Thumbnail registry */ private ThumbnailRegistry thumbnailRegistry; + /** Flag to enable/disable the generation of all thumbnails. */ + private boolean thumbnailsEnabled; + /** Rendition service */ private RenditionService renditionService; @@ -148,6 +151,10 @@ public class ThumbnailServiceImpl implements ThumbnailService, this.thumbnailRegistry = thumbnailRegistry; } + @Override public void setThumbnailsEnabled(boolean thumbnailsEnabled) { this.thumbnailsEnabled = thumbnailsEnabled; } + + @Override public boolean getThumbnailsEnabled() { return this.thumbnailsEnabled; } + /** * Set the policy component to listen for various events * @since 3.5.0 diff --git a/source/java/org/alfresco/repo/thumbnail/UpdateThumbnailActionExecuter.java b/source/java/org/alfresco/repo/thumbnail/UpdateThumbnailActionExecuter.java index 0cf6af5b86..52e1e0fd99 100644 --- a/source/java/org/alfresco/repo/thumbnail/UpdateThumbnailActionExecuter.java +++ b/source/java/org/alfresco/repo/thumbnail/UpdateThumbnailActionExecuter.java @@ -62,9 +62,6 @@ public class UpdateThumbnailActionExecuter extends ActionExecuterAbstractBase /** Node Service */ private NodeService nodeService; - /** Property turns on and off all thumbnail creation */ - private boolean generateThumbnails = true; - // Size limitations indexed by mime type for thumbnail creation private HashMap mimetypeMaxSourceSizeKBytes; @@ -115,10 +112,17 @@ public class UpdateThumbnailActionExecuter extends ActionExecuterAbstractBase /** * Enable thumbnail creation at all regardless of mimetype. * @param generateThumbnails a {@code false} value turns off all thumbnail creation. + * @deprecated Use {@link ThumbnailServiceImpl#setThumbnailsEnabled(boolean)} instead. */ public void setGenerateThumbnails(boolean generateThumbnails) { - this.generateThumbnails = generateThumbnails; + if (logger.isDebugEnabled()) + { + logger.debug("Thumbnail generation is " + + (generateThumbnails ? "enabled" : "disabled") + + "via deprecated method in " + this.getClass().getSimpleName()); + } + this.thumbnailService.setThumbnailsEnabled(generateThumbnails); } /** @@ -128,7 +132,7 @@ public class UpdateThumbnailActionExecuter extends ActionExecuterAbstractBase protected void executeImpl(Action action, NodeRef actionedUponNodeRef) { // Check if thumbnailing is generally disabled - if (!generateThumbnails) + if (!thumbnailService.getThumbnailsEnabled()) { if (logger.isDebugEnabled()) { diff --git a/source/java/org/alfresco/service/cmr/thumbnail/ThumbnailService.java b/source/java/org/alfresco/service/cmr/thumbnail/ThumbnailService.java index 35995bdf16..fcb6efdbde 100644 --- a/source/java/org/alfresco/service/cmr/thumbnail/ThumbnailService.java +++ b/source/java/org/alfresco/service/cmr/thumbnail/ThumbnailService.java @@ -148,4 +148,18 @@ public interface ThumbnailService */ @Auditable(parameters = {"sourceNode"}) Map getFailedThumbnails(NodeRef sourceNode); + + /** + * This method enables or disables the creation of all thumbnails by this service. + * + * @param thumbnailsEnabled true to enable all thumbnail creation (the default setting), or false to disable. + * @since 4.1.7 + */ + void setThumbnailsEnabled(boolean thumbnailsEnabled); + + /** + * This method indicates whether thumbnail creation via this service has been globally enabled or disabled. + * @since 4.1.7 + */ + boolean getThumbnailsEnabled(); }