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:
Roy Wetherall
2008-07-30 18:33:24 +00:00
parent 558a195b5b
commit d368691efc
2 changed files with 107 additions and 67 deletions

View File

@@ -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();

View File

@@ -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? {
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName); // check if any of the content properties have changed
if (propertyDef == null) for (QName propertyQName : after.keySet())
{ {
// 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)) {
{ // the property is not recognised
// not a content type continue;
continue; }
} if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT))
{
try // not a content type
{ continue;
ContentData beforeValue = (ContentData) before.get(propertyQName); }
ContentData afterValue = (ContentData) after.get(propertyQName);
// Figure out if the content is new or not try
boolean newContent = false;
String beforeContentUrl = null;
if (beforeValue != null)
{ {
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; catch (ClassCastException e)
if (afterValue != null)
{ {
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) 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)
for (NodeRef thumbnail : thumbnails)
{ {
List<NodeRef> thumbnails = this.thumbnailService.getThumbnails(nodeRef, contentProperty, null, null); // Execute the update thumbnail action async for each thumbnail
Action action = actionService.createAction(UpdateThumbnailActionExecuter.NAME);
for (NodeRef thumbnail : thumbnails) 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);
}
} }
} }
} }