AnsweredAssumed Answered

Classed-Based Policies and ACP Imports

Question asked by darryl_staflund on Feb 9, 2011
Latest reply on Nov 5, 2013 by mrogers
Hi everyone,

Has anyone ever found that class-based policies don't always fire during ACP imports?  I am running into this very problem.  The following class-based Policy:

package ca.athabascau.alfresco.calendar.policies;

import static java.lang.String.format;

import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.EVERY_EVENT;

import static org.apache.commons.lang.Validate.notNull;

import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Component;

import ca.athabascau.alfresco.calendar.models.content.AuCalendarContentModel;

public class WebFolderCreationPolicy implements OnCreateNodePolicy {
    private static final Logger LOGGER = Logger.getLogger(WebFolderCreationPolicy.class);
    private static final String DELEGATE_METHOD_NAME = "onCreateNode";
    private AuCalendarService auCalendarService;
    private NodeService nodeService;
    private PolicyComponent policyComponent;
    private RuleService ruleService;
    public void setAuCalendarService(final AuCalendarService service){
        auCalendarService = service;
    public void setNodeService(final NodeService service){
        nodeService = service;
    public void setPolicyComponent(final PolicyComponent component) {
        policyComponent = component;
    public void setRuleService(final RuleService service){
        ruleService = service;
    public void init() {
        final Behaviour behaviour = new JavaBehaviour(this, DELEGATE_METHOD_NAME, EVERY_EVENT);
        if (LOGGER.isInfoEnabled()){
  "Delegate Method Name = %s", DELEGATE_METHOD_NAME));
  "Notification Frequency = %s", EVERY_EVENT));
        policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, AuCalendarContentModel.TYPE_WEB_FOLDER, behaviour);

    public void onCreateNode(final ChildAssociationRef childAssociationRef) {
        notNull(childAssociationRef, "ChildAssociationRef must be specified.");
        final NodeRef childRef = childAssociationRef.getChildRef();
        notNull(childAssociationRef.getChildRef(), "ChildRef must be specified.");
        if (! nodeService.getType(childRef).equals(AuCalendarContentModel.TYPE_WEB_FOLDER)){
            if (LOGGER.isDebugEnabled()){
                LOGGER.debug(format("NodeRef %s is not of type %s.  Policy does not apply.", childRef, AuCalendarContentModel.TYPE_WEB_FOLDER));
        if (! ruleService.isEnabled()){
            if (LOGGER.isDebugEnabled()){
                LOGGER.debug("Rules are not enabled in Alfresco.  Policy does not apply.");
        if (! ruleService.rulesEnabled(childRef)){
            if (LOGGER.isDebugEnabled()){
                LOGGER.debug(format("Rules are not enabled for NodeRef %s.  Policy does not apply.", childRef));
        if (LOGGER.isDebugEnabled()){
            LOGGER.debug(format("Add and Update rules have been applied to NodeRef %s.  Policy has been applied.", childRef));

simply does not fire during ACP import, but does fire when a folder of the specified type is scripted or created programmatically.  If I change the above to a service-based policy by changing:

policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, AuCalendarContentModel.TYPE_WEB_FOLDER, behaviour);


policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, WebFolderCreationPolicy.class, behaviour);

then the policy fires during ACP import as well as on scripted and programmed folder creation.  I thought at first that maybe the QName I am using to bind my class behaviour (AuCalendarContentModel.TYPE_WEB_FOLDER) was incorrect, but it can't be because it's fired when folders of the specified type are scripted or created programmatically.  So I am at a loss as to what is going on.

Does anyone know why this policy doesn't fire on ACP import?