Java Code Examples for org.alfresco.repo.policy.PolicyComponent#bindClassBehaviour()

The following examples show how to use org.alfresco.repo.policy.PolicyComponent#bindClassBehaviour() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImapServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void bindBehaviour()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("[bindBeahaviour] Binding behaviours");
    }
    PolicyComponent policyComponent = (PolicyComponent) serviceRegistry.getService(QName.createQName(NamespaceService.ALFRESCO_URI, "policyComponent"));

    // Only listen to folders we've tagged with imap properties - not all folders or we'll really slow down the repository!
    policyComponent.bindAssociationBehaviour(
            OnCreateChildAssociationPolicy.QNAME,
            ImapModel.ASPECT_IMAP_FOLDER,
            ContentModel.ASSOC_CONTAINS,
            new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindAssociationBehaviour(
            OnDeleteChildAssociationPolicy.QNAME,
            ImapModel.ASPECT_IMAP_FOLDER,
            ContentModel.ASSOC_CONTAINS,
            new JavaBehaviour(this, "onDeleteChildAssociation", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            OnUpdatePropertiesPolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            BeforeDeleteNodePolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            OnRestoreNodePolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "onRestoreNode", NotificationFrequency.EVERY_EVENT));
}
 
Example 2
Source File: BaseNodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testAR1303() throws Exception
{
    PolicyComponent policyComponent = (PolicyComponent) this.applicationContext.getBean("policyComponent");
    JavaBehaviour behaviour = new JavaBehaviour(this, "onUpdateProperties");
    BehaviourDefinition<ClassBehaviourBinding> bindClassBehaviour = null;

    Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
    props.put(ContentModel.PROP_NAME, "test_testAR1303.txt");

    NodeRef nodeRef = this.nodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN,
            ContentModel.TYPE_CONTENT, props).getChildRef();

    nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);

    nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "my description");
    nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "my title");
    try
    {
        bindClassBehaviour = policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onUpdateProperties"), ContentModel.ASPECT_TITLED,
                behaviour);

        behaviourExecuted = false;

        // Update the title property and check that the behaviour has been fired
        nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "changed title");
        assertTrue("The onUpdateProperties behaviour has not been fired.", behaviourExecuted);
    }
    finally
    {
        if (bindClassBehaviour != null)
        {
            policyComponent.removeClassDefinition(bindClassBehaviour);
        }
    }
}