mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
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
This commit is contained in:
@@ -248,10 +248,14 @@ public class ThumbnailServiceImpl implements ThumbnailService
|
|||||||
{
|
{
|
||||||
throw new ThumbnailException(ERR_NO_PARENT);
|
throw new ThumbnailException(ERR_NO_PARENT);
|
||||||
}
|
}
|
||||||
else if (parents.size() != 1)
|
// TODO
|
||||||
{
|
// When a node with thumbnails is checked in the assoc's get doubled up. This means we get more than one parent.
|
||||||
throw new ThumbnailException(ERR_TOO_PARENT);
|
// As a work around simply take the first parent retrieved
|
||||||
}
|
//
|
||||||
|
//else if (parents.size() != 1)
|
||||||
|
//{
|
||||||
|
// throw new ThumbnailException(ERR_TOO_PARENT);
|
||||||
|
//}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node = parents.get(0).getParentRef();
|
node = parents.get(0).getParentRef();
|
||||||
|
@@ -25,14 +25,10 @@
|
|||||||
package org.alfresco.repo.thumbnail;
|
package org.alfresco.repo.thumbnail;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
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.node.NodeServicePolicies;
|
||||||
import org.alfresco.repo.policy.Behaviour;
|
import org.alfresco.repo.policy.Behaviour;
|
||||||
import org.alfresco.repo.policy.JavaBehaviour;
|
import org.alfresco.repo.policy.JavaBehaviour;
|
||||||
@@ -57,37 +53,66 @@ import org.alfresco.util.EqualsHelper;
|
|||||||
*/
|
*/
|
||||||
public class ThumbnailedAspect implements NodeServicePolicies.OnUpdatePropertiesPolicy
|
public class ThumbnailedAspect implements NodeServicePolicies.OnUpdatePropertiesPolicy
|
||||||
{
|
{
|
||||||
|
/** Services */
|
||||||
private PolicyComponent policyComponent;
|
private PolicyComponent policyComponent;
|
||||||
private ThumbnailService thumbnailService;
|
private ThumbnailService thumbnailService;
|
||||||
private ActionService actionService;
|
private ActionService actionService;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private DictionaryService dictionaryService;
|
private DictionaryService dictionaryService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the policy component
|
||||||
|
*
|
||||||
|
* @param policyComponent policy component
|
||||||
|
*/
|
||||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||||
{
|
{
|
||||||
this.policyComponent = policyComponent;
|
this.policyComponent = policyComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the action service
|
||||||
|
*
|
||||||
|
* @param actionService action service
|
||||||
|
*/
|
||||||
public void setActionService(ActionService actionService)
|
public void setActionService(ActionService actionService)
|
||||||
{
|
{
|
||||||
this.actionService = actionService;
|
this.actionService = actionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the node service
|
||||||
|
*
|
||||||
|
* @param nodeService node service
|
||||||
|
*/
|
||||||
public void setNodeService(NodeService nodeService)
|
public void setNodeService(NodeService nodeService)
|
||||||
{
|
{
|
||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the thumbnail service
|
||||||
|
*
|
||||||
|
* @param thumbnailService thumbnail service
|
||||||
|
*/
|
||||||
public void setThumbnailService(ThumbnailService thumbnailService)
|
public void setThumbnailService(ThumbnailService thumbnailService)
|
||||||
{
|
{
|
||||||
this.thumbnailService = thumbnailService;
|
this.thumbnailService = thumbnailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dictionary service
|
||||||
|
*
|
||||||
|
* @param dictionaryService dictionary service
|
||||||
|
*/
|
||||||
public void setDictionaryService(DictionaryService dictionaryService)
|
public void setDictionaryService(DictionaryService dictionaryService)
|
||||||
{
|
{
|
||||||
this.dictionaryService = dictionaryService;
|
this.dictionaryService = dictionaryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise method
|
||||||
|
*/
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
this.policyComponent.bindClassBehaviour(
|
this.policyComponent.bindClassBehaviour(
|
||||||
@@ -96,83 +121,94 @@ public class ThumbnailedAspect implements NodeServicePolicies.OnUpdateProperties
|
|||||||
new JavaBehaviour(this, "onUpdateProperties", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
|
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(
|
public void onUpdateProperties(
|
||||||
NodeRef nodeRef,
|
NodeRef nodeRef,
|
||||||
Map<QName, Serializable> before,
|
Map<QName, Serializable> before,
|
||||||
Map<QName, Serializable> after)
|
Map<QName, Serializable> after)
|
||||||
{
|
{
|
||||||
// check if any of the content properties have changed
|
// Ignore working copies
|
||||||
for (QName propertyQName : after.keySet())
|
if (this.nodeService.exists(nodeRef) == true &&
|
||||||
|
this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == false)
|
||||||
{
|
{
|
||||||
// is this a content property?
|
// check if any of the content properties have changed
|
||||||
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
|
for (QName propertyQName : after.keySet())
|
||||||
if (propertyDef == null)
|
|
||||||
{
|
{
|
||||||
// the property is not recognised
|
// is this a content property?
|
||||||
continue;
|
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
|
||||||
}
|
if (propertyDef == null)
|
||||||
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);
|
|
||||||
|
|
||||||
// Figure out if the content is new or not
|
|
||||||
boolean newContent = false;
|
|
||||||
String beforeContentUrl = null;
|
|
||||||
if (beforeValue != null)
|
|
||||||
{
|
{
|
||||||
beforeContentUrl = beforeValue.getContentUrl();
|
// the property is not recognised
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
String afterContentUrl = null;
|
if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
|
||||||
if (afterValue != null)
|
|
||||||
{
|
{
|
||||||
afterContentUrl = afterValue.getContentUrl();
|
// not a content type
|
||||||
}
|
continue;
|
||||||
if (beforeContentUrl == null && afterContentUrl != null)
|
|
||||||
{
|
|
||||||
newContent = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (afterValue != null && afterValue.getContentUrl() == null)
|
try
|
||||||
{
|
{
|
||||||
// no URL - ignore
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (newContent == false && EqualsHelper.nullSafeEquals(beforeValue, afterValue) == false)
|
catch (ClassCastException e)
|
||||||
{
|
{
|
||||||
// Queue the update
|
// properties don't conform to model
|
||||||
queueUpdate(nodeRef, propertyQName);
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
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);
|
List<NodeRef> thumbnails = this.thumbnailService.getThumbnails(nodeRef, contentProperty, null, null);
|
||||||
if (automaticUpdate != null && automaticUpdate.booleanValue() == true)
|
|
||||||
{
|
|
||||||
List<NodeRef> thumbnails = this.thumbnailService.getThumbnails(nodeRef, contentProperty, null, null);
|
|
||||||
|
|
||||||
for (NodeRef thumbnail : thumbnails)
|
for (NodeRef thumbnail : thumbnails)
|
||||||
{
|
{
|
||||||
// Execute the update thumbnail action async for each thumbnail
|
// Execute the update thumbnail action async for each thumbnail
|
||||||
Action action = actionService.createAction(UpdateThumbnailActionExecuter.NAME);
|
Action action = actionService.createAction(UpdateThumbnailActionExecuter.NAME);
|
||||||
action.setParameterValue(CreateThumbnailActionExecuter.PARAM_CONTENT_PROPERTY, contentProperty);
|
action.setParameterValue(CreateThumbnailActionExecuter.PARAM_CONTENT_PROPERTY, contentProperty);
|
||||||
actionService.executeAction(action, thumbnail, false, true);
|
actionService.executeAction(action, thumbnail, false, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user