From c3e0afa696f2d73144e5257b10e183cfecdf3a3a Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Thu, 22 Apr 2010 13:58:15 +0000 Subject: [PATCH] Reimplementation of ALF-2220 fix. The ThumbnailRegistry.initThumbnailDefinitions method now detects if the transaction service is read-only and if it is it does not persist any thumbnail definitions. This behaviour fixes ALF-2220. As part of this change, I have reverted the behaviour so that (for write-mode databases) thumbnail definitions will be persisted on startup even if they have already been persisted. In this way, we can support 3rd party developers who are changing their thumbnail definitions during development. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19953 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/thumbnail-service-context.xml | 1 + .../repo/thumbnail/ThumbnailRegistry.java | 42 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/config/alfresco/thumbnail-service-context.xml b/config/alfresco/thumbnail-service-context.xml index a1d65beac1..23887da073 100644 --- a/config/alfresco/thumbnail-service-context.xml +++ b/config/alfresco/thumbnail-service-context.xml @@ -53,6 +53,7 @@ + diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java index 5899c6cb5c..d0e09dc996 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java @@ -29,6 +29,7 @@ import org.alfresco.service.cmr.rendition.RenditionDefinition; import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.thumbnail.ThumbnailException; +import org.alfresco.service.transaction.TransactionService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; @@ -53,6 +54,9 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi /** Content service */ private ContentService contentService; + /** Transaction service */ + private TransactionService transactionService; + /** Rendition service */ private RenditionService renditionService; @@ -87,6 +91,16 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi this.contentService = contentService; } + /** + * Transaction service + * + * @param transactionService transaction service + */ + public void setTransactionService(TransactionService transactionService) + { + this.transactionService = transactionService; + } + /** * Rendition service * @@ -121,6 +135,16 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi */ private void initThumbnailDefinitions() { + // If the database is in read-only mode, then do not persist the thumbnail definitions. + if (transactionService.isReadOnly()) + { + if (logger.isDebugEnabled()) + { + logger.debug("TransactionService is in read-only mode. Therefore no thumbnail definitions have been initialised."); + } + return; + } + AuthenticationUtil.runAs(new RunAsWork() { public Void doWork() throws Exception { @@ -133,23 +157,7 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi RenditionDefinition renditionDef = thumbnailRenditionConvertor.convert(thumbnailDefinition, null); // Thumbnail definitions are saved into the repository as actions - // but only if they have not already been saved. - boolean alreadyPersisted = renditionService.loadRenditionDefinition(renditionDef.getRenditionName()) != null; - if (!alreadyPersisted) - { - if (logger.isDebugEnabled()) - { - logger.debug("Init'ing and saving thumbnail definition " + thumbnailDefName); - } - renditionService.saveRenditionDefinition(renditionDef); - } - else - { - if (logger.isDebugEnabled()) - { - logger.debug("Init'ing thumbnail definition " + thumbnailDefName); - } - } + renditionService.saveRenditionDefinition(renditionDef); } return null;