mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* We use this specialised trigger for create node beaucse of a problem with the CIFS integration.
|
||||
* <p>
|
||||
* The create node trigger will only be fired if the object is NOT a sub-type of content.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class CreateNodeRuleTrigger extends SingleChildAssocRefPolicyRuleTrigger
|
||||
{
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static Log logger = LogFactory.getLog(CreateNodeRuleTrigger.class);
|
||||
|
||||
DictionaryService dictionaryService;
|
||||
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
public void policyBehaviour(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
// 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??
|
||||
boolean triggerRule = false;
|
||||
QName type = this.nodeService.getType(childAssocRef.getChildRef());
|
||||
ClassDefinition classDefinition = this.dictionaryService.getClass(type);
|
||||
if (classDefinition != null)
|
||||
{
|
||||
for (PropertyDefinition propertyDefinition : classDefinition.getProperties().values())
|
||||
{
|
||||
if (propertyDefinition.getDataType().getName().equals(DataTypeDefinition.CONTENT) == true)
|
||||
{
|
||||
triggerRule = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (triggerRule == false)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
|
||||
/**
|
||||
* Rule trigger interface
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public interface RuleTrigger
|
||||
{
|
||||
/**
|
||||
* Register the rule trigger
|
||||
*/
|
||||
void registerRuleTrigger();
|
||||
|
||||
/**
|
||||
* Register the rule type as using this trigger
|
||||
*
|
||||
* @param ruleType the rule type
|
||||
*/
|
||||
void registerRuleType(RuleType ruleType);
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
|
||||
/**
|
||||
* Rule trigger abstract base
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class RuleTriggerAbstractBase implements RuleTrigger
|
||||
{
|
||||
/**
|
||||
* A list of the rule types that are interested in this trigger
|
||||
*/
|
||||
private Set<RuleType> ruleTypes = new HashSet<RuleType>();
|
||||
|
||||
/**
|
||||
* The policy component
|
||||
*/
|
||||
protected PolicyComponent policyComponent;
|
||||
|
||||
/**
|
||||
* The node service
|
||||
*/
|
||||
protected NodeService nodeService;
|
||||
|
||||
/**
|
||||
* The authentication Component
|
||||
*/
|
||||
|
||||
protected AuthenticationComponent authenticationComponent;
|
||||
|
||||
/**
|
||||
* Set the policy component
|
||||
*
|
||||
* @param policyComponent
|
||||
* the policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService
|
||||
* the node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authenticationComponent
|
||||
*/
|
||||
|
||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration of an interested rule type
|
||||
*/
|
||||
public void registerRuleType(RuleType ruleType)
|
||||
{
|
||||
this.ruleTypes.add(ruleType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the rules that relate to any interested rule types for the node
|
||||
* references passed.
|
||||
*
|
||||
* @param nodeRef
|
||||
* the node reference who rules are to be triggered
|
||||
* @param actionedUponNodeRef
|
||||
* the node reference that will be actioned upon by the rules
|
||||
*/
|
||||
protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
String userName = authenticationComponent.getCurrentUserName();
|
||||
authenticationComponent.setSystemUserAsCurrentUser();
|
||||
try
|
||||
{
|
||||
for (RuleType ruleType : this.ruleTypes)
|
||||
{
|
||||
ruleType.triggerRuleType(nodeRef, actionedUponNodeRef);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
if(userName != null)
|
||||
{
|
||||
authenticationComponent.setCurrentUser(userName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.rule.RuleType;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
|
||||
/**
|
||||
* Rule trigger test
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class RuleTriggerTest extends BaseSpringTest
|
||||
{
|
||||
private static final String ON_CREATE_NODE_TRIGGER = "on-create-node-trigger";
|
||||
private static final String ON_UPDATE_NODE_TRIGGER = "on-update-node-trigger";
|
||||
private static final String ON_DELETE_NODE_TRIGGER = "on-delete-node-trigger";
|
||||
private static final String ON_CREATE_CHILD_ASSOCIATION_TRIGGER = "on-create-child-association-trigger";
|
||||
private static final String ON_DELETE_CHILD_ASSOCIATION_TRIGGER = "on-delete-child-association-trigger";
|
||||
private static final String ON_CREATE_ASSOCIATION_TRIGGER = "on-create-association-trigger";
|
||||
private static final String ON_DELETE_ASSOCIATION_TRIGGER = "on-delete-association-trigger";
|
||||
private static final String ON_CONTENT_UPDATE_TRIGGER = "on-content-update-trigger";
|
||||
|
||||
private NodeService nodeService;
|
||||
private ContentService contentService;
|
||||
|
||||
private StoreRef testStoreRef;
|
||||
private NodeRef rootNodeRef;
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
|
||||
this.contentService = (ContentService)this.applicationContext.getBean("contentService");
|
||||
|
||||
this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
|
||||
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
|
||||
}
|
||||
|
||||
public void testOnCreateNodeTrigger()
|
||||
{
|
||||
TestRuleType ruleType = createTestRuleType(ON_CREATE_NODE_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnUpdateNodeTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_UPDATE_NODE_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "nameChanged");
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnDeleteNodeTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_DELETE_NODE_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.deleteNode(nodeRef);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnCreateChildAssociationTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
NodeRef nodeRef2 = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_CREATE_CHILD_ASSOCIATION_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.addChild(
|
||||
nodeRef,
|
||||
nodeRef2,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnDeleteChildAssociationTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
NodeRef nodeRef2 = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
this.nodeService.addChild(
|
||||
nodeRef,
|
||||
nodeRef2,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN);
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_DELETE_CHILD_ASSOCIATION_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.removeChild(nodeRef, nodeRef2);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnCreateAssociationTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
NodeRef nodeRef2 = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_CREATE_ASSOCIATION_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.createAssociation(nodeRef, nodeRef2, ContentModel.ASSOC_CHILDREN);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnDeleteAssociationTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
NodeRef nodeRef2 = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTAINER).getChildRef();
|
||||
this.nodeService.createAssociation(nodeRef, nodeRef2, ContentModel.ASSOC_CHILDREN);
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_DELETE_ASSOCIATION_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
this.nodeService.removeAssociation(nodeRef, nodeRef2, ContentModel.ASSOC_CHILDREN);
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
public void testOnContentUpdateTrigger()
|
||||
{
|
||||
NodeRef nodeRef = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
|
||||
TestRuleType ruleType = createTestRuleType(ON_CONTENT_UPDATE_TRIGGER);
|
||||
assertFalse(ruleType.rulesTriggered);
|
||||
|
||||
// Try and trigger the type
|
||||
ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.putContent("some content");
|
||||
|
||||
// Check to see if the rule type has been triggered
|
||||
assertTrue(ruleType.rulesTriggered);
|
||||
}
|
||||
|
||||
private TestRuleType createTestRuleType(String ruleTriggerName)
|
||||
{
|
||||
RuleTrigger ruleTrigger = (RuleTrigger)this.applicationContext.getBean(ruleTriggerName);
|
||||
assertNotNull(ruleTrigger);
|
||||
TestRuleType ruleType = new TestRuleType();
|
||||
ruleTrigger.registerRuleType(ruleType);
|
||||
return ruleType;
|
||||
}
|
||||
|
||||
private class TestRuleType implements RuleType
|
||||
{
|
||||
public boolean rulesTriggered = false;
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "testRuleType";
|
||||
}
|
||||
|
||||
public String getDisplayLabel()
|
||||
{
|
||||
return "displayLabel";
|
||||
}
|
||||
|
||||
public void triggerRuleType(NodeRef nodeRef, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// Indicate that the rules have been triggered
|
||||
this.rulesTriggered = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.rule.RuleServiceException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class SingleAssocRefPolicyRuleTrigger extends RuleTriggerAbstractBase
|
||||
{
|
||||
private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set.";
|
||||
|
||||
private String policyNamespace = NamespaceService.ALFRESCO_URI;
|
||||
|
||||
private String policyName;
|
||||
|
||||
public void setPolicyNamespace(String policyNamespace)
|
||||
{
|
||||
this.policyNamespace = policyNamespace;
|
||||
}
|
||||
|
||||
public void setPolicyName(String policyName)
|
||||
{
|
||||
this.policyName = policyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
|
||||
*/
|
||||
public void registerRuleTrigger()
|
||||
{
|
||||
if (policyName == null)
|
||||
{
|
||||
throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET);
|
||||
}
|
||||
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
QName.createQName(this.policyNamespace, this.policyName),
|
||||
this,
|
||||
new JavaBehaviour(this, "policyBehaviour"));
|
||||
}
|
||||
|
||||
public void policyBehaviour(AssociationRef assocRef)
|
||||
{
|
||||
triggerRules(assocRef.getSourceRef(), assocRef.getTargetRef());
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.rule.RuleServiceException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class SingleChildAssocRefPolicyRuleTrigger extends RuleTriggerAbstractBase
|
||||
{
|
||||
private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set.";
|
||||
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static Log logger = LogFactory.getLog(SingleChildAssocRefPolicyRuleTrigger.class);
|
||||
|
||||
private String policyNamespace = NamespaceService.ALFRESCO_URI;
|
||||
|
||||
private String policyName;
|
||||
|
||||
private boolean isClassBehaviour = false;
|
||||
|
||||
public void setPolicyNamespace(String policyNamespace)
|
||||
{
|
||||
this.policyNamespace = policyNamespace;
|
||||
}
|
||||
|
||||
public void setPolicyName(String policyName)
|
||||
{
|
||||
this.policyName = policyName;
|
||||
}
|
||||
|
||||
public void setIsClassBehaviour(boolean isClassBehaviour)
|
||||
{
|
||||
this.isClassBehaviour = isClassBehaviour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
|
||||
*/
|
||||
public void registerRuleTrigger()
|
||||
{
|
||||
if (policyName == null)
|
||||
{
|
||||
throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET);
|
||||
}
|
||||
|
||||
if (isClassBehaviour == true)
|
||||
{
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(this.policyNamespace, this.policyName),
|
||||
this,
|
||||
new JavaBehaviour(this, "policyBehaviour"));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
QName.createQName(this.policyNamespace, this.policyName),
|
||||
this,
|
||||
new JavaBehaviour(this, "policyBehaviour"));
|
||||
}
|
||||
}
|
||||
|
||||
public void policyBehaviour(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Single child assoc trigger (policy = " + this.policyName + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef());
|
||||
}
|
||||
|
||||
triggerRules(childAssocRef.getParentRef(), childAssocRef.getChildRef());
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.repo.rule.ruletrigger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.RuleServiceException;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
public class SingleNodeRefPolicyRuleTrigger extends RuleTriggerAbstractBase
|
||||
{
|
||||
private static final String ERR_POLICY_NAME_NOT_SET = "Unable to register rule trigger since policy name has not been set.";
|
||||
|
||||
private String policyNamespace = NamespaceService.ALFRESCO_URI;
|
||||
|
||||
private String policyName;
|
||||
|
||||
private boolean triggerParentRules = true;
|
||||
|
||||
public void setPolicyNamespace(String policyNamespace)
|
||||
{
|
||||
this.policyNamespace = policyNamespace;
|
||||
}
|
||||
|
||||
public void setPolicyName(String policyName)
|
||||
{
|
||||
this.policyName = policyName;
|
||||
}
|
||||
|
||||
public void setTriggerParentRules(boolean triggerParentRules)
|
||||
{
|
||||
this.triggerParentRules = triggerParentRules;
|
||||
}
|
||||
|
||||
public void registerRuleTrigger()
|
||||
{
|
||||
if (policyName == null)
|
||||
{
|
||||
throw new RuleServiceException(ERR_POLICY_NAME_NOT_SET);
|
||||
}
|
||||
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(this.policyNamespace, this.policyName),
|
||||
this,
|
||||
new JavaBehaviour(this, "policyBehaviour"));
|
||||
}
|
||||
|
||||
public void policyBehaviour(NodeRef nodeRef)
|
||||
{
|
||||
if (triggerParentRules == true)
|
||||
{
|
||||
List<ChildAssociationRef> parentsAssocRefs = this.nodeService.getParentAssocs(nodeRef);
|
||||
for (ChildAssociationRef parentAssocRef : parentsAssocRefs)
|
||||
{
|
||||
triggerRules(parentAssocRef.getParentRef(), nodeRef);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
triggerRules(nodeRef, nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user