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;
import ca.athabascau.alfresco.calendar.services.AuCalendarService;
@Component
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;
@Required
public void setAuCalendarService(final AuCalendarService service){
auCalendarService = service;
}
@Required
public void setNodeService(final NodeService service){
nodeService = service;
}
@Required
public void setPolicyComponent(final PolicyComponent component) {
policyComponent = component;
}
@Required
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()){
LOGGER.info(format("Delegate Method Name = %s", DELEGATE_METHOD_NAME));
LOGGER.info(format("Notification Frequency = %s", EVERY_EVENT));
}
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, AuCalendarContentModel.TYPE_WEB_FOLDER, behaviour);
}
@Override
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));
}
return;
}
if (! ruleService.isEnabled()){
if (LOGGER.isDebugEnabled()){
LOGGER.debug("Rules are not enabled in Alfresco. Policy does not apply.");
}
return;
}
if (! ruleService.rulesEnabled(childRef)){
if (LOGGER.isDebugEnabled()){
LOGGER.debug(format("Rules are not enabled for NodeRef %s. Policy does not apply.", childRef));
}
return;
}
auCalendarService.addUpdateRule(childRef);
auCalendarService.addDeleteRule(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);
to:
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?Thanks,Darryl