mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Work around to ensure rules are fired for empty inline documents
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19236 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -20,6 +20,7 @@ package org.alfresco.repo.rule.ruletrigger;
|
|||||||
|
|
||||||
import org.alfresco.repo.node.NodeServicePolicies;
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
import org.alfresco.repo.policy.JavaBehaviour;
|
import org.alfresco.repo.policy.JavaBehaviour;
|
||||||
|
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
@@ -89,6 +90,37 @@ public class CreateNodeRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
this,
|
this,
|
||||||
new JavaBehaviour(this, POLICY));
|
new JavaBehaviour(this, POLICY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register interest in the addition of the inline editable aspect at the end of the transaction
|
||||||
|
// NOTE: this work around is nessesary because we can't fire the rules directly since CIFS is not transactional
|
||||||
|
policyComponent.bindClassBehaviour(
|
||||||
|
NodeServicePolicies.OnAddAspectPolicy.QNAME,
|
||||||
|
this,
|
||||||
|
new JavaBehaviour(this, "onAddAspect", NotificationFrequency.TRANSACTION_COMMIT));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: this work around is nessesary because we can't fire the rules directly since CIFS is not transactional
|
||||||
|
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName)
|
||||||
|
{
|
||||||
|
if (nodeService.exists(nodeRef) == true)
|
||||||
|
{
|
||||||
|
// See if we have created the node in this transaction
|
||||||
|
if (AlfrescoTransactionSupport.getResource(nodeRef.toString()) != null)
|
||||||
|
{
|
||||||
|
Boolean value = (Boolean)nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "editInline"));
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
boolean editInline = value.booleanValue();
|
||||||
|
if (editInline == true)
|
||||||
|
{
|
||||||
|
// Then we should be triggering the rules
|
||||||
|
NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||||
|
triggerRulesImpl(parentNodeRef, nodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,50 +130,48 @@ public class CreateNodeRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
{
|
{
|
||||||
// Only fire the rule if the node is question has no potential to contain content
|
// Only fire the rule if the node is question has no potential to contain content
|
||||||
// TODO we need to find a better way to do this .. how can this be resolved in CIFS??
|
// TODO we need to find a better way to do this .. how can this be resolved in CIFS??
|
||||||
boolean triggerRule = false;
|
boolean triggerRule = false;
|
||||||
|
|
||||||
NodeRef nodeRef = childAssocRef.getChildRef();
|
NodeRef nodeRef = childAssocRef.getChildRef();
|
||||||
|
QName type = this.nodeService.getType(nodeRef);
|
||||||
// This is a "tempory" fix to identify object created via a web client and trigger the rule immediately
|
ClassDefinition classDefinition = this.dictionaryService.getClass(type);
|
||||||
Boolean value = (Boolean)nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "editInline"));
|
if (classDefinition != null)
|
||||||
boolean editInline = false;
|
|
||||||
if (value != null)
|
|
||||||
{
|
{
|
||||||
editInline = value.booleanValue();
|
for (PropertyDefinition propertyDefinition : classDefinition.getProperties().values())
|
||||||
}
|
|
||||||
|
|
||||||
if (editInline == false)
|
|
||||||
{
|
|
||||||
QName type = this.nodeService.getType(nodeRef);
|
|
||||||
ClassDefinition classDefinition = this.dictionaryService.getClass(type);
|
|
||||||
if (classDefinition != null)
|
|
||||||
{
|
{
|
||||||
for (PropertyDefinition propertyDefinition : classDefinition.getProperties().values())
|
if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) == true)
|
||||||
{
|
{
|
||||||
if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) == true)
|
triggerRule = true;
|
||||||
{
|
break;
|
||||||
triggerRule = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerRule == false)
|
if (triggerRule == false)
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled() == true)
|
triggerRulesImpl(childAssocRef.getParentRef(), childAssocRef.getChildRef());
|
||||||
{
|
|
||||||
logger.debug(
|
|
||||||
"Create node rule trigger fired for parent node " +
|
|
||||||
this.nodeService.getType(childAssocRef.getParentRef()).toString() + " " + childAssocRef.getParentRef() +
|
|
||||||
" and child node " +
|
|
||||||
this.nodeService.getType(childAssocRef.getChildRef()).toString() + " " + childAssocRef.getChildRef());
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regardless of whether the rule is triggered, mark this transaction as having created this node
|
// Regardless of whether the rule is triggered, mark this transaction as having created this node
|
||||||
AlfrescoTransactionSupport.bindResource(childAssocRef.getChildRef().toString(), childAssocRef.getChildRef().toString());
|
AlfrescoTransactionSupport.bindResource(childAssocRef.getChildRef().toString(), childAssocRef.getChildRef().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger the rules with some log
|
||||||
|
*
|
||||||
|
* @param parentNodeRef
|
||||||
|
* @param childNodeRef
|
||||||
|
*/
|
||||||
|
private void triggerRulesImpl(NodeRef parentNodeRef, NodeRef childNodeRef)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
|
"Create node rule trigger fired for parent node " +
|
||||||
|
this.nodeService.getType(parentNodeRef).toString() + " " + parentNodeRef +
|
||||||
|
" and child node " +
|
||||||
|
this.nodeService.getType(childNodeRef).toString() + " " + childNodeRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
triggerRules(parentNodeRef, childNodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,8 @@ import org.alfresco.repo.policy.JavaBehaviour;
|
|||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -89,13 +91,26 @@ public class OnContentUpdateRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
boolean fail = false;
|
boolean fail = false;
|
||||||
if (newContent == true)
|
if (newContent == true)
|
||||||
{
|
{
|
||||||
ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
Boolean value = (Boolean)nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "editInline"));
|
||||||
if (contentReader == null ||
|
if (value != null)
|
||||||
contentReader.exists() == false ||
|
{
|
||||||
isZeroLengthOfficeDoc(contentReader) == true)
|
boolean editInline = value.booleanValue();
|
||||||
{
|
if (editInline == true)
|
||||||
fail = true;
|
{
|
||||||
}
|
fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fail == false)
|
||||||
|
{
|
||||||
|
ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
|
||||||
|
if (contentReader == null ||
|
||||||
|
contentReader.exists() == false ||
|
||||||
|
isZeroLengthOfficeDoc(contentReader) == true)
|
||||||
|
{
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger the rules in the appropriate way
|
// Trigger the rules in the appropriate way
|
||||||
|
Reference in New Issue
Block a user