From d368691efc5a83b9bc9a89091cdfd7aa38fcdd0b Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Wed, 30 Jul 2008 18:33:24 +0000 Subject: [PATCH] Thumbnail Service and Upload: thumbnails now refresh when new content is uploaded, content mime is not reset to binary when new content is checked in git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10145 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/thumbnail/ThumbnailServiceImpl.java | 12 +- .../repo/thumbnail/ThumbnailedAspect.java | 162 +++++++++++------- 2 files changed, 107 insertions(+), 67 deletions(-) diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java index 9905d98957..7c24d4bc03 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImpl.java @@ -248,10 +248,14 @@ public class ThumbnailServiceImpl implements ThumbnailService { throw new ThumbnailException(ERR_NO_PARENT); } - else if (parents.size() != 1) - { - throw new ThumbnailException(ERR_TOO_PARENT); - } + // TODO + // When a node with thumbnails is checked in the assoc's get doubled up. This means we get more than one parent. + // As a work around simply take the first parent retrieved + // + //else if (parents.size() != 1) + //{ + // throw new ThumbnailException(ERR_TOO_PARENT); + //} else { node = parents.get(0).getParentRef(); diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailedAspect.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailedAspect.java index 3244b5fd38..c8fcce9e01 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailedAspect.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailedAspect.java @@ -25,14 +25,10 @@ package org.alfresco.repo.thumbnail; import java.io.Serializable; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import org.alfresco.model.ContentModel; -import org.alfresco.repo.content.ContentServicePolicies; -import org.alfresco.repo.content.ContentServicePolicies.OnContentUpdatePolicy; import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.policy.Behaviour; import org.alfresco.repo.policy.JavaBehaviour; @@ -57,37 +53,66 @@ import org.alfresco.util.EqualsHelper; */ public class ThumbnailedAspect implements NodeServicePolicies.OnUpdatePropertiesPolicy { + /** Services */ private PolicyComponent policyComponent; private ThumbnailService thumbnailService; private ActionService actionService; private NodeService nodeService; private DictionaryService dictionaryService; + /** + * Set the policy component + * + * @param policyComponent policy component + */ public void setPolicyComponent(PolicyComponent policyComponent) { this.policyComponent = policyComponent; } + /** + * Set the action service + * + * @param actionService action service + */ public void setActionService(ActionService actionService) { this.actionService = actionService; } + /** + * Set the node service + * + * @param nodeService node service + */ public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; } + /** + * Set the thumbnail service + * + * @param thumbnailService thumbnail service + */ public void setThumbnailService(ThumbnailService thumbnailService) { this.thumbnailService = thumbnailService; } + /** + * Set the dictionary service + * + * @param dictionaryService dictionary service + */ public void setDictionaryService(DictionaryService dictionaryService) { this.dictionaryService = dictionaryService; } + /** + * Initialise method + */ public void init() { this.policyComponent.bindClassBehaviour( @@ -96,83 +121,94 @@ public class ThumbnailedAspect implements NodeServicePolicies.OnUpdateProperties new JavaBehaviour(this, "onUpdateProperties", Behaviour.NotificationFrequency.TRANSACTION_COMMIT)); } + /** + * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map) + */ public void onUpdateProperties( NodeRef nodeRef, Map before, Map after) { - // check if any of the content properties have changed - for (QName propertyQName : after.keySet()) - { - // is this a content property? - PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName); - if (propertyDef == null) + // Ignore working copies + if (this.nodeService.exists(nodeRef) == true && + this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == false) + { + // check if any of the content properties have changed + for (QName propertyQName : after.keySet()) { - // the property is not recognised - continue; - } - if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) - { - // not a content type - continue; - } - - try - { - ContentData beforeValue = (ContentData) before.get(propertyQName); - ContentData afterValue = (ContentData) after.get(propertyQName); + // is this a content property? + PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName); + if (propertyDef == null) + { + // the property is not recognised + continue; + } + if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) + { + // not a content type + continue; + } - // Figure out if the content is new or not - boolean newContent = false; - String beforeContentUrl = null; - if (beforeValue != null) + try { - beforeContentUrl = beforeValue.getContentUrl(); + ContentData beforeValue = (ContentData) before.get(propertyQName); + ContentData afterValue = (ContentData) after.get(propertyQName); + + // Figure out if the content is new or not + boolean newContent = false; + String beforeContentUrl = null; + if (beforeValue != null) + { + beforeContentUrl = beforeValue.getContentUrl(); + } + String afterContentUrl = null; + if (afterValue != null) + { + afterContentUrl = afterValue.getContentUrl(); + } + if (beforeContentUrl == null && afterContentUrl != null) + { + newContent = true; + } + + if (afterValue != null && afterValue.getContentUrl() == null) + { + // no URL - ignore + } + else if (newContent == false && EqualsHelper.nullSafeEquals(beforeValue, afterValue) == false) + { + // Queue the update + queueUpdate(nodeRef, propertyQName); + } } - String afterContentUrl = null; - if (afterValue != null) + catch (ClassCastException e) { - afterContentUrl = afterValue.getContentUrl(); + // properties don't conform to model + continue; } - if (beforeContentUrl == null && afterContentUrl != null) - { - newContent = true; - } - - if (afterValue != null && afterValue.getContentUrl() == null) - { - // no URL - ignore - } - else if (newContent == false && EqualsHelper.nullSafeEquals(beforeValue, afterValue) == false) - { - // Queue the update - queueUpdate(nodeRef, propertyQName); - } - } - catch (ClassCastException e) - { - // properties don't conform to model - continue; } } } + /** + * Queue the update to happen asynchronously + * + * @param nodeRef node reference + * @param contentProperty content property + */ private void queueUpdate(NodeRef nodeRef, QName contentProperty) - { - if (this.nodeService.exists(nodeRef) == true) + { + Boolean automaticUpdate = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTOMATIC_UPDATE); + if (automaticUpdate != null && automaticUpdate.booleanValue() == true) { - Boolean automaticUpdate = (Boolean)this.nodeService.getProperty(nodeRef, ContentModel.PROP_AUTOMATIC_UPDATE); - if (automaticUpdate != null && automaticUpdate.booleanValue() == true) + List thumbnails = this.thumbnailService.getThumbnails(nodeRef, contentProperty, null, null); + + for (NodeRef thumbnail : thumbnails) { - List thumbnails = this.thumbnailService.getThumbnails(nodeRef, contentProperty, null, null); - - for (NodeRef thumbnail : thumbnails) - { - // Execute the update thumbnail action async for each thumbnail - Action action = actionService.createAction(UpdateThumbnailActionExecuter.NAME); - action.setParameterValue(CreateThumbnailActionExecuter.PARAM_CONTENT_PROPERTY, contentProperty); - actionService.executeAction(action, thumbnail, false, true); - } + // Execute the update thumbnail action async for each thumbnail + Action action = actionService.createAction(UpdateThumbnailActionExecuter.NAME); + action.setParameterValue(CreateThumbnailActionExecuter.PARAM_CONTENT_PROPERTY, contentProperty); + actionService.executeAction(action, thumbnail, false, true); } } }