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:
@@ -227,22 +227,27 @@
|
|||||||
<property name="cm:created">
|
<property name="cm:created">
|
||||||
<title>Created</title>
|
<title>Created</title>
|
||||||
<type>d:datetime</type>
|
<type>d:datetime</type>
|
||||||
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
<property name="cm:creator">
|
<property name="cm:creator">
|
||||||
<title>Creator</title>
|
<title>Creator</title>
|
||||||
<type>d:text</type>
|
<type>d:text</type>
|
||||||
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
<property name="cm:modified">
|
<property name="cm:modified">
|
||||||
<title>Modified</title>
|
<title>Modified</title>
|
||||||
<type>d:datetime</type>
|
<type>d:datetime</type>
|
||||||
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
<property name="cm:modifier">
|
<property name="cm:modifier">
|
||||||
<title>Modifier</title>
|
<title>Modifier</title>
|
||||||
<type>d:text</type>
|
<type>d:text</type>
|
||||||
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
<property name="cm:accessed">
|
<property name="cm:accessed">
|
||||||
<title>Accessed</title>
|
<title>Accessed</title>
|
||||||
<type>d:datetime</type>
|
<type>d:datetime</type>
|
||||||
|
<protected>true</protected>
|
||||||
</property>
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
</aspect>
|
</aspect>
|
||||||
|
@@ -71,14 +71,14 @@
|
|||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Commented out for now -->
|
<bean id="update" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
|
||||||
<!-- <bean id="update" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
|
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<list>
|
<list>
|
||||||
<ref bean="on-property-update-trigger"/>
|
<ref bean="on-property-update-trigger"/>
|
||||||
|
<ref bean="on-content-update-trigger"/>
|
||||||
</list>
|
</list>
|
||||||
</constructor-arg>
|
</constructor-arg>
|
||||||
</bean> -->
|
</bean>
|
||||||
|
|
||||||
<bean id="outbound" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
|
<bean id="outbound" class="org.alfresco.repo.rule.RuleTypeImpl" parent="rule-type-base">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
@@ -100,6 +100,9 @@
|
|||||||
<property name="authenticationComponent">
|
<property name="authenticationComponent">
|
||||||
<ref bean="authenticationComponent"/>
|
<ref bean="authenticationComponent"/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="dictionaryService">
|
||||||
|
<ref bean="dictionaryService"/>
|
||||||
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="on-create-node-trigger" class="org.alfresco.repo.rule.ruletrigger.CreateNodeRuleTrigger" parent="rule-trigger-base">
|
<bean id="on-create-node-trigger" class="org.alfresco.repo.rule.ruletrigger.CreateNodeRuleTrigger" parent="rule-trigger-base">
|
||||||
|
@@ -275,14 +275,20 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
addDefaultAspects(nodeTypeDef, node, childAssocRef.getChildRef(), properties);
|
addDefaultAspects(nodeTypeDef, node, childAssocRef.getChildRef(), properties);
|
||||||
|
|
||||||
// set the properties - it is a new node so only set properties if there are any
|
// set the properties - it is a new node so only set properties if there are any
|
||||||
|
Map<QName, Serializable> propertiesBefore = getProperties(childAssocRef.getChildRef());
|
||||||
|
Map<QName, Serializable> propertiesAfter = null;
|
||||||
if (properties.size() > 0)
|
if (properties.size() > 0)
|
||||||
{
|
{
|
||||||
this.setProperties(node.getNodeRef(), properties);
|
propertiesAfter = setPropertiesImpl(childAssocRef.getChildRef(), properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke policy behaviour
|
// Invoke policy behaviour
|
||||||
invokeOnCreateNode(childAssocRef);
|
invokeOnCreateNode(childAssocRef);
|
||||||
invokeOnUpdateNode(parentRef);
|
invokeOnUpdateNode(parentRef);
|
||||||
|
if (propertiesAfter != null)
|
||||||
|
{
|
||||||
|
invokeOnUpdateProperties(childAssocRef.getChildRef(), propertiesBefore, propertiesAfter);
|
||||||
|
}
|
||||||
|
|
||||||
// done
|
// done
|
||||||
return childAssocRef;
|
return childAssocRef;
|
||||||
@@ -853,6 +859,26 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
// Invoke policy behaviours
|
// Invoke policy behaviours
|
||||||
invokeBeforeUpdateNode(nodeRef);
|
invokeBeforeUpdateNode(nodeRef);
|
||||||
|
|
||||||
|
// Do the set properties
|
||||||
|
Map<QName, Serializable> propertiesBefore = getProperties(nodeRef);
|
||||||
|
Map<QName, Serializable> propertiesAfter = setPropertiesImpl(nodeRef, properties);
|
||||||
|
|
||||||
|
// Invoke policy behaviours
|
||||||
|
invokeOnUpdateNode(nodeRef);
|
||||||
|
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the work of setting the property values. Returns a map containing the state of the properties after the set
|
||||||
|
* operation is complete.
|
||||||
|
*
|
||||||
|
* @param nodeRef the node reference
|
||||||
|
* @param properties the map of property values
|
||||||
|
* @return the map of property values after the set operation is complete
|
||||||
|
* @throws InvalidNodeRefException
|
||||||
|
*/
|
||||||
|
private Map<QName, Serializable> setPropertiesImpl(NodeRef nodeRef, Map<QName, Serializable> properties) throws InvalidNodeRefException
|
||||||
|
{
|
||||||
if (properties == null)
|
if (properties == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Properties may not be null");
|
throw new IllegalArgumentException("Properties may not be null");
|
||||||
@@ -863,8 +889,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
|
|
||||||
// find the node
|
// find the node
|
||||||
Node node = getNodeNotNull(nodeRef);
|
Node node = getNodeNotNull(nodeRef);
|
||||||
// get the properties before
|
|
||||||
Map<QName, Serializable> propertiesBefore = getProperties(nodeRef);
|
|
||||||
|
|
||||||
// copy properties onto node
|
// copy properties onto node
|
||||||
Map<QName, PropertyValue> nodeProperties = node.getProperties();
|
Map<QName, PropertyValue> nodeProperties = node.getProperties();
|
||||||
@@ -880,15 +904,11 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
nodeProperties.put(propertyQName, propertyValue);
|
nodeProperties.put(propertyQName, propertyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// store the properties after the change
|
|
||||||
Map<QName, Serializable> propertiesAfter = Collections.unmodifiableMap(properties);
|
|
||||||
|
|
||||||
// Invoke policy behaviours
|
|
||||||
invokeOnUpdateNode(nodeRef);
|
|
||||||
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
|
|
||||||
|
|
||||||
// update the node status
|
// update the node status
|
||||||
nodeDaoService.recordChangeId(nodeRef);
|
nodeDaoService.recordChangeId(nodeRef);
|
||||||
|
|
||||||
|
// Return the properties after
|
||||||
|
return Collections.unmodifiableMap(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -904,10 +924,29 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
// Invoke policy behaviours
|
// Invoke policy behaviours
|
||||||
invokeBeforeUpdateNode(nodeRef);
|
invokeBeforeUpdateNode(nodeRef);
|
||||||
|
|
||||||
|
// Do the set operation
|
||||||
|
Map<QName, Serializable> propertiesBefore = getProperties(nodeRef);
|
||||||
|
Map<QName, Serializable> propertiesAfter = setPropertyImpl(nodeRef, qname, value);
|
||||||
|
|
||||||
|
// Invoke policy behaviours
|
||||||
|
invokeOnUpdateNode(nodeRef);
|
||||||
|
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the work of setting a property value. Returns the values of the properties after the set operation is
|
||||||
|
* complete.
|
||||||
|
*
|
||||||
|
* @param nodeRef the node reference
|
||||||
|
* @param qname the qname of the property
|
||||||
|
* @param value the value of the property
|
||||||
|
* @return the values of the properties after the set operation is complete
|
||||||
|
* @throws InvalidNodeRefException
|
||||||
|
*/
|
||||||
|
public Map<QName, Serializable> setPropertyImpl(NodeRef nodeRef, QName qname, Serializable value) throws InvalidNodeRefException
|
||||||
|
{
|
||||||
// get the node
|
// get the node
|
||||||
Node node = getNodeNotNull(nodeRef);
|
Node node = getNodeNotNull(nodeRef);
|
||||||
// get properties before
|
|
||||||
Map<QName, Serializable> propertiesBefore = getProperties(nodeRef);
|
|
||||||
|
|
||||||
Map<QName, PropertyValue> properties = node.getProperties();
|
Map<QName, PropertyValue> properties = node.getProperties();
|
||||||
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
|
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
|
||||||
@@ -915,15 +954,10 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
|
|||||||
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
|
PropertyValue propertyValue = makePropertyValue(propertyDef, value);
|
||||||
properties.put(qname, propertyValue);
|
properties.put(qname, propertyValue);
|
||||||
|
|
||||||
// get properties after the change
|
|
||||||
Map<QName, Serializable> propertiesAfter = getProperties(nodeRef);
|
|
||||||
|
|
||||||
// Invoke policy behaviours
|
|
||||||
invokeOnUpdateNode(nodeRef);
|
|
||||||
invokeOnUpdateProperties(nodeRef, propertiesBefore, propertiesAfter);
|
|
||||||
|
|
||||||
// update the node status
|
// update the node status
|
||||||
nodeDaoService.recordChangeId(nodeRef);
|
nodeDaoService.recordChangeId(nodeRef);
|
||||||
|
|
||||||
|
return getProperties(nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1294,6 +1294,134 @@ public class RuleServiceCoverageTest extends TestCase
|
|||||||
ContentModel.ASPECT_VERSIONABLE));
|
ContentModel.ASPECT_VERSIONABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInboundRuleType()
|
||||||
|
{
|
||||||
|
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
||||||
|
params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
|
||||||
|
Rule rule = createRule(
|
||||||
|
RuleType.INBOUND,
|
||||||
|
AddFeaturesActionExecuter.NAME,
|
||||||
|
params,
|
||||||
|
NoConditionEvaluator.NAME,
|
||||||
|
null);
|
||||||
|
|
||||||
|
this.ruleService.saveRule(this.nodeRef, rule);
|
||||||
|
|
||||||
|
// Create a non-content node
|
||||||
|
NodeRef newNodeRef = this.nodeService.createNode(
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||||
|
assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Create a content node
|
||||||
|
NodeRef contentNodeRef = this.nodeService.createNode(
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_CONTENT).getChildRef();
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
addContentToNode(contentNodeRef);
|
||||||
|
assertTrue(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Create a node to be moved
|
||||||
|
NodeRef moveNode = this.nodeService.createNode(
|
||||||
|
newNodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_CONTENT).getChildRef();
|
||||||
|
addContentToNode(moveNode);
|
||||||
|
assertFalse(this.nodeService.hasAspect(moveNode, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
this.nodeService.moveNode(
|
||||||
|
moveNode,
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"));
|
||||||
|
assertTrue(this.nodeService.hasAspect(moveNode, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Enusre the rule type does not get fired when the node is updated
|
||||||
|
this.nodeService.removeAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE);
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
this.nodeService.setProperty(contentNodeRef, ContentModel.PROP_NAME, "name.txt");
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
addContentToNode(contentNodeRef);
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testUpdateRuleType()
|
||||||
|
{
|
||||||
|
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
|
||||||
|
params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
|
||||||
|
Rule rule = createRule(
|
||||||
|
RuleType.UPDATE,
|
||||||
|
AddFeaturesActionExecuter.NAME,
|
||||||
|
params,
|
||||||
|
NoConditionEvaluator.NAME,
|
||||||
|
null);
|
||||||
|
|
||||||
|
this.ruleService.saveRule(this.nodeRef, rule);
|
||||||
|
|
||||||
|
// Create a non-content node
|
||||||
|
NodeRef newNodeRef = this.nodeService.createNode(
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_FOLDER).getChildRef();
|
||||||
|
assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Update the non-content node
|
||||||
|
this.nodeService.setProperty(newNodeRef, ContentModel.PROP_NAME, "testName");
|
||||||
|
assertTrue(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Create a content node
|
||||||
|
NodeRef contentNodeRef = this.nodeService.createNode(
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_CONTENT).getChildRef();
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
addContentToNode(contentNodeRef);
|
||||||
|
assertFalse(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
addContentToNode(contentNodeRef);
|
||||||
|
assertTrue(this.nodeService.hasAspect(contentNodeRef, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
// Create a non content node, setting a property at the same time
|
||||||
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||||
|
props.put(ContentModel.PROP_NAME, "testName");
|
||||||
|
NodeRef nodeRef2 = this.nodeService.createNode(
|
||||||
|
this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
props).getChildRef();
|
||||||
|
assertFalse(this.nodeService.hasAspect(nodeRef2, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
this.nodeService.setProperty(nodeRef2, ContentModel.PROP_NAME, "testName");
|
||||||
|
assertFalse(this.nodeService.hasAspect(nodeRef2, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
this.nodeService.setProperty(nodeRef2, ContentModel.PROP_NAME, "testName2");
|
||||||
|
assertTrue(this.nodeService.hasAspect(nodeRef2, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
TransactionUtil.executeInUserTransaction(this.transactionService, new TransactionUtil.TransactionWork<Object>()
|
||||||
|
{
|
||||||
|
public Object doWork() throws Exception
|
||||||
|
{
|
||||||
|
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||||
|
props.put(ContentModel.PROP_NAME, "testName");
|
||||||
|
NodeRef nodeRef3 = RuleServiceCoverageTest.this.nodeService.createNode(
|
||||||
|
RuleServiceCoverageTest.this.nodeRef,
|
||||||
|
ContentModel.ASSOC_CHILDREN,
|
||||||
|
QName.createQName(TEST_NAMESPACE, "children"),
|
||||||
|
ContentModel.TYPE_FOLDER,
|
||||||
|
props).getChildRef();
|
||||||
|
assertFalse(RuleServiceCoverageTest.this.nodeService.hasAspect(nodeRef3, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
RuleServiceCoverageTest.this.nodeService.setProperty(nodeRef3, ContentModel.PROP_NAME, "testName2");
|
||||||
|
assertFalse(RuleServiceCoverageTest.this.nodeService.hasAspect(nodeRef3, ContentModel.ASPECT_VERSIONABLE));
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test:
|
* Test:
|
||||||
* rule type: outbound
|
* rule type: outbound
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.rule.ruletrigger;
|
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.ClassDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
@@ -78,5 +79,8 @@ public class CreateNodeRuleTrigger extends SingleChildAssocRefPolicyRuleTrigger
|
|||||||
|
|
||||||
triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef());
|
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;
|
package org.alfresco.repo.rule.ruletrigger;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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.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.ChildAssociationRef;
|
||||||
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.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.util.EqualsHelper;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -67,6 +72,50 @@ public class OnPropertyUpdateRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
new JavaBehaviour(this, "onUpdateProperties"));
|
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)
|
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
|
||||||
*/
|
*/
|
||||||
@@ -77,6 +126,11 @@ public class OnPropertyUpdateRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
logger.debug("OnPropertyUpdate rule triggered fired; nodeRef=" + nodeRef.toString() + "; triggerParentRules=" + this.triggerParentRules);
|
logger.debug("OnPropertyUpdate rule triggered fired; nodeRef=" + nodeRef.toString() + "; triggerParentRules=" + this.triggerParentRules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
if (triggerParentRules == true)
|
if (triggerParentRules == true)
|
||||||
{
|
{
|
||||||
List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
|
List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
|
||||||
@@ -90,6 +144,7 @@ public class OnPropertyUpdateRuleTrigger extends RuleTriggerAbstractBase
|
|||||||
triggerRules(nodeRef, nodeRef);
|
triggerRules(nodeRef, nodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.alfresco.repo.policy.PolicyComponent;
|
import org.alfresco.repo.policy.PolicyComponent;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
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.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.rule.RuleType;
|
import org.alfresco.service.cmr.rule.RuleType;
|
||||||
@@ -50,9 +51,11 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
|||||||
/**
|
/**
|
||||||
* The authentication Component
|
* The authentication Component
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected AuthenticationComponent authenticationComponent;
|
protected AuthenticationComponent authenticationComponent;
|
||||||
|
|
||||||
|
/** The dictionary service */
|
||||||
|
protected DictionaryService dictionaryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the policy component
|
* Set the policy component
|
||||||
*
|
*
|
||||||
@@ -78,12 +81,21 @@ public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
|||||||
/**
|
/**
|
||||||
* Set the authenticationComponent
|
* Set the authenticationComponent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||||
{
|
{
|
||||||
this.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
|
* Registration of an interested rule type
|
||||||
*/
|
*/
|
||||||
|
@@ -30,7 +30,8 @@ public interface RuleType
|
|||||||
* Some rule type constants
|
* Some rule type constants
|
||||||
*/
|
*/
|
||||||
public static final String INBOUND = "inbound";
|
public static final String INBOUND = "inbound";
|
||||||
public static final String OUTGOING = "outgoing";
|
public static final String UPDATE = "update";
|
||||||
|
public static final String OUTBOUND = "outbound";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the rule type.
|
* Get the name of the rule type.
|
||||||
|
Reference in New Issue
Block a user