mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
- Added update rule type
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2739 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
@@ -78,5 +79,8 @@ public class CreateNodeRuleTrigger extends SingleChildAssocRefPolicyRuleTrigger
|
||||
|
||||
triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef());
|
||||
}
|
||||
|
||||
// Reguadless of whether the rule is triggered, mark this transaction as having created this node
|
||||
AlfrescoTransactionSupport.bindResource(childAssocRef.getChildRef().toString(), childAssocRef.getChildRef().toString());
|
||||
}
|
||||
}
|
||||
|
@@ -17,15 +17,20 @@
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -67,6 +72,50 @@ public class OnPropertyUpdateRuleTrigger extends RuleTriggerAbstractBase
|
||||
new JavaBehaviour(this, "onUpdateProperties"));
|
||||
}
|
||||
|
||||
private boolean havePropertiesBeenModified(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||
{
|
||||
List<QName> remainder = new ArrayList<QName>(after.keySet());
|
||||
List<QName> modifiedProperties = new ArrayList<QName>();
|
||||
for (QName name : before.keySet())
|
||||
{
|
||||
if (after.containsKey(name) == true)
|
||||
{
|
||||
Serializable beforeValue = before.get(name);
|
||||
Serializable afterValue = after.get(name);
|
||||
if (EqualsHelper.nullSafeEquals(beforeValue, afterValue) != true)
|
||||
{
|
||||
// The property has been changed
|
||||
modifiedProperties.add(name);
|
||||
}
|
||||
|
||||
// Remove the property from the remainder list
|
||||
remainder.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
// Add any properties now remaining whose values have been added for the first time
|
||||
if (remainder.size() != 0)
|
||||
{
|
||||
modifiedProperties.addAll(remainder);
|
||||
}
|
||||
|
||||
// Filter out the protected and content type properties from the list of modified properties
|
||||
for (QName propertyName : new ArrayList<QName>(modifiedProperties))
|
||||
{
|
||||
PropertyDefinition propertyDefinition = this.dictionaryService.getProperty(propertyName);
|
||||
if (propertyDefinition != null)
|
||||
{
|
||||
if (propertyDefinition.isProtected() == true || propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) == true)
|
||||
{
|
||||
// Remove the protected property from the list
|
||||
modifiedProperties.remove(propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (modifiedProperties.isEmpty() == false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
|
||||
*/
|
||||
@@ -77,17 +126,23 @@ public class OnPropertyUpdateRuleTrigger extends RuleTriggerAbstractBase
|
||||
logger.debug("OnPropertyUpdate rule triggered fired; nodeRef=" + nodeRef.toString() + "; triggerParentRules=" + this.triggerParentRules);
|
||||
}
|
||||
|
||||
if (triggerParentRules == true)
|
||||
{
|
||||
List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
|
||||
for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
|
||||
{
|
||||
triggerRules(parentAssocRef.getParentRef(), nodeRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
Object createdNodeRef = AlfrescoTransactionSupport.getResource(nodeRef.toString());
|
||||
|
||||
// Only try and trigger the rules if a non protected propety has been modified
|
||||
if (createdNodeRef == null && havePropertiesBeenModified(nodeRef, before, after) == true)
|
||||
{
|
||||
triggerRules(nodeRef, nodeRef);
|
||||
if (triggerParentRules == true)
|
||||
{
|
||||
List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
|
||||
for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
|
||||
{
|
||||
triggerRules(parentAssocRef.getParentRef(), nodeRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
triggerRules(nodeRef, nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,7 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
@@ -50,9 +51,11 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
||||
/**
|
||||
* The authentication Component
|
||||
*/
|
||||
|
||||
protected AuthenticationComponent authenticationComponent;
|
||||
|
||||
/** The dictionary service */
|
||||
protected DictionaryService dictionaryService;
|
||||
|
||||
/**
|
||||
* Set the policy component
|
||||
*
|
||||
@@ -78,12 +81,21 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
||||
/**
|
||||
* Set the authenticationComponent
|
||||
*/
|
||||
|
||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dictionary service
|
||||
*
|
||||
* @param dictionaryService the dictionary service
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration of an interested rule type
|
||||
*/
|
||||
|
Reference in New Issue
Block a user